merging latest master
[lhc/web/wiklou.git] / includes / api / ApiQuery.php
index 55b00af..7823e2f 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on Sep 7, 2006
  *
- * Copyright © 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
@@ -64,8 +64,8 @@ class ApiQuery extends ApiBase {
        );
 
        private $mQueryListModules = array(
-               'allimages' => 'ApiQueryAllimages',
-               'allpages' => 'ApiQueryAllpages',
+               'allimages' => 'ApiQueryAllImages',
+               'allpages' => 'ApiQueryAllPages',
                'alllinks' => 'ApiQueryAllLinks',
                'allcategories' => 'ApiQueryAllCategories',
                'allusers' => 'ApiQueryAllUsers',
@@ -95,12 +95,18 @@ class ApiQuery extends ApiBase {
        private $mQueryMetaModules = array(
                'siteinfo' => 'ApiQuerySiteinfo',
                'userinfo' => 'ApiQueryUserInfo',
-               'allmessages' => 'ApiQueryAllmessages',
+               'allmessages' => 'ApiQueryAllMessages',
        );
 
        private $mSlaveDB = null;
        private $mNamedDB = array();
 
+       protected $mAllowedGenerators = array();
+
+       /**
+        * @param $main ApiMain
+        * @param $action string
+        */
        public function __construct( $main, $action ) {
                parent::__construct( $main, $action );
 
@@ -114,9 +120,8 @@ class ApiQuery extends ApiBase {
                $this->mListModuleNames = array_keys( $this->mQueryListModules );
                $this->mMetaModuleNames = array_keys( $this->mQueryMetaModules );
 
-               // Allow the entire list of modules at first,
-               // but during module instantiation check if it can be used as a generator.
-               $this->mAllowedGenerators = array_merge( $this->mListModuleNames, $this->mPropModuleNames );
+               $this->makeGeneratorList( $this->mQueryPropModules );
+               $this->makeGeneratorList( $this->mQueryListModules );
        }
 
        /**
@@ -134,7 +139,7 @@ class ApiQuery extends ApiBase {
 
        /**
         * Gets a default slave database connection object
-        * @return Database
+        * @return DatabaseBase
         */
        public function getDB() {
                if ( !isset( $this->mSlaveDB ) ) {
@@ -153,7 +158,7 @@ class ApiQuery extends ApiBase {
         * @param $name string Name to assign to the database connection
         * @param $db int One of the DB_* constants
         * @param $groups array Query groups
-        * @return Database
+        * @return DatabaseBase
         */
        public function getNamedDB( $name, $db, $groups ) {
                if ( !array_key_exists( $name, $this->mNamedDB ) ) {
@@ -201,6 +206,9 @@ class ApiQuery extends ApiBase {
                return null;
        }
 
+       /**
+        * @return ApiFormatRaw|null
+        */
        public function getCustomPrinter() {
                // If &exportnowrap is set, use the raw formatter
                if ( $this->getParameter( 'export' ) &&
@@ -257,6 +265,9 @@ class ApiQuery extends ApiBase {
                $this->outputGeneralPageInfo();
 
                // Execute all requested modules.
+               /**
+                * @var $module ApiQueryBase
+                */
                foreach ( $modules as $module ) {
                        $params = $module->extractRequestParams();
                        $cacheMode = $this->mergeCacheMode(
@@ -302,6 +313,9 @@ class ApiQuery extends ApiBase {
         */
        private function addCustomFldsToPageSet( $modules, $pageSet ) {
                // Query all requested modules.
+               /**
+                * @var $module ApiQueryBase
+                */
                foreach ( $modules as $module ) {
                        $module->requestExtraData( $pageSet );
                }
@@ -383,6 +397,9 @@ class ApiQuery extends ApiBase {
 
                // Show redirect information
                $redirValues = array();
+               /**
+                * @var $titleTo Title
+                */
                foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleTo ) {
                        $r = array(
                                'from' => strval( $titleStrFrom ),
@@ -482,7 +499,7 @@ class ApiQuery extends ApiBase {
                $titles = $pageSet->getGoodTitles();
                if ( count( $titles ) ) {
                        foreach ( $titles as $title ) {
-                               if ( $title->userCanRead() ) {
+                               if ( $title->userCan( 'read' ) ) {
                                        $exportTitles[] = $title;
                                }
                        }
@@ -601,7 +618,6 @@ class ApiQuery extends ApiBase {
                // Make sure the internal object is empty
                // (just in case a sub-module decides to optimize during instantiation)
                $this->mPageSet = null;
-               $this->mAllowedGenerators = array(); // Will be repopulated
 
                $querySeparator = str_repeat( '--- ', 12 );
                $moduleSeparator = str_repeat( '*** ', 14 );
@@ -613,8 +629,6 @@ class ApiQuery extends ApiBase {
                $msg .= $this->makeHelpMsgHelper( $this->mQueryMetaModules, 'meta' );
                $msg .= "\n\n$moduleSeparator Modules: continuation  $moduleSeparator\n\n";
 
-               // Perform the base call last because the $this->mAllowedGenerators
-               // will be updated inside makeHelpMsgHelper()
                // Use parent to make default message for the query module
                $msg = parent::makeHelpMsg() . $msg;
 
@@ -631,6 +645,9 @@ class ApiQuery extends ApiBase {
                $moduleDescriptions = array();
 
                foreach ( $moduleList as $moduleName => $moduleClass ) {
+                       /**
+                        * @var $module ApiQueryBase
+                        */
                        $module = new $moduleClass( $this, $moduleName, null );
 
                        $msg = ApiMain::makeHelpMsgHeader( $module, $paramName );
@@ -639,7 +656,6 @@ class ApiQuery extends ApiBase {
                                $msg .= $msg2;
                        }
                        if ( $module instanceof ApiQueryGeneratorBase ) {
-                               $this->mAllowedGenerators[] = $moduleName;
                                $msg .= "Generator:\n  This module may be used as a generator\n";
                        }
                        $moduleDescriptions[] = $msg;
@@ -648,6 +664,19 @@ class ApiQuery extends ApiBase {
                return implode( "\n", $moduleDescriptions );
        }
 
+       /**
+        * Adds any classes that are a subclass of ApiQueryGeneratorBase
+        * to the allowed generator list
+        * @param $moduleList array()
+        */
+       private function makeGeneratorList( $moduleList ) {
+               foreach( $moduleList as  $moduleName => $moduleClass ) {
+                       if ( is_subclass_of( $moduleClass, 'ApiQueryGeneratorBase'  ) ) {
+                               $this->mAllowedGenerators[] = $moduleName;
+                       }
+               }
+       }
+
        /**
         * Override to add extra parameters from PageSet
         * @return string
@@ -670,7 +699,7 @@ class ApiQuery extends ApiBase {
                                        'NOTE: generator parameter names must be prefixed with a \'g\', see examples' ),
                        'redirects' => 'Automatically resolve redirects',
                        'converttitles' => array( "Convert titles to other variants if necessary. Only works if the wiki's content language supports variant conversion.",
-                                       'Languages that support variant conversion include kk, ku, gan, tg, sr, zh' ),
+                                       'Languages that support variant conversion include ' . implode( ', ', LanguageConverter::$languagesWithVariants ) ),
                        'indexpageids' => 'Include an additional pageids section listing all returned page IDs',
                        'export' => 'Export the current revisions of all given or generated pages',
                        'exportnowrap' => 'Return the export XML without wrapping it in an XML result (same format as Special:Export). Can only be used with export',
@@ -701,9 +730,9 @@ class ApiQuery extends ApiBase {
 
        public function getHelpUrls() {
                return array(
-                       'http://www.mediawiki.org/wiki/API:Meta',
-                       'http://www.mediawiki.org/wiki/API:Properties',
-                       'http://www.mediawiki.org/wiki/API:Lists',
+                       'https://www.mediawiki.org/wiki/API:Meta',
+                       'https://www.mediawiki.org/wiki/API:Properties',
+                       'https://www.mediawiki.org/wiki/API:Lists',
                );
        }