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
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2006 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
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
2006-09-26 06:37:26 +00:00
|
|
|
class ApiPageSet extends ApiQueryBase {
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2008-03-18 15:17:24 +00:00
|
|
|
private $mAllPages; // [ns][dbkey] => page_id or negative when missing
|
|
|
|
|
private $mTitles, $mGoodTitles, $mMissingTitles, $mInvalidTitles;
|
2010-07-10 10:46:20 +00:00
|
|
|
private $mMissingPageIDs, $mRedirectTitles, $mSpecialTitles;
|
2007-07-07 03:05:09 +00:00
|
|
|
private $mNormalizedTitles, $mInterwikiTitles;
|
2006-10-06 01:02:14 +00:00
|
|
|
private $mResolveRedirects, $mPendingRedirectIDs;
|
2010-07-10 11:53:22 +00:00
|
|
|
private $mConvertTitles, $mConvertedTitles;
|
2006-10-13 04:59:14 +00:00
|
|
|
private $mGoodRevIDs, $mMissingRevIDs;
|
2007-07-07 03:05:09 +00:00
|
|
|
private $mFakePageId;
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
private $mRequestedPageFields;
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
2012-07-12 15:53:00 +00:00
|
|
|
* @param $query ApiBase
|
2009-02-11 19:25:25 +00:00
|
|
|
* @param $resolveRedirects bool Whether redirects should be resolved
|
2011-05-29 14:24:27 +00:00
|
|
|
* @param $convertTitles bool
|
2009-02-11 19:25:25 +00:00
|
|
|
*/
|
2010-07-10 11:53:22 +00:00
|
|
|
public function __construct( $query, $resolveRedirects = false, $convertTitles = false ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
parent::__construct( $query, 'query' );
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
$this->mAllPages = array();
|
2006-10-30 00:18:05 +00:00
|
|
|
$this->mTitles = array();
|
2010-02-23 18:05:46 +00:00
|
|
|
$this->mGoodTitles = array();
|
|
|
|
|
$this->mMissingTitles = array();
|
|
|
|
|
$this->mInvalidTitles = array();
|
|
|
|
|
$this->mMissingPageIDs = array();
|
|
|
|
|
$this->mRedirectTitles = array();
|
|
|
|
|
$this->mNormalizedTitles = array();
|
|
|
|
|
$this->mInterwikiTitles = array();
|
2006-10-13 04:59:14 +00:00
|
|
|
$this->mGoodRevIDs = array();
|
|
|
|
|
$this->mMissingRevIDs = array();
|
2010-07-10 10:46:20 +00:00
|
|
|
$this->mSpecialTitles = array();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
$this->mRequestedPageFields = array();
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->mResolveRedirects = $resolveRedirects;
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $resolveRedirects ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
$this->mPendingRedirectIDs = array();
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-07-10 11:53:22 +00:00
|
|
|
$this->mConvertTitles = $convertTitles;
|
|
|
|
|
$this->mConvertedTitles = array();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-04-17 20:58:04 +00:00
|
|
|
$this->mFakePageId = - 1;
|
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
|
|
|
}
|
|
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
|
|
|
|
* Request an additional field from the page table. Must be called
|
|
|
|
|
* before execute()
|
|
|
|
|
* @param $fieldName string Field name
|
|
|
|
|
*/
|
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()
|
|
|
|
|
* @param $fieldName string Field name
|
|
|
|
|
* @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
|
|
|
|
|
* target.
|
2011-05-14 12:48:07 +00:00
|
|
|
* @return array prefixed_title (string) => Title object
|
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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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 the PageSet from the request parameters.
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
|
|
|
|
public function execute() {
|
|
|
|
|
$this->profileIn();
|
2008-12-17 16:34:01 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2006-10-06 01:02:14 +00:00
|
|
|
|
|
|
|
|
// Only one of the titles/pageids/revids is allowed at the same time
|
|
|
|
|
$dataSource = null;
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( isset( $params['titles'] ) ) {
|
2006-10-06 01:02:14 +00:00
|
|
|
$dataSource = 'titles';
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
if ( isset( $params['pageids'] ) ) {
|
|
|
|
|
if ( isset( $dataSource ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsage( "Cannot use 'pageids' at the same time as '$dataSource'", 'multisource' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2006-10-06 01:02:14 +00:00
|
|
|
$dataSource = 'pageids';
|
|
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( isset( $params['revids'] ) ) {
|
|
|
|
|
if ( isset( $dataSource ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsage( "Cannot use 'revids' at the same time as '$dataSource'", 'multisource' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2006-10-06 01:02:14 +00:00
|
|
|
$dataSource = 'revids';
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
switch ( $dataSource ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
case 'titles':
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->initFromTitles( $params['titles'] );
|
2006-10-06 01:02:14 +00:00
|
|
|
break;
|
2010-02-23 18:05:46 +00:00
|
|
|
case 'pageids':
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->initFromPageIds( $params['pageids'] );
|
2006-10-06 01:02:14 +00:00
|
|
|
break;
|
2010-02-23 18:05:46 +00:00
|
|
|
case 'revids':
|
|
|
|
|
if ( $this->mResolveRedirects ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->setWarning( 'Redirect resolution cannot be used together with the revids= parameter. ' .
|
|
|
|
|
'Any redirects the revids= point to have not been resolved.' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2008-08-18 20:48:45 +00:00
|
|
|
$this->mResolveRedirects = false;
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->initFromRevIDs( $params['revids'] );
|
2006-10-06 01:02:14 +00:00
|
|
|
break;
|
2010-02-23 18:05:46 +00:00
|
|
|
default:
|
2006-10-06 01:02:14 +00:00
|
|
|
// Do nothing - some queries do not need any of the data sources.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$this->profileOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Populate this PageSet from a list of Titles
|
|
|
|
|
* @param $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
|
|
|
|
|
* @param $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
|
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
|
|
|
|
|
* @param $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
|
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 ) {
|
2007-07-14 19:04:31 +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
|
|
|
/**
|
|
|
|
|
* Resolve redirects, if applicable
|
|
|
|
|
*/
|
2006-10-06 01:02:14 +00:00
|
|
|
public function finishPageSetGeneration() {
|
|
|
|
|
$this->profileIn();
|
|
|
|
|
$this->resolvePendingRedirects();
|
|
|
|
|
$this->profileOut();
|
|
|
|
|
}
|
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
|
|
|
*
|
|
|
|
|
* @param $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,
|
|
|
|
|
__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
|
|
|
|
|
* @param $pageids array of page IDs
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function initFromPageIds( $pageids ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !count( $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;
|
2011-06-06 08:45:54 +00:00
|
|
|
if ( count( $pageids ) ) {
|
|
|
|
|
$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
|
|
|
|
2011-01-12 00:24:25 +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
|
2009-02-11 19:25:25 +00:00
|
|
|
* @param $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
|
|
|
|
|
* @param $processTitles bool Must be provided together with $remaining.
|
|
|
|
|
* 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
|
|
|
|
|
if( MWNamespace::hasGenderDistinction( $row->page_namespace ) ) {
|
|
|
|
|
$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
|
|
|
|
|
if( MWNamespace::hasGenderDistinction( $ns ) ) {
|
|
|
|
|
$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
|
|
|
|
|
* @param $revids array of revision IDs
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function initFromRevIDs( $revids ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !count( $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
|
|
|
|
2011-06-06 08:45:54 +00:00
|
|
|
if ( count( $revids ) ) {
|
|
|
|
|
$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();
|
|
|
|
|
$res = $db->select( $tables, $fields, $where, __METHOD__ );
|
|
|
|
|
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
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
/**
|
|
|
|
|
* Given an array of title strings, convert them into Title objects.
|
2007-06-14 03:14:44 +00:00
|
|
|
* Alternativelly, 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
|
|
|
*
|
2009-02-11 19:25:25 +00:00
|
|
|
* @param $titles array of Title objects or strings
|
|
|
|
|
* @return LinkBatch
|
2006-09-27 05:13:48 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function processTitlesArray( $titles ) {
|
2012-05-16 14:46:22 +00:00
|
|
|
$genderCache = GenderCache::singleton();
|
|
|
|
|
$genderCache->doTitlesArray( $titles, __METHOD__ );
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
$linkBatch = new LinkBatch();
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $titles as $title ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
$titleObj = is_string( $title ) ? Title::newFromText( $title ) : $title;
|
|
|
|
|
if ( !$titleObj ) {
|
2010-01-23 22:52:40 +00:00
|
|
|
// Handle invalid titles gracefully
|
2008-03-18 15:17:24 +00:00
|
|
|
$this->mAllpages[0][$title] = $this->mFakePageId;
|
|
|
|
|
$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;
|
2007-06-14 03:14:44 +00:00
|
|
|
$iw = $titleObj->getInterwiki();
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( strval( $iw ) !== '' ) {
|
2007-06-14 03:14:44 +00:00
|
|
|
// This title is an interwiki link.
|
|
|
|
|
$this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw;
|
2008-04-14 07:45:50 +00:00
|
|
|
} else {
|
2010-07-10 11:53:22 +00:00
|
|
|
// Variants checking
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
if ( $this->mConvertTitles &&
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $linkBatch;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
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
|
|
|
|
|
foreach( $array as $i => $int ) {
|
|
|
|
|
if ( $int < 0 ) {
|
|
|
|
|
unset( $array[$i] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-23 18:05:46 +00:00
|
|
|
return array(
|
|
|
|
|
'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
|
2006-10-06 01:02:14 +00:00
|
|
|
)
|
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',
|
2006-10-06 01:02:14 +00:00
|
|
|
'revids' => 'A list of revision IDs to work on'
|
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'" ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|