2006-09-25 04:12:07 +00:00
|
|
|
<?php
|
2010-02-23 18:05:46 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2006-09-25 04:12:07 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Sep 24, 2006
|
|
|
|
|
*
|
2013-02-08 20:39:40 +00:00
|
|
|
* Copyright © 2006, 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
|
2006-09-25 04:12:07 +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-09-25 04:12:07 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
|
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
2007-05-20 23:31:44 +00:00
|
|
|
* This class contains a list of pages that the client has requested.
|
2009-02-11 19:25:25 +00:00
|
|
|
* Initially, when the client passes in titles=, pageids=, or revisions=
|
|
|
|
|
* parameter, an instance of the ApiPageSet class will normalize titles,
|
|
|
|
|
* determine if the pages/revisions exist, and prefetch any additional page
|
|
|
|
|
* data requested.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
2009-02-11 19:25:25 +00:00
|
|
|
* When a generator is used, the result of the generator will become the input
|
|
|
|
|
* for the second instance of this class, and all subsequent actions will use
|
|
|
|
|
* the second instance for all their work.
|
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
|
2013-02-08 20:39:40 +00:00
|
|
|
* @since 1.21 derives from ApiBase instead of ApiQueryBase
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
2013-02-08 20:39:40 +00:00
|
|
|
class ApiPageSet extends ApiBase {
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor flag: The new instance of ApiPageSet will ignore the 'generator=' parameter
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
const DISABLE_GENERATORS = 1;
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2013-03-02 00:06:46 +00:00
|
|
|
private $mDbSource;
|
|
|
|
|
private $mParams;
|
|
|
|
|
private $mResolveRedirects;
|
|
|
|
|
private $mConvertTitles;
|
|
|
|
|
private $mAllowGenerator;
|
2013-02-08 20:39:40 +00:00
|
|
|
|
|
|
|
|
private $mAllPages = array(); // [ns][dbkey] => page_id or negative when missing
|
|
|
|
|
private $mTitles = array();
|
|
|
|
|
private $mGoodTitles = array();
|
|
|
|
|
private $mMissingTitles = array();
|
|
|
|
|
private $mInvalidTitles = array();
|
|
|
|
|
private $mMissingPageIDs = array();
|
|
|
|
|
private $mRedirectTitles = array();
|
|
|
|
|
private $mSpecialTitles = array();
|
|
|
|
|
private $mNormalizedTitles = array();
|
|
|
|
|
private $mInterwikiTitles = array();
|
|
|
|
|
private $mPendingRedirectIDs = array();
|
|
|
|
|
private $mConvertedTitles = array();
|
|
|
|
|
private $mGoodRevIDs = array();
|
|
|
|
|
private $mMissingRevIDs = array();
|
|
|
|
|
private $mFakePageId = -1;
|
|
|
|
|
private $mCacheMode = 'public';
|
|
|
|
|
private $mRequestedPageFields = array();
|
2013-04-01 17:16:34 +00:00
|
|
|
/**
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
2013-03-04 21:22:14 +00:00
|
|
|
private $mDefaultNamespace = NS_MAIN;
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
2013-02-08 20:39:40 +00:00
|
|
|
* @param $dbSource ApiBase Module implementing getDB().
|
|
|
|
|
* Allows PageSet to reuse existing db connection from the shared state like ApiQuery.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $flags Zero or more flags like DISABLE_GENERATORS
|
|
|
|
|
* @param int $defaultNamespace the namespace to use if none is specified by a prefix.
|
2013-02-08 20:39:40 +00:00
|
|
|
* @since 1.21 accepts $flags instead of two boolean values
|
|
|
|
|
*/
|
2013-03-04 21:22:14 +00:00
|
|
|
public function __construct( ApiBase $dbSource, $flags = 0, $defaultNamespace = NS_MAIN ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
parent::__construct( $dbSource->getMain(), $dbSource->getModuleName() );
|
|
|
|
|
$this->mDbSource = $dbSource;
|
|
|
|
|
$this->mAllowGenerator = ( $flags & ApiPageSet::DISABLE_GENERATORS ) == 0;
|
2013-03-04 21:22:14 +00:00
|
|
|
$this->mDefaultNamespace = $defaultNamespace;
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
$this->profileIn();
|
|
|
|
|
$this->mParams = $this->extractRequestParams();
|
|
|
|
|
$this->mResolveRedirects = $this->mParams['redirects'];
|
|
|
|
|
$this->mConvertTitles = $this->mParams['converttitles'];
|
|
|
|
|
$this->profileOut();
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-03-02 00:06:46 +00:00
|
|
|
/**
|
|
|
|
|
* In case execute() is not called, call this method to mark all relevant parameters as used
|
|
|
|
|
* This prevents unused parameters from being reported as warnings
|
|
|
|
|
*/
|
|
|
|
|
public function executeDryRun() {
|
|
|
|
|
$this->executeInternal( true );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Populate the PageSet from the request parameters.
|
|
|
|
|
*/
|
|
|
|
|
public function execute() {
|
2013-03-02 00:06:46 +00:00
|
|
|
$this->executeInternal( false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Populate the PageSet from the request parameters.
|
|
|
|
|
* @param bool $isDryRun If true, instantiates generator, but only to mark relevant parameters as used
|
|
|
|
|
*/
|
|
|
|
|
private function executeInternal( $isDryRun ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
$this->profileIn();
|
|
|
|
|
|
|
|
|
|
$generatorName = $this->mAllowGenerator ? $this->mParams['generator'] : null;
|
|
|
|
|
if ( isset( $generatorName ) ) {
|
|
|
|
|
$dbSource = $this->mDbSource;
|
|
|
|
|
$isQuery = $dbSource instanceof ApiQuery;
|
|
|
|
|
if ( !$isQuery ) {
|
|
|
|
|
// If the parent container of this pageset is not ApiQuery, we must create it to run generator
|
|
|
|
|
$dbSource = $this->getMain()->getModuleManager()->getModule( 'query' );
|
|
|
|
|
// Enable profiling for query module because it will be used for db sql profiling
|
|
|
|
|
$dbSource->profileIn();
|
|
|
|
|
}
|
|
|
|
|
$generator = $dbSource->getModuleManager()->getModule( $generatorName, null, true );
|
|
|
|
|
if ( $generator === null ) {
|
|
|
|
|
$this->dieUsage( 'Unknown generator=' . $generatorName, 'badgenerator' );
|
|
|
|
|
}
|
|
|
|
|
if ( !$generator instanceof ApiQueryGeneratorBase ) {
|
|
|
|
|
$this->dieUsage( "Module $generatorName cannot be used as a generator", 'badgenerator' );
|
|
|
|
|
}
|
|
|
|
|
// Create a temporary pageset to store generator's output,
|
|
|
|
|
// add any additional fields generator may need, and execute pageset to populate titles/pageids
|
|
|
|
|
$tmpPageSet = new ApiPageSet( $dbSource, ApiPageSet::DISABLE_GENERATORS );
|
|
|
|
|
$generator->setGeneratorMode( $tmpPageSet );
|
|
|
|
|
$this->mCacheMode = $generator->getCacheMode( $generator->extractRequestParams() );
|
2013-03-02 00:06:46 +00:00
|
|
|
|
|
|
|
|
if ( !$isDryRun ) {
|
|
|
|
|
$generator->requestExtraData( $tmpPageSet );
|
|
|
|
|
}
|
|
|
|
|
$tmpPageSet->executeInternal( $isDryRun );
|
2013-02-08 20:39:40 +00:00
|
|
|
|
|
|
|
|
// populate this pageset with the generator output
|
|
|
|
|
$this->profileOut();
|
|
|
|
|
$generator->profileIn();
|
2013-03-02 00:06:46 +00:00
|
|
|
|
|
|
|
|
if ( !$isDryRun ) {
|
|
|
|
|
$generator->executeGenerator( $this );
|
|
|
|
|
wfRunHooks( 'APIQueryGeneratorAfterExecute', array( &$generator, &$this ) );
|
|
|
|
|
$this->resolvePendingRedirects();
|
|
|
|
|
} else {
|
|
|
|
|
// Prevent warnings from being reported on these parameters
|
|
|
|
|
$main = $this->getMain();
|
|
|
|
|
foreach ( $generator->extractRequestParams() as $paramName => $param ) {
|
|
|
|
|
$main->getVal( $generator->encodeParamName( $paramName ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-08 20:39:40 +00:00
|
|
|
$generator->profileOut();
|
|
|
|
|
$this->profileIn();
|
|
|
|
|
|
|
|
|
|
if ( !$isQuery ) {
|
|
|
|
|
// If this pageset is not part of the query, we called profileIn() above
|
|
|
|
|
$dbSource->profileOut();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Only one of the titles/pageids/revids is allowed at the same time
|
|
|
|
|
$dataSource = null;
|
|
|
|
|
if ( isset( $this->mParams['titles'] ) ) {
|
|
|
|
|
$dataSource = 'titles';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->mParams['pageids'] ) ) {
|
|
|
|
|
if ( isset( $dataSource ) ) {
|
|
|
|
|
$this->dieUsage( "Cannot use 'pageids' at the same time as '$dataSource'", 'multisource' );
|
|
|
|
|
}
|
|
|
|
|
$dataSource = 'pageids';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->mParams['revids'] ) ) {
|
|
|
|
|
if ( isset( $dataSource ) ) {
|
|
|
|
|
$this->dieUsage( "Cannot use 'revids' at the same time as '$dataSource'", 'multisource' );
|
|
|
|
|
}
|
|
|
|
|
$dataSource = 'revids';
|
|
|
|
|
}
|
2013-03-02 00:06:46 +00:00
|
|
|
|
|
|
|
|
if ( !$isDryRun ) {
|
|
|
|
|
// Populate page information with the original user input
|
|
|
|
|
switch( $dataSource ) {
|
|
|
|
|
case 'titles':
|
|
|
|
|
$this->initFromTitles( $this->mParams['titles'] );
|
|
|
|
|
break;
|
|
|
|
|
case 'pageids':
|
|
|
|
|
$this->initFromPageIds( $this->mParams['pageids'] );
|
|
|
|
|
break;
|
|
|
|
|
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( $this->mParams['revids'] );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// Do nothing - some queries do not need any of the data sources.
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->profileOut();
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Check whether this PageSet is resolving redirects
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2006-10-06 01:02:14 +00:00
|
|
|
public function isResolvingRedirects() {
|
|
|
|
|
return $this->mResolveRedirects;
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-15 18:03:19 +00:00
|
|
|
/**
|
|
|
|
|
* Return the parameter name that is the source of data for this PageSet
|
|
|
|
|
*
|
|
|
|
|
* If multiple source parameters are specified (e.g. titles and pageids),
|
|
|
|
|
* one will be named arbitrarily.
|
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getDataSource() {
|
|
|
|
|
if ( $this->mAllowGenerator && isset( $this->mParams['generator'] ) ) {
|
|
|
|
|
return 'generator';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->mParams['titles'] ) ) {
|
|
|
|
|
return 'titles';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->mParams['pageids'] ) ) {
|
|
|
|
|
return 'pageids';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->mParams['revids'] ) ) {
|
|
|
|
|
return 'revids';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
2013-02-08 20:39:40 +00:00
|
|
|
* Request an additional field from the page table.
|
|
|
|
|
* Must be called before execute()
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $fieldName Field name
|
2009-02-11 19:25:25 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function requestField( $fieldName ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->mRequestedPageFields[$fieldName] = null;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Get the value of a custom field previously requested through
|
|
|
|
|
* requestField()
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $fieldName Field name
|
2009-02-11 19:25:25 +00:00
|
|
|
* @return mixed Field value
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function getCustomField( $fieldName ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
return $this->mRequestedPageFields[$fieldName];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Get the fields that have to be queried from the page table:
|
|
|
|
|
* the ones requested through requestField() and a few basic ones
|
|
|
|
|
* we always need
|
|
|
|
|
* @return array of field names
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
|
|
|
|
public function getPageTableFields() {
|
|
|
|
|
// Ensure we get minimum required fields
|
2008-12-14 17:04:24 +00:00
|
|
|
// DON'T change this order
|
2010-02-23 18:05:46 +00:00
|
|
|
$pageFlds = array(
|
2006-10-06 01:02:14 +00:00
|
|
|
'page_namespace' => null,
|
2008-12-14 17:04:24 +00:00
|
|
|
'page_title' => null,
|
|
|
|
|
'page_id' => null,
|
2006-10-06 01:02:14 +00:00
|
|
|
);
|
|
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $this->mResolveRedirects ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
$pageFlds['page_is_redirect'] = null;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2006-10-06 01:02:14 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
// only store non-default fields
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds );
|
2009-02-11 19:25:25 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$pageFlds = array_merge( $pageFlds, $this->mRequestedPageFields );
|
|
|
|
|
return array_keys( $pageFlds );
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-07 03:05:09 +00:00
|
|
|
/**
|
2008-03-18 15:17:24 +00:00
|
|
|
* Returns an array [ns][dbkey] => page_id for all requested titles.
|
|
|
|
|
* page_id is a unique negative number in case title was not found.
|
|
|
|
|
* Invalid titles will also have negative page IDs and will be in namespace 0
|
2009-02-11 19:25:25 +00:00
|
|
|
* @return array
|
2007-07-07 03:05:09 +00:00
|
|
|
*/
|
|
|
|
|
public function getAllTitlesByNamespace() {
|
|
|
|
|
return $this->mAllPages;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-30 00:18:05 +00:00
|
|
|
/**
|
|
|
|
|
* All Title objects provided.
|
|
|
|
|
* @return array of Title objects
|
|
|
|
|
*/
|
|
|
|
|
public function getTitles() {
|
|
|
|
|
return $this->mTitles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of unique pages (not revisions) in the set.
|
2009-02-11 19:25:25 +00:00
|
|
|
* @return int
|
2006-10-30 00:18:05 +00:00
|
|
|
*/
|
|
|
|
|
public function getTitleCount() {
|
2010-01-11 15:55:52 +00:00
|
|
|
return count( $this->mTitles );
|
2006-10-30 00:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
|
|
|
|
* Title objects that were found in the database.
|
|
|
|
|
* @return array page_id (int) => Title (obj)
|
|
|
|
|
*/
|
2006-09-27 05:13:48 +00:00
|
|
|
public function getGoodTitles() {
|
|
|
|
|
return $this->mGoodTitles;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
/**
|
2006-10-30 00:18:05 +00:00
|
|
|
* Returns the number of found unique pages (not revisions) in the set.
|
2009-02-11 19:25:25 +00:00
|
|
|
* @return int
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
|
|
|
|
public function getGoodTitleCount() {
|
2010-01-11 15:55:52 +00:00
|
|
|
return count( $this->mGoodTitles );
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
|
|
|
|
* Title objects that were NOT found in the database.
|
2007-07-07 03:05:09 +00:00
|
|
|
* The array's index will be negative for each item
|
2006-09-25 04:12:07 +00:00
|
|
|
* @return array of Title objects
|
|
|
|
|
*/
|
2006-09-27 05:13:48 +00:00
|
|
|
public function getMissingTitles() {
|
|
|
|
|
return $this->mMissingTitles;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-03-18 15:17:24 +00:00
|
|
|
/**
|
|
|
|
|
* Titles that were deemed invalid by Title::newFromText()
|
|
|
|
|
* The array's index will be unique and negative for each item
|
|
|
|
|
* @return array of strings (not Title objects)
|
|
|
|
|
*/
|
|
|
|
|
public function getInvalidTitles() {
|
|
|
|
|
return $this->mInvalidTitles;
|
|
|
|
|
}
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2006-10-01 20:17:16 +00:00
|
|
|
/**
|
|
|
|
|
* Page IDs that were not found in the database
|
|
|
|
|
* @return array of page IDs
|
|
|
|
|
*/
|
|
|
|
|
public function getMissingPageIDs() {
|
|
|
|
|
return $this->mMissingPageIDs;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Get a list of redirect resolutions - maps a title to its redirect
|
2013-02-08 20:39:40 +00:00
|
|
|
* target, as an array of output-ready arrays
|
|
|
|
|
* @return array
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
2006-09-27 05:13:48 +00:00
|
|
|
public function getRedirectTitles() {
|
|
|
|
|
return $this->mRedirectTitles;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of redirect resolutions - maps a title to its redirect
|
|
|
|
|
* target.
|
|
|
|
|
* @param $result ApiResult
|
|
|
|
|
* @return array of prefixed_title (string) => Title object
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getRedirectTitlesAsResult( $result = null ) {
|
|
|
|
|
$values = array();
|
|
|
|
|
foreach ( $this->getRedirectTitles() as $titleStrFrom => $titleTo ) {
|
|
|
|
|
$r = array(
|
|
|
|
|
'from' => strval( $titleStrFrom ),
|
|
|
|
|
'to' => $titleTo->getPrefixedText(),
|
|
|
|
|
);
|
|
|
|
|
if ( $titleTo->getFragment() !== '' ) {
|
|
|
|
|
$r['tofragment'] = $titleTo->getFragment();
|
|
|
|
|
}
|
|
|
|
|
$values[] = $r;
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $values ) && $result ) {
|
|
|
|
|
$result->setIndexedTagName( $values, 'r' );
|
|
|
|
|
}
|
|
|
|
|
return $values;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-25 06:10:16 +00:00
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Get a list of title normalizations - maps a title to its normalized
|
|
|
|
|
* version.
|
2008-04-14 07:45:50 +00:00
|
|
|
* @return array raw_prefixed_title (string) => prefixed_title (string)
|
2006-09-25 06:10:16 +00:00
|
|
|
*/
|
2006-09-27 05:13:48 +00:00
|
|
|
public function getNormalizedTitles() {
|
|
|
|
|
return $this->mNormalizedTitles;
|
2006-09-25 06:10:16 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of title normalizations - maps a title to its normalized
|
|
|
|
|
* version in the form of result array.
|
|
|
|
|
* @param $result ApiResult
|
|
|
|
|
* @return array of raw_prefixed_title (string) => prefixed_title (string)
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getNormalizedTitlesAsResult( $result = null ) {
|
|
|
|
|
$values = array();
|
|
|
|
|
foreach ( $this->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
|
|
|
|
|
$values[] = array(
|
|
|
|
|
'from' => $rawTitleStr,
|
|
|
|
|
'to' => $titleStr
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $values ) && $result ) {
|
|
|
|
|
$result->setIndexedTagName( $values, 'n' );
|
|
|
|
|
}
|
|
|
|
|
return $values;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-10 11:53:22 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of title conversions - maps a title to its converted
|
|
|
|
|
* version.
|
|
|
|
|
* @return array raw_prefixed_title (string) => prefixed_title (string)
|
2010-07-23 07:33:40 +00:00
|
|
|
*/
|
2010-07-10 11:53:22 +00:00
|
|
|
public function getConvertedTitles() {
|
|
|
|
|
return $this->mConvertedTitles;
|
|
|
|
|
}
|
2006-09-26 06:37:26 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of title conversions - maps a title to its converted
|
|
|
|
|
* version as a result array.
|
|
|
|
|
* @param $result ApiResult
|
|
|
|
|
* @return array of (from, to) strings
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getConvertedTitlesAsResult( $result = null ) {
|
|
|
|
|
$values = array();
|
|
|
|
|
foreach ( $this->getConvertedTitles() as $rawTitleStr => $titleStr ) {
|
|
|
|
|
$values[] = array(
|
|
|
|
|
'from' => $rawTitleStr,
|
|
|
|
|
'to' => $titleStr
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $values ) && $result ) {
|
|
|
|
|
$result->setIndexedTagName( $values, 'c' );
|
|
|
|
|
}
|
|
|
|
|
return $values;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-14 03:14:44 +00:00
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Get a list of interwiki titles - maps a title to its interwiki
|
|
|
|
|
* prefix.
|
2008-04-14 07:45:50 +00:00
|
|
|
* @return array raw_prefixed_title (string) => interwiki_prefix (string)
|
2007-06-14 03:14:44 +00:00
|
|
|
*/
|
|
|
|
|
public function getInterwikiTitles() {
|
|
|
|
|
return $this->mInterwikiTitles;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of interwiki titles - maps a title to its interwiki
|
|
|
|
|
* prefix as result.
|
|
|
|
|
* @param $result ApiResult
|
|
|
|
|
* @param $iwUrl boolean
|
|
|
|
|
* @return array raw_prefixed_title (string) => interwiki_prefix (string)
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getInterwikiTitlesAsResult( $result = null, $iwUrl = false ) {
|
|
|
|
|
$values = array();
|
|
|
|
|
foreach ( $this->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
|
|
|
|
|
$item = array(
|
|
|
|
|
'title' => $rawTitleStr,
|
|
|
|
|
'iw' => $interwikiStr,
|
|
|
|
|
);
|
|
|
|
|
if ( $iwUrl ) {
|
|
|
|
|
$title = Title::newFromText( $rawTitleStr );
|
|
|
|
|
$item['url'] = $title->getFullURL( '', false, PROTO_CURRENT );
|
|
|
|
|
}
|
|
|
|
|
$values[] = $item;
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $values ) && $result ) {
|
|
|
|
|
$result->setIndexedTagName( $values, 'i' );
|
|
|
|
|
}
|
|
|
|
|
return $values;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-30 08:06:27 +00:00
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Get the list of revision IDs (requested with the revids= parameter)
|
2006-10-13 04:59:14 +00:00
|
|
|
* @return array revID (int) => pageID (int)
|
2006-09-30 08:06:27 +00:00
|
|
|
*/
|
|
|
|
|
public function getRevisionIDs() {
|
2006-10-13 04:59:14 +00:00
|
|
|
return $this->mGoodRevIDs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Revision IDs that were not found in the database
|
|
|
|
|
* @return array of revision IDs
|
|
|
|
|
*/
|
|
|
|
|
public function getMissingRevisionIDs() {
|
|
|
|
|
return $this->mMissingRevIDs;
|
2006-09-30 08:06:27 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Revision IDs that were not found in the database as result array.
|
|
|
|
|
* @param $result ApiResult
|
|
|
|
|
* @return array of revision IDs
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getMissingRevisionIDsAsResult( $result = null ) {
|
|
|
|
|
$values = array();
|
|
|
|
|
foreach ( $this->getMissingRevisionIDs() as $revid ) {
|
|
|
|
|
$values[$revid] = array(
|
|
|
|
|
'revid' => $revid
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $values ) && $result ) {
|
|
|
|
|
$result->setIndexedTagName( $values, 'rev' );
|
|
|
|
|
}
|
|
|
|
|
return $values;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-10 10:46:20 +00:00
|
|
|
/**
|
|
|
|
|
* Get the list of titles with negative namespace
|
|
|
|
|
* @return array Title
|
|
|
|
|
*/
|
|
|
|
|
public function getSpecialTitles() {
|
|
|
|
|
return $this->mSpecialTitles;
|
|
|
|
|
}
|
2006-10-01 02:02:13 +00:00
|
|
|
|
2006-09-30 08:06:27 +00:00
|
|
|
/**
|
2012-07-10 12:48:06 +00:00
|
|
|
* Returns the number of revisions (requested with revids= parameter).
|
|
|
|
|
* @return int Number of revisions.
|
2006-09-30 08:06:27 +00:00
|
|
|
*/
|
|
|
|
|
public function getRevisionCount() {
|
2010-01-11 15:55:52 +00:00
|
|
|
return count( $this->getRevisionIDs() );
|
2006-09-30 08:06:27 +00:00
|
|
|
}
|
2006-09-25 06:10:16 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Populate this PageSet from a list of Titles
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $titles of Title objects
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function populateFromTitles( $titles ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->profileIn();
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->initFromTitles( $titles );
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->profileOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Populate this PageSet from a list of page IDs
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $pageIDs of page IDs
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function populateFromPageIDs( $pageIDs ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->profileIn();
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->initFromPageIds( $pageIDs );
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->profileOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Populate this PageSet from a rowset returned from the database
|
2012-02-09 18:01:54 +00:00
|
|
|
* @param $db DatabaseBase object
|
2010-10-20 18:50:33 +00:00
|
|
|
* @param $queryResult ResultWrapper Query result object
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function populateFromQueryResult( $db, $queryResult ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->profileIn();
|
2011-01-12 00:24:25 +00:00
|
|
|
$this->initFromQueryResult( $queryResult );
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->profileOut();
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-14 16:02:42 +00:00
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Populate this PageSet from a list of revision IDs
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $revIDs of revision IDs
|
2006-10-14 16:02:42 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function populateFromRevisionIDs( $revIDs ) {
|
2006-10-14 16:02:42 +00:00
|
|
|
$this->profileIn();
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->initFromRevIDs( $revIDs );
|
2006-10-14 16:02:42 +00:00
|
|
|
$this->profileOut();
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
/**
|
|
|
|
|
* Extract all requested fields from the row received from the database
|
2009-02-11 19:25:25 +00:00
|
|
|
* @param $row Result row
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function processDbRow( $row ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
// Store Title object in various data structures
|
2012-06-06 16:39:30 +00:00
|
|
|
$title = Title::newFromRow( $row );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$pageId = intval( $row->page_id );
|
2007-07-14 19:04:31 +00:00
|
|
|
$this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
|
|
|
|
|
$this->mTitles[] = $title;
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->mResolveRedirects && $row->page_is_redirect == '1' ) {
|
2007-07-14 19:04:31 +00:00
|
|
|
$this->mPendingRedirectIDs[$pageId] = $title;
|
|
|
|
|
} else {
|
|
|
|
|
$this->mGoodTitles[$pageId] = $title;
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
2007-07-14 19:04:31 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
foreach ( $this->mRequestedPageFields as $fieldName => &$fieldValues ) {
|
2013-03-24 10:01:51 +00:00
|
|
|
$fieldValues[$pageId] = $row->$fieldName;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
2013-02-08 20:39:40 +00:00
|
|
|
* Do not use, does nothing, will be removed
|
|
|
|
|
* @deprecated 1.21
|
2009-02-11 19:25:25 +00:00
|
|
|
*/
|
2006-10-06 01:02:14 +00:00
|
|
|
public function finishPageSetGeneration() {
|
2013-02-08 20:39:40 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.21' );
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
|
|
|
|
* This method populates internal variables with page information
|
2006-09-25 06:10:16 +00:00
|
|
|
* based on the given array of title strings.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
2006-09-25 04:12:07 +00:00
|
|
|
* Steps:
|
|
|
|
|
* #1 For each title, get data from `page` table
|
|
|
|
|
* #2 If page was not found in the DB, store it as missing
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
2006-09-25 04:12:07 +00:00
|
|
|
* Additionally, when resolving redirects:
|
|
|
|
|
* #3 If no more redirects left, stop.
|
2009-02-11 19:25:25 +00:00
|
|
|
* #4 For each redirect, get its target from the `redirect` table.
|
2006-09-25 04:12:07 +00:00
|
|
|
* #5 Substitute the original LinkBatch object with the new list
|
2008-04-14 07:45:50 +00:00
|
|
|
* #6 Repeat from step #1
|
2009-02-11 19:25:25 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $titles of Title objects or strings
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function initFromTitles( $titles ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
// Get validated and normalized title objects
|
2010-01-11 15:55:52 +00:00
|
|
|
$linkBatch = $this->processTitlesArray( $titles );
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $linkBatch->isEmpty() ) {
|
2006-10-13 06:13:13 +00:00
|
|
|
return;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-01-22 23:50:42 +00:00
|
|
|
$db = $this->getDB();
|
2010-01-11 15:55:52 +00:00
|
|
|
$set = $linkBatch->constructSet( 'page', $db );
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
// Get pageIDs data from the `page` table
|
|
|
|
|
$this->profileDBIn();
|
2010-01-11 15:55:52 +00:00
|
|
|
$res = $db->select( 'page', $this->getPageTableFields(), $set,
|
|
|
|
|
__METHOD__ );
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->profileDBOut();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
// Hack: get the ns:titles stored in array(ns => array(titles)) format
|
2011-01-12 00:24:25 +00:00
|
|
|
$this->initFromQueryResult( $res, $linkBatch->data, true ); // process Titles
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
// Resolve any found redirects
|
|
|
|
|
$this->resolvePendingRedirects();
|
|
|
|
|
}
|
2006-09-26 06:37:26 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Does the same as initFromTitles(), but is based on page IDs instead
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $pageids of page IDs
|
2009-02-11 19:25:25 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function initFromPageIds( $pageids ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( !$pageids ) {
|
2006-10-13 06:13:13 +00:00
|
|
|
return;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2007-07-08 03:35:37 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$pageids = array_map( 'intval', $pageids ); // paranoia
|
2011-06-05 18:01:30 +00:00
|
|
|
$remaining = array_flip( $pageids );
|
|
|
|
|
|
|
|
|
|
$pageids = self::getPositiveIntegers( $pageids );
|
|
|
|
|
|
2011-06-06 15:58:55 +00:00
|
|
|
$res = null;
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( !empty( $pageids ) ) {
|
2011-06-06 08:45:54 +00:00
|
|
|
$set = array(
|
|
|
|
|
'page_id' => $pageids
|
|
|
|
|
);
|
|
|
|
|
$db = $this->getDB();
|
|
|
|
|
|
|
|
|
|
// Get pageIDs data from the `page` table
|
|
|
|
|
$this->profileDBIn();
|
|
|
|
|
$res = $db->select( 'page', $this->getPageTableFields(), $set,
|
|
|
|
|
__METHOD__ );
|
|
|
|
|
$this->profileDBOut();
|
|
|
|
|
}
|
2011-08-17 22:24:21 +00:00
|
|
|
|
2013-03-07 16:50:43 +00:00
|
|
|
$this->initFromQueryResult( $res, $remaining, false ); // process PageIDs
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
// Resolve any found redirects
|
|
|
|
|
$this->resolvePendingRedirects();
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
/**
|
|
|
|
|
* Iterate through the result of the query on 'page' table,
|
|
|
|
|
* and for each row create and store title object and save any extra fields requested.
|
2010-10-20 18:50:33 +00:00
|
|
|
* @param $res ResultWrapper DB Query result
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $remaining of either pageID or ns/title elements (optional).
|
2006-10-06 01:02:14 +00:00
|
|
|
* If given, any missing items will go to $mMissingPageIDs and $mMissingTitles
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param bool $processTitles Must be provided together with $remaining.
|
2006-10-06 01:02:14 +00:00
|
|
|
* If true, treat $remaining as an array of [ns][title]
|
|
|
|
|
* If false, treat it as an array of [pageIDs]
|
|
|
|
|
*/
|
2011-01-12 00:24:25 +00:00
|
|
|
private function initFromQueryResult( $res, &$remaining = null, $processTitles = null ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !is_null( $remaining ) && is_null( $processTitles ) ) {
|
|
|
|
|
ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2012-05-16 14:46:22 +00:00
|
|
|
$usernames = array();
|
2011-06-06 15:58:55 +00:00
|
|
|
if ( $res ) {
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$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] );
|
|
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-06-06 15:58:55 +00:00
|
|
|
// Store any extra fields requested by modules
|
|
|
|
|
$this->processDbRow( $row );
|
2012-05-16 14:46:22 +00:00
|
|
|
|
|
|
|
|
// Need gender information
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( MWNamespace::hasGenderDistinction( $row->page_namespace ) ) {
|
2012-05-16 14:46:22 +00:00
|
|
|
$usernames[] = $row->page_title;
|
|
|
|
|
}
|
2011-06-06 15:58:55 +00:00
|
|
|
}
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( isset( $remaining ) ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
// Any items left in the $remaining list are added as missing
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $processTitles ) {
|
2009-01-01 02:02:03 +00:00
|
|
|
// The remaining titles in $remaining are non-existent pages
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $remaining as $ns => $dbkeys ) {
|
2010-11-06 16:11:19 +00:00
|
|
|
foreach ( array_keys( $dbkeys ) as $dbkey ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
$title = Title::makeTitle( $ns, $dbkey );
|
2007-07-07 03:05:09 +00:00
|
|
|
$this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
|
|
|
|
|
$this->mMissingTitles[$this->mFakePageId] = $title;
|
|
|
|
|
$this->mFakePageId--;
|
2006-10-30 00:18:05 +00:00
|
|
|
$this->mTitles[] = $title;
|
2012-05-16 14:46:22 +00:00
|
|
|
|
|
|
|
|
// need gender information
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( MWNamespace::hasGenderDistinction( $ns ) ) {
|
2012-05-16 14:46:22 +00:00
|
|
|
$usernames[] = $dbkey;
|
|
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
} else {
|
2006-10-06 01:02:14 +00:00
|
|
|
// The remaining pageids do not exist
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !$this->mMissingPageIDs ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mMissingPageIDs = array_keys( $remaining );
|
2010-02-23 18:05:46 +00:00
|
|
|
} else {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mMissingPageIDs = array_merge( $this->mMissingPageIDs, array_keys( $remaining ) );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-05-16 14:46:22 +00:00
|
|
|
|
|
|
|
|
// Get gender information
|
|
|
|
|
$genderCache = GenderCache::singleton();
|
|
|
|
|
$genderCache->doQuery( $usernames, __METHOD__ );
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Does the same as initFromTitles(), but is based on revision IDs
|
|
|
|
|
* instead
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $revids of revision IDs
|
2009-02-11 19:25:25 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function initFromRevIDs( $revids ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( !$revids ) {
|
2006-10-13 06:13:13 +00:00
|
|
|
return;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$revids = array_map( 'intval', $revids ); // paranoia
|
2007-01-22 23:50:42 +00:00
|
|
|
$db = $this->getDB();
|
2006-10-13 04:59:14 +00:00
|
|
|
$pageids = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
$remaining = array_flip( $revids );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-06-05 18:01:30 +00:00
|
|
|
$revids = self::getPositiveIntegers( $revids );
|
* (bug 25734) API: possible issue with revids validation
It seems, on databases with loads of revision rows (ie enwiki, not testwiki), although the EXPLAIN is sane, it's doing something stupid (table scan? I've nfi). So, as any revision id's less than 0 aren't valid, just prefilter them from the database SQL query
mysql> DESCRIBE SELECT /* ApiPageSet::initFromRevIDs */ rev_id,rev_page FROM `revision`,`page` WHERE rev_id IN ('10','20','30','40','-50','60') AND (rev_page = page_id);
+----+-------------+----------+-------+-------------------------------+---------+---------+-----------------------+-------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+-------------------------------+---------+---------+-----------------------+-------+--------------------------+
| 1 | SIMPLE | page | index | PRIMARY | PRIMARY | 4 | NULL | 22982 | Using index |
| 1 | SIMPLE | revision | ref | PRIMARY,rev_id,page_timestamp | PRIMARY | 4 | testwiki.page.page_id | 1 | Using where; Using index |
+----+-------------+----------+-------+-------------------------------+---------+---------+-----------------------+-------+--------------------------+
2011-06-05 17:49:00 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( !empty( $revids ) ) {
|
2011-06-06 08:45:54 +00:00
|
|
|
$tables = array( 'revision', 'page' );
|
|
|
|
|
$fields = array( 'rev_id', 'rev_page' );
|
|
|
|
|
$where = array( 'rev_id' => $revids, 'rev_page = page_id' );
|
|
|
|
|
|
|
|
|
|
// Get pageIDs data from the `page` table
|
|
|
|
|
$this->profileDBIn();
|
2013-02-03 18:47:42 +00:00
|
|
|
$res = $db->select( $tables, $fields, $where, __METHOD__ );
|
2011-06-06 08:45:54 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$revid = intval( $row->rev_id );
|
|
|
|
|
$pageid = intval( $row->rev_page );
|
|
|
|
|
$this->mGoodRevIDs[$revid] = $pageid;
|
|
|
|
|
$pageids[$pageid] = '';
|
|
|
|
|
unset( $remaining[$revid] );
|
|
|
|
|
}
|
|
|
|
|
$this->profileDBOut();
|
2006-10-13 04:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mMissingRevIDs = array_keys( $remaining );
|
2006-10-13 04:59:14 +00:00
|
|
|
|
|
|
|
|
// Populate all the page information
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->initFromPageIds( array_keys( $pageids ) );
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Resolve any redirects in the result if redirect resolution was
|
|
|
|
|
* requested. This function is called repeatedly until all redirects
|
|
|
|
|
* have been resolved.
|
|
|
|
|
*/
|
2006-10-06 01:02:14 +00:00
|
|
|
private function resolvePendingRedirects() {
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $this->mResolveRedirects ) {
|
2007-01-22 23:50:42 +00:00
|
|
|
$db = $this->getDB();
|
2006-10-06 01:02:14 +00:00
|
|
|
$pageFlds = $this->getPageTableFields();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
// Repeat until all redirects have been resolved
|
|
|
|
|
// The infinite loop is prevented by keeping all known pages in $this->mAllPages
|
2010-01-11 15:55:52 +00:00
|
|
|
while ( $this->mPendingRedirectIDs ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
// Resolve redirects by querying the pagelinks table, and repeat the process
|
|
|
|
|
// Create a new linkBatch object for the next pass
|
|
|
|
|
$linkBatch = $this->getRedirectTargets();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $linkBatch->isEmpty() ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
break;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$set = $linkBatch->constructSet( 'page', $db );
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $set === false ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
break;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
// Get pageIDs data from the `page` table
|
|
|
|
|
$this->profileDBIn();
|
2010-01-11 15:55:52 +00:00
|
|
|
$res = $db->select( 'page', $pageFlds, $set, __METHOD__ );
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->profileDBOut();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
// Hack: get the ns:titles stored in array(ns => array(titles)) format
|
2011-01-12 00:24:25 +00:00
|
|
|
$this->initFromQueryResult( $res, $linkBatch->data, true );
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
2006-10-01 20:17:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Get the targets of the pending redirects from the database
|
|
|
|
|
*
|
|
|
|
|
* Also creates entries in the redirect table for redirects that don't
|
|
|
|
|
* have one.
|
|
|
|
|
* @return LinkBatch
|
|
|
|
|
*/
|
2006-10-06 01:02:14 +00:00
|
|
|
private function getRedirectTargets() {
|
2008-04-04 11:22:58 +00:00
|
|
|
$lb = new LinkBatch();
|
2007-01-22 23:50:42 +00:00
|
|
|
$db = $this->getDB();
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2012-12-12 21:51:54 +00:00
|
|
|
$this->profileDBIn();
|
2010-02-23 18:05:46 +00:00
|
|
|
$res = $db->select(
|
|
|
|
|
'redirect',
|
|
|
|
|
array(
|
2008-04-04 11:22:58 +00:00
|
|
|
'rd_from',
|
|
|
|
|
'rd_namespace',
|
2011-05-14 12:48:07 +00:00
|
|
|
'rd_fragment',
|
|
|
|
|
'rd_interwiki',
|
2008-04-04 11:22:58 +00:00
|
|
|
'rd_title'
|
2012-12-12 21:51:54 +00:00
|
|
|
), array( 'rd_from' => array_keys( $this->mPendingRedirectIDs ) ),
|
2008-04-04 11:22:58 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2012-12-12 21:51:54 +00:00
|
|
|
$this->profileDBOut();
|
2010-06-20 18:48:34 +00:00
|
|
|
foreach ( $res as $row ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$rdfrom = intval( $row->rd_from );
|
2012-12-12 21:51:54 +00:00
|
|
|
$from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
|
2011-05-14 12:48:07 +00:00
|
|
|
$to = Title::makeTitle( $row->rd_namespace, $row->rd_title, $row->rd_fragment, $row->rd_interwiki );
|
2012-12-12 21:51:54 +00:00
|
|
|
unset( $this->mPendingRedirectIDs[$rdfrom] );
|
|
|
|
|
if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
|
|
|
|
|
$lb->add( $row->rd_namespace, $row->rd_title );
|
|
|
|
|
}
|
|
|
|
|
$this->mRedirectTitles[$from] = $to;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
2010-06-20 17:48:21 +00:00
|
|
|
|
2012-12-12 21:51:54 +00:00
|
|
|
if ( $this->mPendingRedirectIDs ) {
|
2010-01-23 22:52:40 +00:00
|
|
|
// We found pages that aren't in the redirect table
|
|
|
|
|
// Add them
|
2012-12-12 21:51:54 +00:00
|
|
|
foreach ( $this->mPendingRedirectIDs as $id => $title ) {
|
|
|
|
|
$page = WikiPage::factory( $title );
|
2011-11-12 07:36:41 +00:00
|
|
|
$rt = $page->insertRedirect();
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !$rt ) {
|
2010-01-23 22:52:40 +00:00
|
|
|
// What the hell. Let's just ignore this
|
2008-04-11 15:20:45 +00:00
|
|
|
continue;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2012-12-12 21:51:54 +00:00
|
|
|
$lb->addObj( $rt );
|
|
|
|
|
$this->mRedirectTitles[$title->getPrefixedText()] = $rt;
|
|
|
|
|
unset( $this->mPendingRedirectIDs[$id] );
|
2008-04-11 15:20:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-12-12 21:51:54 +00:00
|
|
|
return $lb;
|
2006-09-27 05:13:48 +00:00
|
|
|
}
|
2006-09-29 07:29:13 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get the cache mode for the data generated by this module.
|
|
|
|
|
* All PageSet users should take into account whether this returns a more-restrictive
|
|
|
|
|
* cache mode than the using module itself. For possible return values and other
|
|
|
|
|
* details about cache modes, see ApiMain::setCacheMode()
|
|
|
|
|
*
|
|
|
|
|
* Public caching will only be allowed if *all* the modules that supply
|
|
|
|
|
* data for a given request return a cache mode of public.
|
|
|
|
|
*
|
|
|
|
|
* @param $params
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getCacheMode( $params = null ) {
|
|
|
|
|
return $this->mCacheMode;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
/**
|
|
|
|
|
* Given an array of title strings, convert them into Title objects.
|
2013-03-02 00:06:46 +00:00
|
|
|
* Alternatively, an array of Title objects may be given.
|
2008-04-14 07:45:50 +00:00
|
|
|
* This method validates access rights for the title,
|
2006-09-27 05:13:48 +00:00
|
|
|
* and appends normalization values to the output.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $titles of Title objects or strings
|
2009-02-11 19:25:25 +00:00
|
|
|
* @return LinkBatch
|
2006-09-27 05:13:48 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function processTitlesArray( $titles ) {
|
2013-03-04 21:22:14 +00:00
|
|
|
$usernames = array();
|
2006-09-27 05:13:48 +00:00
|
|
|
$linkBatch = new LinkBatch();
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $titles as $title ) {
|
2013-03-04 21:22:14 +00:00
|
|
|
if ( is_string( $title ) ) {
|
|
|
|
|
$titleObj = Title::newFromText( $title, $this->mDefaultNamespace );
|
|
|
|
|
} else {
|
|
|
|
|
$titleObj = $title;
|
|
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !$titleObj ) {
|
2010-01-23 22:52:40 +00:00
|
|
|
// Handle invalid titles gracefully
|
2013-03-07 20:31:43 +00:00
|
|
|
$this->mAllPages[0][$title] = $this->mFakePageId;
|
2008-03-18 15:17:24 +00:00
|
|
|
$this->mInvalidTitles[$this->mFakePageId] = $title;
|
|
|
|
|
$this->mFakePageId--;
|
|
|
|
|
continue; // There's nothing else we can do
|
|
|
|
|
}
|
2010-07-10 11:53:22 +00:00
|
|
|
$unconvertedTitle = $titleObj->getPrefixedText();
|
2010-07-23 07:33:40 +00:00
|
|
|
$titleWasConverted = false;
|
2013-03-04 21:22:14 +00:00
|
|
|
if ( $titleObj->isExternal() ) {
|
2007-06-14 03:14:44 +00:00
|
|
|
// This title is an interwiki link.
|
2013-03-04 21:22:14 +00:00
|
|
|
$this->mInterwikiTitles[$unconvertedTitle] = $titleObj->getInterwiki();
|
2008-04-14 07:45:50 +00:00
|
|
|
} else {
|
2010-07-10 11:53:22 +00:00
|
|
|
// Variants checking
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
if ( $this->mConvertTitles &&
|
2013-03-07 16:50:43 +00:00
|
|
|
count( $wgContLang->getVariants() ) > 1 &&
|
2010-07-20 09:26:56 +00:00
|
|
|
!$titleObj->exists() ) {
|
2013-01-11 09:00:32 +00:00
|
|
|
// Language::findVariantLink will modify titleText and titleObj into
|
2010-07-10 11:53:22 +00:00
|
|
|
// the canonical variant if possible
|
2013-01-11 09:00:32 +00:00
|
|
|
$titleText = is_string( $title ) ? $title : $titleObj->getPrefixedText();
|
|
|
|
|
$wgContLang->findVariantLink( $titleText, $titleObj );
|
2010-07-10 11:53:22 +00:00
|
|
|
$titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
|
|
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $titleObj->getNamespace() < 0 ) {
|
2010-07-10 11:53:22 +00:00
|
|
|
// Handle Special and Media pages
|
2010-07-10 10:46:20 +00:00
|
|
|
$titleObj = $titleObj->fixSpecialName();
|
|
|
|
|
$this->mSpecialTitles[$this->mFakePageId] = $titleObj;
|
|
|
|
|
$this->mFakePageId--;
|
2010-02-23 18:05:46 +00:00
|
|
|
} else {
|
2010-07-10 11:53:22 +00:00
|
|
|
// Regular page
|
2010-01-11 15:55:52 +00:00
|
|
|
$linkBatch->addObj( $titleObj );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2007-06-14 03:14:44 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
// Make sure we remember the original title that was
|
|
|
|
|
// given to us. This way the caller can correlate new
|
|
|
|
|
// titles with the originally requested when e.g. the
|
|
|
|
|
// namespace is localized or the capitalization is
|
|
|
|
|
// different
|
2010-07-10 11:53:22 +00:00
|
|
|
if ( $titleWasConverted ) {
|
2013-01-11 09:00:32 +00:00
|
|
|
$this->mConvertedTitles[$unconvertedTitle] = $titleObj->getPrefixedText();
|
|
|
|
|
// In this case the page can't be Special.
|
|
|
|
|
if ( is_string( $title ) && $title !== $unconvertedTitle ) {
|
|
|
|
|
$this->mNormalizedTitles[$title] = $unconvertedTitle;
|
|
|
|
|
}
|
2010-07-10 11:53:22 +00:00
|
|
|
} elseif ( is_string( $title ) && $title !== $titleObj->getPrefixedText() ) {
|
2007-05-14 05:28:06 +00:00
|
|
|
$this->mNormalizedTitles[$title] = $titleObj->getPrefixedText();
|
2006-09-27 05:13:48 +00:00
|
|
|
}
|
2013-03-04 21:22:14 +00:00
|
|
|
|
|
|
|
|
// Need gender information
|
|
|
|
|
if ( MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) {
|
|
|
|
|
$usernames[] = $titleObj->getText();
|
|
|
|
|
}
|
2006-09-27 05:13:48 +00:00
|
|
|
}
|
2013-03-04 21:22:14 +00:00
|
|
|
// Get gender information
|
|
|
|
|
$genderCache = GenderCache::singleton();
|
|
|
|
|
$genderCache->doQuery( $usernames, __METHOD__ );
|
2006-09-27 05:13:48 +00:00
|
|
|
|
|
|
|
|
return $linkBatch;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get the database connection (read-only)
|
|
|
|
|
* @return DatabaseBase
|
|
|
|
|
*/
|
|
|
|
|
protected function getDB() {
|
|
|
|
|
return $this->mDbSource->getDB();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-05 18:01:30 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the input array of integers with all values < 0 removed
|
|
|
|
|
*
|
|
|
|
|
* @param $array array
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private static function getPositiveIntegers( $array ) {
|
|
|
|
|
// bug 25734 API: possible issue with revids validation
|
|
|
|
|
// It seems with a load of revision rows, MySQL gets upset
|
|
|
|
|
// Remove any < 0 integers, as they can't be valid
|
2013-02-08 20:39:40 +00:00
|
|
|
foreach ( $array as $i => $int ) {
|
2011-06-05 18:01:30 +00:00
|
|
|
if ( $int < 0 ) {
|
|
|
|
|
unset( $array[$i] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
public function getAllowedParams( $flags = 0 ) {
|
|
|
|
|
$result = array(
|
2010-02-23 18:05:46 +00:00
|
|
|
'titles' => array(
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true
|
2006-09-30 08:06:27 +00:00
|
|
|
),
|
2010-02-23 18:05:46 +00:00
|
|
|
'pageids' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true
|
2006-09-30 08:06:27 +00:00
|
|
|
),
|
2010-02-23 18:05:46 +00:00
|
|
|
'revids' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true
|
2013-02-08 20:39:40 +00:00
|
|
|
),
|
|
|
|
|
'redirects' => false,
|
|
|
|
|
'converttitles' => false,
|
2006-09-30 08:06:27 +00:00
|
|
|
);
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( $this->mAllowGenerator ) {
|
2013-02-08 23:43:25 +00:00
|
|
|
if ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
|
|
|
|
|
$result['generator'] = array(
|
|
|
|
|
ApiBase::PARAM_TYPE => $this->getGenerators()
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$result['generator'] = null;
|
|
|
|
|
}
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static $generators = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get an array of all available generators
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private function getGenerators() {
|
|
|
|
|
if ( self::$generators === null ) {
|
|
|
|
|
$query = $this->mDbSource;
|
|
|
|
|
if ( !( $query instanceof ApiQuery ) ) {
|
|
|
|
|
// If the parent container of this pageset is not ApiQuery,
|
|
|
|
|
// we must create it to get module manager
|
|
|
|
|
$query = $this->getMain()->getModuleManager()->getModule( 'query' );
|
|
|
|
|
}
|
2013-02-08 23:43:25 +00:00
|
|
|
$gens = array();
|
|
|
|
|
$mgr = $query->getModuleManager();
|
|
|
|
|
foreach ( $mgr->getNamesWithClasses() as $name => $class ) {
|
|
|
|
|
if ( is_subclass_of( $class, 'ApiQueryGeneratorBase' ) ) {
|
|
|
|
|
$gens[] = $name;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-08 20:39:40 +00:00
|
|
|
sort( $gens );
|
|
|
|
|
self::$generators = $gens;
|
|
|
|
|
}
|
|
|
|
|
return self::$generators;
|
2006-09-30 08:06:27 +00:00
|
|
|
}
|
2006-10-01 02:02:13 +00:00
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getParamDescription() {
|
2010-02-23 18:05:46 +00:00
|
|
|
return array(
|
2006-09-30 08:06:27 +00:00
|
|
|
'titles' => 'A list of titles to work on',
|
|
|
|
|
'pageids' => 'A list of page IDs to work on',
|
2013-02-08 20:39:40 +00:00
|
|
|
'revids' => 'A list of revision IDs to work on',
|
|
|
|
|
'generator' => array( 'Get the list of pages to work on by executing the specified query module.',
|
|
|
|
|
'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 ' . implode( ', ', LanguageConverter::$languagesWithVariants ) ),
|
2006-09-30 08:06:27 +00:00
|
|
|
);
|
2006-09-25 06:10:16 +00:00
|
|
|
}
|
2006-10-01 21:20:55 +00:00
|
|
|
|
2010-02-13 01:21:52 +00:00
|
|
|
public function getPossibleErrors() {
|
|
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'code' => 'multisource', 'info' => "Cannot use 'pageids' at the same time as 'dataSource'" ),
|
|
|
|
|
array( 'code' => 'multisource', 'info' => "Cannot use 'revids' at the same time as 'dataSource'" ),
|
2013-02-08 20:39:40 +00:00
|
|
|
array( 'code' => 'badgenerator', 'info' => 'Module $generatorName cannot be used as a generator' ),
|
2010-02-13 01:21:52 +00:00
|
|
|
) );
|
|
|
|
|
}
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|