jenkins-bot has submitted this change and it was merged.

Change subject: Add support for PHP CodeSniffer checks
......................................................................


Add support for PHP CodeSniffer checks

* Move global functions into class.
* Fix any remaining errors and warnings.

Change-Id: I8f94e2e3f1a136a01f0da45085197bc026925a93
---
M .gitignore
A AccessControl.hooks.php
M AccessControl.php
M changelog.txt
A composer.json
A phpcs.xml
6 files changed, 395 insertions(+), 354 deletions(-)

Approvals:
  Paladox: Looks good to me, but someone else must approve
  Hashar: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.gitignore b/.gitignore
index 98b092a..854a2d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
-.svn
 *~
 *.kate-swp
 .*.swp
+node_modules/
+/composer.lock
+/vendor/
diff --git a/AccessControl.hooks.php b/AccessControl.hooks.php
new file mode 100644
index 0000000..b78f658
--- /dev/null
+++ b/AccessControl.hooks.php
@@ -0,0 +1,352 @@
+<?php
+
+class AccessControlHooks {
+       public function onUnknownAction( $action, Page $article ) {
+               global $wgOut;
+               switch ( $action ) {
+                       default:
+                               $wgOut->setPageTitle( $article->getTitle() . 
"->" . $action );
+                               $wgOut->addWikiText( wfMessage( 
'accesscontrol-actions-deny' )->text() );
+               }
+
+               return false;
+       }
+
+       public function accessControlExtension( Parser $parser ) {
+               /* This the hook function adds the tag <accesscontrol> to the 
wiki parser */
+               $parser->setHook( "accesscontrol", array( &$this, 
"doControlUserAccess" ) );
+
+               return true;
+       }
+
+       public function doControlUserAccess( $input, array $args, Parser 
$parser, PPFrame $frame ) {
+               /* Funcion called by accessControlExtension */
+               return self::displayGroups();
+       }
+
+       public function accessControl( $tagContent ) {
+               $accessgroup = array( array(), array() );
+               $listaccesslist = explode( ',', $tagContent );
+               foreach ( $listaccesslist as $accesslist ) {
+                       if ( strpos( $accesslist, "(ro)" ) !== false ) {
+                               $accesslist = trim( str_replace( "(ro)", "", 
$accesslist ) );
+                               $group = self::makeGrouparray( $accesslist );
+                               $accessgroup[1] = array_merge( $accessgroup[1], 
$group[0] );
+                               $accessgroup[1] = array_merge( $accessgroup[1], 
$group[1] );
+                       } else {
+                               $accesslist = trim( $accesslist );
+                               $group = self::makeGrouparray( $accesslist );
+                               $accessgroup[0] = array_merge( $accessgroup[0], 
$group[0] );
+                               $accessgroup[1] = array_merge( $accessgroup[1], 
$group[1] );
+                       }
+               }
+
+               return $accessgroup;
+       }
+
+       public function makeGrouparray( $accesslist ) {
+               /* Function returns array with two lists.
+                       First is list full access users.
+                       Second is list readonly users. */
+               $userswrite = array();
+               $usersreadonly = array();
+               $users = self::getUsersFromPages( $accesslist );
+               foreach ( array_keys( $users ) as $user ) {
+                       switch ( $users[$user] ) {
+                               case 'read':
+                                       $usersreadonly[] = $user;
+                                       break;
+                               case 'edit':
+                                       $userswrite[] = $user;
+                                       break;
+                       }
+               }
+
+               return array( $userswrite, $usersreadonly );
+       }
+
+       public function displayGroups() {
+               /** Function replace the tag <accesscontrol> and his content,
+                * behind info about a protection this the page
+                */
+               $style = "<p id=\"accesscontrol\" 
style=\"text-align:center;color:#BA0000;font-size:8pt\">";
+               $text = wfMessage( 'accesscontrol-info' )->text();
+               $style_end = "</p>";
+               $wgAllowInfo = $style . $text . $style_end;
+
+               return $wgAllowInfo;
+       }
+
+       public function getContentPage( $namespace, $title ) {
+               /* Function get content the page identified by title object 
from database */
+               $Title = new Title();
+               $gt = $Title->makeTitle( $namespace, $title );
+               if ( method_exists( 'WikiPage', 'getContent' ) ) {
+                       $contentPage = new WikiPage( $gt );
+                       if ( $contentPage->getContent() != null ) {
+                               return 
$contentPage->getContent()->getNativeData();
+                       }
+               } else {
+                       // create Article and get the content
+                       $contentPage = new Article( $gt, 0 );
+
+                       return $contentPage->fetchContent( 0 );
+               }
+       }
+
+       public function getTemplatePage( $template ) {
+               /* Function get content the template page identified by title 
object from database */
+               $Title = new Title();
+               $gt = $Title->makeTitle( 10, $template );
+               if ( method_exists( 'WikiPage', 'getContent' ) ) {
+                       $contentPage = new WikiPage( $gt );
+
+                       return $contentPage->getContent()->getNativeData();
+               } else {
+                       // create Article and get the content
+                       $contentPage = new Article( $gt, 0 );
+
+                       return $contentPage->fetchContent( 0 );
+               }
+       }
+
+       public function getUsersFromPages( $group ) {
+               /* Extracts the allowed users from the userspace access list */
+               $allowedAccess = array();
+               $allow = array();
+               $Title = new Title();
+               // Remark: position to add code to use namespace from mediawiki
+               $gt = $Title->makeTitle( 0, $group );
+               if ( method_exists( 'WikiPage', 'getContent' ) ) {
+                       $groupPage = new WikiPage( $gt );
+                       $allowedUsers = 
$groupPage->getContent()->getNativeData();
+               } else {
+                       // create Article and get the content
+                       $groupPage = new Article( $gt, 0 );
+                       $allowedUsers = $groupPage->fetchContent( 0 );
+               }
+               $groupPage = null;
+               $usersAccess = explode( "\n", $allowedUsers );
+               foreach ( $usersAccess as $userEntry ) {
+                       $userItem = trim( $userEntry );
+                       if ( substr( $userItem, 0, 1 ) == "*" ) {
+                               if ( strpos( $userItem, "(ro)" ) === false ) {
+                                       $user = trim( str_replace( "*", "", 
$userItem ) );
+                                       $allow[$user] = 'edit';
+                               } else {
+                                       $user = trim( str_replace( "*", "", 
$userItem ) );
+                                       $user = trim( str_replace( "(ro)", "", 
$user ) );
+                                       $allow[$user] = 'read';
+                               }
+                       }
+               }
+               if ( is_array( $allow ) ) {
+                       $allowedAccess = $allow;
+                       unset( $allow );
+               }
+
+               return $allowedAccess;
+       }
+
+       public function doRedirect( $info ) {
+               /* make redirection for non authorized users */
+               global $wgScript, $wgSitename, $wgOut, $wgAccessControlRedirect;
+               if ( !$info ) {
+                       $info = "No_access";
+               }
+               if ( isset( $_SESSION['redirect'] ) ) {
+                       // removing info about redirect from session after 
move..
+                       unset( $_SESSION['redirect'] );
+               }
+               $wgOut->clearHTML();
+               $wgOut->prependHTML( wfMessage( 'accesscontrol-info-box' 
)->text() );
+               if ( $wgAccessControlRedirect ) {
+                       header( "Location: " . $wgScript . "/" . $wgSitename . 
":" . wfMessage( $info )->text() );
+               }
+       }
+
+       public function fromTemplates( $string ) {
+               global $wgUser, $wgAdminCanReadAll;
+               // Template extraction
+               if ( strpos( $string, '{{' ) >= 0 ) {
+                       if ( substr( $string, strpos( $string, '{{' ), 3 ) === 
'{{{' ) {
+                               $start = strpos( $string, '{{{' );
+                               $end = strlen( $string );
+                               $skok = $start + 3;
+                               self::fromTemplates( substr( $string, $skok, 
$end - $skok ) );
+                       } else {
+                               $start = strpos( $string, '{{' );
+                               $end = strpos( $string, '}}' );
+                               $skok = $start + 2;
+                               $templatepage = substr( $string, $skok, $end - 
$skok );
+                               if ( substr( $templatepage, 0, 1 ) == '{' ) {
+                                       // The check of included code
+                                       $rights = self::fromTemplates( 
$templatepage );
+                               } elseif ( substr( $templatepage, 0, 1 ) == ':' 
) {
+                                       // The check of included page
+                                       $rights = self::allRightTags( 
self::getContentPage( 0, substr( $templatepage, 1 ) ) );
+                               } elseif ( ctype_alnum( substr( $templatepage, 
0, 1 ) ) ) {
+                                       // The check of included template
+                                       if ( strpos( $templatepage, '|' ) > 0 ) 
{
+                                               $templatename = substr( 
$templatepage, 0, strpos( $templatepage, '|' ) );
+                                               $rights = self::allRightTags( 
self::getContentPage( 10, $templatename ) );
+                                       } else {
+                                               $rights = self::allRightTags( 
self::getContentPage( 10, $templatepage ) );
+                                       }
+                               }
+
+                               if ( isset( $rights ) ) {
+                                       if ( is_array( $rights ) ) {
+                                               if ( $wgUser->mId === 0 ) {
+                                                       /* Redirection unknown 
users */
+                                                       $wgActions['view'] = 
false;
+                                                       self::doRedirect( 
'accesscontrol-move-anonymous' );
+                                               } else {
+                                                       if ( in_array( 'sysop', 
$wgUser->mGroups, true ) ) {
+                                                               if ( isset( 
$wgAdminCanReadAll ) ) {
+                                                                       if ( 
$wgAdminCanReadAll ) {
+                                                                               
return true;
+                                                                       }
+                                                               }
+                                                       }
+                                                       $users = 
self::accessControl( $rights['groups'] );
+                                                       if ( !in_array( 
$wgUser->mName, $users[0], true ) ) {
+                                                               
$wgActions['edit'] = false;
+                                                               
$wgActions['history'] = false;
+                                                               
$wgActions['submit'] = false;
+                                                               
$wgActions['info'] = false;
+                                                               
$wgActions['raw'] = false;
+                                                               
$wgActions['delete'] = false;
+                                                               
$wgActions['revert'] = false;
+                                                               
$wgActions['revisiondelete'] = false;
+                                                               
$wgActions['rollback'] = false;
+                                                               
$wgActions['markpatrolled'] = false;
+                                                               if ( !in_array( 
$wgUser->mName, $users[1], true ) ) {
+                                                                       
$wgActions['view'] = false;
+
+                                                                       return 
self::doRedirect( 'accesscontrol-move-users' );
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       public function allRightTags( $string ) {
+               /* Function for extraction content tag accesscontrol from raw 
source the page */
+               $contenttag = array();
+               $starttag = "<accesscontrol>";
+               $endtag = "</accesscontrol>";
+               $redirecttag = "redirect";
+
+               if ( ( mb_substr( trim( $string ), 0, 1 ) == "#" ) &&
+                       ( stripos( mb_substr( trim( $string ), 1, 9 ), 
$redirecttag ) == "0" )
+               ) {
+                       # Treatment redirects - content variable $string must
+                       # be replaced over content the target page
+                       $sourceredirecttag = mb_substr( $string, 0, strpos( 
$string, ']]' ) );
+                       $redirecttarget = trim( substr( $sourceredirecttag, 
strpos( $sourceredirecttag, '[[' ) + 2 ) );
+                       if ( strpos( $redirecttarget, '|' ) ) {
+                               $redirecttarget = trim( substr( 
$redirecttarget, 0, strpos( $redirecttarget, '|' ) ) );
+                       }
+                       $Title = new Title();
+                       $gt = $Title->makeTitle( 0, $redirecttarget );
+
+                       return self::allRightTags( self::getContentPage( 
$gt->getNamespace(), $gt ) );
+               }
+
+               // The control of included pages and templates on appearing of 
accesscontrol tag
+               self::fromTemplates( $string );
+               $start = strpos( $string, $starttag );
+               if ( $start !== false ) {
+                       $start += strlen( $starttag );
+                       $end = strpos( $string, $endtag );
+                       if ( $end !== false ) {
+                               $groupsString = substr( $string, $start, $end - 
$start );
+                               if ( strlen( $groupsString ) == 0 ) {
+                                       $contenttag['end'] = strlen( $starttag 
) + strlen( $endtag );
+                               } else {
+                                       $contenttag['groups'] = $groupsString;
+                                       $contenttag['end'] = $end + strlen( 
$endtag );
+                               }
+
+                               if ( isset( $_SESSION['redirect'] ) ) {
+                                       $_SESSION['redirect'] = $contenttag;
+                               } else {
+                                       return $contenttag;
+                               }
+                       }
+               } else {
+                       if ( isset( $_SESSION['redirect'] ) ) {
+                               return $_SESSION['redirect'];
+                       } else {
+                               return false;
+                       }
+               }
+       }
+
+       public function onUserCan( &$title, &$wgUser, $action, &$result ) {
+               /* Main function control access for all users */
+               global $wgActions, $wgAdminCanReadAll;
+               if ( $wgUser->mId === 0 ) {
+                       /* Deny actions for all anonymous */
+                       $wgActions['edit'] = false;
+                       $wgActions['history'] = false;
+                       $wgActions['submit'] = false;
+                       $wgActions['info'] = false;
+                       $wgActions['raw'] = false;
+                       $wgActions['delete'] = false;
+                       $wgActions['revert'] = false;
+                       $wgActions['revisiondelete'] = false;
+                       $wgActions['rollback'] = false;
+                       $wgActions['markpatrolled'] = false;
+               }
+
+               $rights = self::allRightTags( self::getContentPage(
+                       $title->getNamespace(),
+                       $title->mDbkeyform
+               ) );
+
+               if ( is_array( $rights ) ) {
+                       if ( $wgUser->mId === 0 ) {
+                               /* Redirection unknown users */
+                               $wgActions['view'] = false;
+                               self::doRedirect( 
'accesscontrol-redirect-anonymous' );
+                       } else {
+                               if ( in_array( 'sysop', $wgUser->getGroups(), 
true ) ) {
+                                       if ( isset( $wgAdminCanReadAll ) ) {
+                                               if ( $wgAdminCanReadAll ) {
+                                                       return true;
+                                               }
+                                       }
+                               }
+                               $users = self::accessControl( $rights['groups'] 
);
+                               if ( in_array( $wgUser->mName, $users[0], true 
) ) {
+                                       return true;
+                               } else {
+                                       $wgActions['edit'] = false;
+                                       $wgActions['history'] = false;
+                                       $wgActions['submit'] = false;
+                                       $wgActions['info'] = false;
+                                       $wgActions['raw'] = false;
+                                       $wgActions['delete'] = false;
+                                       $wgActions['revert'] = false;
+                                       $wgActions['revisiondelete'] = false;
+                                       $wgActions['rollback'] = false;
+                                       $wgActions['markpatrolled'] = false;
+                                       if ( in_array( $wgUser->mName, 
$users[1], true ) ) {
+                                               return true;
+                                       } else {
+                                               $wgActions['view'] = false;
+
+                                               return self::doRedirect( 
'accesscontrol-redirect-users' );
+                                       }
+                               }
+                       }
+               } else {
+                       return true;
+               }
+       }
+}
diff --git a/AccessControl.php b/AccessControl.php
index be1c676..46bc35e 100644
--- a/AccessControl.php
+++ b/AccessControl.php
@@ -11,8 +11,8 @@
  * @licence GNU General Public Licence
  */
 
-if( !defined( 'MEDIAWIKI' ) ) {
-       echo ( "This file is an extension to the MediaWiki software and cannot 
be used standalone.\n" );
+if ( !defined( 'MEDIAWIKI' ) ) {
+       echo "This file is an extension to the MediaWiki software and cannot be 
used standalone.\n";
        die();
 }
 
@@ -21,355 +21,22 @@
 $wgAccessControlRedirect = true;
 
 $wgExtensionCredits['parserhook'][] = array(
-       'path'                  => __FILE__,
-       'name'                  => 'AccessControl',
-       'author'                => array( 
'[https://www.mediawiki.org/wiki/m:User:Want Aleš Kapica]' ),
-       'url'                   => 
'http://www.mediawiki.org/wiki/Extension:AccessControl',
-       'version'               => '2.5',
-       'descriptionmsg'        => 'accesscontrol-desc'
+       'path' => __FILE__,
+       'name' => 'AccessControl',
+       'author' => array( '[https://www.mediawiki.org/wiki/m:User:Want Aleš 
Kapica]' ),
+       'url' => 'http://www.mediawiki.org/wiki/Extension:AccessControl',
+       'version' => '2.6',
+       'descriptionmsg' => 'accesscontrol-desc'
 );
 
-$wgHooks['ParserFirstCallInit'][] = 'wfAccessControlExtension' ;
+$wgAutoloadClasses['AccessControlHooks'] = __DIR__ . 
'/AccessControl.hooks.php';
 
-$dir = dirname( __FILE__ ) . '/';
+$wgHooks['ParserFirstCallInit'][] = 
'AccessControlHooks::accessControlExtension';
+
 $wgMessagesDirs['AccessControl'] = __DIR__ . '/i18n';
 
+// Hook the userCan function for bypassing the cache
+$wgHooks['userCan'][] = 'AccessControlHooks::onUserCan';
 
-//Hook the userCan function for bypassing the cache
-$wgHooks['userCan'][] = 'hookUserCan';
-
-//Hook the UnknownAction function for information user about restrictions
-$wgHooks['UnknownAction'][] = 'onUnknownAction' ;
-
-function onUnknownAction ( $action, Page $article ) {
-       global $wgOut;
-       switch ( $action ) {
-               default:
-                       $wgOut->setPageTitle( $article->getTitle() . "->" . 
$action );
-                       $wgOut->addWikiText( wfMessage( 
'accesscontrol-actions-deny' )->text());
-       }
-       return false;
-}
-
-function wfAccessControlExtension( Parser $parser ) {
-       /* This the hook function adds the tag <accesscontrol> to the wiki 
parser */
-       $parser->setHook( "accesscontrol", "doControlUserAccess" );
-       return true;
-}
-
-function doControlUserAccess( $input, array $args, Parser $parser, PPFrame 
$frame ) {
-       /* Funcion called by wfAccessControlExtension */
-       return displayGroups();
-}
-
-function accessControl( $tagContent ){
-       $accessgroup = Array( Array(), Array() );
-       $listaccesslist = explode( ",", $tagContent );
-       foreach ( $listaccesslist as $accesslist ) {
-               if ( strpos( $accesslist, "(ro)" ) !== false ) {
-                       $accesslist = trim( str_replace( "(ro)", "", 
$accesslist ) );
-                       $group = makeGroupArray( $accesslist );
-                       $accessgroup[1] = array_merge( $accessgroup[1], 
$group[0] );
-                       $accessgroup[1] = array_merge( $accessgroup[1], 
$group[1] );
-               } else {
-                       $accesslist = trim( $accesslist );
-                       $group = makeGroupArray ( $accesslist );
-                       $accessgroup[0] = array_merge( $accessgroup[0], 
$group[0] );
-                       $accessgroup[1] = array_merge( $accessgroup[1], 
$group[1] );
-               }
-       }
-       return $accessgroup;
-}
-
-function makeGroupArray( $accesslist ) {
-       /* Function returns array with two lists.
-               First is list full access users.
-               Second is list readonly users. */
-       $userswrite = Array();
-       $usersreadonly = Array();
-       $users = getUsersFromPages( $accesslist );
-       foreach ( array_keys( $users ) as $user ) {
-               switch ( $users[$user] ) {
-                       case 'read':
-                               $usersreadonly[] = $user;
-                               break;
-                       case 'edit':
-                               $userswrite[] = $user;
-                               break;
-               }
-       }
-       return array( $userswrite, $usersreadonly );
-}
-
-function displayGroups() {
-       /* Function replace the tag <accesscontrol> and his content, behind 
info about a protection this the page */
-       $style = "<p id=\"accesscontrol\" 
style=\"text-align:center;color:#BA0000;font-size:8pt\">";
-       $text = wfMessage( 'accesscontrol-info' )->text();
-       $style_end = "</p>";
-       $wgAllowInfo = $style . $text . $style_end;
-       return $wgAllowInfo;
-}
-
-function getContentPage( $namespace, $title ) {
-       /* Function get content the page identified by title object from 
database */
-       $Title = new Title();
-       $gt = $Title->makeTitle( $namespace, $title );
-       if ( method_exists( 'WikiPage', 'getContent' ) ) {
-               $contentPage = new WikiPage( $gt );
-               if ( $contentPage->getContent() != NULL ) {
-                       return $contentPage->getContent()->getNativeData();
-               }
-       } else {
-               //echo print_r($gt);
-               // create Article and get the content
-               $contentPage = new Article( $gt, 0 );
-               return $contentPage->fetchContent( 0 );
-       }
-}
-
-function getTemplatePage( $template ) {
-       /* Function get content the template page identified by title object 
from database */
-       $Title = new Title();
-       $gt = $Title->makeTitle( 10, $template );
-       if ( method_exists( 'WikiPage', 'getContent' ) ) {
-               $contentPage = new WikiPage( $gt );
-               return $contentPage->getContent()->getNativeData();
-       } else {
-               // create Article and get the content
-               $contentPage = new Article( $gt, 0 );
-               return $contentPage->fetchContent( 0 );
-       }
-}
-
-function getUsersFromPages( $group ) {
-       /* Extracts the allowed users from the userspace access list */
-       $allowedAccess = Array();
-       $allow = Array();
-       $Title = new Title();
-// Remark: position to add code to use namespace from mediawiki
-       $gt = $Title->makeTitle( 0, $group );
-       if ( method_exists( 'WikiPage', 'getContent' ) ) {
-               $groupPage = new WikiPage( $gt );
-               $allowedUsers = $groupPage->getContent()->getNativeData();
-       } else {
-               // create Article and get the content
-               $groupPage = new Article( $gt, 0 );
-               $allowedUsers = $groupPage->fetchContent( 0 );
-       }
-       $groupPage = NULL;
-       $usersAccess = explode( "\n", $allowedUsers );
-       foreach  ($usersAccess as $userEntry ) {
-               $userItem = trim( $userEntry );
-               if ( substr( $userItem, 0, 1 ) == "*" ) {
-                       if ( strpos( $userItem, "(ro)" ) === false ) {
-                               $user = trim( str_replace( "*", "", $userItem ) 
);
-                               $allow[$user] = 'edit';
-                       } else {
-                               $user = trim( str_replace( "*", "", $userItem ) 
);
-                               $user = trim( str_replace( "(ro)", "", $user ) 
);
-                               $allow[$user] = 'read';
-                       }
-               }
-       }
-       if ( is_array( $allow ) ) {
-               $allowedAccess = $allow;
-               unset( $allow );
-       }
-       return $allowedAccess;
-}
-
-function doRedirect( $info ) {
-       /* make redirection for non authorized users */
-       global $wgScript, $wgSitename, $wgOut, $wgAccessControlRedirect;
-       if ( ! $info ) {
-           $info = "No_access";
-           }
-       if ( isset( $_SESSION['redirect'] ) ) {
-               // removing info about redirect from session after move..
-               unset( $_SESSION['redirect'] );
-       }
-       $wgOut -> clearHTML() ;
-       $wgOut -> prependHTML( wfMessage( 'accesscontrol-info-box' ) -> text() 
);
-       if ( $wgAccessControlRedirect ) {
-               header( "Location: " . $wgScript . "/" . $wgSitename . ":" . 
wfMessage( $info )->text() );
-       }
-}
-
-function fromTemplates( $string ) {
-       global $wgUser, $wgAdminCanReadAll;
-       // Template extraction
-       if ( strpos( $string, '{{' ) >= 0 ) {
-               if ( substr( $string, strpos ( $string, '{{' ), 3 ) === '{{{' ) 
{
-                       $start = strpos( $string, '{{{' );
-                       $end = strlen( $string );
-                       $skok = $start + 3;
-                       fromTemplates( substr( $string, $skok, $end - $skok ) );
-               } else {
-                       $start = strpos( $string, '{{' );
-                       $end = strpos( $string, '}}' );
-                       $skok = $start + 2;
-                       $templatepage = substr( $string, $skok, $end - $skok );
-                       if ( substr( $templatepage, 0, 1 ) == '{' ) {
-                               // The check of included code
-                               $rights = fromTemplates( $templatepage );
-                       } elseif ( substr( $templatepage, 0, 1 ) == ':' ) {
-                               // The check of included page
-                               $rights = allRightTags( getContentPage( 0, 
substr( $templatepage, 1 ) ) );
-                       } elseif ( ctype_alnum( substr( $templatepage, 0, 1 ) 
)) {
-                               // The check of included template
-                               if ( strpos( $templatepage, '|' ) > 0) {
-                                       $templatename = substr( $templatepage, 
0, strpos( $templatepage, '|' ) );
-                                       $rights = allRightTags( getContentPage( 
10, $templatename ) );
-                               } else {
-                                       $rights = allRightTags( getContentPage( 
10, $templatepage ) );
-                               }
-                       } else {
-                               // echo "The end of work with code of article";
-                       }
-                       if ( isset( $rights ) ) {
-                               if ( is_array( $rights ) ) {
-                                       if ( $wgUser->mId === 0 ) {
-                                               /* Redirection unknown users */
-                                               $wgActions['view'] = false;
-                                               
doRedirect('accesscontrol-move-anonymous');
-                                       } else {
-                                               if ( in_array( 'sysop', 
$wgUser->mGroups, true ) ) {
-                                                       if ( isset( 
$wgAdminCanReadAll ) ) {
-                                                               if ( 
$wgAdminCanReadAll ) {
-                                                                       return 
true;
-                                                               }
-                                                       }
-                                               }
-                                               $users = accessControl( 
$rights['groups'] );
-                                               if ( ! in_array( 
$wgUser->mName, $users[0], true ) ) {
-                                                       $wgActions['edit']      
     = false;
-                                                       $wgActions['history']   
     = false;
-                                                       $wgActions['submit']    
     = false;
-                                                       $wgActions['info']      
     = false;
-                                                       $wgActions['raw']       
     = false;
-                                                       $wgActions['delete']    
     = false;
-                                                       $wgActions['revert']    
     = false;
-                                                       
$wgActions['revisiondelete'] = false;
-                                                       $wgActions['rollback']  
     = false;
-                                                       
$wgActions['markpatrolled']  = false;
-                                                       if ( ! in_array( 
$wgUser->mName, $users[1], true ) ) {
-                                                               
$wgActions['view']   = false;
-                                                               return 
doRedirect( 'accesscontrol-move-users' );
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-}
-
-
-function allRightTags( $string ) {
-       /* Function for extraction content tag accesscontrol from raw source 
the page */
-       $contenttag  = Array();
-       $starttag    = "<accesscontrol>";
-       $endtag      = "</accesscontrol>";
-       $redirecttag = "redirect";
-
-       if ( ( mb_substr( trim( $string ), 0, 1 ) == "#" )
-               && ( stripos( mb_substr( trim( $string ), 1, 9 ), $redirecttag 
) == "0" )
-               ) {
-               /* Treatment redirects - content variable $string must be 
replaced over content the target page */
-               $sourceredirecttag = mb_substr( $string, 0, strpos( $string, 
']]' ) );
-               $redirecttarget = trim( substr( $sourceredirecttag, strpos( 
$sourceredirecttag, '[[' ) + 2 ) );
-               if ( strpos( $redirecttarget, '|' ) ) {
-                       $redirecttarget = trim( substr( $redirecttarget, 0, 
strpos( $redirecttarget, '|' ) ) );
-               }
-               $Title = new Title();
-               $gt = $Title->makeTitle( 0, $redirecttarget );
-               return allRightTags( getContentPage( $gt->getNamespace(), $gt ) 
);
-       }
-
-       // The control of included pages and templates on appearing of 
accesscontrol tag
-       fromTemplates( $string );
-       $start = strpos( $string, $starttag );
-       if ( $start !== false ) {
-               $start += strlen( $starttag );
-               $end = strpos( $string, $endtag );
-               if ( $end !== false ) {
-                       $groupsString = substr( $string, $start, $end-$start );
-                       if ( strlen( $groupsString ) == 0 ) {
-                               $contenttag['end'] = strlen( $starttag ) + 
strlen( $endtag );
-                       } else {
-                               $contenttag['groups'] = $groupsString;
-                               $contenttag['end'] = $end + strlen( $endtag );
-                       }
-
-                       if( isset( $_SESSION['redirect'] ) ) {
-                               $_SESSION['redirect'] = $contenttag;
-                       } else {
-                               return $contenttag;
-                       }
-               }
-       } else {
-               if( isset( $_SESSION['redirect'] ) ) {
-                       return $_SESSION['redirect'];
-               } else {
-                       return false;
-               }
-       }
-}
-
-function hookUserCan( &$title, &$wgUser, $action, &$result ) {
-       /* Main function control access for all users */
-       global $wgActions, $wgAdminCanReadAll;
-       if ( $wgUser->mId === 0 ) {
-               /* Deny actions for all anonymous */
-               $wgActions['edit']           = false;
-               $wgActions['history']        = false;
-               $wgActions['submit']         = false;
-               $wgActions['info']           = false;
-               $wgActions['raw']            = false;
-               $wgActions['delete']         = false;
-               $wgActions['revert']         = false;
-               $wgActions['revisiondelete'] = false;
-               $wgActions['rollback']       = false;
-               $wgActions['markpatrolled']  = false;
-       }
-
-       $rights = allRightTags( getContentPage( $title->getNamespace(), 
$title->mDbkeyform ) );
-       if ( is_array( $rights ) ) {
-               if ( $wgUser->mId === 0 ) {
-                       /* Redirection unknown users */
-                       $wgActions['view'] = false;
-                       doRedirect( 'accesscontrol-redirect-anonymous' );
-               } else {
-                       if ( in_array( 'sysop', $wgUser->getGroups(), true ) ) {
-                               if ( isset( $wgAdminCanReadAll ) ) {
-                                       if ( $wgAdminCanReadAll ) {
-                                               return true;
-                                       }
-                               }
-                       }
-                       $users = accessControl( $rights['groups'] );
-                       if ( in_array( $wgUser->mName, $users[0], true ) ) {
-                               return true;
-                       } else {
-                               $wgActions['edit']           = false;
-                               $wgActions['history']        = false;
-                               $wgActions['submit']         = false;
-                               $wgActions['info']           = false;
-                               $wgActions['raw']            = false;
-                               $wgActions['delete']         = false;
-                               $wgActions['revert']         = false;
-                               $wgActions['revisiondelete'] = false;
-                               $wgActions['rollback']       = false;
-                               $wgActions['markpatrolled']  = false;
-                               if ( in_array( $wgUser->mName, $users[1], true 
) ) {
-                                       return true;
-                               } else {
-                                       $wgActions['view']   = false;
-                                       return doRedirect( 
'accesscontrol-redirect-users' );
-                               }
-                       }
-               }
-       } else {
-               return true;
-       }
-}
+// Hook the UnknownAction function for information user about restrictions
+$wgHooks['UnknownAction'][] = 'AccessControlHooks::onUnknownAction';
diff --git a/changelog.txt b/changelog.txt
index cb9a4bd..3a9a821 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,6 +1,6 @@
 version 2.5
 * Actualization of description header
-* Fix for uninitialize an variable $rights in function fromTemplates() and 
repair of indents in code
+* Fix for uninitialize an variable $rights in function wfFromTemplates() and 
repair of indents in code
 * New the variable $wgAccessControlRedirect to allow set display of search 
results (default is false)
 * New language string accesscontrol-info-box in i18n localization file
 
@@ -12,9 +12,9 @@
 * Migrate to JSON i18n
 
 verison 2.3
-* Fixed function doRedirect() and fromTemplates()
+* Fixed function wfDoRedirect() and wfFromTemplates()
 * Removed unused messages from localization file
-* New function onUnknownAction()
+* New function wfOnUnknownAction()
 
 version 2.2
 * Fix for MediaWiki >= 1.21 by unknown AccessControl user
@@ -32,11 +32,11 @@
     $wgAccessControlMessages
 
 version 1.3
-* Gabor Simon fixed problem in function getUsersFromPages()
+* Gabor Simon fixed problem in function wfGetUsersFromPages()
 * Applying patch from Stephan Herrmann
 
 version 1.2
-* Fixed errors in parameter fuction doControlUserAccess()
+* Fixed errors in parameter fuction wfDoControlUserAccess()
 * Repairing while lopp in function getContentTag()
 
 version 1.1
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..4365e8a
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,12 @@
+{
+       "require-dev": {
+               "jakub-onderka/php-parallel-lint": "0.9",
+               "mediawiki/mediawiki-codesniffer": "0.4.0"
+       },
+       "scripts": {
+               "test": [
+                       "parallel-lint . --exclude vendor",
+                       "phpcs -p -s"
+               ]
+       }
+}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..d81a292
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<ruleset>
+       <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+       <file>.</file>
+       <arg name="extensions" value="php,php5,inc"/>
+       <arg name="encoding" value="utf8"/>
+       <exclude-pattern>vendor</exclude-pattern>
+</ruleset>

-- 
To view, visit https://gerrit.wikimedia.org/r/241717
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8f94e2e3f1a136a01f0da45085197bc026925a93
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/AccessControl
Gerrit-Branch: master
Gerrit-Owner: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Alex Monk <kren...@gmail.com>
Gerrit-Reviewer: Hashar <has...@free.fr>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com>
Gerrit-Reviewer: Polybuildr <v.a.ghai...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Want <kap...@fel.cvut.cz>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to