Documentation
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 801ae4c..cf06e5a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * API for MediaWiki 1.8+
+ *
  *
  * Created on Sep 4, 2006
  *
@@ -63,6 +63,8 @@ class ApiMain extends ApiBase {
                'feedwatchlist' => 'ApiFeedWatchlist',
                'help' => 'ApiHelp',
                'paraminfo' => 'ApiParamInfo',
+               'rsd' => 'ApiRsd',
+               'compare' => 'ApiComparePages',
 
                // Write modules
                'purge' => 'ApiPurge',
@@ -75,6 +77,7 @@ class ApiMain extends ApiBase {
                'move' => 'ApiMove',
                'edit' => 'ApiEditPage',
                'upload' => 'ApiUpload',
+               'filerevert' => 'ApiFileRevert',
                'emailuser' => 'ApiEmailUser',
                'watch' => 'ApiWatch',
                'patrol' => 'ApiPatrol',
@@ -122,7 +125,12 @@ class ApiMain extends ApiBase {
                )
        );
 
-       private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
+       /**
+        * @var ApiFormatBase
+        */
+       private $mPrinter;
+
+       private $mModules, $mModuleNames, $mFormats, $mFormatNames;
        private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
        private $mInternalMode, $mSquidMaxage, $mModule;
 
@@ -174,6 +182,7 @@ class ApiMain extends ApiBase {
 
        /**
         * Return true if the API was started by other PHP code using FauxRequest
+        * @return bool
         */
        public function isInternalMode() {
                return $this->mInternalMode;
@@ -198,6 +207,8 @@ class ApiMain extends ApiBase {
 
        /**
         * Get the API module object. Only works after executeAction()
+        *
+        * @return ApiBase
         */
        public function getModule() {
                return $this->mModule;
@@ -214,6 +225,8 @@ class ApiMain extends ApiBase {
 
        /**
         * Set how long the response should be cached.
+        *
+        * @param $maxage
         */
        public function setCacheMaxAge( $maxage ) {
                $this->setCacheControl( array(
@@ -267,7 +280,7 @@ class ApiMain extends ApiBase {
        }
 
        /**
-        * @deprecated Private caching is now the default, so there is usually no
+        * @deprecated since 1.17 Private caching is now the default, so there is usually no
         * need to call this function. If there is a need, you can use
         * $this->setCacheMode('private')
         */
@@ -295,7 +308,7 @@ class ApiMain extends ApiBase {
         * given URL must either always or never call this function; if it sometimes does and
         * sometimes doesn't, stuff will break.
         *
-        * @deprecated Use setCacheMode( 'anon-public-user-private' )
+        * @deprecated since 1.17 Use setCacheMode( 'anon-public-user-private' )
         */
        public function setVaryCookie() {
                $this->setCacheMode( 'anon-public-user-private' );
@@ -303,6 +316,10 @@ class ApiMain extends ApiBase {
 
        /**
         * Create an instance of an output formatter by its name
+        *
+        * @param $format string
+        *
+        * @return ApiFormatBase
         */
        public function createPrinterByName( $format ) {
                if ( !isset( $this->mFormats[$format] ) ) {
@@ -448,6 +465,8 @@ class ApiMain extends ApiBase {
        /**
         * Replace the result data with the information about an exception.
         * Returns the error code
+        * @param $e Exception
+        * @return string
         */
        protected function substituteResultWithError( $e ) {
                // Printer may not be initialized if the extractRequestParams() fails for the main module
@@ -465,9 +484,7 @@ class ApiMain extends ApiBase {
                }
 
                if ( $e instanceof UsageException ) {
-                       //
                        // User entered incorrect parameters - print usage screen
-                       //
                        $errMessage = $e->getMessageArray();
 
                        // Only print the help message when this is for the developer, not runtime
@@ -477,9 +494,7 @@ class ApiMain extends ApiBase {
 
                } else {
                        global $wgShowSQLErrors, $wgShowExceptionDetails;
-                       //
                        // Something is seriously wrong
-                       //
                        if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
                                $info = 'Database query error';
                        } else {
@@ -509,6 +524,7 @@ class ApiMain extends ApiBase {
 
        /**
         * Set up for the execution.
+        * @return array
         */
        protected function setupExecuteAction() {
                // First add the id to the top element
@@ -551,7 +567,7 @@ class ApiMain extends ApiBase {
                                $this->dieUsageMsg( array( 'missingparam', 'token' ) );
                        } else {
                                global $wgUser;
-                               if ( !$wgUser->matchEditToken( $moduleParams['token'], $salt ) ) {
+                               if ( !$wgUser->matchEditToken( $moduleParams['token'], $salt, $this->getMain()->getRequest() ) ) {
                                        $this->dieUsageMsg( array( 'sessionfailure' ) );
                                }
                        }
@@ -664,6 +680,8 @@ class ApiMain extends ApiBase {
 
        /**
         * Print results using the current printer
+        *
+        * @param $isError bool
         */
        protected function printResult( $isError ) {
                $this->getResult()->cleanUpUTF8();
@@ -685,12 +703,17 @@ class ApiMain extends ApiBase {
                $printer->profileOut();
        }
 
+       /**
+        * @return bool
+        */
        public function isReadMode() {
                return false;
        }
 
        /**
         * See ApiBase for description.
+        *
+        * @return array
         */
        public function getAllowedParams() {
                return array(
@@ -721,6 +744,8 @@ class ApiMain extends ApiBase {
 
        /**
         * See ApiBase for description.
+        *
+        * @return array
         */
        public function getParamDescription() {
                return array(
@@ -737,19 +762,21 @@ class ApiMain extends ApiBase {
 
        /**
         * See ApiBase for description.
+        *
+        * @return array
         */
        public function getDescription() {
                return array(
                        '',
                        '',
-                       '******************************************************************************************',
-                       '**                                                                                      **',
-                       '**              This is an auto-generated MediaWiki API documentation page              **',
-                       '**                                                                                      **',
-                       '**                            Documentation and Examples:                               **',
-                       '**                         http://www.mediawiki.org/wiki/API                            **',
-                       '**                                                                                      **',
-                       '******************************************************************************************',
+                       '**********************************************************************************************************',
+                       '**                                                                                                      **',
+                       '**                      This is an auto-generated MediaWiki API documentation page                      **',
+                       '**                                                                                                      **',
+                       '**                                    Documentation and Examples:                                       **',
+                       '**                                 http://www.mediawiki.org/wiki/API                                    **',
+                       '**                                                                                                      **',
+                       '**********************************************************************************************************',
                        '',
                        'Status:                All features shown on this page should be working, but the API',
                        '                       is still in active development, and  may change at any time.',
@@ -767,6 +794,9 @@ class ApiMain extends ApiBase {
                );
        }
 
+       /**
+        * @return array
+        */
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'readonlytext' ),
@@ -779,11 +809,12 @@ class ApiMain extends ApiBase {
 
        /**
         * Returns an array of strings with credits for the API
+        * @return array
         */
        protected function getCredits() {
                return array(
                        'API developers:',
-                       '    Roan Kattouw <Firstname>.<Lastname>@home.nl (lead developer Sep 2007-present)',
+                       '    Roan Kattouw <Firstname>.<Lastname>@gmail.com (lead developer Sep 2007-present)',
                        '    Victor Vasiliev - vasilvv at gee mail dot com',
                        '    Bryan Tong Minh - bryan . tongminh @ gmail . com',
                        '    Sam Reed - sam @ reedyboy . net',
@@ -793,8 +824,11 @@ class ApiMain extends ApiBase {
                        'or file a bug report at http://bugzilla.wikimedia.org/'
                );
        }
+
        /**
         * Sets whether the pretty-printer should format *bold* and $italics$
+        *
+        * @param $help bool
         */
        public function setHelp( $help = true ) {
                $this->mPrinter->setHelp( $help );
@@ -802,36 +836,41 @@ class ApiMain extends ApiBase {
 
        /**
         * Override the parent to generate help messages for all available modules.
+        *
+        * @return string
         */
        public function makeHelpMsg() {
-               global $wgMemc, $wgAPICacheHelp, $wgAPICacheHelpTimeout;
+               global $wgMemc, $wgAPICacheHelpTimeout;
                $this->setHelp();
                // Get help text from cache if present
                $key = wfMemcKey( 'apihelp', $this->getModuleName(),
                        SpecialVersion::getVersion( 'nodb' ) .
                        $this->getMain()->getShowVersions() );
-               if ( $wgAPICacheHelp ) {
+               if ( $wgAPICacheHelpTimeout > 0 ) {
                        $cached = $wgMemc->get( $key );
                        if ( $cached ) {
                                return $cached;
                        }
                }
                $retval = $this->reallyMakeHelpMsg();
-               if ( $wgAPICacheHelp ) {
+               if ( $wgAPICacheHelpTimeout > 0 ) {
                        $wgMemc->set( $key, $retval, $wgAPICacheHelpTimeout );
                }
                return $retval;
        }
 
+       /**
+        * @return mixed|string
+        */
        public function reallyMakeHelpMsg() {
                $this->setHelp();
 
                // Use parent to make default message for the main module
                $msg = parent::makeHelpMsg();
 
-               $astriks = str_repeat( '*** ', 10 );
+               $astriks = str_repeat( '*** ', 14 );
                $msg .= "\n\n$astriks Modules  $astriks\n\n";
-               foreach ( $this->mModules as $moduleName => $unused ) {
+               foreach ( array_keys( $this->mModules ) as $moduleName ) {
                        $module = new $this->mModules[$moduleName] ( $this, $moduleName );
                        $msg .= self::makeHelpMsgHeader( $module, 'action' );
                        $msg2 = $module->makeHelpMsg();
@@ -850,7 +889,7 @@ class ApiMain extends ApiBase {
                }
 
                $msg .= "\n$astriks Formats  $astriks\n\n";
-               foreach ( $this->mFormats as $formatName => $unused ) {
+               foreach ( array_keys( $this->mFormats ) as $formatName ) {
                        $module = $this->createPrinterByName( $formatName );
                        $msg .= self::makeHelpMsgHeader( $module, 'format' );
                        $msg2 = $module->makeHelpMsg();
@@ -865,6 +904,11 @@ class ApiMain extends ApiBase {
                return $msg;
        }
 
+       /**
+        * @param $module ApiBase
+        * @param $paramName String What type of request is this? e.g. action, query, list, prop, meta, format
+        * @return string
+        */
        public static function makeHelpMsgHeader( $module, $paramName ) {
                $modulePrefix = $module->getModulePrefix();
                if ( strval( $modulePrefix ) !== '' ) {
@@ -874,36 +918,8 @@ class ApiMain extends ApiBase {
                return "* $paramName={$module->getModuleName()} $modulePrefix*";
        }
 
-       private $mIsBot = null;
-       private $mIsSysop = null;
        private $mCanApiHighLimits = null;
 
-       /**
-        * Returns true if the currently logged in user is a bot, false otherwise
-        * OBSOLETE, use canApiHighLimits() instead
-        */
-       public function isBot() {
-               if ( !isset( $this->mIsBot ) ) {
-                       global $wgUser;
-                       $this->mIsBot = $wgUser->isAllowed( 'bot' );
-               }
-               return $this->mIsBot;
-       }
-
-       /**
-        * Similar to isBot(), this method returns true if the logged in user is
-        * a sysop, and false if not.
-        * OBSOLETE, use canApiHighLimits() instead
-        */
-       public function isSysop() {
-               if ( !isset( $this->mIsSysop ) ) {
-                       global $wgUser;
-                       $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups() );
-               }
-
-               return $this->mIsSysop;
-       }
-
        /**
         * Check whether the current user is allowed to use high limits
         * @return bool
@@ -928,9 +944,11 @@ class ApiMain extends ApiBase {
        /**
         * Returns the version information of this file, plus it includes
         * the versions for all files that are not callable proper API modules
+        *
+        * @return array
         */
        public function getVersion() {
-               $vers = array ();
+               $vers = array();
                $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n    http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
                $vers[] = __CLASS__ . ': $Id$';
                $vers[] = ApiBase::getBaseVersion();
@@ -955,8 +973,8 @@ 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.
         *
-        * @param $fmtName The identifier for this format.
-        * @param $fmtClass The class implementing this format.
+        * @param $fmtName string The identifier for this format.
+        * @param $fmtClass ApiFormatBase The class implementing this format.
         */
        protected function addFormat( $fmtName, $fmtClass ) {
                $this->mFormats[$fmtName] = $fmtClass;
@@ -964,10 +982,21 @@ class ApiMain extends ApiBase {
 
        /**
         * Get the array mapping module names to class names
+        * @return array
         */
        function getModules() {
                return $this->mModules;
        }
+
+       /**
+        * Returns the list of supported formats in form ( 'format' => 'ClassName' )
+        *
+        * @since 1.18
+        * @return array
+        */
+       public function getFormats() {
+               return $this->mFormats;
+       }
 }
 
 /**