API: fix copyright symbol, coding style cleanup, more braces
authorJack Phoenix <ashley@users.mediawiki.org>
Tue, 23 Feb 2010 18:05:46 +0000 (18:05 +0000)
committerJack Phoenix <ashley@users.mediawiki.org>
Tue, 23 Feb 2010 18:05:46 +0000 (18:05 +0000)
12 files changed:
includes/api/ApiFormatXml.php
includes/api/ApiFormatYaml.php
includes/api/ApiHelp.php
includes/api/ApiImport.php
includes/api/ApiLogout.php
includes/api/ApiMain.php
includes/api/ApiOpenSearch.php
includes/api/ApiPageSet.php
includes/api/ApiParamInfo.php
includes/api/ApiParse.php
includes/api/ApiPatrol.php
includes/api/ApiProtect.php

index 413e4a4..a09fd47 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Sep 19, 2006
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( 'ApiFormatBase.php' );
+       require_once( 'ApiFormatBase.php' );
 }
 
 /**
@@ -38,7 +38,7 @@ class ApiFormatXml extends ApiFormatBase {
        private $mXslt = null;
 
        public function __construct( $main, $format ) {
-               parent :: __construct( $main, $format );
+               parent::__construct( $main, $format );
        }
 
        public function getMimeType() {
@@ -59,45 +59,50 @@ class ApiFormatXml extends ApiFormatBase {
                $this->mXslt = $params['xslt'];
 
                $this->printText( '<?xml version="1.0"?>' );
-               if ( !is_null( $this->mXslt ) )
+               if ( !is_null( $this->mXslt ) ) {
                        $this->addXslt();
-               $this->printText( self::recXmlPrint( $this->mRootElemName,
+               }
+               $this->printText(
+                       self::recXmlPrint( $this->mRootElemName,
                                $this->getResultData(),
                                $this->getIsHtml() ? - 2 : null,
-                               $this->mDoubleQuote ) );
+                               $this->mDoubleQuote
+                       )
+               );
        }
 
        /**
-       * This method takes an array and converts it to XML.
-       * There are several noteworthy cases:
-       *
-       *  If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element'].
-             Example:        name='root',  value = array( '_element'=>'page', 'x', 'y', 'z') creates <root>  <page>x</page>  <page>y</page>  <page>z</page> </root>
-       *
-       *  If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content.
-             Example:        name='root',  value = array( '*'=>'text', 'lang'=>'en', 'id'=>10)   creates  <root lang='en' id='10'>text</root>
-       *
-       * If neither key is found, all keys become element names, and values become element content.
-       * The method is recursive, so the same rules apply to any sub-arrays.
-       */
+        * This method takes an array and converts it to XML.
+        * There are several noteworthy cases:
+        *
+        *  If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element'].
+        *      Example:        name='root',  value = array( '_element'=>'page', 'x', 'y', 'z') creates <root>  <page>x</page>  <page>y</page>  <page>z</page> </root>
+        *
+        *  If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content.
+        *      Example:        name='root',  value = array( '*'=>'text', 'lang'=>'en', 'id'=>10)   creates  <root lang='en' id='10'>text</root>
+        *
+        * If neither key is found, all keys become element names, and values become element content.
+        * The method is recursive, so the same rules apply to any sub-arrays.
+        */
        public static function recXmlPrint( $elemName, $elemValue, $indent, $doublequote = false ) {
                $retval = '';
                if ( !is_null( $indent ) ) {
                        $indent += 2;
-                       $indstr = "\n" . str_repeat( " ", $indent );
+                       $indstr = "\n" . str_repeat( ' ', $indent );
                } else {
                        $indstr = '';
                }
                $elemName = str_replace( ' ', '_', $elemName );
 
                switch ( gettype( $elemValue ) ) {
-                       case 'array' :
-                               if ( isset ( $elemValue['*'] ) ) {
+                       case 'array':
+                               if ( isset( $elemValue['*'] ) ) {
                                        $subElemContent = $elemValue['*'];
-                                       if ( $doublequote )
+                                       if ( $doublequote ) {
                                                $subElemContent = Sanitizer::encodeAttribute( $subElemContent );
-                                       unset ( $elemValue['*'] );
-                                       
+                                       }
+                                       unset( $elemValue['*'] );
+
                                        // Add xml:space="preserve" to the
                                        // element so XML parsers will leave
                                        // whitespace in the content alone
@@ -106,59 +111,65 @@ class ApiFormatXml extends ApiFormatBase {
                                        $subElemContent = null;
                                }
 
-                               if ( isset ( $elemValue['_element'] ) ) {
+                               if ( isset( $elemValue['_element'] ) ) {
                                        $subElemIndName = $elemValue['_element'];
-                                       unset ( $elemValue['_element'] );
+                                       unset( $elemValue['_element'] );
                                } else {
                                        $subElemIndName = null;
                                }
 
-                               $indElements = array ();
-                               $subElements = array ();
+                               $indElements = array();
+                               $subElements = array();
                                foreach ( $elemValue as $subElemId => & $subElemValue ) {
-                                       if ( is_string( $subElemValue ) && $doublequote )
+                                       if ( is_string( $subElemValue ) && $doublequote ) {
                                                $subElemValue = Sanitizer::encodeAttribute( $subElemValue );
-                                       
+                                       }
+
                                        if ( gettype( $subElemId ) === 'integer' ) {
                                                $indElements[] = $subElemValue;
-                                               unset ( $elemValue[$subElemId] );
+                                               unset( $elemValue[$subElemId] );
                                        } elseif ( is_array( $subElemValue ) ) {
                                                $subElements[$subElemId] = $subElemValue;
                                                unset ( $elemValue[$subElemId] );
                                        }
                                }
 
-                               if ( is_null( $subElemIndName ) && count( $indElements ) )
-                                       ApiBase :: dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." );
+                               if ( is_null( $subElemIndName ) && count( $indElements ) ) {
+                                       ApiBase::dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." );
+                               }
 
-                               if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) )
-                                       ApiBase :: dieDebug( __METHOD__, "($elemName, ...) has content and subelements" );
+                               if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) ) {
+                                       ApiBase::dieDebug( __METHOD__, "($elemName, ...) has content and subelements" );
+                               }
 
                                if ( !is_null( $subElemContent ) ) {
                                        $retval .= $indstr . Xml::element( $elemName, $elemValue, $subElemContent );
                                } elseif ( !count( $indElements ) && !count( $subElements ) ) {
-                                               $retval .= $indstr . Xml::element( $elemName, $elemValue );
+                                       $retval .= $indstr . Xml::element( $elemName, $elemValue );
                                } else {
                                        $retval .= $indstr . Xml::element( $elemName, $elemValue, null );
 
-                                       foreach ( $subElements as $subElemId => & $subElemValue )
+                                       foreach ( $subElements as $subElemId => & $subElemValue ) {
                                                $retval .= self::recXmlPrint( $subElemId, $subElemValue, $indent );
+                                       }
 
-                                       foreach ( $indElements as $subElemId => & $subElemValue )
+                                       foreach ( $indElements as $subElemId => & $subElemValue ) {
                                                $retval .= self::recXmlPrint( $subElemIndName, $subElemValue, $indent );
+                                       }
 
                                        $retval .= $indstr . Xml::closeElement( $elemName );
                                }
                                break;
-                       case 'object' :
+                       case 'object':
                                // ignore
                                break;
-                       default :
+                       default:
                                $retval .= $indstr . Xml::element( $elemName, null, $elemValue );
                                break;
                }
                return $retval;
        }
