[MediaWiki-commits] [Gerrit] Add support for PHP CodeSniffer checks - change (mediawiki...AccessControl)

2015-10-19 Thread jenkins-bot (Code Review)
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 000..b78f658
--- /dev/null
+++ b/AccessControl.hooks.php
@@ -0,0 +1,352 @@
+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  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  and his content,
+* behind info about a protection this the page
+*/
+   $style = "";
+   $text = wfMessage( 'accesscontrol-info' )->text();
+   $style_end = "";
+   $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 );

[MediaWiki-commits] [Gerrit] Add support for PHP CodeSniffer checks - change (mediawiki...AccessControl)

2015-09-28 Thread Siebrand (Code Review)
Siebrand has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/241717

Change subject: Add support for PHP CodeSniffer checks
..

Add support for PHP CodeSniffer checks

Also fix any remaining errors and warnings.

Change-Id: I8f94e2e3f1a136a01f0da45085197bc026925a93
---
M AccessControl.php
M changelog.txt
2 files changed, 119 insertions(+), 109 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AccessControl 
refs/changes/17/241717/1

diff --git a/AccessControl.php b/AccessControl.php
index be1c676..7895a6e 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,73 +21,74 @@
 $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.5',
+   'descriptionmsg' => 'accesscontrol-desc'
 );
 
-$wgHooks['ParserFirstCallInit'][] = 'wfAccessControlExtension' ;
+$wgHooks['ParserFirstCallInit'][] = 'wfAccessControlExtension';
 
-$dir = dirname( __FILE__ ) . '/';
 $wgMessagesDirs['AccessControl'] = __DIR__ . '/i18n';
 
+// Hook the userCan function for bypassing the cache
+$wgHooks['userCan'][] = 'wfHookUserCan';
 
-//Hook the userCan function for bypassing the cache
-$wgHooks['userCan'][] = 'hookUserCan';
+// Hook the UnknownAction function for information user about restrictions
+$wgHooks['UnknownAction'][] = 'wfOnUnknownAction';
 
-//Hook the UnknownAction function for information user about restrictions
-$wgHooks['UnknownAction'][] = 'onUnknownAction' ;
-
-function onUnknownAction ( $action, Page $article ) {
+function wfOnUnknownAction( $action, Page $article ) {
global $wgOut;
switch ( $action ) {
default:
$wgOut->setPageTitle( $article->getTitle() . "->" . 
$action );
-   $wgOut->addWikiText( wfMessage( 
'accesscontrol-actions-deny' )->text());
+   $wgOut->addWikiText( wfMessage( 
'accesscontrol-actions-deny' )->text() );
}
+
return false;
 }
 
 function wfAccessControlExtension( Parser $parser ) {
/* This the hook function adds the tag  to the wiki 
parser */
-   $parser->setHook( "accesscontrol", "doControlUserAccess" );
+   $parser->setHook( "accesscontrol", "wfDoControlUserAccess" );
+
return true;
 }
 
-function doControlUserAccess( $input, array $args, Parser $parser, PPFrame 
$frame ) {
+function wfDoControlUserAccess( $input, array $args, Parser $parser, PPFrame 
$frame ) {
/* Funcion called by wfAccessControlExtension */
-   return displayGroups();
+   return wfDisplayGroups();
 }
 
-function accessControl( $tagContent ){
-   $accessgroup = Array( Array(), Array() );
+function wfAccessControl( $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 );
+   $group = wfMakeGrouparray( $accesslist );
$accessgroup[1] = array_merge( $accessgroup[1], 
$group[0] );
$accessgroup[1] = array_merge( $accessgroup[1], 
$group[1] );
} else {
$accesslist = trim( $accesslist );
-   $group = makeGroupArray ( $accesslist );
+   $group = wfMakeGrouparray( $accesslist );
$accessgroup[0] = array_merge( $accessgroup[0], 
$group[0] );
$accessgroup[1] = array_merge( $accessgroup[1], 
$group[1] );
}
}
+
return $accessgroup;
 }
 
-function makeGroupArray( $accesslist ) {
+function wfMakeGrouparray( $accesslist ) {
/* Function returns array with two lists.
First is list