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 {
|
|
|
|
|
/**
|
|
|
|
|
* 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();
|
2014-09-26 14:56:00 +00:00
|
|
|
private $mGoodAndMissingPages = array(); // [ns][dbkey] => page_id or negative when missing
|
|
|
|
|
private $mGoodPages = array(); // [ns][dbkey] => page_id
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mGoodTitles = array();
|
2014-09-26 14:56:00 +00:00
|
|
|
private $mMissingPages = array(); // [ns][dbkey] => fake page_id
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mMissingTitles = array();
|
|
|
|
|
private $mInvalidTitles = array();
|
|
|
|
|
private $mMissingPageIDs = array();
|
|
|
|
|
private $mRedirectTitles = array();
|
|
|
|
|
private $mSpecialTitles = array();
|
|
|
|
|
private $mNormalizedTitles = array();
|
|
|
|
|
private $mInterwikiTitles = array();
|
2014-07-08 21:40:06 +00:00
|
|
|
/** @var Title[] */
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mPendingRedirectIDs = array();
|
|
|
|
|
private $mConvertedTitles = array();
|
|
|
|
|
private $mGoodRevIDs = array();
|
2014-09-29 17:47:08 +00:00
|
|
|
private $mLiveRevIDs = array();
|
|
|
|
|
private $mDeletedRevIDs = array();
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mMissingRevIDs = array();
|
2014-11-24 21:21:49 +00:00
|
|
|
private $mGeneratorData = array(); // [ns][dbkey] => data array
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mFakePageId = -1;
|
|
|
|
|
private $mCacheMode = 'public';
|
|
|
|
|
private $mRequestedPageFields = array();
|
2014-07-08 21:40:06 +00:00
|
|
|
/** @var int */
|
2013-03-04 21:22:14 +00:00
|
|
|
private $mDefaultNamespace = NS_MAIN;
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2014-01-29 18:10:36 +00:00
|
|
|
/**
|
|
|
|
|
* Add all items from $values into the result
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $result Output
|
|
|
|
|
* @param array $values Values to add
|
|
|
|
|
* @param string $flag The name of the boolean flag to mark this element
|
|
|
|
|
* @param string $name If given, name of the value
|
2014-01-29 18:10:36 +00:00
|
|
|
*/
|
|
|
|
|
private static function addValues( array &$result, $values, $flag = null, $name = null ) {
|
|
|
|
|
foreach ( $values as $val ) {
|
|
|
|
|
if ( $val instanceof Title ) {
|
|
|
|
|
$v = array();
|
|
|
|
|
ApiQueryBase::addTitleInfo( $v, $val );
|
|
|
|
|
} elseif ( $name !== null ) {
|
|
|
|
|
$v = array( $name => $val );
|
|
|
|
|
} else {
|
|
|
|
|
$v = $val;
|
|
|
|
|
}
|
|
|
|
|
if ( $flag !== null ) {
|
|
|
|
|
$v[$flag] = '';
|
|
|
|
|
}
|
|
|
|
|
$result[] = $v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiBase $dbSource Module implementing getDB().
|
2013-02-08 20:39:40 +00:00
|
|
|
* 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
|
2014-04-15 18:12:09 +00:00
|
|
|
* @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.
|
2013-11-14 18:03:09 +00:00
|
|
|
* @param bool $isDryRun If true, instantiates generator, but only to mark
|
|
|
|
|
* relevant parameters as used
|
2013-03-02 00:06:46 +00:00
|
|
|
*/
|
|
|
|
|
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 ) );
|
|
|
|
|
} 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();
|
|
|
|
|
|
2013-07-22 17:08:31 +00:00
|
|
|
if ( !$isDryRun ) {
|
|
|
|
|
$this->resolvePendingRedirects();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
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
|
2013-04-26 14:42:31 +00:00
|
|
|
switch ( $dataSource ) {
|
2013-03-02 00:06:46 +00:00
|
|
|
case 'titles':
|
|
|
|
|
$this->initFromTitles( $this->mParams['titles'] );
|
|
|
|
|
break;
|
|
|
|
|
case 'pageids':
|
|
|
|
|
$this->initFromPageIds( $this->mParams['pageids'] );
|
|
|
|
|
break;
|
|
|
|
|
case 'revids':
|
|
|
|
|
if ( $this->mResolveRedirects ) {
|
2013-11-14 18:03:09 +00:00
|
|
|
$this->setWarning( 'Redirect resolution cannot be used ' .
|
|
|
|
|
'together with the revids= parameter. Any redirects ' .
|
|
|
|
|
'the revids= point to have not been resolved.' );
|
2013-03-02 00:06:46 +00:00
|
|
|
}
|
|
|
|
|
$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';
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-03-15 18:03:19 +00:00
|
|
|
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
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array 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 );
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
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.
|
2013-12-30 17:32:53 +00:00
|
|
|
* @return Title[]
|
2006-10-30 00:18:05 +00:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2014-09-26 14:56:00 +00:00
|
|
|
/**
|
|
|
|
|
* Returns an array [ns][dbkey] => page_id for all good titles.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getGoodTitlesByNamespace() {
|
|
|
|
|
return $this->mGoodPages;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
|
|
|
|
* Title objects that were found in the database.
|
2013-12-30 17:32:53 +00:00
|
|
|
* @return Title[] Array page_id (int) => Title (obj)
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
2014-09-26 14:56:00 +00:00
|
|
|
/**
|
|
|
|
|
* Returns an array [ns][dbkey] => fake_page_id for all missing titles.
|
|
|
|
|
* fake_page_id is a unique negative number.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getMissingTitlesByNamespace() {
|
|
|
|
|
return $this->mMissingPages;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2013-12-30 17:32:53 +00:00
|
|
|
* @return Title[]
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
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
|
|
|
|
2014-09-26 14:56:00 +00:00
|
|
|
/**
|
|
|
|
|
* Returns an array [ns][dbkey] => page_id for all good and missing titles.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getGoodAndMissingTitlesByNamespace() {
|
|
|
|
|
return $this->mGoodAndMissingPages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Title objects for good and missing titles.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getGoodAndMissingTitles() {
|
|
|
|
|
return $this->mGoodTitles + $this->mMissingTitles;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2013-12-30 17:32:53 +00:00
|
|
|
* @return string[] Array of strings (not Title objects)
|
2008-03-18 15:17:24 +00:00
|
|
|
*/
|
|
|
|
|
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
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array Array of page IDs
|
2006-10-01 20:17:16 +00:00
|
|
|
*/
|
|
|
|
|
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
|
2014-07-08 21:40:06 +00:00
|
|
|
* @return Title[]
|
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.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiResult $result
|
|
|
|
|
* @return array Array of prefixed_title (string) => Title object
|
2013-02-08 20:39:40 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getRedirectTitlesAsResult( $result = null ) {
|
|
|
|
|
$values = array();
|
|
|
|
|
foreach ( $this->getRedirectTitles() as $titleStrFrom => $titleTo ) {
|
|
|
|
|
$r = array(
|
|
|
|
|
'from' => strval( $titleStrFrom ),
|
|
|
|
|
'to' => $titleTo->getPrefixedText(),
|
|
|
|
|
);
|
2014-01-02 11:16:21 +00:00
|
|
|
if ( $titleTo->hasFragment() ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
$r['tofragment'] = $titleTo->getFragment();
|
|
|
|
|
}
|
|
|
|
|
$values[] = $r;
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $values ) && $result ) {
|
|
|
|
|
$result->setIndexedTagName( $values, 'r' );
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
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.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array Array of 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.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiResult $result
|
|
|
|
|
* @return array Array of raw_prefixed_title (string) => prefixed_title (string)
|
2013-02-08 20:39:40 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
2013-04-26 14:42:31 +00:00
|
|
|
public function getNormalizedTitlesAsResult( $result = null ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
$values = array();
|
|
|
|
|
foreach ( $this->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
|
|
|
|
|
$values[] = array(
|
|
|
|
|
'from' => $rawTitleStr,
|
|
|
|
|
'to' => $titleStr
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $values ) && $result ) {
|
|
|
|
|
$result->setIndexedTagName( $values, 'n' );
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
return $values;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-10 11:53:22 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of title conversions - maps a title to its converted
|
|
|
|
|
* version.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array Array of 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.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiResult $result
|
|
|
|
|
* @return array Array of (from, to) strings
|
2013-02-08 20:39:40 +00:00
|
|
|
* @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' );
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
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.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array Array of 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.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiResult $result
|
|
|
|
|
* @param bool $iwUrl
|
|
|
|
|
* @return array Array of raw_prefixed_title (string) => interwiki_prefix (string)
|
2013-02-08 20:39:40 +00:00
|
|
|
* @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' );
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
return $values;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 18:10:36 +00:00
|
|
|
/**
|
|
|
|
|
* Get an array of invalid/special/missing titles.
|
|
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $invalidChecks List of types of invalid titles to include.
|
2014-01-29 18:10:36 +00:00
|
|
|
* Recognized values are:
|
|
|
|
|
* - invalidTitles: Titles from $this->getInvalidTitles()
|
|
|
|
|
* - special: Titles from $this->getSpecialTitles()
|
|
|
|
|
* - missingIds: ids from $this->getMissingPageIDs()
|
|
|
|
|
* - missingRevIds: ids from $this->getMissingRevisionIDs()
|
|
|
|
|
* - missingTitles: Titles from $this->getMissingTitles()
|
|
|
|
|
* - interwikiTitles: Titles from $this->getInterwikiTitlesAsResult()
|
|
|
|
|
* @return array Array suitable for inclusion in the response
|
|
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
2014-02-05 10:20:17 +00:00
|
|
|
public function getInvalidTitlesAndRevisions( $invalidChecks = array( 'invalidTitles',
|
|
|
|
|
'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' )
|
|
|
|
|
) {
|
2014-01-29 18:10:36 +00:00
|
|
|
$result = array();
|
|
|
|
|
if ( in_array( "invalidTitles", $invalidChecks ) ) {
|
|
|
|
|
self::addValues( $result, $this->getInvalidTitles(), 'invalid', 'title' );
|
|
|
|
|
}
|
|
|
|
|
if ( in_array( "special", $invalidChecks ) ) {
|
|
|
|
|
self::addValues( $result, $this->getSpecialTitles(), 'special', 'title' );
|
|
|
|
|
}
|
|
|
|
|
if ( in_array( "missingIds", $invalidChecks ) ) {
|
2014-02-05 11:02:29 +00:00
|
|
|
self::addValues( $result, $this->getMissingPageIDs(), 'missing', 'pageid' );
|
2014-01-29 18:10:36 +00:00
|
|
|
}
|
|
|
|
|
if ( in_array( "missingRevIds", $invalidChecks ) ) {
|
|
|
|
|
self::addValues( $result, $this->getMissingRevisionIDs(), 'missing', 'revid' );
|
|
|
|
|
}
|
|
|
|
|
if ( in_array( "missingTitles", $invalidChecks ) ) {
|
|
|
|
|
self::addValues( $result, $this->getMissingTitles(), 'missing' );
|
|
|
|
|
}
|
|
|
|
|
if ( in_array( "interwikiTitles", $invalidChecks ) ) {
|
|
|
|
|
self::addValues( $result, $this->getInterwikiTitlesAsResult() );
|
|
|
|
|
}
|
2014-02-05 11:02:29 +00:00
|
|
|
|
2014-01-29 18:10:36 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-30 08:06:27 +00:00
|
|
|
/**
|
2014-09-29 17:47:08 +00:00
|
|
|
* Get the list of valid revision IDs (requested with the revids= parameter)
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array Array of 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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-29 17:47:08 +00:00
|
|
|
/**
|
|
|
|
|
* Get the list of non-deleted revision IDs (requested with the revids= parameter)
|
|
|
|
|
* @return array Array of revID (int) => pageID (int)
|
|
|
|
|
*/
|
|
|
|
|
public function getLiveRevisionIDs() {
|
|
|
|
|
return $this->mLiveRevIDs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the list of revision IDs that were associated with deleted titles.
|
|
|
|
|
* @return array Array of revID (int) => pageID (int)
|
|
|
|
|
*/
|
|
|
|
|
public function getDeletedRevisionIDs() {
|
|
|
|
|
return $this->mDeletedRevIDs;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-13 04:59:14 +00:00
|
|
|
/**
|
|
|
|
|
* Revision IDs that were not found in the database
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array Array of revision IDs
|
2006-10-13 04:59:14 +00:00
|
|
|
*/
|
|
|
|
|
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.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiResult $result
|
|
|
|
|
* @return array Array of revision IDs
|
2013-02-08 20:39:40 +00:00
|
|
|
* @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' );
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
return $values;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-10 10:46:20 +00:00
|
|
|
/**
|
|
|
|
|
* Get the list of titles with negative namespace
|
2014-07-08 21:40:06 +00:00
|
|
|
* @return Title[]
|
2010-07-10 10:46:20 +00:00
|
|
|
*/
|
|
|
|
|
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
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $titles Array 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
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $pageIDs Array 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
|
2014-10-30 17:23:09 +00:00
|
|
|
*
|
|
|
|
|
* Note that the query result must include the columns returned by
|
|
|
|
|
* $this->getPageTableFields().
|
|
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param DatabaseBase $db
|
|
|
|
|
* @param ResultWrapper $queryResult 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
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $revIDs Array 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
|
2013-11-16 21:15:17 +00:00
|
|
|
* @param stdClass $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 {
|
2014-09-26 14:56:00 +00:00
|
|
|
$this->mGoodPages[$row->page_namespace][$row->page_title] = $pageId;
|
|
|
|
|
$this->mGoodAndMissingPages[$row->page_namespace][$row->page_title] = $pageId;
|
2007-07-14 19:04:31 +00:00
|
|
|
$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
|
2013-05-15 00:53:49 +00:00
|
|
|
* @deprecated since 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
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $titles Array 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,
|
2013-11-14 12:47:20 +00:00
|
|
|
__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
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $pageids Array 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,
|
2013-11-14 12:47:20 +00:00
|
|
|
__METHOD__ );
|
2011-06-06 08:45:54 +00:00
|
|
|
$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.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ResultWrapper $res DB Query result
|
|
|
|
|
* @param array $remaining Array 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;
|
2014-09-26 14:56:00 +00:00
|
|
|
$this->mMissingPages[$ns][$dbkey] = $this->mFakePageId;
|
|
|
|
|
$this->mGoodAndMissingPages[$ns][$dbkey] = $this->mFakePageId;
|
2007-07-07 03:05:09 +00:00
|
|
|
$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
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $revids Array 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;
|
2014-09-29 17:47:08 +00:00
|
|
|
$this->mLiveRevIDs[$revid] = $pageid;
|
2011-06-06 08:45:54 +00:00
|
|
|
$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 ) );
|
2014-09-29 17:47:08 +00:00
|
|
|
|
|
|
|
|
// If the user can see deleted revisions, pull out the corresponding
|
|
|
|
|
// titles from the archive table and include them too. We ignore
|
|
|
|
|
// ar_page_id because deleted revisions are tied by title, not page_id.
|
|
|
|
|
if ( !empty( $this->mMissingRevIDs ) && $this->getUser()->isAllowed( 'deletedhistory' ) ) {
|
|
|
|
|
$remaining = array_flip( $this->mMissingRevIDs );
|
|
|
|
|
$tables = array( 'archive' );
|
|
|
|
|
$fields = array( 'ar_rev_id', 'ar_namespace', 'ar_title' );
|
|
|
|
|
$where = array( 'ar_rev_id' => $this->mMissingRevIDs );
|
|
|
|
|
|
|
|
|
|
$this->profileDBIn();
|
|
|
|
|
$res = $db->select( $tables, $fields, $where, __METHOD__ );
|
|
|
|
|
$titles = array();
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$revid = intval( $row->ar_rev_id );
|
|
|
|
|
$titles[$revid] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
|
|
|
|
|
unset( $remaining[$revid] );
|
|
|
|
|
}
|
|
|
|
|
$this->profileDBOut();
|
|
|
|
|
|
|
|
|
|
$this->initFromTitles( $titles );
|
|
|
|
|
|
|
|
|
|
foreach ( $titles as $revid => $title ) {
|
|
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbkey = $title->getDBkey();
|
|
|
|
|
|
|
|
|
|
// Handle converted titles
|
|
|
|
|
if ( !isset( $this->mAllPages[$ns][$dbkey] ) &&
|
|
|
|
|
isset( $this->mConvertedTitles[$title->getPrefixedText()] )
|
|
|
|
|
) {
|
|
|
|
|
$title = Title::newFromText( $this->mConvertedTitles[$title->getPrefixedText()] );
|
|
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbkey = $title->getDBkey();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $this->mAllPages[$ns][$dbkey] ) ) {
|
|
|
|
|
$this->mGoodRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
|
|
|
|
|
$this->mDeletedRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
|
|
|
|
|
} else {
|
|
|
|
|
$remaining[$revid] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->mMissingRevIDs = array_keys( $remaining );
|
|
|
|
|
}
|
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();
|
2013-11-14 18:03:09 +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] );
|
2013-05-11 18:44:55 +00:00
|
|
|
if ( !$to->isExternal() && !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
|
2012-12-12 21:51:54 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 12:47:20 +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.
|
|
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array|null $params
|
2013-02-08 20:39:40 +00:00
|
|
|
* @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
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $titles Array 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-11-14 12:47:20 +00:00
|
|
|
count( $wgContLang->getVariants() ) > 1 &&
|
|
|
|
|
!$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
|
|
|
|
2014-11-24 21:21:49 +00:00
|
|
|
/**
|
|
|
|
|
* Set data for a title.
|
|
|
|
|
*
|
|
|
|
|
* This data may be extracted into an ApiResult using
|
|
|
|
|
* self::populateGeneratorData. This should generally be limited to
|
|
|
|
|
* data that is likely to be particularly useful to end users rather than
|
|
|
|
|
* just being a dump of everything returned in non-generator mode.
|
|
|
|
|
*
|
|
|
|
|
* Redirects here will *not* be followed, even if 'redirects' was
|
|
|
|
|
* specified, since in the case of multiple redirects we can't know which
|
|
|
|
|
* source's data to use on the target.
|
|
|
|
|
*
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param array $data
|
|
|
|
|
*/
|
|
|
|
|
public function setGeneratorData( Title $title, array $data ) {
|
|
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbkey = $title->getDBkey();
|
|
|
|
|
$this->mGeneratorData[$ns][$dbkey] = $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Populate the generator data for all titles in the result
|
|
|
|
|
*
|
|
|
|
|
* The page data may be inserted into an ApiResult object or into an
|
|
|
|
|
* associative array. The $path parameter specifies the path within the
|
|
|
|
|
* ApiResult or array to find the "pages" node.
|
|
|
|
|
*
|
|
|
|
|
* The "pages" node itself must be an associative array mapping the page ID
|
|
|
|
|
* or fake page ID values returned by this pageset (see
|
|
|
|
|
* self::getAllTitlesByNamespace() and self::getSpecialTitles()) to
|
|
|
|
|
* associative arrays of page data. Each of those subarrays will have the
|
|
|
|
|
* data from self::setGeneratorData() merged in.
|
|
|
|
|
*
|
|
|
|
|
* Data that was set by self::setGeneratorData() for pages not in the
|
|
|
|
|
* "pages" node will be ignored.
|
|
|
|
|
*
|
|
|
|
|
* @param ApiResult|array &$result
|
|
|
|
|
* @param array $path
|
|
|
|
|
* @return boolean Whether the data fit
|
|
|
|
|
*/
|
|
|
|
|
public function populateGeneratorData( &$result, array $path = array() ) {
|
|
|
|
|
if ( $result instanceof ApiResult ) {
|
|
|
|
|
$data = $result->getData();
|
|
|
|
|
} else {
|
|
|
|
|
$data = &$result;
|
|
|
|
|
}
|
|
|
|
|
foreach ( $path as $key ) {
|
|
|
|
|
if ( !isset( $data[$key] ) ) {
|
|
|
|
|
// Path isn't in $result, so nothing to add, so everything
|
|
|
|
|
// "fits"
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
$data = &$data[$key];
|
|
|
|
|
}
|
|
|
|
|
foreach ( $this->mGeneratorData as $ns => $dbkeys ) {
|
|
|
|
|
if ( $ns === -1 ) {
|
|
|
|
|
$pages = array();
|
|
|
|
|
foreach ( $this->mSpecialTitles as $id => $title ) {
|
|
|
|
|
$pages[$title->getDBkey()] = $id;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ( !isset( $this->mAllPages[$ns] ) ) {
|
|
|
|
|
// No known titles in the whole namespace. Skip it.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$pages = $this->mAllPages[$ns];
|
|
|
|
|
}
|
|
|
|
|
foreach ( $dbkeys as $dbkey => $genData ) {
|
|
|
|
|
if ( !isset( $pages[$dbkey] ) ) {
|
|
|
|
|
// Unknown title. Forget it.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$pageId = $pages[$dbkey];
|
|
|
|
|
if ( !isset( $data[$pageId] ) ) {
|
|
|
|
|
// $pageId didn't make it into the result. Ignore it.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $result instanceof ApiResult ) {
|
|
|
|
|
$path2 = array_merge( $path, array( $pageId ) );
|
|
|
|
|
foreach ( $genData as $key => $value ) {
|
|
|
|
|
if ( !$result->addValue( $path2, $key, $value ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$data[$pageId] = array_merge( $data[$pageId], $genData );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $array
|
2011-06-05 18:01:30 +00:00
|
|
|
* @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(
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-pageset-param-titles',
|
2006-09-30 08:06:27 +00:00
|
|
|
),
|
2010-02-23 18:05:46 +00:00
|
|
|
'pageids' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-pageset-param-pageids',
|
2006-09-30 08:06:27 +00:00
|
|
|
),
|
2010-02-23 18:05:46 +00:00
|
|
|
'revids' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-pageset-param-revids',
|
|
|
|
|
),
|
|
|
|
|
'generator' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => null,
|
|
|
|
|
ApiBase::PARAM_VALUE_LINKS => array(),
|
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-pageset-param-generator',
|
|
|
|
|
),
|
|
|
|
|
'redirects' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_HELP_MSG => $this->mAllowGenerator
|
|
|
|
|
? 'api-pageset-param-redirects-generator'
|
|
|
|
|
: 'api-pageset-param-redirects-nogenerator',
|
|
|
|
|
),
|
|
|
|
|
'converttitles' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_HELP_MSG => array(
|
|
|
|
|
'api-pageset-param-converttitles',
|
|
|
|
|
$this->getLanguage()->commaList( LanguageConverter::$languagesWithVariants ),
|
|
|
|
|
),
|
2013-02-08 20:39:40 +00:00
|
|
|
),
|
2006-09-30 08:06:27 +00:00
|
|
|
);
|
2014-09-18 17:38:23 +00:00
|
|
|
|
|
|
|
|
if ( !$this->mAllowGenerator ) {
|
|
|
|
|
unset( $result['generator'] );
|
|
|
|
|
} elseif ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
|
2014-12-09 14:28:35 +00:00
|
|
|
foreach ( $this->getGenerators() as $g ) {
|
2014-09-18 17:38:23 +00:00
|
|
|
$result['generator'][ApiBase::PARAM_TYPE][] = $g;
|
|
|
|
|
$result['generator'][ApiBase::PARAM_VALUE_LINKS][$g] = "Special:ApiHelp/query+$g";
|
2013-02-08 23:43:25 +00:00
|
|
|
}
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
return self::$generators;
|
2006-09-30 08:06:27 +00:00
|
|
|
}
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|