+
        function addXslt() {
                $nt = Title::newFromText( $this->mXslt );
                if ( is_null( $nt ) || !$nt->exists() ) {
@@ -175,23 +186,23 @@ class ApiFormatXml extends ApiFormatBase {
                }
                $this->printText( '<?xml-stylesheet href="' . $nt->escapeLocalURL( 'action=raw' ) . '" type="text/xsl" ?>' );
        }
-       
+
        public function getAllowedParams() {
-               return array (
+               return array(
                        'xmldoublequote' => false,
                        'xslt' => null,
                );
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        'xmldoublequote' => 'If specified, double quotes all attributes and content.',
                        'xslt' => 'If specified, adds <xslt> as stylesheet',
                );
        }
 
        public function getDescription() {
-               return 'Output data in XML format' . parent :: getDescription();
+               return 'Output data in XML format' . parent::getDescription();
        }
 
        public function getVersion() {
index 5397bd4..66d4f32 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Sep 19, 2006
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( 'ApiFormatBase.php' );
+       require_once( 'ApiFormatBase.php' );
 }
 
 /**
@@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiFormatYaml extends ApiFormatBase {
 
        public function __construct( $main, $format ) {
-               parent :: __construct( $main, $format );
+               parent::__construct( $main, $format );
        }
 
        public function getMimeType() {
@@ -42,11 +42,11 @@ class ApiFormatYaml extends ApiFormatBase {
        }
 
        public function execute() {
-               $this->printText( Spyc :: YAMLDump( $this->getResultData() ) );
+               $this->printText( Spyc::YAMLDump( $this->getResultData() ) );
        }
 
        public function getDescription() {
-               return 'Output data in YAML format' . parent :: getDescription();
+               return 'Output data in YAML format' . parent::getDescription();
        }
 
        public function getVersion() {
index 7eaa2ab..761143f 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Sep 6, 2006
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -55,7 +55,7 @@ class ApiHelp extends ApiBase {
        }
 
        public function getDescription() {
-               return array (
+               return array(
                        'Display this help screen.'
                );
        }
index 2d0cfb3..8b7d1c1 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Feb 4, 2009
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( 'ApiBase.php' );
+       require_once( 'ApiBase.php' );
 }
 
 /**
@@ -36,58 +36,65 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiImport extends ApiBase {
 
        public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
+               parent::__construct( $main, $action );
        }
 
        public function execute() {
                global $wgUser;
-               if ( !$wgUser->isAllowed( 'import' ) )
+               if ( !$wgUser->isAllowed( 'import' ) ) {
                        $this->dieUsageMsg( array( 'cantimport' ) );
+               }
                $params = $this->extractRequestParams();
 
                $source = null;
                $isUpload = false;
-               if ( isset( $params['interwikisource'] ) )
-               {
-                       if ( !isset( $params['interwikipage'] ) )
+               if ( isset( $params['interwikisource'] ) ) {
+                       if ( !isset( $params['interwikipage'] ) ) {
                                $this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) );
+                       }
                        $source = ImportStreamSource::newFromInterwiki(
-                                       $params['interwikisource'],
-                                       $params['interwikipage'],
-                                       $params['fullhistory'],
-                                       $params['templates'] );
-               }
-               else
-               {
+                               $params['interwikisource'],
+                               $params['interwikipage'],
+                               $params['fullhistory'],
+                               $params['templates']
+                       );
+               } else {
                        $isUpload = true;
-                       if ( !$wgUser->isAllowed( 'importupload' ) )
+                       if ( !$wgUser->isAllowed( 'importupload' ) ) {
                                $this->dieUsageMsg( array( 'cantimport-upload' ) );
+                       }
                        $source = ImportStreamSource::newFromUpload( 'xml' );
                }
-               if ( $source instanceof WikiErrorMsg )
+               if ( $source instanceof WikiErrorMsg ) {
                        $this->dieUsageMsg( array_merge(
                                array( $source->getMessageKey() ),
                                $source->getMessageArgs() ) );
-               else if ( WikiError::isError( $source ) )
+               } elseif ( WikiError::isError( $source ) ) {
                        // This shouldn't happen
                        $this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) );
+               }
 
                $importer = new WikiImporter( $source );
-               if ( isset( $params['namespace'] ) )
+               if ( isset( $params['namespace'] ) ) {
                        $importer->setTargetNamespace( $params['namespace'] );
-               $reporter = new ApiImportReporter( $importer, $isUpload,
-                                       $params['interwikisource'],
-                                       $params['summary'] );
+               }
+               $reporter = new ApiImportReporter(
+                       $importer,
+                       $isUpload,
+                       $params['interwikisource'],
+                       $params['summary']
+               );
 
                $result = $importer->doImport();
-               if ( $result instanceof WikiXmlError )
+               if ( $result instanceof WikiXmlError ) {
                        $this->dieUsageMsg( array( 'import-xml-error',
                                $result->mLine,
                                $result->mColumn,
                                $result->mByte . $result->mContext,
                                xml_error_string( $result->mXmlError ) ) );
-               else if ( WikiError::isError( $result ) )
+               } elseif ( WikiError::isError( $result ) ) {
                        $this->dieUsageMsg( array( 'import-unknownerror', $result->getMessage() ) ); // This shouldn't happen
+               }
 
                $resultData = $reporter->getData();
                $this->getResult()->setIndexedTagName( $resultData, 'page' );
@@ -104,24 +111,24 @@ class ApiImport extends ApiBase {
 
        public function getAllowedParams() {
                global $wgImportSources;
-               return array (
+               return array(
                        'token' => null,
                        'summary' => null,
                        'xml' => null,
                        'interwikisource' => array(
-                               ApiBase :: PARAM_TYPE => $wgImportSources
+                               ApiBase::PARAM_TYPE => $wgImportSources
                        ),
                        'interwikipage' => null,
                        'fullhistory' => false,
                        'templates' => false,
                        'namespace' => array(
-                               ApiBase :: PARAM_TYPE => 'namespace'
+                               ApiBase::PARAM_TYPE => 'namespace'
                        )
                );
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        'token' => 'Import token obtained through prop=info',
                        'summary' => 'Import summary',
                        'xml' => 'Uploaded XML file',
@@ -134,11 +141,11 @@ class ApiImport extends ApiBase {
        }
 
        public function getDescription() {
-               return array (
+               return array(
                        'Import a page from another wiki, or an XML file'
                );
        }
-       
+
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'cantimport' ),
@@ -148,7 +155,7 @@ class ApiImport extends ApiBase {
                        array( 'import-unknownerror', 'result' ),
                ) );
        }
-       
+
        public function getTokenSalt() {
                return '';
        }
@@ -172,8 +179,7 @@ class ApiImport extends ApiBase {
 class ApiImportReporter extends ImportReporter {
        private $mResultArr = array();
 
-       function reportPage( $title, $origTitle, $revisionCount, $successCount )
-       {
+       function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
                // Add a result entry
                $r = array();
                ApiQueryBase::addTitleInfo( $r, $title );
@@ -184,8 +190,7 @@ class ApiImportReporter extends ImportReporter {
                parent::reportPage( $title, $origTitle, $revisionCount, $successCount );
        }
 
-       function getData()
-       {
+       function getData() {
                return $this->mResultArr;
        }
 }
\ No newline at end of file
index 942aad8..4eacb07 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Jan 4, 2008
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
+ * Copyright © 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( 'ApiBase.php' );
+       require_once( 'ApiBase.php' );
 }
 
 /**
@@ -37,14 +37,14 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiLogout extends ApiBase {
 
        public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
+               parent::__construct( $main, $action );
        }
 
        public function execute() {
                global $wgUser;
                $oldName = $wgUser->getName();
                $wgUser->logout();
-               
+
                // Give extensions to do something after user logout
                $injected_html = '';
                wfRunHooks( 'UserLogoutComplete', array( &$wgUser, &$injected_html, $oldName ) );
@@ -55,15 +55,15 @@ class ApiLogout extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array ();
+               return array();
        }
 
        public function getParamDescription() {
-               return array ();
+               return array();
        }
 
        public function getDescription() {
-               return array (
+               return array(
                        'This module is used to logout and clear session data'
                );
        }
index f83a052..944f96c 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Sep 4, 2006
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( 'ApiBase.php' );
+       require_once( 'ApiBase.php' );
 }
 
 /**
@@ -55,7 +55,7 @@ class ApiMain extends ApiBase {
        /**
         * List of available modules: action name => module class
         */
-       private static $Modules = array (
+       private static $Modules = array(
                'login' => 'ApiLogin',
                'logout' => 'ApiLogout',
                'query' => 'ApiQuery',
@@ -87,7 +87,7 @@ class ApiMain extends ApiBase {
        /**
         * List of available formats: format name => format class
         */
-       private static $Formats = array (
+       private static $Formats = array(
                'json' => 'ApiFormatJson',
                'jsonfm' => 'ApiFormatJson',
                'php' => 'ApiFormatPhp',
@@ -111,17 +111,17 @@ class ApiMain extends ApiBase {
         *                           'params' => array ( $someVarToSubst ) ),
         *                          );
         */
-       private static $mRights = array( 'writeapi' => array(
-                                               'msg' => 'Use of the write API',
-                                               'params' => array()
-                                       ),
-                                       'apihighlimits' => array(
-                                               'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.',
-                                               'params' => array ( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 )
-                                       )
+       private static $mRights = array(
+               'writeapi' => array(
+                       'msg' => 'Use of the write API',
+                       'params' => array()
+               ),
+               'apihighlimits' => array(
+                       'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.',
+                       'params' => array( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 )
+               )
        );
 
-
        private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
        private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
        private $mInternalMode, $mSquidMaxage, $mModule;
@@ -129,20 +129,18 @@ class ApiMain extends ApiBase {
        private $mCacheControl = array( 'must-revalidate' => true );
 
        /**
-       * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
-       *
-       * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs
-       * @param $enableWrite bool should be set to true if the api may modify data
-       */
+        * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
+        *
+        * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs
+        * @param $enableWrite bool should be set to true if the api may modify data
+        */
        public function __construct( $request, $enableWrite = false ) {
-
                $this->mInternalMode = ( $request instanceof FauxRequest );
 
                // Special handling for the main module: $parent === $this
-               parent :: __construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
+               parent::__construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
 
                if ( !$this->mInternalMode ) {
-
                        // Impose module restrictions.
                        // If the current user cannot read,
                        // Remove all modules other than login
@@ -157,19 +155,19 @@ class ApiMain extends ApiBase {
                }
 
                global $wgAPIModules; // extension modules
-               $this->mModules = $wgAPIModules + self :: $Modules;
+               $this->mModules = $wgAPIModules + self::$Modules;
 
                $this->mModuleNames = array_keys( $this->mModules );
-               $this->mFormats = self :: $Formats;
+               $this->mFormats = self::$Formats;
                $this->mFormatNames = array_keys( $this->mFormats );
 
                $this->mResult = new ApiResult( $this );
                $this->mShowVersions = false;
                $this->mEnableWrite = $enableWrite;
 
-               $this->mRequest = & $request;
+               $this->mRequest = &$request;
 
-               $this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling()
+               $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
                $this->mCommit = false;
        }
 
@@ -206,10 +204,12 @@ class ApiMain extends ApiBase {
         * @deprecated Use isWriteMode() instead
         */
        public function requestWriteMode() {
-               if ( !$this->mEnableWrite )
+               if ( !$this->mEnableWrite ) {
                        $this->dieUsageMsg( array( 'writedisabled' ) );
-               if ( wfReadOnly() )
+               }
+               if ( wfReadOnly() ) {
                        $this->dieUsageMsg( array( 'readonlytext' ) );
+               }
        }
 
        /**
@@ -235,8 +235,9 @@ class ApiMain extends ApiBase {
         * Create an instance of an output formatter by its name
         */
        public function createPrinterByName( $format ) {
-               if ( !isset( $this->mFormats[$format] ) )
+               if ( !isset( $this->mFormats[$format] ) ) {
                        $this->dieUsage( "Unrecognized format: {$format}", 'unknown_format' );
+               }
                return new $this->mFormats[$format] ( $this, $format );
        }
 
@@ -245,10 +246,11 @@ class ApiMain extends ApiBase {
         */
        public function execute() {
                $this->profileIn();
-               if ( $this->mInternalMode )
+               if ( $this->mInternalMode ) {
                        $this->executeAction();
-               else
+               } else {
                        $this->executeActionWithErrorHandling();
+               }
 
                $this->profileOut();
        }
@@ -258,7 +260,6 @@ class ApiMain extends ApiBase {
         * have been accumulated, and replace it with an error message and a help screen.
         */
        protected function executeActionWithErrorHandling() {
-
                // In case an error occurs during data output,
                // clear the output buffer and print just the error information
                ob_start();
@@ -283,10 +284,11 @@ class ApiMain extends ApiBase {
                        $this->setCacheMaxAge( 0 );
 
                        $headerStr = 'MediaWiki-API-Error: ' . $errCode;
-                       if ( $e->getCode() === 0 )
+                       if ( $e->getCode() === 0 ) {
                                header( $headerStr );
-                       else
+                       } else {
                                header( $headerStr, true, $e->getCode() );
+                       }
 
                        // Reset and print just the error message
                        ob_clean();
@@ -324,11 +326,12 @@ class ApiMain extends ApiBase {
                                $separator = ', ';
                        }
                }
-                       
+
                header( "Cache-Control: $ccHeader" );
 
-               if ( $this->mPrinter->getIsHtml() )
+               if ( $this->mPrinter->getIsHtml() ) {
                        echo wfReportTime();
+               }
 
                ob_end_flush();
        }
@@ -338,17 +341,18 @@ class ApiMain extends ApiBase {
         * Returns the error code
         */
        protected function substituteResultWithError( $e ) {
-
                // Printer may not be initialized if the extractRequestParams() fails for the main module
                if ( !isset ( $this->mPrinter ) ) {
                        // The printer has not been created yet. Try to manually get formatter value.
                        $value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT );
-                       if ( !in_array( $value, $this->mFormatNames ) )
+                       if ( !in_array( $value, $this->mFormatNames ) ) {
                                $value = self::API_DEFAULT_FORMAT;
+                       }
 
                        $this->mPrinter = $this->createPrinterByName( $value );
-                       if ( $this->mPrinter->getNeedsRawData() )
+                       if ( $this->mPrinter->getNeedsRawData() ) {
                                $this->getResult()->setRawMode();
+                       }
                }
 
                if ( $e instanceof UsageException ) {
@@ -358,8 +362,9 @@ class ApiMain extends ApiBase {
                        $errMessage = $e->getMessageArray();
 
                        // Only print the help message when this is for the developer, not runtime
-                       if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' )
-                               ApiResult :: setContent( $errMessage, $this->makeHelpMsg() );
+                       if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) {
+                               ApiResult::setContent( $errMessage, $this->makeHelpMsg() );
+                       }
 
                } else {
                        global $wgShowSQLErrors, $wgShowExceptionDetails;
@@ -367,24 +372,25 @@ class ApiMain extends ApiBase {
                        // Something is seriously wrong
                        //
                        if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
-                               $info = "Database query error";
+                               $info = 'Database query error';
                        } else {
                                $info = "Exception Caught: {$e->getMessage()}";
                        }
 
-                       $errMessage = array (
+                       $errMessage = array(
                                'code' => 'internal_api_error_' . get_class( $e ),
                                'info' => $info,
                        );
-                       ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" );
+                       ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' );
                }
 
                $this->getResult()->reset();
                $this->getResult()->disableSizeCheck();
                // Re-add the id
                $requestid = $this->getParameter( 'requestid' );
-               if ( !is_null( $requestid ) )
+               if ( !is_null( $requestid ) ) {
                        $this->getResult()->addValue( null, 'requestid', $requestid );
+               }
                $this->getResult()->addValue( null, 'error', $errMessage );
 
                return $errMessage['code'];
@@ -396,8 +402,9 @@ class ApiMain extends ApiBase {
        protected function executeAction() {
                // First add the id to the top element
                $requestid = $this->getParameter( 'requestid' );
-               if ( !is_null( $requestid ) )
+               if ( !is_null( $requestid ) ) {
                        $this->getResult()->addValue( null, 'requestid', $requestid );
+               }
 
                $params = $this->extractRequestParams();
 
@@ -405,19 +412,18 @@ class ApiMain extends ApiBase {
                $this->mAction = $params['action'];
 
                if ( !is_string( $this->mAction ) ) {
-                       $this->dieUsage( "The API requires a valid action parameter", 'unknown_action' );
+                       $this->dieUsage( 'The API requires a valid action parameter', 'unknown_action' );
                }
-               
+
                // Instantiate the module requested by the user
                $module = new $this->mModules[$this->mAction] ( $this, $this->mAction );
                $this->mModule = $module;
 
                $moduleParams = $module->extractRequestParams();
-               
+
                // Die if token required, but not provided (unless there is a gettoken parameter)
                $salt = $module->getTokenSalt();
-               if ( $salt !== false && !isset( $moduleParams['gettoken'] ) )
-               {
+               if ( $salt !== false && !isset( $moduleParams['gettoken'] ) ) {
                        if ( !isset( $moduleParams['token'] ) ) {
                                $this->dieUsageMsg( array( 'missingparam', 'token' ) );
                        } else {
@@ -447,20 +453,26 @@ class ApiMain extends ApiBase {
 
                global $wgUser, $wgGroupPermissions;
                if ( $module->isReadMode() && !$wgGroupPermissions['*']['read'] && !$wgUser->isAllowed( 'read' ) )
+               {
                        $this->dieUsageMsg( array( 'readrequired' ) );
+               }
                if ( $module->isWriteMode() ) {
-                       if ( !$this->mEnableWrite )
+                       if ( !$this->mEnableWrite ) {
                                $this->dieUsageMsg( array( 'writedisabled' ) );
-                       if ( !$wgUser->isAllowed( 'writeapi' ) )
+                       }
+                       if ( !$wgUser->isAllowed( 'writeapi' ) ) {
                                $this->dieUsageMsg( array( 'writerequired' ) );
-                       if ( wfReadOnly() )
+                       }
+                       if ( wfReadOnly() ) {
                                $this->dieReadOnly();
+                       }
                }
 
                if ( !$this->mInternalMode ) {
                        // Ignore mustBePosted() for internal calls
-                       if ( $module->mustBePosted() && !$this->mRequest->wasPosted() )
-                               $this->dieUsageMsg( array ( 'mustbeposted', $this->mAction ) );
+                       if ( $module->mustBePosted() && !$this->mRequest->wasPosted() ) {
+                               $this->dieUsageMsg( array( 'mustbeposted', $this->mAction ) );
+                       }
 
                        // See if custom printer is used
                        $this->mPrinter = $module->getCustomPrinter();
@@ -469,8 +481,9 @@ class ApiMain extends ApiBase {
                                $this->mPrinter = $this->createPrinterByName( $params['format'] );
                        }
 
-                       if ( $this->mPrinter->getNeedsRawData() )
+                       if ( $this->mPrinter->getNeedsRawData() ) {
                                $this->getResult()->setRawMode();
+                       }
                }
 
                // Execute
@@ -493,10 +506,12 @@ class ApiMain extends ApiBase {
                $printer = $this->mPrinter;
                $printer->profileIn();
 
-               /* If the help message is requested in the default (xmlfm) format,
+               /**
+                * If the help message is requested in the default (xmlfm) format,
                 * tell the printer not to escape ampersands so that our links do
-                * not break. */
-               $printer->setUnescapeAmps ( ( $this->mAction == 'help' || $isError )
+                * not break.
+                */
+               $printer->setUnescapeAmps( ( $this->mAction == 'help' || $isError )
                                && $printer->getFormat() == 'XML' && $printer->getIsHtml() );
 
                $printer->initPrinter( $isError );
@@ -514,26 +529,26 @@ class ApiMain extends ApiBase {
         * See ApiBase for description.
         */
        public function getAllowedParams() {
-               return array (
-                       'format' => array (
-                               ApiBase :: PARAM_DFLT => ApiMain :: API_DEFAULT_FORMAT,
-                               ApiBase :: PARAM_TYPE => $this->mFormatNames
+               return array(
+                       'format' => array(
+                               ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT,
+                               ApiBase::PARAM_TYPE => $this->mFormatNames
                        ),
-                       'action' => array (
-                               ApiBase :: PARAM_DFLT => 'help',
-                               ApiBase :: PARAM_TYPE => $this->mModuleNames
+                       'action' => array(
+                               ApiBase::PARAM_DFLT => 'help',
+                               ApiBase::PARAM_TYPE => $this->mModuleNames
                        ),
                        'version' => false,
-                       'maxlag'  => array (
-                               ApiBase :: PARAM_TYPE => 'integer'
+                       'maxlag'  => array(
+                               ApiBase::PARAM_TYPE => 'integer'
                        ),
-                       'smaxage' => array (
-                               ApiBase :: PARAM_TYPE => 'integer',
-                               ApiBase :: PARAM_DFLT => 0
+                       'smaxage' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_DFLT => 0
                        ),
-                       'maxage' => array (
-                               ApiBase :: PARAM_TYPE => 'integer',
-                               ApiBase :: PARAM_DFLT => 0
+                       'maxage' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_DFLT => 0
                        ),
                        'requestid' => null,
                );
@@ -543,7 +558,7 @@ class ApiMain extends ApiBase {
         * See ApiBase for description.
         */
        public function getParamDescription() {
-               return array (
+               return array(
                        'format' => 'The format of the output',
                        'action' => 'What action you would like to perform',
                        'version' => 'When showing help, include version for each module',
@@ -558,7 +573,7 @@ class ApiMain extends ApiBase {
         * See ApiBase for description.
         */
        public function getDescription() {
-               return array (
+               return array(
                        '',
                        '',
                        '******************************************************************',
@@ -585,14 +600,14 @@ class ApiMain extends ApiBase {
                );
        }
 
-    public function getPossibleErrors() {
+       public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'readonlytext' ),
                        array( 'code' => 'unknown_format', 'info' => 'Unrecognized format: format' ),
                        array( 'code' => 'unknown_action', 'info' => 'The API requires a valid action parameter' ),
                        array( 'code' => 'maxlag', 'info' => 'Waiting for host: x seconds lagged' ),
                        array( 'code' => 'maxlag', 'info' => 'Waiting for a database server: x seconds lagged' ),
-        ) );
+               ) );
        }
 
        /**
@@ -624,21 +639,22 @@ class ApiMain extends ApiBase {
                        $this->getMain()->getShowVersions() );
                if ( $wgAPICacheHelp ) {
                        $cached = $wgMemc->get( $key );
-                       if ( $cached )
+                       if ( $cached ) {
                                return $cached;
+                       }
                }
                $retval = $this->reallyMakeHelpMsg();
-               if ( $wgAPICacheHelp )
+               if ( $wgAPICacheHelp ) {
                        $wgMemc->set( $key, $retval, $wgAPICacheHelpTimeout );
+               }
                return $retval;
        }
 
        public function reallyMakeHelpMsg() {
-
                $this->mPrinter->setHelp();
 
                // Use parent to make default message for the main module
-               $msg = parent :: makeHelpMsg();
+               $msg = parent::makeHelpMsg();
 
                $astriks = str_repeat( '*** ', 10 );
                $msg .= "\n\n$astriks Modules  $astriks\n\n";
@@ -646,16 +662,17 @@ class ApiMain extends ApiBase {
                        $module = new $this->mModules[$moduleName] ( $this, $moduleName );
                        $msg .= self::makeHelpMsgHeader( $module, 'action' );
                        $msg2 = $module->makeHelpMsg();
-                       if ( $msg2 !== false )
+                       if ( $msg2 !== false ) {
                                $msg .= $msg2;
+                       }
                        $msg .= "\n";
                }
 
                $msg .= "\n$astriks Permissions $astriks\n\n";
-               foreach ( self :: $mRights as $right => $rightMsg ) {
+               foreach ( self::$mRights as $right => $rightMsg ) {
                        $groups = User::getGroupsWithPermission( $right );
                        $msg .= "* " . $right . " *\n  " . wfMsgReplaceArgs( $rightMsg[ 'msg' ], $rightMsg[ 'params' ] ) .
-                                               "\nGranted to:\n  " . str_replace( "*", "all", implode( ", ", $groups ) ) . "\n";
+                                               "\nGranted to:\n  " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n";
 
                }
 
@@ -664,8 +681,9 @@ class ApiMain extends ApiBase {
                        $module = $this->createPrinterByName( $formatName );
                        $msg .= self::makeHelpMsgHeader( $module, 'format' );
                        $msg2 = $module->makeHelpMsg();
-                       if ( $msg2 !== false )
+                       if ( $msg2 !== false ) {
                                $msg .= $msg2;
+                       }
                        $msg .= "\n";
                }
 
@@ -677,8 +695,9 @@ class ApiMain extends ApiBase {
 
        public static function makeHelpMsgHeader( $module, $paramName ) {
                $modulePrefix = $module->getModulePrefix();
-               if ( strval( $modulePrefix ) !== '' )
+               if ( strval( $modulePrefix ) !== '' ) {
                        $modulePrefix = "($modulePrefix) ";
+               }
 
                return "* $paramName={$module->getModuleName()} $modulePrefix*";
        }
@@ -692,7 +711,7 @@ class ApiMain extends ApiBase {
         * OBSOLETE, use canApiHighLimits() instead
         */
        public function isBot() {
-               if ( !isset ( $this->mIsBot ) ) {
+               if ( !isset( $this->mIsBot ) ) {
                        global $wgUser;
                        $this->mIsBot = $wgUser->isAllowed( 'bot' );
                }
@@ -705,7 +724,7 @@ class ApiMain extends ApiBase {
         * OBSOLETE, use canApiHighLimits() instead
         */
        public function isSysop() {
-               if ( !isset ( $this->mIsSysop ) ) {
+               if ( !isset( $this->mIsSysop ) ) {
                        global $wgUser;
                        $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups() );
                }
@@ -742,9 +761,9 @@ class ApiMain extends ApiBase {
                $vers = array ();
                $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n    http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
                $vers[] = __CLASS__ . ': $Id$';
-               $vers[] = ApiBase :: getBaseVersion();
-               $vers[] = ApiFormatBase :: getBaseVersion();
-               $vers[] = ApiQueryBase :: getBaseVersion();
+               $vers[] = ApiBase::getBaseVersion();
+               $vers[] = ApiFormatBase::getBaseVersion();
+               $vers[] = ApiQueryBase::getBaseVersion();
                return $vers;
        }
 
@@ -753,7 +772,6 @@ class ApiMain extends ApiBase {
         * classes who wish to add their own modules to their lexicon or override the
         * behavior of inherent ones.
         *
-        * @access protected
         * @param $mdlName String The identifier for this module.
         * @param $mdlClass String The class where this module is implemented.
         */
@@ -765,7 +783,6 @@ class ApiMain extends ApiBase {
         * Add or overwrite an output format for this ApiMain. Intended for use by extending
         * classes who wish to add to or modify current formatters.
         *
-        * @access protected
         * @param $fmtName The identifier for this format.
         * @param $fmtClass The class implementing this format.
         */
@@ -793,22 +810,26 @@ class UsageException extends Exception {
        private $mExtraData;
 
        public function __construct( $message, $codestr, $code = 0, $extradata = null ) {
-               parent :: __construct( $message, $code );
+               parent::__construct( $message, $code );
                $this->mCodestr = $codestr;
                $this->mExtraData = $extradata;
        }
+
        public function getCodeString() {
                return $this->mCodestr;
        }
+
        public function getMessageArray() {
-               $result = array (
-                               'code' => $this->mCodestr,
-                               'info' => $this->getMessage()
+               $result = array(
+                       'code' => $this->mCodestr,
+                       'info' => $this->getMessage()
                );
-               if ( is_array( $this->mExtraData ) )
+               if ( is_array( $this->mExtraData ) ) {
                        $result = array_merge( $result, $this->mExtraData );
+               }
                return $result;
        }
+
        public function __toString() {
                return "{$this->getCodeString()}: {$this->getMessage()}";
        }
index 567f36b..397d715 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Oct 13, 2006
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( "ApiBase.php" );
+       require_once( "ApiBase.php" );
 }
 
 /**
@@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiOpenSearch extends ApiBase {
 
        public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
+               parent::__construct( $main, $action );
        }
 
        public function getCustomPrinter() {
@@ -50,9 +50,9 @@ class ApiOpenSearch extends ApiBase {
                $suggest = $params['suggest'];
 
                // MWSuggest or similar hit
-               if ( $suggest && !$wgEnableOpenSearchSuggest )
+               if ( $suggest && !$wgEnableOpenSearchSuggest ) {
                        $srchres = array();
-               else {
+               else {
                        // Open search results may be stored for a very long
                        // time
                        $this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry );
@@ -68,26 +68,26 @@ class ApiOpenSearch extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array (
+               return array(
                        'search' => null,
                        'limit' => array(
-                               ApiBase :: PARAM_DFLT => 10,
-                               ApiBase :: PARAM_TYPE => 'limit',
-                               ApiBase :: PARAM_MIN => 1,
-                               ApiBase :: PARAM_MAX => 100,
-                               ApiBase :: PARAM_MAX2 => 100
+                               ApiBase::PARAM_DFLT => 10,
+                               ApiBase::PARAM_TYPE => 'limit',
+                               ApiBase::PARAM_MIN => 1,
+                               ApiBase::PARAM_MAX => 100,
+                               ApiBase::PARAM_MAX2 => 100
                        ),
                        'namespace' => array(
-                               ApiBase :: PARAM_DFLT => NS_MAIN,
-                               ApiBase :: PARAM_TYPE => 'namespace',
-                               ApiBase :: PARAM_ISMULTI => true
+                               ApiBase::PARAM_DFLT => NS_MAIN,
+                               ApiBase::PARAM_TYPE => 'namespace',
+                               ApiBase::PARAM_ISMULTI => true
                        ),
                        'suggest' => false,
                );
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        'search' => 'Search string',
                        'limit' => 'Maximum amount of results to return',
                        'namespace' => 'Namespaces to search',
@@ -100,7 +100,7 @@ class ApiOpenSearch extends ApiBase {
        }
 
        protected function getExamples() {
-               return array (
+               return array(
                        'api.php?action=opensearch&search=Te'
                );
        }
index ac1682e..fee4750 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Sep 24, 2006
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( 'ApiQueryBase.php' );
+       require_once( 'ApiQueryBase.php' );
 }
 
 /**
@@ -59,26 +59,27 @@ class ApiPageSet extends ApiQueryBase {
         * @param $resolveRedirects bool Whether redirects should be resolved
         */
        public function __construct( $query, $resolveRedirects = false ) {
-               parent :: __construct( $query, 'query' );
+               parent::__construct( $query, 'query' );
 
-               $this->mAllPages = array ();
+               $this->mAllPages = array();
                $this->mTitles = array();
-               $this->mGoodTitles = array ();
-               $this->mMissingTitles = array ();
-               $this->mInvalidTitles = array ();
-               $this->mMissingPageIDs = array ();
-               $this->mRedirectTitles = array ();
-               $this->mNormalizedTitles = array ();
-               $this->mInterwikiTitles = array ();
+               $this->mGoodTitles = array();
+               $this->mMissingTitles = array();
+               $this->mInvalidTitles = array();
+               $this->mMissingPageIDs = array();
+               $this->mRedirectTitles = array();
+               $this->mNormalizedTitles = array();
+               $this->mInterwikiTitles = array();
                $this->mGoodRevIDs = array();
                $this->mMissingRevIDs = array();
 
-               $this->mRequestedPageFields = array ();
+               $this->mRequestedPageFields = array();
                $this->mResolveRedirects = $resolveRedirects;
-               if ( $resolveRedirects )
+               if ( $resolveRedirects ) {
                        $this->mPendingRedirectIDs = array();
+               }
 
-               $this->mFakePageId = - 1;
+               $this->mFakePageId = -1;
        }
 
        /**
@@ -117,14 +118,15 @@ class ApiPageSet extends ApiQueryBase {
        public function getPageTableFields() {
                // Ensure we get minimum required fields
                // DON'T change this order
-               $pageFlds = array (
+               $pageFlds = array(
                        'page_namespace' => null,
                        'page_title' => null,
                        'page_id' => null,
                );
 
-               if ( $this->mResolveRedirects )
+               if ( $this->mResolveRedirects ) {
                        $pageFlds['page_is_redirect'] = null;
+               }
 
                // only store non-default fields
                $this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds );
@@ -261,34 +263,38 @@ class ApiPageSet extends ApiQueryBase {
 
                // Only one of the titles/pageids/revids is allowed at the same time
                $dataSource = null;
-               if ( isset ( $params['titles'] ) )
+               if ( isset( $params['titles'] ) ) {
                        $dataSource = 'titles';
-               if ( isset ( $params['pageids'] ) ) {
-                       if ( isset ( $dataSource ) )
+               }
+               if ( isset( $params['pageids'] ) ) {
+                       if ( isset( $dataSource ) ) {
                                $this->dieUsage( "Cannot use 'pageids' at the same time as '$dataSource'", 'multisource' );
+                       }
                        $dataSource = 'pageids';
                }
-               if ( isset ( $params['revids'] ) ) {
-                       if ( isset ( $dataSource ) )
+               if ( isset( $params['revids'] ) ) {
+                       if ( isset( $dataSource ) ) {
                                $this->dieUsage( "Cannot use 'revids' at the same time as '$dataSource'", 'multisource' );
+                       }
                        $dataSource = 'revids';
                }
 
                switch ( $dataSource ) {
-                       case 'titles' :
+                       case 'titles':
                                $this->initFromTitles( $params['titles'] );
                                break;
-                       case 'pageids' :
+                       case 'pageids':
                                $this->initFromPageIds( $params['pageids'] );
                                break;
-                       case 'revids' :
-                               if ( $this->mResolveRedirects )
+                       case 'revids':
+                               if ( $this->mResolveRedirects ) {
                                        $this->setWarning( 'Redirect resolution cannot be used together with the revids= parameter. ' .
                                        'Any redirects the revids= point to have not been resolved.' );
+                               }
                                $this->mResolveRedirects = false;
                                $this->initFromRevIDs( $params['revids'] );
                                break;
-                       default :
+                       default:
                                // Do nothing - some queries do not need any of the data sources.
                                break;
                }
@@ -341,9 +347,8 @@ class ApiPageSet extends ApiQueryBase {
         * @param $row Result row
         */
        public function processDbRow( $row ) {
-
                // Store Title object in various data structures
-               $title = Title :: makeTitle( $row->page_namespace, $row->page_title );
+               $title = Title::makeTitle( $row->page_namespace, $row->page_title );
 
                $pageId = intval( $row->page_id );
                $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
@@ -355,8 +360,9 @@ class ApiPageSet extends ApiQueryBase {
                        $this->mGoodTitles[$pageId] = $title;
                }
 
-               foreach ( $this->mRequestedPageFields as $fieldName => & $fieldValues )
+               foreach ( $this->mRequestedPageFields as $fieldName => &$fieldValues ) {
                        $fieldValues[$pageId] = $row-> $fieldName;
+               }
        }
 
        /**
@@ -385,11 +391,11 @@ class ApiPageSet extends ApiQueryBase {
         * @param $titles array of Title objects or strings
         */
        private function initFromTitles( $titles ) {
-
                // Get validated and normalized title objects
                $linkBatch = $this->processTitlesArray( $titles );
-               if ( $linkBatch->isEmpty() )
+               if ( $linkBatch->isEmpty() ) {
                        return;
+               }
 
                $db = $this->getDB();
                $set = $linkBatch->constructSet( 'page', $db );
@@ -401,7 +407,7 @@ class ApiPageSet extends ApiQueryBase {
                $this->profileDBOut();
 
                // Hack: get the ns:titles stored in array(ns => array(titles)) format
-               $this->initFromQueryResult( $db, $res, $linkBatch->data, true );        // process Titles
+               $this->initFromQueryResult( $db, $res, $linkBatch->data, true ); // process Titles
 
                // Resolve any found redirects
                $this->resolvePendingRedirects();
@@ -412,11 +418,12 @@ class ApiPageSet extends ApiQueryBase {
         * @param $pageids array of page IDs
         */
        private function initFromPageIds( $pageids ) {
-               if ( !count( $pageids ) )
+               if ( !count( $pageids ) ) {
                        return;
+               }
 
                $pageids = array_map( 'intval', $pageids ); // paranoia
-               $set = array (
+               $set = array(
                        'page_id' => $pageids
                );
                $db = $this->getDB();
@@ -446,19 +453,20 @@ class ApiPageSet extends ApiQueryBase {
         *        If false, treat it as an array of [pageIDs]
         */
        private function initFromQueryResult( $db, $res, &$remaining = null, $processTitles = null ) {
-               if ( !is_null( $remaining ) && is_null( $processTitles ) )
-                       ApiBase :: dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
+               if ( !is_null( $remaining ) && is_null( $processTitles ) ) {
+                       ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
+               }
 
                while ( $row = $db->fetchObject( $res ) ) {
-
                        $pageId = intval( $row->page_id );
 
                        // Remove found page from the list of remaining items
                        if ( isset( $remaining ) ) {
-                               if ( $processTitles )
-                                       unset ( $remaining[$row->page_namespace][$row->page_title] );
-                               else
-                                       unset ( $remaining[$pageId] );
+                               if ( $processTitles ) {
+                                       unset( $remaining[$row->page_namespace][$row->page_title] );
+                               } else {
+                                       unset( $remaining[$pageId] );
+                               }
                        }
 
                        // Store any extra fields requested by modules
@@ -472,21 +480,20 @@ class ApiPageSet extends ApiQueryBase {
                                // The remaining titles in $remaining are non-existent pages
                                foreach ( $remaining as $ns => $dbkeys ) {
                                        foreach ( $dbkeys as $dbkey => $unused ) {
-                                               $title = Title :: makeTitle( $ns, $dbkey );
+                                               $title = Title::makeTitle( $ns, $dbkey );
                                                $this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
                                                $this->mMissingTitles[$this->mFakePageId] = $title;
                                                $this->mFakePageId--;
                                                $this->mTitles[] = $title;
                                        }
                                }
-                       }
-                       else
-                       {
+                       } else {
                                // The remaining pageids do not exist
-                               if ( !$this->mMissingPageIDs )
+                               if ( !$this->mMissingPageIDs ) {
                                        $this->mMissingPageIDs = array_keys( $remaining );
-                               else
+                               } else {
                                        $this->mMissingPageIDs = array_merge( $this->mMissingPageIDs, array_keys( $remaining ) );
+                               }
                        }
                }
        }
@@ -497,9 +504,9 @@ class ApiPageSet extends ApiQueryBase {
         * @param $revids array of revision IDs
         */
        private function initFromRevIDs( $revids ) {
-
-               if ( !count( $revids ) )
+               if ( !count( $revids ) ) {
                        return;
+               }
 
                $revids = array_map( 'intval', $revids ); // paranoia
                $db = $this->getDB();
@@ -535,7 +542,6 @@ class ApiPageSet extends ApiQueryBase {
         * have been resolved.
         */
        private function resolvePendingRedirects() {
-
                if ( $this->mResolveRedirects ) {
                        $db = $this->getDB();
                        $pageFlds = $this->getPageTableFields();
@@ -543,17 +549,18 @@ class ApiPageSet extends ApiQueryBase {
                        // Repeat until all redirects have been resolved
                        // The infinite loop is prevented by keeping all known pages in $this->mAllPages
                        while ( $this->mPendingRedirectIDs ) {
-
                                // Resolve redirects by querying the pagelinks table, and repeat the process
                                // Create a new linkBatch object for the next pass
                                $linkBatch = $this->getRedirectTargets();
 
-                               if ( $linkBatch->isEmpty() )
+                               if ( $linkBatch->isEmpty() ) {
                                        break;
+                               }
 
                                $set = $linkBatch->constructSet( 'page', $db );
-                               if ( $set === false )
+                               if ( $set === false ) {
                                        break;
+                               }
 
                                // Get pageIDs data from the `page` table
                                $this->profileDBIn();
@@ -578,7 +585,9 @@ class ApiPageSet extends ApiQueryBase {
                $db = $this->getDB();
 
                $this->profileDBIn();
-               $res = $db->select( 'redirect', array(
+               $res = $db->select(
+                       'redirect',
+                       array(
                                'rd_from',
                                'rd_namespace',
                                'rd_title'
@@ -587,28 +596,27 @@ class ApiPageSet extends ApiQueryBase {
                );
                $this->profileDBOut();
 
-               while ( $row = $db->fetchObject( $res ) )
-               {
+               while ( $row = $db->fetchObject( $res ) ) {
                        $rdfrom = intval( $row->rd_from );
                        $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
                        $to = Title::makeTitle( $row->rd_namespace, $row->rd_title )->getPrefixedText();
                        unset( $this->mPendingRedirectIDs[$rdfrom] );
-                       if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) )
+                       if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
                                $lb->add( $row->rd_namespace, $row->rd_title );
+                       }
                        $this->mRedirectTitles[$from] = $to;
                }
                $db->freeResult( $res );
-               if ( $this->mPendingRedirectIDs )
-               {
+               if ( $this->mPendingRedirectIDs ) {
                        // We found pages that aren't in the redirect table
                        // Add them
-                       foreach ( $this->mPendingRedirectIDs as $id => $title )
-                       {
+                       foreach ( $this->mPendingRedirectIDs as $id => $title ) {
                                $article = new Article( $title );
                                $rt = $article->insertRedirect();
-                               if ( !$rt )
+                               if ( !$rt ) {
                                        // What the hell. Let's just ignore this
                                        continue;
+                               }
                                $lb->addObj( $rt );
                                $this->mRedirectTitles[$title->getPrefixedText()] = $rt->getPrefixedText();
                                unset( $this->mPendingRedirectIDs[$id] );
@@ -627,14 +635,11 @@ class ApiPageSet extends ApiQueryBase {
         * @return LinkBatch
         */
        private function processTitlesArray( $titles ) {
-
                $linkBatch = new LinkBatch();
 
                foreach ( $titles as $title ) {
-
-                       $titleObj = is_string( $title ) ? Title :: newFromText( $title ) : $title;
-                       if ( !$titleObj )
-                       {
+                       $titleObj = is_string( $title ) ? Title::newFromText( $title ) : $title;
+                       if ( !$titleObj ) {
                                // Handle invalid titles gracefully
                                $this->mAllpages[0][$title] = $this->mFakePageId;
                                $this->mInvalidTitles[$this->mFakePageId] = $title;
@@ -646,12 +651,12 @@ class ApiPageSet extends ApiQueryBase {
                                // This title is an interwiki link.
                                $this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw;
                        } else {
-
                                // Validation
-                               if ( $titleObj->getNamespace() < 0 )
-                                       $this->setWarning( "No support for special pages has been implemented" );
-                               else
+                               if ( $titleObj->getNamespace() < 0 ) {
+                                       $this->setWarning( 'No support for special pages has been implemented' );
+                               } else {
                                        $linkBatch->addObj( $titleObj );
+                               }
                        }
 
                        // Make sure we remember the original title that was
@@ -668,23 +673,23 @@ class ApiPageSet extends ApiQueryBase {
        }
 
        protected function getAllowedParams() {
-               return array (
-                       'titles' => array (
-                               ApiBase :: PARAM_ISMULTI => true
+               return array(
+                       'titles' => array(
+                               ApiBase::PARAM_ISMULTI => true
                        ),
-                       'pageids' => array (
-                               ApiBase :: PARAM_TYPE => 'integer',
-                               ApiBase :: PARAM_ISMULTI => true
+                       'pageids' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_ISMULTI => true
                        ),
-                       'revids' => array (
-                               ApiBase :: PARAM_TYPE => 'integer',
-                               ApiBase :: PARAM_ISMULTI => true
+                       'revids' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_ISMULTI => true
                        )
                );
        }
 
        protected function getParamDescription() {
-               return array (
+               return array(
                        'titles' => 'A list of titles to work on',
                        'pageids' => 'A list of page IDs to work on',
                        'revids' => 'A list of revision IDs to work on'
index 85ded55..8770bd4 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Dec 01, 2007
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( "ApiBase.php" );
+       require_once( "ApiBase.php" );
 }
 
 /**
@@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiParamInfo extends ApiBase {
 
        public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
+               parent::__construct( $main, $action );
        }
 
        public function execute() {
@@ -43,14 +43,11 @@ class ApiParamInfo extends ApiBase {
                $result = $this->getResult();
                $queryObj = new ApiQuery( $this->getMain(), 'query' );
                $r = array();
-               if ( is_array( $params['modules'] ) )
-               {
+               if ( is_array( $params['modules'] ) ) {
                        $modArr = $this->getMain()->getModules();
                        $r['modules'] = array();
-                       foreach ( $params['modules'] as $m )
-                       {
-                               if ( !isset( $modArr[$m] ) )
-                               {
+                       foreach ( $params['modules'] as $m ) {
+                               if ( !isset( $modArr[$m] ) ) {
                                        $r['modules'][] = array( 'name' => $m, 'missing' => '' );
                                        continue;
                                }
@@ -61,14 +58,11 @@ class ApiParamInfo extends ApiBase {
                        }
                        $result->setIndexedTagName( $r['modules'], 'module' );
                }
-               if ( is_array( $params['querymodules'] ) )
-               {
+               if ( is_array( $params['querymodules'] ) ) {
                        $qmodArr = $queryObj->getModules();
                        $r['querymodules'] = array();
-                       foreach ( $params['querymodules'] as $qm )
-                       {
-                               if ( !isset( $qmodArr[$qm] ) )
-                               {
+                       foreach ( $params['querymodules'] as $qm ) {
+                               if ( !isset( $qmodArr[$qm] ) ) {
                                        $r['querymodules'][] = array( 'name' => $qm, 'missing' => '' );
                                        continue;
                                }
@@ -79,60 +73,59 @@ class ApiParamInfo extends ApiBase {
                        }
                        $result->setIndexedTagName( $r['querymodules'], 'module' );
                }
-               if ( $params['mainmodule'] )
+               if ( $params['mainmodule'] ) {
                        $r['mainmodule'] = $this->getClassInfo( $this->getMain() );
-               if ( $params['pagesetmodule'] )
-               {
+               }
+               if ( $params['pagesetmodule'] ) {
                        $pageSet = new ApiPageSet( $queryObj );
                        $r['pagesetmodule'] = $this->getClassInfo( $pageSet );
                }
                $result->addValue( null, $this->getModuleName(), $r );
        }
 
-       function getClassInfo( $obj )
-       {
+       function getClassInfo( $obj ) {
                $result = $this->getResult();
                $retval['classname'] = get_class( $obj );
                $retval['description'] = implode( "\n", (array)$obj->getDescription() );
                $retval['version'] = implode( "\n", (array)$obj->getVersion() );
                $retval['prefix'] = $obj->getModulePrefix();
 
-               if ( $obj->isReadMode() )
+               if ( $obj->isReadMode() ) {
                        $retval['readrights'] = '';
-               if ( $obj->isWriteMode() )
+               }
+               if ( $obj->isWriteMode() ) {
                        $retval['writerights'] = '';
-               if ( $obj->mustBePosted() )
+               }
+               if ( $obj->mustBePosted() ) {
                        $retval['mustbeposted'] = '';
-               if ( $obj instanceof ApiQueryGeneratorBase )
+               }
+               if ( $obj instanceof ApiQueryGeneratorBase ) {
                        $retval['generator'] = '';
+               }
 
                $allowedParams = $obj->getFinalParams();
-               if ( !is_array( $allowedParams ) )
+               if ( !is_array( $allowedParams ) ) {
                        return $retval;
-       
+               }
+
                $retval['parameters'] = array();
                $paramDesc = $obj->getFinalParamDescription();
-               foreach ( $allowedParams as $n => $p )
-               {
+               foreach ( $allowedParams as $n => $p ) {
                        $a = array( 'name' => $n );
-                       if ( isset( $paramDesc[$n] ) )
+                       if ( isset( $paramDesc[$n] ) ) {
                                $a['description'] = implode( "\n", (array)$paramDesc[$n] );
-                       if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] )
+                       }
+                       if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) {
                                $a['deprecated'] = '';
-                       if ( !is_array( $p ) )
-                       {
-                               if ( is_bool( $p ) )
-                               {
+                       }
+                       if ( !is_array( $p ) ) {
+                               if ( is_bool( $p ) ) {
                                        $a['type'] = 'bool';
                                        $a['default'] = ( $p ? 'true' : 'false' );
-                               }
-                               else if ( is_string( $p ) || is_null( $p ) )
-                               {
+                               } elseif ( is_string( $p ) || is_null( $p ) ) {
                                        $a['type'] = 'string';
                                        $a['default'] = strval( $p );
-                               }
-                               else if ( is_int( $p ) )
-                               {
+                               } elseif ( is_int( $p ) ) {
                                        $a['type'] = 'integer';
                                        $a['default'] = intval( $p );
                                }
@@ -140,42 +133,48 @@ class ApiParamInfo extends ApiBase {
                                continue;
                        }
 
-                       if ( isset( $p[ApiBase::PARAM_DFLT] ) )
+                       if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
                                $a['default'] = $p[ApiBase::PARAM_DFLT];
-                       if ( isset( $p[ApiBase::PARAM_ISMULTI] ) )
-                               if ( $p[ApiBase::PARAM_ISMULTI] )
-                               {
+                       }
+                       if ( isset( $p[ApiBase::PARAM_ISMULTI] ) ) {
+                               if ( $p[ApiBase::PARAM_ISMULTI] ) {
                                        $a['multi'] = '';
                                        $a['limit'] = $this->getMain()->canApiHighLimits() ?
                                                        ApiBase::LIMIT_SML2 :
                                                        ApiBase::LIMIT_SML1;
                                }
+                       }
 
-                       if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) )
-                               if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] )
+                       if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) {
+                               if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) {
                                        $a['allowsduplicates'] = '';
+                               }
+                       }
 
-                       if ( isset( $p[ApiBase::PARAM_TYPE] ) )
-                       {
+                       if ( isset( $p[ApiBase::PARAM_TYPE] ) ) {
                                $a['type'] = $p[ApiBase::PARAM_TYPE];
-                               if ( is_array( $a['type'] ) )
+                               if ( is_array( $a['type'] ) ) {
                                        $result->setIndexedTagName( $a['type'], 't' );
+                               }
                        }
-                       if ( isset( $p[ApiBase::PARAM_MAX] ) )
+                       if ( isset( $p[ApiBase::PARAM_MAX] ) ) {
                                $a['max'] = $p[ApiBase::PARAM_MAX];
-                       if ( isset( $p[ApiBase::PARAM_MAX2] ) )
+                       }
+                       if ( isset( $p[ApiBase::PARAM_MAX2] ) ) {
                                $a['highmax'] = $p[ApiBase::PARAM_MAX2];
-                       if ( isset( $p[ApiBase::PARAM_MIN] ) )
+                       }
+                       if ( isset( $p[ApiBase::PARAM_MIN] ) ) {
                                $a['min'] = $p[ApiBase::PARAM_MIN];
+                       }
                        $retval['parameters'][] = $a;
                }
                $result->setIndexedTagName( $retval['parameters'], 'param' );
-               
+
                // Errors
                $retval['errors'] = $this->parseErrors( $obj->getPossibleErrors() );
-               
+
                $result->setIndexedTagName( $retval['errors'], 'error' );
-               
+
                return $retval;
        }
 
@@ -184,12 +183,12 @@ class ApiParamInfo extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array (
+               return array(
                        'modules' => array(
-                               ApiBase :: PARAM_ISMULTI => true
+                               ApiBase::PARAM_ISMULTI => true
                        ),
                        'querymodules' => array(
-                               ApiBase :: PARAM_ISMULTI => true
+                               ApiBase::PARAM_ISMULTI => true
                        ),
                        'mainmodule' => false,
                        'pagesetmodule' => false,
@@ -197,7 +196,7 @@ class ApiParamInfo extends ApiBase {
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        'modules' => 'List of module names (value of the action= parameter)',
                        'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
                        'mainmodule' => 'Get information about the main (top-level) module as well',
@@ -210,7 +209,7 @@ class ApiParamInfo extends ApiBase {
        }
 
        protected function getExamples() {
-               return array (
+               return array(
                        'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
                );
        }
index f978ece..a943d34 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Dec 01, 2007
  *
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( "ApiBase.php" );
+       require_once( "ApiBase.php" );
 }
 
 /**
@@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiParse extends ApiBase {
 
        public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
+               parent::__construct( $main, $action );
        }
 
        public function execute() {
@@ -44,8 +44,9 @@ class ApiParse extends ApiBase {
                $title = $params['title'];
                $page = $params['page'];
                $oldid = $params['oldid'];
-               if ( !is_null( $page ) && ( !is_null( $text ) || $title != "API" ) )
-                       $this->dieUsage( "The page parameter cannot be used together with the text and title parameters", 'params' );
+               if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) {
+                       $this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' );
+               }
                $prop = array_flip( $params['prop'] );
                $revid = false;
 
@@ -56,26 +57,23 @@ class ApiParse extends ApiBase {
                $popts->setTidy( true );
                $popts->enableLimitReport();
                $redirValues = null;
-               if ( !is_null( $oldid ) || !is_null( $page ) )
-               {
-                       if ( !is_null( $oldid ) )
-                       {
+               if ( !is_null( $oldid ) || !is_null( $page ) ) {
+                       if ( !is_null( $oldid ) ) {
                                // Don't use the parser cache
                                $rev = Revision::newFromID( $oldid );
-                               if ( !$rev )
+                               if ( !$rev ) {
                                        $this->dieUsage( "There is no revision ID $oldid", 'missingrev' );
-                               if ( !$rev->userCan( Revision::DELETED_TEXT ) )
+                               }
+                               if ( !$rev->userCan( Revision::DELETED_TEXT ) ) {
                                        $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' );
+                               }
 
                                $text = $rev->getText( Revision::FOR_THIS_USER );
                                $titleObj = $rev->getTitle();
                                $wgTitle = $titleObj;
                                $p_result = $wgParser->parse( $text, $titleObj, $popts );
-                       }
-                       else
-                       {
-                               if ( $params['redirects'] )
-                               {
+                       } else {
+                               if ( $params['redirects'] ) {
                                        $req = new FauxRequest( array(
                                                'action' => 'query',
                                                'redirects' => '',
@@ -86,42 +84,45 @@ class ApiParse extends ApiBase {
                                        $data = $main->getResultData();
                                        $redirValues = @$data['query']['redirects'];
                                        $to = $page;
-                                       foreach ( (array)$redirValues as $r )
+                                       foreach ( (array)$redirValues as $r ) {
                                                $to = $r['to'];
-                               }
-                               else
+                                       }
+                               } else {
                                        $to = $page;
+                               }
                                $titleObj = Title::newFromText( $to );
-                               if ( !$titleObj )
+                               if ( !$titleObj ) {
                                        $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
+                               }
 
                                $articleObj = new Article( $titleObj );
-                               if ( isset( $prop['revid'] ) )
+                               if ( isset( $prop['revid'] ) ) {
                                        $oldid = $articleObj->getRevIdFetched();
+                               }
                                // Try the parser cache first
                                $p_result = false;
                                $pcache = ParserCache::singleton();
-                               if ( $wgEnableParserCache )
+                               if ( $wgEnableParserCache ) {
                                        $p_result = $pcache->get( $articleObj, $wgUser );
-                               if ( !$p_result )
-                               {
+                               }
+                               if ( !$p_result ) {
                                        $p_result = $wgParser->parse( $articleObj->getContent(), $titleObj, $popts );
-                                       
-                                       if ( $wgEnableParserCache )
+
+                                       if ( $wgEnableParserCache ) {
                                                $pcache->save( $p_result, $articleObj, $popts );
+                                       }
                                }
                        }
-               }
-               else
-               {
+               } else {
                        $titleObj = Title::newFromText( $title );
-                       if ( !$titleObj )
-                               $titleObj = Title::newFromText( "API" );
+                       if ( !$titleObj ) {
+                               $titleObj = Title::newFromText( 'API' );
+                       }
                        $wgTitle = $titleObj;
-                       if ( $params['pst'] || $params['onlypst'] )
+                       if ( $params['pst'] || $params['onlypst'] ) {
                                $text = $wgParser->preSaveTransform( $text, $titleObj, $wgUser, $popts );
-                       if ( $params['onlypst'] )
-                       {
+                       }
+                       if ( $params['onlypst'] ) {
                                // Build a result and bail out
                                $result_array['text'] = array();
                                $this->getResult()->setContent( $result_array['text'], $text );
@@ -134,50 +135,61 @@ class ApiParse extends ApiBase {
                // Return result
                $result = $this->getResult();
                $result_array = array();
-               if ( $params['redirects'] && !is_null( $redirValues ) )
+               if ( $params['redirects'] && !is_null( $redirValues ) ) {
                        $result_array['redirects'] = $redirValues;
-               
+               }
+
                if ( isset( $prop['text'] ) ) {
                        $result_array['text'] = array();
                        $result->setContent( $result_array['text'], $p_result->getText() );
                }
-               
+
                if ( !is_null( $params['summary'] ) ) {
                        $result_array['parsedsummary'] = array();
                        $result->setContent( $result_array['parsedsummary'], $wgUser->getSkin()->formatComment( $params['summary'], $titleObj ) );
                }
-               
-               if ( isset( $prop['langlinks'] ) )
+
+               if ( isset( $prop['langlinks'] ) ) {
                        $result_array['langlinks'] = $this->formatLangLinks( $p_result->getLanguageLinks() );
-               if ( isset( $prop['categories'] ) )
+               }
+               if ( isset( $prop['categories'] ) ) {
                        $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
-               if ( isset( $prop['links'] ) )
+               }
+               if ( isset( $prop['links'] ) ) {
                        $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
-               if ( isset( $prop['templates'] ) )
+               }
+               if ( isset( $prop['templates'] ) ) {
                        $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
-               if ( isset( $prop['images'] ) )
+               }
+               if ( isset( $prop['images'] ) ) {
                        $result_array['images'] = array_keys( $p_result->getImages() );
-               if ( isset( $prop['externallinks'] ) )
+               }
+               if ( isset( $prop['externallinks'] ) ) {
                        $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
-               if ( isset( $prop['sections'] ) )
+               }
+               if ( isset( $prop['sections'] ) ) {
                        $result_array['sections'] = $p_result->getSections();
-               if ( isset( $prop['displaytitle'] ) )
+               }
+               if ( isset( $prop['displaytitle'] ) ) {
                        $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
                                                        $p_result->getDisplayTitle() :
                                                        $titleObj->getPrefixedText();
-                       
-               if ( isset( $prop['headitems'] ) )
+               }
+
+               if ( isset( $prop['headitems'] ) ) {
                        $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );
-               
+               }
+
                if ( isset( $prop['headhtml'] ) ) {
                        $out = new OutputPage;
                        $out->addParserOutputNoText( $p_result );
                        $result_array['headhtml'] = array();
                        $result->setContent( $result_array['headhtml'], $out->headElement( $wgUser->getSkin() ) );
                }
-               
-               if ( !is_null( $oldid ) )
+
+               if ( !is_null( $oldid ) ) {
                        $result_array['revid'] = intval( $oldid );
+               }
 
                $result_mapping = array(
                        'redirects' => 'r',
@@ -224,8 +236,9 @@ class ApiParse extends ApiBase {
                                $entry = array();
                                $entry['ns'] = $ns;
                                $this->getResult()->setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
-                               if ( $id != 0 )
+                               if ( $id != 0 ) {
                                        $entry['exists'] = '';
+                               }
                                $result[] = $entry;
                        }
                }
@@ -245,15 +258,16 @@ class ApiParse extends ApiBase {
 
        private function setIndexedTagNames( &$array, $mapping ) {
                foreach ( $mapping as $key => $name ) {
-                       if ( isset( $array[$key] ) )
+                       if ( isset( $array[$key] ) ) {
                                $this->getResult()->setIndexedTagName( $array[$key], $name );
+                       }
                }
        }
 
        public function getAllowedParams() {
-               return array (
+               return array(
                        'title' => array(
-                               ApiBase :: PARAM_DFLT => 'API',
+                               ApiBase::PARAM_DFLT => 'API',
                        ),
                        'text' => null,
                        'summary' => null,
@@ -261,9 +275,9 @@ class ApiParse extends ApiBase {
                        'redirects' => false,
                        'oldid' => null,
                        'prop' => array(
-                               ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle',
-                               ApiBase :: PARAM_ISMULTI => true,
-                               ApiBase :: PARAM_TYPE => array(
+                               ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle',
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_TYPE => array(
                                        'text',
                                        'langlinks',
                                        'categories',
@@ -284,7 +298,7 @@ class ApiParse extends ApiBase {
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        'text' => 'Wikitext to parse',
                        'summary' => 'Summary to parse',
                        'redirects' => 'If the page parameter is set to a redirect, resolve it',
@@ -306,7 +320,7 @@ class ApiParse extends ApiBase {
        public function getDescription() {
                return 'This module parses wikitext and returns parser output';
        }
-       
+
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'code' => 'params', 'info' => 'The page parameter cannot be used together with the text and title parameters' ),
@@ -317,7 +331,7 @@ class ApiParse extends ApiBase {
        }
 
        protected function getExamples() {
-               return array (
+               return array(
                        'api.php?action=parse&text={{Project:Sandbox}}'
                );
        }
index 63ce0ce..5d14c00 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-/*
+/**
  * Created on Sep 2, 2008
  *
  * API for MediaWiki 1.14+
  *
- * Copyright (C) 2008 Soxred93 soxred93@gmail.com,
+ * Copyright © 2008 Soxred93 soxred93@gmail.com,
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiPatrol extends ApiBase {
 
        public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
+               parent::__construct( $main, $action );
        }
 
        /**
@@ -42,18 +42,21 @@ class ApiPatrol extends ApiBase {
         */
        public function execute() {
                $params = $this->extractRequestParams();
-               
-               if ( !isset( $params['rcid'] ) )
+
+               if ( !isset( $params['rcid'] ) ) {
                        $this->dieUsageMsg( array( 'missingparam', 'rcid' ) );
+               }
 
                $rc = RecentChange::newFromID( $params['rcid'] );
-               if ( !$rc instanceof RecentChange )
+               if ( !$rc instanceof RecentChange ) {
                        $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
+               }
                $retval = RecentChange::markPatrolled( $params['rcid'] );
-                       
-               if ( $retval )
+
+               if ( $retval ) {
                        $this->dieUsageMsg( reset( $retval ) );
-               
+               }
+
                $result = array( 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) );
                ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
                $this->getResult()->addValue( null, $this->getModuleName(), $result );
@@ -64,34 +67,34 @@ class ApiPatrol extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array (
+               return array(
                        'token' => null,
                        'rcid' => array(
-                               ApiBase :: PARAM_TYPE => 'integer'
+                               ApiBase::PARAM_TYPE => 'integer'
                        ),
                );
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        'token' => 'Patrol token obtained from list=recentchanges',
                        'rcid' => 'Recentchanges ID to patrol',
                );
        }
 
        public function getDescription() {
-               return array (
+               return array(
                        'Patrol a page or revision. '
                );
        }
-       
-    public function getPossibleErrors() {
+
+       public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'missingparam', 'rcid' ),
                        array( 'nosuchrcid', 'rcid' ),
-        ) );
+               ) );
        }
-       
+
        public function getTokenSalt() {
                return '';
        }
index a1aff82..3c9b423 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 
-/*
+/**
  * Created on Sep 1, 2007
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ( "ApiBase.php" );
+       require_once( "ApiBase.php" );
 }
 
 /**
@@ -33,7 +33,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiProtect extends ApiBase {
 
        public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
+               parent::__construct( $main, $action );
        }
 
        public function execute() {
@@ -41,60 +41,68 @@ class ApiProtect extends ApiBase {
                $params = $this->extractRequestParams();
 
                $titleObj = null;
-               if ( !isset( $params['title'] ) )
+               if ( !isset( $params['title'] ) ) {
                        $this->dieUsageMsg( array( 'missingparam', 'title' ) );
-               if ( empty( $params['protections'] ) )
+               }
+               if ( empty( $params['protections'] ) ) {
                        $this->dieUsageMsg( array( 'missingparam', 'protections' ) );
+               }
 
                $titleObj = Title::newFromText( $params['title'] );
-               if ( !$titleObj )
+               if ( !$titleObj ) {
                        $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+               }
 
                $errors = $titleObj->getUserPermissionsErrors( 'protect', $wgUser );
-               if ( $errors )
+               if ( $errors ) {
                        // We don't care about multiple errors, just report one of them
                        $this->dieUsageMsg( reset( $errors ) );
+               }
 
                $expiry = (array)$params['expiry'];
-               if ( count( $expiry ) != count( $params['protections'] ) )
-               {
-                       if ( count( $expiry ) == 1 )
+               if ( count( $expiry ) != count( $params['protections'] ) ) {
+                       if ( count( $expiry ) == 1 ) {
                                $expiry = array_fill( 0, count( $params['protections'] ), $expiry[0] );
-                       else
+                       } else {
                                $this->dieUsageMsg( array( 'toofewexpiries', count( $expiry ), count( $params['protections'] ) ) );
+                       }
                }
-               
+
                $restrictionTypes = $titleObj->getRestrictionTypes();
-                       
+
                $protections = array();
                $expiryarray = array();
                $resultProtections = array();
-               foreach ( $params['protections'] as $i => $prot )
-               {
+               foreach ( $params['protections'] as $i => $prot ) {
                        $p = explode( '=', $prot );
                        $protections[$p[0]] = ( $p[1] == 'all' ? '' : $p[1] );
 
-                       if ( $titleObj->exists() && $p[0] == 'create' )
+                       if ( $titleObj->exists() && $p[0] == 'create' ) {
                                $this->dieUsageMsg( array( 'create-titleexists' ) );
-                       if ( !$titleObj->exists() && $p[0] != 'create' )
+                       }
+                       if ( !$titleObj->exists() && $p[0] != 'create' ) {
                                $this->dieUsageMsg( array( 'missingtitle-createonly' ) );
+                       }
 
-                       if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' )
+                       if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' ) {
                                $this->dieUsageMsg( array( 'protect-invalidaction', $p[0] ) );
-                       if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' )
+                       }
+                       if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' ) {
                                $this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) );
+                       }
 
-                       if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) )
+                       if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) {
                                $expiryarray[$p[0]] = Block::infinity();
-                       else
-                       {
+                       } else {
                                $exp = strtotime( $expiry[$i] );
-                               if ( $exp < 0 || $exp == false )
+                               if ( $exp < 0 || $exp == false ) {
                                        $this->dieUsageMsg( array( 'invalidexpiry', $expiry[$i] ) );
+                               }
 
                                $exp = wfTimestamp( TS_MW, $exp );
-                               if ( $exp < wfTimestampNow() )
+                               if ( $exp < wfTimestampNow() ) {
                                        $this->dieUsageMsg( array( 'pastexpiry', $expiry[$i] ) );
+                               }
                                $expiryarray[$p[0]] = $exp;
                        }
                        $resultProtections[] = array( $p[0] => $protections[$p[0]],
@@ -105,19 +113,26 @@ class ApiProtect extends ApiBase {
 
                $cascade = $params['cascade'];
                $articleObj = new Article( $titleObj );
-               if ( $params['watch'] )
+               if ( $params['watch'] ) {
                        $articleObj->doWatch();
-               if ( $titleObj->exists() )
+               }
+               if ( $titleObj->exists() ) {
                        $ok = $articleObj->updateRestrictions( $protections, $params['reason'], $cascade, $expiryarray );
-               else
+               } else {
                        $ok = $titleObj->updateTitleProtection( $protections['create'], $params['reason'], $expiryarray['create'] );
-               if ( !$ok )
+               }
+               if ( !$ok ) {
                        // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime?
                        // Just throw an unknown error in this case, as it's very likely to be a race condition
                        $this->dieUsageMsg( array() );
-               $res = array( 'title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'] );
-               if ( $cascade )
+               }
+               $res = array(
+                       'title' => $titleObj->getPrefixedText(),
+                       'reason' => $params['reason']
+               );
+               if ( $cascade ) {
                        $res['cascade'] = '';
+               }
                $res['protections'] = $resultProtections;
                $this->getResult()->setIndexedTagName( $res['protections'], 'protection' );
                $this->getResult()->addValue( null, $this->getModuleName(), $res );
@@ -132,16 +147,16 @@ class ApiProtect extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array (
+               return array(
                        'title' => null,
                        'token' => null,
                        'protections' => array(
-                               ApiBase :: PARAM_ISMULTI => true
+                               ApiBase::PARAM_ISMULTI => true
                        ),
                        'expiry' => array(
-                               ApiBase :: PARAM_ISMULTI => true,
-                               ApiBase :: PARAM_ALLOW_DUPLICATES => true,
-                               ApiBase :: PARAM_DFLT => 'infinite',
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_ALLOW_DUPLICATES => true,
+                               ApiBase::PARAM_DFLT => 'infinite',
                        ),
                        'reason' => '',
                        'cascade' => false,
@@ -150,7 +165,7 @@ class ApiProtect extends ApiBase {
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        'title' => 'Title of the page you want to (un)protect.',
                        'token' => 'A protect token previously retrieved through prop=info',
                        'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)',
@@ -168,7 +183,7 @@ class ApiProtect extends ApiBase {
                        'Change the protection level of a page.'
                );
        }
-       
+
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'missingparam', 'title' ),
@@ -183,13 +198,13 @@ class ApiProtect extends ApiBase {
                        array( 'pastexpiry', 'expiry' ),
                ) );
        }
-       
+
        public function getTokenSalt() {
                return null;
        }
 
        protected function getExamples() {
-               return array (
+               return array(
                        'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000|never',
                        'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions'
                );