2006-10-01 04:38:31 +00:00
|
|
|
<?php
|
2010-02-24 13:34:11 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2006-10-01 04:38:31 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Sep 7, 2006
|
|
|
|
|
*
|
2010-02-24 13:34:11 +00:00
|
|
|
* Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
|
2006-10-01 04:38:31 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-10-01 04:38:31 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2006-10-01 04:38:31 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2006-10-01 04:38:31 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
2010-02-24 13:34:11 +00:00
|
|
|
require_once( 'ApiBase.php' );
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
2009-02-13 14:13:03 +00:00
|
|
|
* This is the main query class. It behaves similar to ApiMain: based on the
|
|
|
|
|
* parameters given, it will create a list of titles to work on (an ApiPageSet
|
|
|
|
|
* object), instantiate and execute various property/list/meta modules, and
|
|
|
|
|
* assemble all resulting data into a single ApiResult object.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
2009-02-13 14:13:03 +00:00
|
|
|
* In generator mode, a generator will be executed first to populate a second
|
|
|
|
|
* ApiPageSet object, and that object will be used for all subsequent modules.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
2006-10-01 04:38:31 +00:00
|
|
|
class ApiQuery extends ApiBase {
|
|
|
|
|
|
2006-10-01 20:17:16 +00:00
|
|
|
private $mPropModuleNames, $mListModuleNames, $mMetaModuleNames;
|
2010-12-23 20:00:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var ApiPageSet
|
|
|
|
|
*/
|
2006-10-01 20:17:16 +00:00
|
|
|
private $mPageSet;
|
2010-12-23 20:00:02 +00:00
|
|
|
|
2010-10-06 21:18:55 +00:00
|
|
|
private $params, $redirects, $convertTitles;
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-02-24 13:34:11 +00:00
|
|
|
private $mQueryPropModules = array(
|
2006-10-01 04:38:31 +00:00
|
|
|
'info' => 'ApiQueryInfo',
|
2007-05-14 05:28:06 +00:00
|
|
|
'revisions' => 'ApiQueryRevisions',
|
|
|
|
|
'links' => 'ApiQueryLinks',
|
2010-05-14 20:54:55 +00:00
|
|
|
'iwlinks' => 'ApiQueryIWLinks',
|
2007-05-14 05:28:06 +00:00
|
|
|
'langlinks' => 'ApiQueryLangLinks',
|
|
|
|
|
'images' => 'ApiQueryImages',
|
2007-07-07 03:05:09 +00:00
|
|
|
'imageinfo' => 'ApiQueryImageInfo',
|
2010-11-16 06:57:46 +00:00
|
|
|
'stashimageinfo' => 'ApiQueryStashImageInfo',
|
2007-05-14 05:28:06 +00:00
|
|
|
'templates' => 'ApiQueryLinks',
|
2007-05-14 06:21:49 +00:00
|
|
|
'categories' => 'ApiQueryCategories',
|
2007-05-14 07:04:13 +00:00
|
|
|
'extlinks' => 'ApiQueryExternalLinks',
|
2008-04-26 15:30:27 +00:00
|
|
|
'categoryinfo' => 'ApiQueryCategoryInfo',
|
2008-09-27 11:42:28 +00:00
|
|
|
'duplicatefiles' => 'ApiQueryDuplicateFiles',
|
2010-08-07 18:50:23 +00:00
|
|
|
'pageprops' => 'ApiQueryPageProps',
|
2006-10-01 04:38:31 +00:00
|
|
|
);
|
|
|
|
|
|
2010-02-24 13:34:11 +00:00
|
|
|
private $mQueryListModules = array(
|
2008-03-17 08:25:22 +00:00
|
|
|
'allimages' => 'ApiQueryAllimages',
|
2006-10-13 06:13:13 +00:00
|
|
|
'allpages' => 'ApiQueryAllpages',
|
2007-07-08 03:35:37 +00:00
|
|
|
'alllinks' => 'ApiQueryAllLinks',
|
2007-12-10 15:55:12 +00:00
|
|
|
'allcategories' => 'ApiQueryAllCategories',
|
2007-07-08 07:50:56 +00:00
|
|
|
'allusers' => 'ApiQueryAllUsers',
|
2006-10-30 00:18:05 +00:00
|
|
|
'backlinks' => 'ApiQueryBacklinks',
|
2007-12-02 14:24:07 +00:00
|
|
|
'blocks' => 'ApiQueryBlocks',
|
2007-06-16 00:39:01 +00:00
|
|
|
'categorymembers' => 'ApiQueryCategoryMembers',
|
2007-12-02 14:24:07 +00:00
|
|
|
'deletedrevs' => 'ApiQueryDeletedrevs',
|
2006-10-30 00:18:05 +00:00
|
|
|
'embeddedin' => 'ApiQueryBacklinks',
|
2010-05-10 22:41:16 +00:00
|
|
|
'filearchive' => 'ApiQueryFilearchive',
|
2007-05-14 05:28:06 +00:00
|
|
|
'imageusage' => 'ApiQueryBacklinks',
|
2010-05-25 19:50:20 +00:00
|
|
|
'iwbacklinks' => 'ApiQueryIWBacklinks',
|
2007-06-16 00:39:01 +00:00
|
|
|
'logevents' => 'ApiQueryLogEvents',
|
|
|
|
|
'recentchanges' => 'ApiQueryRecentChanges',
|
2007-07-30 08:09:15 +00:00
|
|
|
'search' => 'ApiQuerySearch',
|
2009-11-01 10:42:41 +00:00
|
|
|
'tags' => 'ApiQueryTags',
|
2007-06-16 00:39:01 +00:00
|
|
|
'usercontribs' => 'ApiQueryContributions',
|
|
|
|
|
'watchlist' => 'ApiQueryWatchlist',
|
2008-10-04 13:33:44 +00:00
|
|
|
'watchlistraw' => 'ApiQueryWatchlistRaw',
|
2007-07-07 09:35:05 +00:00
|
|
|
'exturlusage' => 'ApiQueryExtLinksUsage',
|
2008-01-27 20:28:36 +00:00
|
|
|
'users' => 'ApiQueryUsers',
|
2008-01-28 13:56:20 +00:00
|
|
|
'random' => 'ApiQueryRandom',
|
2009-02-13 21:34:46 +00:00
|
|
|
'protectedtitles' => 'ApiQueryProtectedTitles',
|
2010-12-22 20:35:37 +00:00
|
|
|
'querypage' => 'ApiQueryQueryPage',
|
2007-07-07 03:05:09 +00:00
|
|
|
);
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-02-24 13:34:11 +00:00
|
|
|
private $mQueryMetaModules = array(
|
2007-07-07 03:05:09 +00:00
|
|
|
'siteinfo' => 'ApiQuerySiteinfo',
|
2007-07-31 17:53:37 +00:00
|
|
|
'userinfo' => 'ApiQueryUserInfo',
|
2007-12-01 17:04:13 +00:00
|
|
|
'allmessages' => 'ApiQueryAllmessages',
|
2007-07-07 03:05:09 +00:00
|
|
|
);
|
2006-10-01 20:17:16 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
private $mSlaveDB = null;
|
2007-05-15 02:16:48 +00:00
|
|
|
private $mNamedDB = array();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $action ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
parent::__construct( $main, $action );
|
2007-05-15 03:35:32 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
// Allow custom modules to be added in LocalSettings.php
|
2008-09-25 20:47:47 +00:00
|
|
|
global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules;
|
2010-02-24 13:34:11 +00:00
|
|
|
self::appendUserModules( $this->mQueryPropModules, $wgAPIPropModules );
|
|
|
|
|
self::appendUserModules( $this->mQueryListModules, $wgAPIListModules );
|
|
|
|
|
self::appendUserModules( $this->mQueryMetaModules, $wgAPIMetaModules );
|
2007-05-15 03:35:32 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mPropModuleNames = array_keys( $this->mQueryPropModules );
|
|
|
|
|
$this->mListModuleNames = array_keys( $this->mQueryListModules );
|
|
|
|
|
$this->mMetaModuleNames = array_keys( $this->mQueryMetaModules );
|
2006-10-01 04:38:31 +00:00
|
|
|
|
|
|
|
|
// Allow the entire list of modules at first,
|
|
|
|
|
// but during module instantiation check if it can be used as a generator.
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mAllowedGenerators = array_merge( $this->mListModuleNames, $this->mPropModuleNames );
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-06 04:41:35 +00:00
|
|
|
/**
|
|
|
|
|
* Helper function to append any add-in modules to the list
|
2009-02-13 14:13:03 +00:00
|
|
|
* @param $modules array Module array
|
|
|
|
|
* @param $newModules array Module array to add to $modules
|
2007-06-06 04:41:35 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private static function appendUserModules( &$modules, $newModules ) {
|
|
|
|
|
if ( is_array( $newModules ) ) {
|
|
|
|
|
foreach ( $newModules as $moduleName => $moduleClass ) {
|
2007-05-21 05:25:36 +00:00
|
|
|
$modules[$moduleName] = $moduleClass;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-06 04:41:35 +00:00
|
|
|
/**
|
|
|
|
|
* Gets a default slave database connection object
|
2009-02-13 14:13:03 +00:00
|
|
|
* @return Database
|
2007-06-06 04:41:35 +00:00
|
|
|
*/
|
2007-01-22 23:50:42 +00:00
|
|
|
public function getDB() {
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !isset( $this->mSlaveDB ) ) {
|
2006-10-25 03:54:56 +00:00
|
|
|
$this->profileDBIn();
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mSlaveDB = wfGetDB( DB_SLAVE, 'api' );
|
2006-10-25 03:54:56 +00:00
|
|
|
$this->profileDBOut();
|
|
|
|
|
}
|
2006-10-01 04:38:31 +00:00
|
|
|
return $this->mSlaveDB;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-15 02:16:48 +00:00
|
|
|
/**
|
|
|
|
|
* Get the query database connection with the given name.
|
2008-04-14 07:45:50 +00:00
|
|
|
* If no such connection has been requested before, it will be created.
|
|
|
|
|
* Subsequent calls with the same $name will return the same connection
|
2009-02-13 14:13:03 +00:00
|
|
|
* as the first, regardless of the values of $db and $groups
|
|
|
|
|
* @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
|
2007-05-15 02:16:48 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function getNamedDB( $name, $db, $groups ) {
|
|
|
|
|
if ( !array_key_exists( $name, $this->mNamedDB ) ) {
|
2007-05-15 02:16:48 +00:00
|
|
|
$this->profileDBIn();
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mNamedDB[$name] = wfGetDB( $db, $groups );
|
2007-05-15 02:16:48 +00:00
|
|
|
$this->profileDBOut();
|
|
|
|
|
}
|
|
|
|
|
return $this->mNamedDB[$name];
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-06 04:41:35 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the set of pages the user has requested (or generated)
|
2009-02-13 14:13:03 +00:00
|
|
|
* @return ApiPageSet
|
2007-06-06 04:41:35 +00:00
|
|
|
*/
|
2006-10-01 20:17:16 +00:00
|
|
|
public function getPageSet() {
|
|
|
|
|
return $this->mPageSet;
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-01-23 18:40:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get the array mapping module names to class names
|
2009-02-13 14:13:03 +00:00
|
|
|
* @return array(modulename => classname)
|
2008-01-23 18:40:40 +00:00
|
|
|
*/
|
|
|
|
|
function getModules() {
|
2010-01-11 15:55:52 +00:00
|
|
|
return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules );
|
2008-01-23 18:40:40 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-05-08 11:45:41 +00:00
|
|
|
/**
|
|
|
|
|
* Get whether the specified module is a prop, list or a meta query module
|
|
|
|
|
* @param $moduleName string Name of the module to find type for
|
|
|
|
|
* @return mixed string or null
|
|
|
|
|
*/
|
|
|
|
|
function getModuleType( $moduleName ) {
|
|
|
|
|
if ( array_key_exists ( $moduleName, $this->mQueryPropModules ) ) {
|
|
|
|
|
return 'prop';
|
|
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-05-08 11:45:41 +00:00
|
|
|
if ( array_key_exists ( $moduleName, $this->mQueryListModules ) ) {
|
|
|
|
|
return 'list';
|
|
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-05-08 11:45:41 +00:00
|
|
|
if ( array_key_exists ( $moduleName, $this->mQueryMetaModules ) ) {
|
|
|
|
|
return 'meta';
|
|
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-05-08 11:45:41 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2009-02-02 20:07:33 +00:00
|
|
|
public function getCustomPrinter() {
|
|
|
|
|
// If &exportnowrap is set, use the raw formatter
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->getParameter( 'export' ) &&
|
|
|
|
|
$this->getParameter( 'exportnowrap' ) )
|
2010-02-24 13:34:11 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
return new ApiFormatRaw( $this->getMain(),
|
|
|
|
|
$this->getMain()->createPrinterByName( 'xml' ) );
|
2010-02-24 13:34:11 +00:00
|
|
|
} else {
|
2009-02-02 20:07:33 +00:00
|
|
|
return null;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2009-02-02 20:07:33 +00:00
|
|
|
}
|
2006-10-01 04:38:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query execution happens in the following steps:
|
|
|
|
|
* #1 Create a PageSet object with any pages requested by the user
|
2009-02-13 14:13:03 +00:00
|
|
|
* #2 If using a generator, execute it to get a new ApiPageSet object
|
2008-04-14 07:45:50 +00:00
|
|
|
* #3 Instantiate all requested modules.
|
2006-10-01 04:38:31 +00:00
|
|
|
* This way the PageSet object will know what shared data is required,
|
2008-04-14 07:45:50 +00:00
|
|
|
* and minimize DB calls.
|
2006-10-01 04:38:31 +00:00
|
|
|
* #4 Output all normalization and redirect resolution information
|
|
|
|
|
* #5 Execute all requested modules
|
|
|
|
|
*/
|
|
|
|
|
public function execute() {
|
2007-05-21 05:25:36 +00:00
|
|
|
$this->params = $this->extractRequestParams();
|
2007-05-28 08:06:40 +00:00
|
|
|
$this->redirects = $this->params['redirects'];
|
2010-07-10 11:53:22 +00:00
|
|
|
$this->convertTitles = $this->params['converttitles'];
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
// Create PageSet
|
2010-07-10 11:53:22 +00:00
|
|
|
$this->mPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2007-05-21 05:25:36 +00:00
|
|
|
// Instantiate requested modules
|
2010-02-24 13:34:11 +00:00
|
|
|
$modules = array();
|
2010-07-21 10:30:02 +00:00
|
|
|
$this->instantiateModules( $modules, 'prop', $this->mQueryPropModules );
|
|
|
|
|
$this->instantiateModules( $modules, 'list', $this->mQueryListModules );
|
|
|
|
|
$this->instantiateModules( $modules, 'meta', $this->mQueryMetaModules );
|
2006-10-01 20:17:16 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
$cacheMode = 'public';
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
// If given, execute generator to substitute user supplied data with generated data.
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( isset( $this->params['generator'] ) ) {
|
2010-07-23 07:17:56 +00:00
|
|
|
$generator = $this->newGenerator( $this->params['generator'] );
|
|
|
|
|
$params = $generator->extractRequestParams();
|
2010-07-23 07:33:40 +00:00
|
|
|
$cacheMode = $this->mergeCacheMode( $cacheMode,
|
2010-07-23 07:17:56 +00:00
|
|
|
$generator->getCacheMode( $params ) );
|
|
|
|
|
$this->executeGeneratorModule( $generator, $modules );
|
2007-06-03 17:22:09 +00:00
|
|
|
} else {
|
|
|
|
|
// Append custom fields and populate page/revision information
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addCustomFldsToPageSet( $modules, $this->mPageSet );
|
2007-06-03 17:22:09 +00:00
|
|
|
$this->mPageSet->execute();
|
|
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
|
2006-10-03 05:41:55 +00:00
|
|
|
// Record page information (title, namespace, if exists, etc)
|
2006-10-01 20:17:16 +00:00
|
|
|
$this->outputGeneralPageInfo();
|
|
|
|
|
|
|
|
|
|
// Execute all requested modules.
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $modules as $module ) {
|
2010-07-23 07:17:56 +00:00
|
|
|
$params = $module->extractRequestParams();
|
2010-07-23 07:33:40 +00:00
|
|
|
$cacheMode = $this->mergeCacheMode(
|
2010-07-23 07:17:56 +00:00
|
|
|
$cacheMode, $module->getCacheMode( $params ) );
|
2006-10-01 20:17:16 +00:00
|
|
|
$module->profileIn();
|
|
|
|
|
$module->execute();
|
2010-01-11 15:55:52 +00:00
|
|
|
wfRunHooks( 'APIQueryAfterExecute', array( &$module ) );
|
2006-10-01 20:17:16 +00:00
|
|
|
$module->profileOut();
|
|
|
|
|
}
|
2010-07-23 07:17:56 +00:00
|
|
|
|
|
|
|
|
// Set the cache mode
|
|
|
|
|
$this->getMain()->setCacheMode( $cacheMode );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update a cache mode string, applying the cache mode of a new module to it.
|
2010-07-23 07:33:40 +00:00
|
|
|
* The cache mode may increase in the level of privacy, but public modules
|
2010-07-23 07:17:56 +00:00
|
|
|
* added to private data do not decrease the level of privacy.
|
|
|
|
|
*/
|
|
|
|
|
protected function mergeCacheMode( $cacheMode, $modCacheMode ) {
|
|
|
|
|
if ( $modCacheMode === 'anon-public-user-private' ) {
|
|
|
|
|
if ( $cacheMode !== 'private' ) {
|
|
|
|
|
$cacheMode = 'anon-public-user-private';
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $modCacheMode === 'public' ) {
|
|
|
|
|
// do nothing, if it's public already it will stay public
|
|
|
|
|
} else { // private
|
|
|
|
|
$cacheMode = 'private';
|
|
|
|
|
}
|
|
|
|
|
return $cacheMode;
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-06-03 17:22:09 +00:00
|
|
|
/**
|
|
|
|
|
* Query modules may optimize data requests through the $this->getPageSet() object
|
|
|
|
|
* by adding extra fields from the page table.
|
2008-04-14 07:45:50 +00:00
|
|
|
* This function will gather all the extra request fields from the modules.
|
2009-02-13 14:13:03 +00:00
|
|
|
* @param $modules array of module objects
|
|
|
|
|
* @param $pageSet ApiPageSet
|
2007-06-03 17:22:09 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function addCustomFldsToPageSet( $modules, $pageSet ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
// Query all requested modules.
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $modules as $module ) {
|
|
|
|
|
$module->requestExtraData( $pageSet );
|
2007-06-03 17:22:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
|
2007-05-21 05:25:36 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Create instances of all modules requested by the client
|
2010-10-20 18:50:33 +00:00
|
|
|
* @param $modules Array to append instantiated modules to
|
2009-02-13 14:13:03 +00:00
|
|
|
* @param $param string Parameter name to read modules from
|
2010-10-20 18:50:33 +00:00
|
|
|
* @param $moduleList Array array(modulename => classname)
|
2007-05-21 05:25:36 +00:00
|
|
|
*/
|
2010-07-21 10:30:02 +00:00
|
|
|
private function instantiateModules( &$modules, $param, $moduleList ) {
|
2008-08-16 20:52:56 +00:00
|
|
|
$list = @$this->params[$param];
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !is_null ( $list ) ) {
|
|
|
|
|
foreach ( $list as $moduleName ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$modules[] = new $moduleList[$moduleName] ( $this, $moduleName );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-05-21 05:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-03 17:22:09 +00:00
|
|
|
/**
|
2009-02-13 14:13:03 +00:00
|
|
|
* Appends an element for each page in the current pageSet with the
|
|
|
|
|
* most general information (id, title), plus any title normalizations
|
|
|
|
|
* and missing or invalid title/pageids/revids.
|
2007-06-03 17:22:09 +00:00
|
|
|
*/
|
2006-10-01 20:17:16 +00:00
|
|
|
private function outputGeneralPageInfo() {
|
|
|
|
|
$pageSet = $this->getPageSet();
|
2006-10-18 05:27:43 +00:00
|
|
|
$result = $this->getResult();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-01-23 22:52:40 +00:00
|
|
|
// We don't check for a full result set here because we can't be adding
|
|
|
|
|
// more than 380K. The maximum revision size is in the megabyte range,
|
|
|
|
|
// and the maximum result size must be even higher than that.
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
// Title normalizations
|
2010-02-24 13:34:11 +00:00
|
|
|
$normValues = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $pageSet->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
$normValues[] = array(
|
2006-10-01 04:38:31 +00:00
|
|
|
'from' => $rawTitleStr,
|
|
|
|
|
'to' => $titleStr
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( count( $normValues ) ) {
|
|
|
|
|
$result->setIndexedTagName( $normValues, 'n' );
|
|
|
|
|
$result->addValue( 'query', 'normalized', $normValues );
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-07-10 11:53:22 +00:00
|
|
|
// Title conversions
|
|
|
|
|
$convValues = array();
|
|
|
|
|
foreach ( $pageSet->getConvertedTitles() as $rawTitleStr => $titleStr ) {
|
|
|
|
|
$convValues[] = array(
|
|
|
|
|
'from' => $rawTitleStr,
|
|
|
|
|
'to' => $titleStr
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( count( $convValues ) ) {
|
|
|
|
|
$result->setIndexedTagName( $convValues, 'c' );
|
|
|
|
|
$result->addValue( 'query', 'converted', $convValues );
|
2010-07-23 07:33:40 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-06-14 03:14:44 +00:00
|
|
|
// Interwiki titles
|
2010-02-24 13:34:11 +00:00
|
|
|
$intrwValues = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $pageSet->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
$intrwValues[] = array(
|
2007-06-14 03:14:44 +00:00
|
|
|
'title' => $rawTitleStr,
|
|
|
|
|
'iw' => $interwikiStr
|
|
|
|
|
);
|
|
|
|
|
}
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( count( $intrwValues ) ) {
|
|
|
|
|
$result->setIndexedTagName( $intrwValues, 'i' );
|
|
|
|
|
$result->addValue( 'query', 'interwiki', $intrwValues );
|
2007-06-14 03:14:44 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
// Show redirect information
|
2010-02-24 13:34:11 +00:00
|
|
|
$redirValues = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleStrTo ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
$redirValues[] = array(
|
2010-01-11 15:55:52 +00:00
|
|
|
'from' => strval( $titleStrFrom ),
|
2006-10-01 04:38:31 +00:00
|
|
|
'to' => $titleStrTo
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( count( $redirValues ) ) {
|
|
|
|
|
$result->setIndexedTagName( $redirValues, 'r' );
|
|
|
|
|
$result->addValue( 'query', 'redirects', $redirValues );
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-13 04:59:14 +00:00
|
|
|
// Missing revision elements
|
|
|
|
|
$missingRevIDs = $pageSet->getMissingRevisionIDs();
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( count( $missingRevIDs ) ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
$revids = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $missingRevIDs as $revid ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
$revids[$revid] = array(
|
2006-10-13 04:59:14 +00:00
|
|
|
'revid' => $revid
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$result->setIndexedTagName( $revids, 'rev' );
|
|
|
|
|
$result->addValue( 'query', 'badrevids', $revids );
|
2006-10-13 04:59:14 +00:00
|
|
|
}
|
2006-10-25 03:54:56 +00:00
|
|
|
|
2006-10-01 20:17:16 +00:00
|
|
|
// Page elements
|
2010-02-24 13:34:11 +00:00
|
|
|
$pages = array();
|
2006-10-01 20:17:16 +00:00
|
|
|
|
|
|
|
|
// Report any missing titles
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $pageSet->getMissingTitles() as $fakeId => $title ) {
|
2007-05-21 05:25:36 +00:00
|
|
|
$vals = array();
|
2010-02-24 13:34:11 +00:00
|
|
|
ApiQueryBase::addTitleInfo( $vals, $title );
|
2007-05-21 05:25:36 +00:00
|
|
|
$vals['missing'] = '';
|
2007-07-07 03:05:09 +00:00
|
|
|
$pages[$fakeId] = $vals;
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
2008-03-18 15:17:24 +00:00
|
|
|
// Report any invalid titles
|
2010-02-24 13:34:11 +00:00
|
|
|
foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$pages[$fakeId] = array( 'title' => $title, 'invalid' => '' );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
// Report any missing page ids
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $pageSet->getMissingPageIDs() as $pageid ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
$pages[$pageid] = array(
|
2006-10-21 08:26:32 +00:00
|
|
|
'pageid' => $pageid,
|
2006-10-01 20:17:16 +00:00
|
|
|
'missing' => ''
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-07-10 10:46:20 +00:00
|
|
|
// Report special pages
|
|
|
|
|
foreach ( $pageSet->getSpecialTitles() as $fakeId => $title ) {
|
|
|
|
|
$vals = array();
|
|
|
|
|
ApiQueryBase::addTitleInfo( $vals, $title );
|
|
|
|
|
$vals['special'] = '';
|
2010-07-23 07:33:40 +00:00
|
|
|
if ( $title->getNamespace() == NS_SPECIAL &&
|
2010-07-10 10:46:20 +00:00
|
|
|
!SpecialPage::exists( $title->getText() ) ) {
|
2010-07-23 07:33:40 +00:00
|
|
|
$vals['missing'] = '';
|
2010-07-21 14:40:24 +00:00
|
|
|
} elseif ( $title->getNamespace() == NS_MEDIA &&
|
|
|
|
|
!wfFindFile( $title ) ) {
|
|
|
|
|
$vals['missing'] = '';
|
2010-07-10 10:46:20 +00:00
|
|
|
}
|
|
|
|
|
$pages[$fakeId] = $vals;
|
|
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
|
|
|
|
|
// Output general page information for found titles
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $pageSet->getGoodTitles() as $pageid => $title ) {
|
2007-05-21 05:25:36 +00:00
|
|
|
$vals = array();
|
|
|
|
|
$vals['pageid'] = $pageid;
|
2010-02-24 13:34:11 +00:00
|
|
|
ApiQueryBase::addTitleInfo( $vals, $title );
|
2007-05-21 05:25:36 +00:00
|
|
|
$pages[$pageid] = $vals;
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( count( $pages ) ) {
|
|
|
|
|
if ( $this->params['indexpageids'] ) {
|
|
|
|
|
$pageIDs = array_keys( $pages );
|
2007-05-21 05:25:36 +00:00
|
|
|
// json treats all map keys as strings - converting to match
|
2010-01-11 15:55:52 +00:00
|
|
|
$pageIDs = array_map( 'strval', $pageIDs );
|
|
|
|
|
$result->setIndexedTagName( $pageIDs, 'id' );
|
|
|
|
|
$result->addValue( 'query', 'pageids', $pageIDs );
|
2007-05-21 05:25:36 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$result->setIndexedTagName( $pages, 'page' );
|
|
|
|
|
$result->addValue( 'query', 'pages', $pages );
|
2009-03-20 11:40:54 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->params['export'] ) {
|
2010-10-29 12:20:11 +00:00
|
|
|
$this->doExport( $pageSet, $result );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-11-01 11:57:23 +00:00
|
|
|
* @param $pageSet ApiPageSet Pages to be exported
|
|
|
|
|
* @param $result ApiResult Result to output to
|
2010-10-29 12:20:11 +00:00
|
|
|
*/
|
|
|
|
|
private function doExport( $pageSet, $result ) {
|
|
|
|
|
$exportTitles = array();
|
|
|
|
|
$titles = $pageSet->getGoodTitles();
|
|
|
|
|
if( count( $titles ) ) {
|
|
|
|
|
foreach ( $titles as $title ) {
|
|
|
|
|
if ( $title->userCanRead() ) {
|
|
|
|
|
$exportTitles[] = $title;
|
2010-10-27 15:42:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-10-29 12:20:11 +00:00
|
|
|
}
|
|
|
|
|
// only export when there are titles
|
|
|
|
|
if ( !count( $exportTitles ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-10-27 15:42:32 +00:00
|
|
|
|
2010-10-29 12:20:11 +00:00
|
|
|
$exporter = new WikiExporter( $this->getDB() );
|
|
|
|
|
// WikiExporter writes to stdout, so catch its
|
|
|
|
|
// output with an ob
|
|
|
|
|
ob_start();
|
|
|
|
|
$exporter->openStream();
|
|
|
|
|
foreach ( $exportTitles as $title ) {
|
|
|
|
|
$exporter->pageByTitle( $title );
|
|
|
|
|
}
|
|
|
|
|
$exporter->closeStream();
|
|
|
|
|
$exportxml = ob_get_contents();
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
|
|
|
|
|
// Don't check the size of exported stuff
|
|
|
|
|
// It's not continuable, so it would cause more
|
|
|
|
|
// problems than it'd solve
|
|
|
|
|
$result->disableSizeCheck();
|
|
|
|
|
if ( $this->params['exportnowrap'] ) {
|
|
|
|
|
$result->reset();
|
|
|
|
|
// Raw formatter will handle this
|
|
|
|
|
$result->addValue( null, 'text', $exportxml );
|
|
|
|
|
$result->addValue( null, 'mime', 'text/xml' );
|
|
|
|
|
} else {
|
|
|
|
|
$r = array();
|
|
|
|
|
ApiResult::setContent( $r, $exportxml );
|
|
|
|
|
$result->addValue( 'query', 'export', $r );
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
2010-10-29 12:20:11 +00:00
|
|
|
$result->enableSizeCheck();
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-03 17:22:09 +00:00
|
|
|
/**
|
2010-07-23 07:17:56 +00:00
|
|
|
* Create a generator object of the given type and return it
|
2010-07-23 10:15:29 +00:00
|
|
|
* @param $generatorName string Module name
|
2010-10-06 21:18:55 +00:00
|
|
|
* @return ApiQueryGeneratorBase
|
2007-06-03 17:22:09 +00:00
|
|
|
*/
|
2010-07-23 07:17:56 +00:00
|
|
|
public function newGenerator( $generatorName ) {
|
2006-10-01 04:38:31 +00:00
|
|
|
// Find class that implements requested generator
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( isset( $this->mQueryListModules[$generatorName] ) ) {
|
2006-10-02 23:56:19 +00:00
|
|
|
$className = $this->mQueryListModules[$generatorName];
|
2010-02-24 13:34:11 +00:00
|
|
|
} elseif ( isset( $this->mQueryPropModules[$generatorName] ) ) {
|
2006-10-03 05:41:55 +00:00
|
|
|
$className = $this->mQueryPropModules[$generatorName];
|
|
|
|
|
} else {
|
2010-02-24 13:34:11 +00:00
|
|
|
ApiBase::dieDebug( __METHOD__, "Unknown generator=$generatorName" );
|
2006-10-03 05:41:55 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$generator = new $className ( $this, $generatorName );
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !$generator instanceof ApiQueryGeneratorBase ) {
|
|
|
|
|
$this->dieUsage( "Module $generatorName cannot be used as a generator", 'badgenerator' );
|
|
|
|
|
}
|
2006-10-03 05:41:55 +00:00
|
|
|
$generator->setGeneratorMode();
|
2010-07-23 07:17:56 +00:00
|
|
|
return $generator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For generator mode, execute generator, and use its output as new
|
|
|
|
|
* ApiPageSet
|
2010-10-06 21:18:55 +00:00
|
|
|
* @param $generator ApiQueryGeneratorBase Generator Module
|
2010-07-23 07:17:56 +00:00
|
|
|
* @param $modules array of module objects
|
|
|
|
|
*/
|
|
|
|
|
protected function executeGeneratorModule( $generator, $modules ) {
|
|
|
|
|
// Generator results
|
|
|
|
|
$resultPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
|
2007-06-03 17:22:09 +00:00
|
|
|
|
|
|
|
|
// Add any additional fields modules may need
|
2010-01-11 15:55:52 +00:00
|
|
|
$generator->requestExtraData( $this->mPageSet );
|
|
|
|
|
$this->addCustomFldsToPageSet( $modules, $resultPageSet );
|
2007-06-03 17:22:09 +00:00
|
|
|
|
|
|
|
|
// Populate page information with the original user input
|
|
|
|
|
$this->mPageSet->execute();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2006-10-03 05:41:55 +00:00
|
|
|
// populate resultPageSet with the generator output
|
2006-10-02 23:56:19 +00:00
|
|
|
$generator->profileIn();
|
2010-01-11 15:55:52 +00:00
|
|
|
$generator->executeGenerator( $resultPageSet );
|
|
|
|
|
wfRunHooks( 'APIQueryGeneratorAfterExecute', array( &$generator, &$resultPageSet ) );
|
2006-10-06 01:02:14 +00:00
|
|
|
$resultPageSet->finishPageSetGeneration();
|
2006-10-02 23:56:19 +00:00
|
|
|
$generator->profileOut();
|
2006-10-25 03:54:56 +00:00
|
|
|
|
2006-10-03 05:41:55 +00:00
|
|
|
// Swap the resulting pageset back in
|
|
|
|
|
$this->mPageSet = $resultPageSet;
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-24 13:34:11 +00:00
|
|
|
return array(
|
|
|
|
|
'prop' => array(
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => $this->mPropModuleNames
|
2006-10-01 04:38:31 +00:00
|
|
|
),
|
2010-02-24 13:34:11 +00:00
|
|
|
'list' => array(
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => $this->mListModuleNames
|
2006-10-01 20:17:16 +00:00
|
|
|
),
|
2010-02-24 13:34:11 +00:00
|
|
|
'meta' => array(
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => $this->mMetaModuleNames
|
2006-10-02 23:56:19 +00:00
|
|
|
),
|
2010-02-24 13:34:11 +00:00
|
|
|
'generator' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => $this->mAllowedGenerators
|
2006-10-06 01:02:14 +00:00
|
|
|
),
|
2007-05-21 05:25:36 +00:00
|
|
|
'redirects' => false,
|
2010-07-10 11:53:22 +00:00
|
|
|
'converttitles' => false,
|
2007-05-21 05:25:36 +00:00
|
|
|
'indexpageids' => false,
|
2009-02-02 20:07:33 +00:00
|
|
|
'export' => false,
|
|
|
|
|
'exportnowrap' => false,
|
2006-10-01 04:38:31 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Override the parent to generate help messages for all available query modules.
|
2009-02-13 14:13:03 +00:00
|
|
|
* @return string
|
2006-10-01 04:38:31 +00:00
|
|
|
*/
|
|
|
|
|
public function makeHelpMsg() {
|
2007-06-06 04:41:35 +00:00
|
|
|
$msg = '';
|
2006-10-01 04:38:31 +00:00
|
|
|
|
|
|
|
|
// Make sure the internal object is empty
|
|
|
|
|
// (just in case a sub-module decides to optimize during instantiation)
|
2006-10-01 20:17:16 +00:00
|
|
|
$this->mPageSet = null;
|
2010-02-24 13:34:11 +00:00
|
|
|
$this->mAllowedGenerators = array(); // Will be repopulated
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-10-20 23:36:21 +00:00
|
|
|
$querySeparator = str_repeat( '--- ', 8 );
|
|
|
|
|
$moduleSeparator = str_repeat( '*** ', 10 );
|
|
|
|
|
$msg .= "\n$querySeparator Query: Prop $querySeparator\n\n";
|
2010-01-11 15:55:52 +00:00
|
|
|
$msg .= $this->makeHelpMsgHelper( $this->mQueryPropModules, 'prop' );
|
2010-10-20 23:36:21 +00:00
|
|
|
$msg .= "\n$querySeparator Query: List $querySeparator\n\n";
|
2010-01-11 15:55:52 +00:00
|
|
|
$msg .= $this->makeHelpMsgHelper( $this->mQueryListModules, 'list' );
|
2010-10-20 23:36:21 +00:00
|
|
|
$msg .= "\n$querySeparator Query: Meta $querySeparator\n\n";
|
2010-01-11 15:55:52 +00:00
|
|
|
$msg .= $this->makeHelpMsgHelper( $this->mQueryMetaModules, 'meta' );
|
2010-10-20 23:36:21 +00:00
|
|
|
$msg .= "\n\n$moduleSeparator Modules: continuation $moduleSeparator\n\n";
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2007-06-06 04:41:35 +00:00
|
|
|
// Perform the base call last because the $this->mAllowedGenerators
|
|
|
|
|
// will be updated inside makeHelpMsgHelper()
|
|
|
|
|
// Use parent to make default message for the query module
|
2010-02-24 13:34:11 +00:00
|
|
|
$msg = parent::makeHelpMsg() . $msg;
|
2007-06-06 04:41:35 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
return $msg;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-03 17:22:09 +00:00
|
|
|
/**
|
|
|
|
|
* For all modules in $moduleList, generate help messages and join them together
|
2010-10-20 18:50:33 +00:00
|
|
|
* @param $moduleList Array array(modulename => classname)
|
2009-02-13 14:13:03 +00:00
|
|
|
* @param $paramName string Parameter name
|
|
|
|
|
* @return string
|
2007-06-03 17:22:09 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function makeHelpMsgHelper( $moduleList, $paramName ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
$moduleDescriptions = array();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $moduleList as $moduleName => $moduleClass ) {
|
|
|
|
|
$module = new $moduleClass ( $this, $moduleName, null );
|
2007-05-21 06:32:32 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$msg = ApiMain::makeHelpMsgHeader( $module, $paramName );
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg2 = $module->makeHelpMsg();
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( $msg2 !== false ) {
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg .= $msg2;
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $module instanceof ApiQueryGeneratorBase ) {
|
2007-06-06 04:41:35 +00:00
|
|
|
$this->mAllowedGenerators[] = $moduleName;
|
2006-10-01 20:17:16 +00:00
|
|
|
$msg .= "Generator:\n This module may be used as a generator\n";
|
2007-06-06 04:41:35 +00:00
|
|
|
}
|
2009-02-13 14:13:03 +00:00
|
|
|
$moduleDescriptions[] = $msg;
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
return implode( "\n", $moduleDescriptions );
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Override to add extra parameters from PageSet
|
2009-02-13 14:13:03 +00:00
|
|
|
* @return string
|
2006-10-01 04:38:31 +00:00
|
|
|
*/
|
|
|
|
|
public function makeHelpMsgParameters() {
|
2010-01-11 15:55:52 +00:00
|
|
|
$psModule = new ApiPageSet( $this );
|
2010-02-24 13:34:11 +00:00
|
|
|
return $psModule->makeHelpMsgParameters() . parent::makeHelpMsgParameters();
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-19 15:57:58 +00:00
|
|
|
public function shouldCheckMaxlag() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2010-02-24 13:34:11 +00:00
|
|
|
return array(
|
2010-05-15 11:07:31 +00:00
|
|
|
'prop' => 'Which properties to get for the titles/revisions/pageids. Module help is available below',
|
|
|
|
|
'list' => 'Which lists to get. Module help is available below',
|
|
|
|
|
'meta' => 'Which metadata to get about the site. Module help is available below',
|
2010-01-11 15:55:52 +00:00
|
|
|
'generator' => array( 'Use the output of a list as the input for other prop/list/meta items',
|
2010-05-14 11:25:41 +00:00
|
|
|
'NOTE: generator parameter names must be prefixed with a \'g\', see examples' ),
|
2007-05-21 05:25:36 +00:00
|
|
|
'redirects' => 'Automatically resolve redirects',
|
2010-10-03 12:11:42 +00:00
|
|
|
'converttitles' => array( "Convert titles to other variants if necessary. Only works if the wiki's content language supports variant conversion.",
|
2010-10-04 09:11:15 +00:00
|
|
|
'Languages that support variant conversion include kk, ku, gan, tg, sr, zh' ),
|
2010-05-11 22:30:18 +00:00
|
|
|
'indexpageids' => 'Include an additional pageids section listing all returned page IDs',
|
2009-02-02 20:07:33 +00:00
|
|
|
'export' => 'Export the current revisions of all given or generated pages',
|
2009-03-11 13:35:19 +00:00
|
|
|
'exportnowrap' => 'Return the export XML without wrapping it in an XML result (same format as Special:Export). Can only be used with export',
|
2006-10-01 04:38:31 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2010-02-24 13:34:11 +00:00
|
|
|
return array(
|
2006-10-01 04:38:31 +00:00
|
|
|
'Query API module allows applications to get needed pieces of data from the MediaWiki databases,',
|
2009-02-02 20:07:33 +00:00
|
|
|
'and is loosely based on the old query.php interface.',
|
2010-05-11 22:30:18 +00:00
|
|
|
'All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites'
|
2006-10-01 04:38:31 +00:00
|
|
|
);
|
|
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
2010-02-13 00:48:31 +00:00
|
|
|
public function getPossibleErrors() {
|
|
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'code' => 'badgenerator', 'info' => 'Module $generatorName cannot be used as a generator' ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
2006-10-01 04:38:31 +00:00
|
|
|
|
|
|
|
|
protected function getExamples() {
|
2010-02-24 13:34:11 +00:00
|
|
|
return array(
|
2009-03-09 10:36:48 +00:00
|
|
|
'api.php?action=query&prop=revisions&meta=siteinfo&titles=Main%20Page&rvprop=user|comment',
|
|
|
|
|
'api.php?action=query&generator=allpages&gapprefix=API/&prop=revisions',
|
2006-10-01 04:38:31 +00:00
|
|
|
);
|
|
|
|
|
}
|
2006-10-01 21:20:55 +00:00
|
|
|
|
|
|
|
|
public function getVersion() {
|
2010-01-11 15:55:52 +00:00
|
|
|
$psModule = new ApiPageSet( $this );
|
2010-02-24 13:34:11 +00:00
|
|
|
$vers = array();
|
2007-12-06 18:33:18 +00:00
|
|
|
$vers[] = __CLASS__ . ': $Id$';
|
2006-10-02 18:27:06 +00:00
|
|
|
$vers[] = $psModule->getVersion();
|
2006-10-01 21:20:55 +00:00
|
|
|
return $vers;
|
|
|
|
|
}
|
2009-11-01 10:42:41 +00:00
|
|
|
}
|