2006-09-25 04:12:07 +00:00
|
|
|
<?php
|
2010-02-23 18:05:46 +00:00
|
|
|
/**
|
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
|
|
|
*/
|
2019-08-21 19:53:53 +00:00
|
|
|
|
2024-09-25 16:17:29 +00:00
|
|
|
namespace MediaWiki\Api;
|
|
|
|
|
|
2022-06-06 01:24:41 +00:00
|
|
|
use MediaWiki\Api\Validator\SubmoduleDef;
|
2024-02-08 19:09:50 +00:00
|
|
|
use MediaWiki\Cache\GenderCache;
|
|
|
|
|
use MediaWiki\Cache\LinkBatch;
|
2021-07-04 13:40:19 +00:00
|
|
|
use MediaWiki\Cache\LinkBatchFactory;
|
2024-02-08 19:09:50 +00:00
|
|
|
use MediaWiki\Cache\LinkCache;
|
2024-06-14 21:24:11 +00:00
|
|
|
use MediaWiki\Context\DerivativeContext;
|
2024-08-08 09:39:26 +00:00
|
|
|
use MediaWiki\Language\ILanguageConverter;
|
|
|
|
|
use MediaWiki\Language\Language;
|
2024-09-25 16:17:29 +00:00
|
|
|
use MediaWiki\Language\LanguageConverter;
|
2021-04-30 14:41:54 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
2022-04-13 15:28:26 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2016-11-22 23:14:43 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-06-14 21:24:11 +00:00
|
|
|
use MediaWiki\Message\Message;
|
2021-04-30 14:41:54 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
|
|
|
|
use MediaWiki\Page\PageReference;
|
2022-10-28 10:04:25 +00:00
|
|
|
use MediaWiki\Request\FauxRequest;
|
2023-09-15 09:32:18 +00:00
|
|
|
use MediaWiki\SpecialPage\RedirectSpecialArticle;
|
2021-07-04 13:40:19 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPageFactory;
|
2023-09-18 15:00:50 +00:00
|
|
|
use MediaWiki\Title\MalformedTitleException;
|
2023-09-18 14:17:28 +00:00
|
|
|
use MediaWiki\Title\NamespaceInfo;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-11-26 01:15:16 +00:00
|
|
|
use MediaWiki\Title\TitleFactory;
|
2024-09-25 16:17:29 +00:00
|
|
|
use stdClass;
|
2019-08-21 19:53:53 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
2024-06-02 17:09:49 +00:00
|
|
|
use Wikimedia\Rdbms\IReadableDatabase;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
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
|
|
|
|
|
*/
|
2020-05-15 21:36:51 +00:00
|
|
|
private const DISABLE_GENERATORS = 1;
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2021-05-09 01:02:21 +00:00
|
|
|
/** @var ApiBase used for getDb() call */
|
2013-03-02 00:06:46 +00:00
|
|
|
private $mDbSource;
|
2021-05-09 01:02:21 +00:00
|
|
|
|
|
|
|
|
/** @var array */
|
2021-05-12 08:47:18 +00:00
|
|
|
private $mParams;
|
2021-05-09 01:02:21 +00:00
|
|
|
|
|
|
|
|
/** @var bool */
|
2013-03-02 00:06:46 +00:00
|
|
|
private $mResolveRedirects;
|
2021-05-09 01:02:21 +00:00
|
|
|
|
|
|
|
|
/** @var bool */
|
2013-03-02 00:06:46 +00:00
|
|
|
private $mConvertTitles;
|
2021-05-09 01:02:21 +00:00
|
|
|
|
|
|
|
|
/** @var bool */
|
2013-03-02 00:06:46 +00:00
|
|
|
private $mAllowGenerator;
|
2013-02-08 20:39:40 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,array<string,int>> [ns][dbkey] => page_id or negative when missing */
|
2021-05-09 01:02:21 +00:00
|
|
|
private $mAllPages = [];
|
|
|
|
|
|
|
|
|
|
/** @var Title[] */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,array<string,int>> [ns][dbkey] => page_id or negative when missing */
|
2021-05-09 01:02:21 +00:00
|
|
|
private $mGoodAndMissingPages = [];
|
|
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,array<string,int>> [ns][dbkey] => page_id */
|
2021-05-09 01:02:21 +00:00
|
|
|
private $mGoodPages = [];
|
|
|
|
|
|
2024-01-08 09:16:39 +00:00
|
|
|
/** @var array<int,Title> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mGoodTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,array<string,int>> [ns][dbkey] => fake page_id */
|
2021-05-09 01:02:21 +00:00
|
|
|
private $mMissingPages = [];
|
|
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,Title> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mMissingTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,array{title:string,invalidreason:array}> [fake_page_id] => [ 'title' => $title, 'invalidreason' => $reason ] */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mInvalidTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
|
|
|
|
/** @var int[] */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mMissingPageIDs = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<string,Title> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mRedirectTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,Title> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mSpecialTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,array<string,int>> separate from mAllPages to avoid breaking getAllTitlesByNamespace() */
|
2021-05-09 01:02:21 +00:00
|
|
|
private $mAllSpecials = [];
|
|
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<string,string> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mNormalizedTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<string,string> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mInterwikiTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,Title> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mPendingRedirectIDs = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<string,array{Title,Title}> [dbkey] => [ Title $from, Title $to ] */
|
2021-05-09 01:02:21 +00:00
|
|
|
private $mPendingRedirectSpecialPages = [];
|
|
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<string,Title> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mResolvedRedirectTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<string,string> */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mConvertedTitles = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,int> Array of revID (int) => pageID (int) */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mGoodRevIDs = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,int> Array of revID (int) => pageID (int) */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mLiveRevIDs = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,int> Array of revID (int) => pageID (int) */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mDeletedRevIDs = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
|
|
|
|
/** @var int[] */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mMissingRevIDs = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<int,array<string,array>> [ns][dbkey] => data array */
|
2021-05-09 01:02:21 +00:00
|
|
|
private $mGeneratorData = [];
|
|
|
|
|
|
|
|
|
|
/** @var int */
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mFakePageId = -1;
|
2021-05-09 01:02:21 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mCacheMode = 'public';
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2024-07-07 14:30:26 +00:00
|
|
|
/** @var array<string,array<int,mixed>> [fieldName][pageId] => value */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $mRequestedPageFields = [];
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2014-07-08 21:40:06 +00:00
|
|
|
/** @var int */
|
2021-05-12 08:47:18 +00:00
|
|
|
private $mDefaultNamespace;
|
2021-05-09 01:02:21 +00:00
|
|
|
|
2015-10-07 21:03:15 +00:00
|
|
|
/** @var callable|null */
|
|
|
|
|
private $mRedirectMergePolicy;
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2024-07-02 09:57:44 +00:00
|
|
|
/** @var array<string,string>|null see getGenerators() */
|
2021-05-09 01:02:21 +00:00
|
|
|
private static $generators = null;
|
|
|
|
|
|
2023-08-28 15:32:58 +00:00
|
|
|
private Language $contentLanguage;
|
|
|
|
|
private LinkCache $linkCache;
|
|
|
|
|
private NamespaceInfo $namespaceInfo;
|
|
|
|
|
private GenderCache $genderCache;
|
|
|
|
|
private LinkBatchFactory $linkBatchFactory;
|
|
|
|
|
private TitleFactory $titleFactory;
|
|
|
|
|
private ILanguageConverter $languageConverter;
|
|
|
|
|
private SpecialPageFactory $specialPageFactory;
|
2021-07-04 13:40:19 +00:00
|
|
|
|
2014-01-29 18:10:36 +00:00
|
|
|
/**
|
|
|
|
|
* Add all items from $values into the result
|
2019-11-23 22:28:57 +00:00
|
|
|
* @param array &$result Output
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $values Values to add
|
2016-08-15 18:27:40 +00:00
|
|
|
* @param string[] $flags The names of boolean flags to mark this element
|
2019-11-23 22:28:57 +00:00
|
|
|
* @param string|null $name If given, name of the value
|
2014-01-29 18:10:36 +00:00
|
|
|
*/
|
2016-08-15 18:27:40 +00:00
|
|
|
private static function addValues( array &$result, $values, $flags = [], $name = null ) {
|
2014-01-29 18:10:36 +00:00
|
|
|
foreach ( $values as $val ) {
|
|
|
|
|
if ( $val instanceof Title ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$v = [];
|
2014-01-29 18:10:36 +00:00
|
|
|
ApiQueryBase::addTitleInfo( $v, $val );
|
|
|
|
|
} elseif ( $name !== null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$v = [ $name => $val ];
|
2014-01-29 18:10:36 +00:00
|
|
|
} else {
|
|
|
|
|
$v = $val;
|
|
|
|
|
}
|
2016-08-15 18:27:40 +00:00
|
|
|
foreach ( $flags as $flag ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$v[$flag] = true;
|
2014-01-29 18:10:36 +00:00
|
|
|
}
|
|
|
|
|
$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;
|
2017-07-23 01:24:09 +00:00
|
|
|
$this->mAllowGenerator = ( $flags & self::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->mParams = $this->extractRequestParams();
|
|
|
|
|
$this->mResolveRedirects = $this->mParams['redirects'];
|
|
|
|
|
$this->mConvertTitles = $this->mParams['converttitles'];
|
2021-07-04 13:40:19 +00:00
|
|
|
|
|
|
|
|
// Needs service injection - T283314
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$this->contentLanguage = $services->getContentLanguage();
|
|
|
|
|
$this->linkCache = $services->getLinkCache();
|
|
|
|
|
$this->namespaceInfo = $services->getNamespaceInfo();
|
|
|
|
|
$this->genderCache = $services->getGenderCache();
|
|
|
|
|
$this->linkBatchFactory = $services->getLinkBatchFactory();
|
|
|
|
|
$this->titleFactory = $services->getTitleFactory();
|
|
|
|
|
$this->languageConverter = $services->getLanguageConverterFactory()
|
|
|
|
|
->getLanguageConverter( $this->contentLanguage );
|
|
|
|
|
$this->specialPageFactory = $services->getSpecialPageFactory();
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
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
|
|
|
$generatorName = $this->mAllowGenerator ? $this->mParams['generator'] : null;
|
|
|
|
|
if ( isset( $generatorName ) ) {
|
|
|
|
|
$dbSource = $this->mDbSource;
|
2015-03-10 22:26:31 +00:00
|
|
|
if ( !$dbSource instanceof ApiQuery ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
// If the parent container of this pageset is not ApiQuery, we must create it to run generator
|
|
|
|
|
$dbSource = $this->getMain()->getModuleManager()->getModule( 'query' );
|
|
|
|
|
}
|
|
|
|
|
$generator = $dbSource->getModuleManager()->getModule( $generatorName, null, true );
|
|
|
|
|
if ( $generator === null ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-badgenerator-unknown', $generatorName ], 'badgenerator' );
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
|
|
|
|
if ( !$generator instanceof ApiQueryGeneratorBase ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-badgenerator-notgenerator', $generatorName ], 'badgenerator' );
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
|
|
|
|
// Create a temporary pageset to store generator's output,
|
|
|
|
|
// add any additional fields generator may need, and execute pageset to populate titles/pageids
|
2021-10-25 19:15:52 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable T240141
|
2017-07-23 01:24:09 +00:00
|
|
|
$tmpPageSet = new ApiPageSet( $dbSource, self::DISABLE_GENERATORS );
|
2013-02-08 20:39:40 +00:00
|
|
|
$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
|
2013-03-02 00:06:46 +00:00
|
|
|
if ( !$isDryRun ) {
|
|
|
|
|
$generator->executeGenerator( $this );
|
2016-12-25 19:32:22 +00:00
|
|
|
|
2021-10-25 19:15:52 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable T240141
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getHookRunner()->onAPIQueryGeneratorAfterExecute( $generator, $this );
|
2013-03-02 00:06:46 +00:00
|
|
|
} else {
|
|
|
|
|
// Prevent warnings from being reported on these parameters
|
|
|
|
|
$main = $this->getMain();
|
|
|
|
|
foreach ( $generator->extractRequestParams() as $paramName => $param ) {
|
2016-01-11 18:20:22 +00:00
|
|
|
$main->markParamsUsed( $generator->encodeParamName( $paramName ) );
|
2013-03-02 00:06:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-02-08 20:39:40 +00:00
|
|
|
|
2013-07-22 17:08:31 +00:00
|
|
|
if ( !$isDryRun ) {
|
|
|
|
|
$this->resolvePendingRedirects();
|
|
|
|
|
}
|
2013-02-08 20:39:40 +00:00
|
|
|
} 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 ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError(
|
|
|
|
|
[
|
|
|
|
|
'apierror-invalidparammix-cannotusewith',
|
|
|
|
|
$this->encodeParamName( 'pageids' ),
|
|
|
|
|
$this->encodeParamName( $dataSource )
|
|
|
|
|
],
|
|
|
|
|
'multisource'
|
|
|
|
|
);
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
|
|
|
|
$dataSource = 'pageids';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->mParams['revids'] ) ) {
|
|
|
|
|
if ( isset( $dataSource ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError(
|
|
|
|
|
[
|
|
|
|
|
'apierror-invalidparammix-cannotusewith',
|
|
|
|
|
$this->encodeParamName( 'revids' ),
|
|
|
|
|
$this->encodeParamName( $dataSource )
|
|
|
|
|
],
|
|
|
|
|
'multisource'
|
|
|
|
|
);
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
|
|
|
|
$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 ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->addWarning( 'apiwarn-redirectsandrevids' );
|
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
|
|
|
}
|
|
|
|
|
}
|
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()
|
2024-07-07 14:30:26 +00:00
|
|
|
* @param string $fieldName A page table field, e.g. "page_touched"
|
2009-02-11 19:25:25 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function requestField( $fieldName ) {
|
2024-07-07 14:30:26 +00:00
|
|
|
$this->mRequestedPageFields[$fieldName] = [];
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-11 19:25:25 +00:00
|
|
|
/**
|
2024-07-07 14:30:26 +00:00
|
|
|
* Get the values of one of the previously requested page table fields. Can only be used
|
|
|
|
|
* after execute() and only for fields previously requested through requestField().
|
|
|
|
|
* @param string $fieldName A page table field, e.g. "page_touched"
|
|
|
|
|
* @return array<int,mixed> Field values per page id, initialized only after execute()
|
2009-02-11 19:25:25 +00:00
|
|
|
*/
|
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
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[] 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
|
2016-02-17 09:09:32 +00:00
|
|
|
$pageFlds = [
|
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,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
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
|
|
|
|
2019-12-17 16:20:32 +00:00
|
|
|
$pageFlds['page_content_model'] = null;
|
2015-01-14 18:50:18 +00:00
|
|
|
|
2022-04-13 15:28:26 +00:00
|
|
|
if ( $this->getConfig()->get( MainConfigNames::PageLanguageUseDB ) ) {
|
2015-12-19 15:25:45 +00:00
|
|
|
$pageFlds['page_lang'] = null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-15 18:27:40 +00:00
|
|
|
foreach ( LinkCache::getSelectFields() as $field ) {
|
|
|
|
|
$pageFlds[$field] = null;
|
|
|
|
|
}
|
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
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<int,array<string,int>>
|
2007-07-07 03:05:09 +00:00
|
|
|
*/
|
|
|
|
|
public function getAllTitlesByNamespace() {
|
|
|
|
|
return $this->mAllPages;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-30 00:18:05 +00:00
|
|
|
/**
|
2021-04-30 14:41:54 +00:00
|
|
|
* All existing and missing pages including redirects.
|
|
|
|
|
* Does not include special pages, interwiki links, and invalid titles.
|
|
|
|
|
* If redirects are resolved, both the redirect and the target will be included here.
|
|
|
|
|
*
|
2024-07-19 22:09:15 +00:00
|
|
|
* @deprecated since 1.37, use getPages() instead, hard-deprecated since 1.43.
|
2013-12-30 17:32:53 +00:00
|
|
|
* @return Title[]
|
2006-10-30 00:18:05 +00:00
|
|
|
*/
|
|
|
|
|
public function getTitles() {
|
2024-07-19 22:09:15 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.37' );
|
2006-10-30 00:18:05 +00:00
|
|
|
return $this->mTitles;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 14:41:54 +00:00
|
|
|
/**
|
|
|
|
|
* All existing and missing pages including redirects.
|
|
|
|
|
* Does not include special pages, interwiki links, and invalid titles.
|
|
|
|
|
* If redirects are resolved, both the redirect and the target will be included here.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @return PageIdentity[]
|
|
|
|
|
*/
|
|
|
|
|
public function getPages(): array {
|
|
|
|
|
return $this->mTitles;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-30 00:18:05 +00:00
|
|
|
/**
|
|
|
|
|
* 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.
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<int,array<string,int>>
|
2014-09-26 14:56:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getGoodTitlesByNamespace() {
|
|
|
|
|
return $this->mGoodPages;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
2021-04-30 14:41:54 +00:00
|
|
|
* Title objects that were found in the database, including redirects.
|
|
|
|
|
* If redirects are resolved, this will include existing redirect targets.
|
2024-07-19 22:09:15 +00:00
|
|
|
* @deprecated since 1.37, use getGoodPages() instead, hard-deprecated since 1.43.
|
2024-01-08 09:16:39 +00:00
|
|
|
* @return array<int,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() {
|
2024-07-19 22:09:15 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.37' );
|
2006-09-27 05:13:48 +00:00
|
|
|
return $this->mGoodTitles;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-30 14:41:54 +00:00
|
|
|
/**
|
|
|
|
|
* Pages that were found in the database, including redirects.
|
|
|
|
|
* If redirects are resolved, this will include existing redirect targets.
|
|
|
|
|
* @since 1.37
|
2024-01-08 09:16:39 +00:00
|
|
|
* @return array<int,PageIdentity> Array page_id (int) => PageIdentity (obj)
|
2021-04-30 14:41:54 +00:00
|
|
|
*/
|
|
|
|
|
public function getGoodPages(): array {
|
|
|
|
|
return $this->mGoodTitles;
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<int,array<string,int>>
|
2014-09-26 14:56:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getMissingTitlesByNamespace() {
|
|
|
|
|
return $this->mMissingPages;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
|
|
|
|
* Title objects that were NOT found in the database.
|
2021-04-30 14:41:54 +00:00
|
|
|
* The array's index will be negative for each item.
|
|
|
|
|
* If redirects are resolved, this will include missing redirect targets.
|
2024-07-19 22:09:15 +00:00
|
|
|
* @deprecated since 1.37, use getMissingPages instead, hard-deprecated since 1.43.
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<int,Title>
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
2006-09-27 05:13:48 +00:00
|
|
|
public function getMissingTitles() {
|
2024-07-19 22:09:15 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.37' );
|
2006-09-27 05:13:48 +00:00
|
|
|
return $this->mMissingTitles;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2021-04-30 14:41:54 +00:00
|
|
|
/**
|
|
|
|
|
* Pages that were NOT found in the database.
|
|
|
|
|
* The array's index will be negative for each item.
|
|
|
|
|
* If redirects are resolved, this will include missing redirect targets.
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @return PageIdentity[]
|
|
|
|
|
*/
|
|
|
|
|
public function getMissingPages(): array {
|
|
|
|
|
return $this->mMissingTitles;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 14:56:00 +00:00
|
|
|
/**
|
|
|
|
|
* Returns an array [ns][dbkey] => page_id for all good and missing titles.
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<int,array<string,int>>
|
2014-09-26 14:56:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getGoodAndMissingTitlesByNamespace() {
|
|
|
|
|
return $this->mGoodAndMissingPages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Title objects for good and missing titles.
|
2024-07-19 22:09:15 +00:00
|
|
|
* @deprecated since 1.37, use getGoodAndMissingPages() instead, hard-deprecated since 1.43.
|
2020-02-13 10:24:10 +00:00
|
|
|
* @return Title[]
|
2014-09-26 14:56:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getGoodAndMissingTitles() {
|
2024-07-19 22:09:15 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.37' );
|
2014-09-26 14:56:00 +00:00
|
|
|
return $this->mGoodTitles + $this->mMissingTitles;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 14:41:54 +00:00
|
|
|
/**
|
|
|
|
|
* Pages for good and missing titles.
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @return PageIdentity[]
|
|
|
|
|
*/
|
|
|
|
|
public function getGoodAndMissingPages(): array {
|
|
|
|
|
return $this->mGoodTitles + $this->mMissingTitles;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 19:33:37 +00:00
|
|
|
/**
|
|
|
|
|
* Titles that were deemed invalid by Title::newFromText()
|
|
|
|
|
* The array's index will be unique and negative for each item
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<int,array{title:string,invalidreason:array}>
|
2015-05-06 19:33:37 +00:00
|
|
|
*/
|
|
|
|
|
public function getInvalidTitlesAndReasons() {
|
2008-03-18 15:17:24 +00:00
|
|
|
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
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return int[] 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
|
2021-04-30 14:41:54 +00:00
|
|
|
* target.
|
2024-07-19 22:09:15 +00:00
|
|
|
* @deprecated since 1.37, use getRedirectTargets instead, hard-deprecated since 1.43.
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<string,Title>
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
2006-09-27 05:13:48 +00:00
|
|
|
public function getRedirectTitles() {
|
2024-07-19 22:09:15 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.37' );
|
2006-09-27 05:13:48 +00:00
|
|
|
return $this->mRedirectTitles;
|
2006-09-25 04:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-30 14:41:54 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of redirect resolutions - maps a title to its redirect
|
|
|
|
|
* target.
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @return LinkTarget[]
|
|
|
|
|
*/
|
|
|
|
|
public function getRedirectTargets(): array {
|
|
|
|
|
return $this->mRedirectTitles;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of redirect resolutions - maps a title to its redirect
|
2015-08-10 17:51:22 +00:00
|
|
|
* target. Includes generator data for redirect source when available.
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param ApiResult|null $result
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[][]
|
2013-02-08 20:39:40 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getRedirectTitlesAsResult( $result = null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$values = [];
|
2024-06-30 12:46:24 +00:00
|
|
|
foreach ( $this->mRedirectTitles as $titleStrFrom => $titleTo ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$r = [
|
2013-02-08 20:39:40 +00:00
|
|
|
'from' => strval( $titleStrFrom ),
|
|
|
|
|
'to' => $titleTo->getPrefixedText(),
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-01-02 11:16:21 +00:00
|
|
|
if ( $titleTo->hasFragment() ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
$r['tofragment'] = $titleTo->getFragment();
|
|
|
|
|
}
|
2014-12-29 17:50:50 +00:00
|
|
|
if ( $titleTo->isExternal() ) {
|
|
|
|
|
$r['tointerwiki'] = $titleTo->getInterwiki();
|
|
|
|
|
}
|
2015-08-10 17:51:22 +00:00
|
|
|
if ( isset( $this->mResolvedRedirectTitles[$titleStrFrom] ) ) {
|
|
|
|
|
$titleFrom = $this->mResolvedRedirectTitles[$titleStrFrom];
|
|
|
|
|
$ns = $titleFrom->getNamespace();
|
|
|
|
|
$dbkey = $titleFrom->getDBkey();
|
|
|
|
|
if ( isset( $this->mGeneratorData[$ns][$dbkey] ) ) {
|
|
|
|
|
$r = array_merge( $this->mGeneratorData[$ns][$dbkey], $r );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
$values[] = $r;
|
|
|
|
|
}
|
2023-09-08 20:42:48 +00:00
|
|
|
if ( $values && $result ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $values, 'r' );
|
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 $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.
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<string,string> 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.
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param ApiResult|null $result
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return 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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$values = [];
|
2013-02-08 20:39:40 +00:00
|
|
|
foreach ( $this->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
|
2021-07-04 13:40:19 +00:00
|
|
|
$encode = $this->contentLanguage->normalize( $rawTitleStr ) !== $rawTitleStr;
|
2016-02-17 09:09:32 +00:00
|
|
|
$values[] = [
|
2016-08-24 18:07:43 +00:00
|
|
|
'fromencoded' => $encode,
|
|
|
|
|
'from' => $encode ? rawurlencode( $rawTitleStr ) : $rawTitleStr,
|
2013-02-08 20:39:40 +00:00
|
|
|
'to' => $titleStr
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
2023-09-08 20:42:48 +00:00
|
|
|
if ( $values && $result ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $values, 'n' );
|
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 $values;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-10 11:53:22 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of title conversions - maps a title to its converted
|
|
|
|
|
* version.
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[] 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.
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param ApiResult|null $result
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[][] Array of (from, to) strings
|
2013-02-08 20:39:40 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getConvertedTitlesAsResult( $result = null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$values = [];
|
2013-02-08 20:39:40 +00:00
|
|
|
foreach ( $this->getConvertedTitles() as $rawTitleStr => $titleStr ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$values[] = [
|
2013-02-08 20:39:40 +00:00
|
|
|
'from' => $rawTitleStr,
|
|
|
|
|
'to' => $titleStr
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
2023-09-08 20:42:48 +00:00
|
|
|
if ( $values && $result ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $values, 'c' );
|
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 $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.
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[] 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.
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param ApiResult|null $result
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param bool $iwUrl
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[][]
|
2013-02-08 20:39:40 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getInterwikiTitlesAsResult( $result = null, $iwUrl = false ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$values = [];
|
2013-02-08 20:39:40 +00:00
|
|
|
foreach ( $this->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$item = [
|
2013-02-08 20:39:40 +00:00
|
|
|
'title' => $rawTitleStr,
|
|
|
|
|
'iw' => $interwikiStr,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( $iwUrl ) {
|
2021-07-04 13:40:19 +00:00
|
|
|
$title = $this->titleFactory->newFromText( $rawTitleStr );
|
2013-02-08 20:39:40 +00:00
|
|
|
$item['url'] = $title->getFullURL( '', false, PROTO_CURRENT );
|
|
|
|
|
}
|
|
|
|
|
$values[] = $item;
|
|
|
|
|
}
|
2023-09-08 20:42:48 +00:00
|
|
|
if ( $values && $result ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $values, 'i' );
|
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 $values;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 18:10:36 +00:00
|
|
|
/**
|
|
|
|
|
* Get an array of invalid/special/missing titles.
|
|
|
|
|
*
|
2020-10-28 10:01:33 +00:00
|
|
|
* @param string[] $invalidChecks List of types of invalid titles to include.
|
2014-01-29 18:10:36 +00:00
|
|
|
* Recognized values are:
|
2015-05-06 19:33:37 +00:00
|
|
|
* - invalidTitles: Titles and reasons from $this->getInvalidTitlesAndReasons()
|
2024-06-30 12:46:24 +00:00
|
|
|
* - special: Titles from $this->getSpecialPages()
|
2014-01-29 18:10:36 +00:00
|
|
|
* - missingIds: ids from $this->getMissingPageIDs()
|
|
|
|
|
* - missingRevIds: ids from $this->getMissingRevisionIDs()
|
2024-06-30 12:46:24 +00:00
|
|
|
* - missingTitles: Titles from $this->getMissingPages()
|
2014-01-29 18:10:36 +00:00
|
|
|
* - interwikiTitles: Titles from $this->getInterwikiTitlesAsResult()
|
|
|
|
|
* @return array Array suitable for inclusion in the response
|
|
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public function getInvalidTitlesAndRevisions( $invalidChecks = [ 'invalidTitles',
|
|
|
|
|
'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' ]
|
2014-02-05 10:20:17 +00:00
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [];
|
2016-03-08 08:04:45 +00:00
|
|
|
if ( in_array( 'invalidTitles', $invalidChecks ) ) {
|
2016-08-15 18:27:40 +00:00
|
|
|
self::addValues( $result, $this->getInvalidTitlesAndReasons(), [ 'invalid' ] );
|
2014-01-29 18:10:36 +00:00
|
|
|
}
|
2016-03-08 08:04:45 +00:00
|
|
|
if ( in_array( 'special', $invalidChecks ) ) {
|
2016-08-15 18:27:40 +00:00
|
|
|
$known = [];
|
|
|
|
|
$unknown = [];
|
2024-06-30 12:46:24 +00:00
|
|
|
foreach ( $this->mSpecialTitles as $title ) {
|
2016-08-15 18:27:40 +00:00
|
|
|
if ( $title->isKnown() ) {
|
|
|
|
|
$known[] = $title;
|
|
|
|
|
} else {
|
|
|
|
|
$unknown[] = $title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self::addValues( $result, $unknown, [ 'special', 'missing' ] );
|
|
|
|
|
self::addValues( $result, $known, [ 'special' ] );
|
2014-01-29 18:10:36 +00:00
|
|
|
}
|
2016-03-08 08:04:45 +00:00
|
|
|
if ( in_array( 'missingIds', $invalidChecks ) ) {
|
2016-08-15 18:27:40 +00:00
|
|
|
self::addValues( $result, $this->getMissingPageIDs(), [ 'missing' ], 'pageid' );
|
2014-01-29 18:10:36 +00:00
|
|
|
}
|
2016-03-08 08:04:45 +00:00
|
|
|
if ( in_array( 'missingRevIds', $invalidChecks ) ) {
|
2016-08-15 18:27:40 +00:00
|
|
|
self::addValues( $result, $this->getMissingRevisionIDs(), [ 'missing' ], 'revid' );
|
2014-01-29 18:10:36 +00:00
|
|
|
}
|
2016-03-08 08:04:45 +00:00
|
|
|
if ( in_array( 'missingTitles', $invalidChecks ) ) {
|
2016-08-15 18:27:40 +00:00
|
|
|
$known = [];
|
|
|
|
|
$unknown = [];
|
2024-06-30 12:46:24 +00:00
|
|
|
foreach ( $this->mMissingTitles as $title ) {
|
2016-08-15 18:27:40 +00:00
|
|
|
if ( $title->isKnown() ) {
|
|
|
|
|
$known[] = $title;
|
|
|
|
|
} else {
|
|
|
|
|
$unknown[] = $title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self::addValues( $result, $unknown, [ 'missing' ] );
|
|
|
|
|
self::addValues( $result, $known, [ 'missing', 'known' ] );
|
2014-01-29 18:10:36 +00:00
|
|
|
}
|
2016-03-08 08:04:45 +00:00
|
|
|
if ( in_array( 'interwikiTitles', $invalidChecks ) ) {
|
2014-01-29 18:10:36 +00:00
|
|
|
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)
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return int[] 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)
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return int[] Array of revID (int) => pageID (int)
|
2014-09-29 17:47:08 +00:00
|
|
|
*/
|
|
|
|
|
public function getLiveRevisionIDs() {
|
|
|
|
|
return $this->mLiveRevIDs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the list of revision IDs that were associated with deleted titles.
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return int[] Array of revID (int) => pageID (int)
|
2014-09-29 17:47:08 +00:00
|
|
|
*/
|
|
|
|
|
public function getDeletedRevisionIDs() {
|
|
|
|
|
return $this->mDeletedRevIDs;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-13 04:59:14 +00:00
|
|
|
/**
|
|
|
|
|
* Revision IDs that were not found in the database
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return int[] 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.
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param ApiResult|null $result
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<int,array>
|
2013-02-08 20:39:40 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function getMissingRevisionIDsAsResult( $result = null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$values = [];
|
2013-02-08 20:39:40 +00:00
|
|
|
foreach ( $this->getMissingRevisionIDs() as $revid ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$values[$revid] = [
|
2022-02-05 13:21:02 +00:00
|
|
|
'revid' => $revid,
|
|
|
|
|
'missing' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-02-08 20:39:40 +00:00
|
|
|
}
|
2023-09-08 20:42:48 +00:00
|
|
|
if ( $values && $result ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $values, 'rev' );
|
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 $values;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-10 10:46:20 +00:00
|
|
|
/**
|
|
|
|
|
* Get the list of titles with negative namespace
|
2024-07-19 22:09:15 +00:00
|
|
|
* @deprecated since 1.37, use getSpecialPages() instead, hard-deprecated since 1.43.
|
2014-07-08 21:40:06 +00:00
|
|
|
* @return Title[]
|
2010-07-10 10:46:20 +00:00
|
|
|
*/
|
|
|
|
|
public function getSpecialTitles() {
|
2024-07-19 22:09:15 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.37' );
|
2010-07-10 10:46:20 +00:00
|
|
|
return $this->mSpecialTitles;
|
|
|
|
|
}
|
2006-10-01 02:02:13 +00:00
|
|
|
|
2021-04-30 14:41:54 +00:00
|
|
|
/**
|
|
|
|
|
* Get the list of pages with negative namespace
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @return PageReference[]
|
|
|
|
|
*/
|
|
|
|
|
public function getSpecialPages(): array {
|
|
|
|
|
return $this->mSpecialTitles;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/**
|
2021-04-30 14:41:54 +00:00
|
|
|
* Populate this PageSet
|
|
|
|
|
* @param string[]|LinkTarget[]|PageReference[] $titles
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function populateFromTitles( $titles ) {
|
|
|
|
|
$this->initFromTitles( $titles );
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-11 19:25:25 +00:00
|
|
|
* Populate this PageSet from a list of page IDs
|
2020-10-28 10:01:33 +00:00
|
|
|
* @param int[] $pageIDs
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function populateFromPageIDs( $pageIDs ) {
|
|
|
|
|
$this->initFromPageIds( $pageIDs );
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
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().
|
|
|
|
|
*
|
2024-06-02 17:09:49 +00:00
|
|
|
* @param IReadableDatabase $db Unused since 2011
|
2019-06-19 19:43:51 +00:00
|
|
|
* @param IResultWrapper $queryResult
|
2006-10-06 01:02:14 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function populateFromQueryResult( $db, $queryResult ) {
|
2011-01-12 00:24:25 +00:00
|
|
|
$this->initFromQueryResult( $queryResult );
|
2006-10-06 01:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
2020-10-28 10:01:33 +00:00
|
|
|
* @param int[] $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 ) {
|
|
|
|
|
$this->initFromRevIDs( $revIDs );
|
2006-10-14 16:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
2021-07-04 13:40:19 +00:00
|
|
|
$title = $this->titleFactory->newFromRow( $row );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2021-07-04 13:40:19 +00:00
|
|
|
$this->linkCache->addGoodLinkObjFromRow( $title, $row );
|
2016-08-15 18:27:40 +00:00
|
|
|
|
2019-02-25 00:38:33 +00:00
|
|
|
$pageId = (int)$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
|
|
|
|
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
|
|
|
*
|
2021-04-30 14:41:54 +00:00
|
|
|
* @param string[]|LinkTarget[]|PageReference[] $titles
|
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() ) {
|
2017-03-06 19:46:58 +00:00
|
|
|
// There might be special-page redirects
|
|
|
|
|
$this->resolvePendingRedirects();
|
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();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2006-10-06 01:02:14 +00:00
|
|
|
// Get pageIDs data from the `page` table
|
2022-08-05 19:02:15 +00:00
|
|
|
$res = $db->newSelectQueryBuilder()
|
|
|
|
|
->select( $this->getPageTableFields() )
|
|
|
|
|
->from( 'page' )
|
|
|
|
|
->where( $linkBatch->constructSet( 'page', $db ) )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2016-07-25 01:25:09 +00:00
|
|
|
// Hack: get the ns:titles stored in [ ns => [ 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
|
2020-10-28 10:01:33 +00:00
|
|
|
* @param int[] $pageids
|
2016-07-14 18:55:22 +00:00
|
|
|
* @param bool $filterIds Whether the IDs need filtering
|
2009-02-11 19:25:25 +00:00
|
|
|
*/
|
2018-12-12 18:12:57 +00:00
|
|
|
private function initFromPageIds( $pageids, $filterIds = true ) {
|
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
|
2021-06-11 02:52:06 +00:00
|
|
|
$remaining = array_fill_keys( $pageids, true );
|
2011-06-05 18:01:30 +00:00
|
|
|
|
2016-07-14 18:55:22 +00:00
|
|
|
if ( $filterIds ) {
|
|
|
|
|
$pageids = $this->filterIDs( [ [ 'page', 'page_id' ] ], $pageids );
|
|
|
|
|
}
|
2011-06-05 18:01:30 +00:00
|
|
|
|
2011-06-06 15:58:55 +00:00
|
|
|
$res = null;
|
2023-09-08 20:42:48 +00:00
|
|
|
if ( $pageids ) {
|
2011-06-06 08:45:54 +00:00
|
|
|
$db = $this->getDB();
|
|
|
|
|
|
|
|
|
|
// Get pageIDs data from the `page` table
|
2022-08-05 19:02:15 +00:00
|
|
|
$res = $db->newSelectQueryBuilder()
|
|
|
|
|
->select( $this->getPageTableFields() )
|
|
|
|
|
->from( 'page' )
|
|
|
|
|
->where( [ 'page_id' => $pageids ] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
2011-06-06 08:45:54 +00:00
|
|
|
}
|
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.
|
2022-02-19 10:30:02 +00:00
|
|
|
* @param IResultWrapper|null $res DB Query result
|
2019-11-23 22:28:57 +00:00
|
|
|
* @param array|null &$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
|
2019-11-23 22:28:57 +00:00
|
|
|
* @param bool|null $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 ) {
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $remaining !== null && $processTitles === null ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$usernames = [];
|
2011-06-06 15:58:55 +00:00
|
|
|
if ( $res ) {
|
|
|
|
|
foreach ( $res as $row ) {
|
2019-02-25 00:38:33 +00:00
|
|
|
$pageId = (int)$row->page_id;
|
2011-06-06 15:58:55 +00:00
|
|
|
|
|
|
|
|
// Remove found page from the list of remaining items
|
2021-08-26 19:59:32 +00:00
|
|
|
if ( $remaining ) {
|
2011-06-06 15:58:55 +00:00
|
|
|
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
|
2021-07-04 13:40:19 +00:00
|
|
|
if ( $this->namespaceInfo->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
|
|
|
|
2021-08-26 19:59:32 +00:00
|
|
|
if ( $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 ) {
|
2023-07-08 19:54:11 +00:00
|
|
|
foreach ( $dbkeys as $dbkey => $_ ) {
|
2021-07-04 13:40:19 +00:00
|
|
|
$title = $this->titleFactory->makeTitle( $ns, $dbkey );
|
|
|
|
|
$this->linkCache->addBadLinkObj( $title );
|
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
|
2021-07-04 13:40:19 +00:00
|
|
|
if ( $this->namespaceInfo->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
|
2021-07-04 13:40:19 +00:00
|
|
|
$this->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
|
2020-10-28 10:01:33 +00:00
|
|
|
* @param int[] $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();
|
2016-02-17 09:09:32 +00:00
|
|
|
$pageids = [];
|
2021-06-11 02:52:06 +00:00
|
|
|
$remaining = array_fill_keys( $revids, true );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-07-14 18:55:22 +00:00
|
|
|
$revids = $this->filterIDs( [ [ 'revision', 'rev_id' ], [ 'archive', 'ar_rev_id' ] ], $revids );
|
2021-06-11 02:52:06 +00:00
|
|
|
$goodRemaining = array_fill_keys( $revids, true );
|
* (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
|
|
|
|
2016-07-14 18:55:22 +00:00
|
|
|
if ( $revids ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$fields = [ 'rev_id', 'rev_page' ];
|
2011-06-06 08:45:54 +00:00
|
|
|
|
|
|
|
|
// Get pageIDs data from the `page` table
|
2022-08-05 19:02:15 +00:00
|
|
|
$res = $db->newSelectQueryBuilder()
|
|
|
|
|
->select( $fields )
|
|
|
|
|
->from( 'page' )
|
|
|
|
|
->where( [ 'rev_id' => $revids ] )
|
|
|
|
|
->join( 'revision', null, [ 'rev_page = page_id' ] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
2011-06-06 08:45:54 +00:00
|
|
|
foreach ( $res as $row ) {
|
2019-02-25 00:38:33 +00:00
|
|
|
$revid = (int)$row->rev_id;
|
|
|
|
|
$pageid = (int)$row->rev_page;
|
2011-06-06 08:45:54 +00:00
|
|
|
$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] );
|
2016-07-14 18:55:22 +00:00
|
|
|
unset( $goodRemaining[$revid] );
|
2011-06-06 08:45:54 +00:00
|
|
|
}
|
2006-10-13 04:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Populate all the page information
|
2016-07-14 18:55:22 +00:00
|
|
|
$this->initFromPageIds( array_keys( $pageids ), false );
|
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.
|
2019-08-16 18:13:56 +00:00
|
|
|
if ( $goodRemaining &&
|
2021-01-11 15:26:02 +00:00
|
|
|
$this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
|
2014-09-29 17:47:08 +00:00
|
|
|
|
2022-08-05 19:02:15 +00:00
|
|
|
$res = $db->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'ar_rev_id', 'ar_namespace', 'ar_title' ] )
|
|
|
|
|
->from( 'archive' )
|
|
|
|
|
->where( [ 'ar_rev_id' => array_keys( $goodRemaining ) ] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$titles = [];
|
2014-09-29 17:47:08 +00:00
|
|
|
foreach ( $res as $row ) {
|
2019-02-25 00:38:33 +00:00
|
|
|
$revid = (int)$row->ar_rev_id;
|
2021-07-04 13:40:19 +00:00
|
|
|
$titles[$revid] = $this->titleFactory->makeTitle( $row->ar_namespace, $row->ar_title );
|
2014-09-29 17:47:08 +00:00
|
|
|
unset( $remaining[$revid] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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()] )
|
|
|
|
|
) {
|
2021-07-04 13:40:19 +00:00
|
|
|
$title = $this->titleFactory->newFromText( $this->mConvertedTitles[$title->getPrefixedText()] );
|
2014-09-29 17:47:08 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-14 18:55:22 +00:00
|
|
|
|
|
|
|
|
$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();
|
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
|
2017-03-06 19:46:58 +00:00
|
|
|
while ( $this->mPendingRedirectIDs || $this->mPendingRedirectSpecialPages ) {
|
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
|
2021-04-30 14:41:54 +00:00
|
|
|
$linkBatch = $this->loadRedirectTargets();
|
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
|
2022-08-05 19:02:15 +00:00
|
|
|
$res = $db->newSelectQueryBuilder()
|
|
|
|
|
->select( $this->getPageTableFields() )
|
|
|
|
|
->from( 'page' )
|
|
|
|
|
->where( $set )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-08-07 10:27:38 +00:00
|
|
|
// Hack: get the ns:titles stored in [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
|
|
|
|
|
*/
|
2021-04-30 14:41:54 +00:00
|
|
|
private function loadRedirectTargets() {
|
2017-02-07 15:22:47 +00:00
|
|
|
$titlesToResolve = [];
|
2007-01-22 23:50:42 +00:00
|
|
|
$db = $this->getDB();
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2017-03-06 19:46:58 +00:00
|
|
|
if ( $this->mPendingRedirectIDs ) {
|
2022-08-05 19:02:15 +00:00
|
|
|
$res = $db->newSelectQueryBuilder()
|
|
|
|
|
->select( [
|
2017-03-06 19:46:58 +00:00
|
|
|
'rd_from',
|
|
|
|
|
'rd_namespace',
|
|
|
|
|
'rd_fragment',
|
|
|
|
|
'rd_interwiki',
|
|
|
|
|
'rd_title'
|
2022-08-05 19:02:15 +00:00
|
|
|
] )
|
|
|
|
|
->from( 'redirect' )
|
|
|
|
|
->where( [ 'rd_from' => array_keys( $this->mPendingRedirectIDs ) ] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
|
|
|
|
|
2017-03-06 19:46:58 +00:00
|
|
|
foreach ( $res as $row ) {
|
2019-02-25 00:38:33 +00:00
|
|
|
$rdfrom = (int)$row->rd_from;
|
2017-03-06 19:46:58 +00:00
|
|
|
$from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
|
2021-07-04 13:40:19 +00:00
|
|
|
$to = $this->titleFactory->makeTitle(
|
2017-03-06 19:46:58 +00:00
|
|
|
$row->rd_namespace,
|
|
|
|
|
$row->rd_title,
|
2023-10-03 17:29:38 +00:00
|
|
|
$row->rd_fragment,
|
|
|
|
|
$row->rd_interwiki
|
2017-03-06 19:46:58 +00:00
|
|
|
);
|
|
|
|
|
$this->mResolvedRedirectTitles[$from] = $this->mPendingRedirectIDs[$rdfrom];
|
|
|
|
|
unset( $this->mPendingRedirectIDs[$rdfrom] );
|
|
|
|
|
if ( $to->isExternal() ) {
|
|
|
|
|
$this->mInterwikiTitles[$to->getPrefixedText()] = $to->getInterwiki();
|
2023-03-25 14:00:34 +00:00
|
|
|
} elseif ( !isset( $this->mAllPages[$to->getNamespace()][$to->getDBkey()] )
|
|
|
|
|
&& !( $this->mConvertTitles && isset( $this->mConvertedTitles[$to->getPrefixedText()] ) )
|
|
|
|
|
) {
|
2017-03-06 19:46:58 +00:00
|
|
|
$titlesToResolve[] = $to;
|
|
|
|
|
}
|
|
|
|
|
$this->mRedirectTitles[$from] = $to;
|
2012-12-12 21:51:54 +00:00
|
|
|
}
|
2017-03-06 19:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->mPendingRedirectSpecialPages ) {
|
2022-08-14 01:10:31 +00:00
|
|
|
foreach ( $this->mPendingRedirectSpecialPages as [ $from, $to ] ) {
|
2020-02-13 10:24:10 +00:00
|
|
|
/** @var Title $from */
|
2017-03-06 19:46:58 +00:00
|
|
|
$fromKey = $from->getPrefixedText();
|
|
|
|
|
$this->mResolvedRedirectTitles[$fromKey] = $from;
|
|
|
|
|
$this->mRedirectTitles[$fromKey] = $to;
|
|
|
|
|
if ( $to->isExternal() ) {
|
|
|
|
|
$this->mInterwikiTitles[$to->getPrefixedText()] = $to->getInterwiki();
|
|
|
|
|
} elseif ( !isset( $this->mAllPages[$to->getNamespace()][$to->getDBkey()] ) ) {
|
|
|
|
|
$titlesToResolve[] = $to;
|
2017-02-07 15:22:47 +00:00
|
|
|
}
|
2008-04-11 15:20:45 +00:00
|
|
|
}
|
2017-03-06 19:46:58 +00:00
|
|
|
$this->mPendingRedirectSpecialPages = [];
|
|
|
|
|
|
|
|
|
|
// Set private caching since we don't know what criteria the
|
|
|
|
|
// special pages used to decide on these redirects.
|
|
|
|
|
$this->mCacheMode = 'private';
|
2008-04-11 15:20:45 +00:00
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2017-02-07 15:22:47 +00:00
|
|
|
return $this->processTitlesArray( $titlesToResolve );
|
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
|
|
|
*
|
2021-04-30 14:41:54 +00:00
|
|
|
* @param string[]|LinkTarget[]|PageReference[] $titles
|
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 ) {
|
2021-07-04 13:40:19 +00:00
|
|
|
$linkBatch = $this->linkBatchFactory->newLinkBatch();
|
2021-04-30 14:41:54 +00:00
|
|
|
|
|
|
|
|
/** @var Title[] $titleObjects */
|
2018-09-22 09:31:02 +00:00
|
|
|
$titleObjects = [];
|
|
|
|
|
foreach ( $titles as $index => $title ) {
|
2013-03-04 21:22:14 +00:00
|
|
|
if ( is_string( $title ) ) {
|
2015-05-06 19:33:37 +00:00
|
|
|
try {
|
2020-02-13 10:24:10 +00:00
|
|
|
/** @var Title $titleObj */
|
2021-07-04 13:40:19 +00:00
|
|
|
$titleObj = $this->titleFactory->newFromTextThrow( $title, $this->mDefaultNamespace );
|
2015-05-06 19:33:37 +00:00
|
|
|
} catch ( MalformedTitleException $ex ) {
|
|
|
|
|
// Handle invalid titles gracefully
|
2017-02-07 15:22:47 +00:00
|
|
|
if ( !isset( $this->mAllPages[0][$title] ) ) {
|
|
|
|
|
$this->mAllPages[0][$title] = $this->mFakePageId;
|
|
|
|
|
$this->mInvalidTitles[$this->mFakePageId] = [
|
|
|
|
|
'title' => $title,
|
|
|
|
|
'invalidreason' => $this->getErrorFormatter()->formatException( $ex, [ 'bc' => true ] ),
|
|
|
|
|
];
|
|
|
|
|
$this->mFakePageId--;
|
|
|
|
|
}
|
2015-05-06 19:33:37 +00:00
|
|
|
continue; // There's nothing else we can do
|
|
|
|
|
}
|
2021-04-30 14:41:54 +00:00
|
|
|
} elseif ( $title instanceof LinkTarget ) {
|
2023-04-22 13:57:00 +00:00
|
|
|
$titleObj = $this->titleFactory->newFromLinkTarget( $title );
|
2013-03-04 21:22:14 +00:00
|
|
|
} else {
|
2023-04-22 13:57:00 +00:00
|
|
|
$titleObj = $this->titleFactory->newFromPageReference( $title );
|
2013-03-04 21:22:14 +00:00
|
|
|
}
|
2018-09-22 09:31:02 +00:00
|
|
|
|
|
|
|
|
$titleObjects[$index] = $titleObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get gender information
|
2021-07-04 13:40:19 +00:00
|
|
|
$this->genderCache->doTitlesArray( $titleObjects, __METHOD__ );
|
2018-09-22 09:31:02 +00:00
|
|
|
|
|
|
|
|
foreach ( $titleObjects as $index => $titleObj ) {
|
|
|
|
|
$title = is_string( $titles[$index] ) ? $titles[$index] : false;
|
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
|
2018-07-29 12:24:54 +00:00
|
|
|
if (
|
2020-05-06 00:26:09 +00:00
|
|
|
$this->mConvertTitles
|
2021-07-04 13:40:19 +00:00
|
|
|
&& $this->languageConverter->hasVariants()
|
2020-05-06 00:26:09 +00:00
|
|
|
&& !$titleObj->exists()
|
2013-11-14 12:47:20 +00:00
|
|
|
) {
|
2021-05-22 01:53:27 +00:00
|
|
|
// ILanguageConverter::findVariantLink will modify titleText and
|
|
|
|
|
// titleObj into the canonical variant if possible
|
2018-09-22 09:31:02 +00:00
|
|
|
$titleText = $title !== false ? $title : $titleObj->getPrefixedText();
|
2021-07-04 13:40:19 +00:00
|
|
|
$this->languageConverter->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();
|
2017-02-07 15:22:47 +00:00
|
|
|
$ns = $titleObj->getNamespace();
|
|
|
|
|
$dbkey = $titleObj->getDBkey();
|
|
|
|
|
if ( !isset( $this->mAllSpecials[$ns][$dbkey] ) ) {
|
|
|
|
|
$this->mAllSpecials[$ns][$dbkey] = $this->mFakePageId;
|
2017-03-06 19:46:58 +00:00
|
|
|
$target = null;
|
|
|
|
|
if ( $ns === NS_SPECIAL && $this->mResolveRedirects ) {
|
2021-07-04 13:40:19 +00:00
|
|
|
$special = $this->specialPageFactory->getPage( $dbkey );
|
2017-03-06 19:46:58 +00:00
|
|
|
if ( $special instanceof RedirectSpecialArticle ) {
|
|
|
|
|
// Only RedirectSpecialArticle is intended to redirect to an article, other kinds of
|
2020-03-13 00:55:30 +00:00
|
|
|
// RedirectSpecialPage are probably applying weird URL parameters we don't want to
|
|
|
|
|
// handle.
|
2017-03-06 19:46:58 +00:00
|
|
|
$context = new DerivativeContext( $this );
|
|
|
|
|
$context->setTitle( $titleObj );
|
|
|
|
|
$context->setRequest( new FauxRequest );
|
|
|
|
|
$special->setContext( $context );
|
2021-07-04 13:40:19 +00:00
|
|
|
[ /* $alias */, $subpage ] = $this->specialPageFactory->resolveAlias( $dbkey );
|
2017-03-06 19:46:58 +00:00
|
|
|
$target = $special->getRedirect( $subpage );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $target ) {
|
|
|
|
|
$this->mPendingRedirectSpecialPages[$dbkey] = [ $titleObj, $target ];
|
|
|
|
|
} else {
|
|
|
|
|
$this->mSpecialTitles[$this->mFakePageId] = $titleObj;
|
|
|
|
|
$this->mFakePageId--;
|
|
|
|
|
}
|
2017-02-07 15:22:47 +00:00
|
|
|
}
|
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.
|
2018-09-22 09:31:02 +00:00
|
|
|
if ( $title !== false && $title !== $unconvertedTitle ) {
|
2013-01-11 09:00:32 +00:00
|
|
|
$this->mNormalizedTitles[$title] = $unconvertedTitle;
|
|
|
|
|
}
|
2018-09-22 09:31:02 +00:00
|
|
|
} elseif ( $title !== false && $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
|
|
|
|
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.
|
|
|
|
|
*
|
2021-04-30 14:41:54 +00:00
|
|
|
* @param PageReference|LinkTarget $title
|
2014-11-24 21:21:49 +00:00
|
|
|
* @param array $data
|
|
|
|
|
*/
|
2021-04-30 14:41:54 +00:00
|
|
|
public function setGeneratorData( $title, array $data ) {
|
2014-11-24 21:21:49 +00:00
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbkey = $title->getDBkey();
|
|
|
|
|
$this->mGeneratorData[$ns][$dbkey] = $data;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-07 21:03:15 +00:00
|
|
|
/**
|
|
|
|
|
* Controls how generator data about a redirect source is merged into
|
|
|
|
|
* the generator data for the redirect target. When not set no data
|
|
|
|
|
* is merged. Note that if multiple titles redirect to the same target
|
|
|
|
|
* the order of operations is undefined.
|
|
|
|
|
*
|
|
|
|
|
* Example to include generated data from redirect in target, prefering
|
|
|
|
|
* the data generated for the destination when there is a collision:
|
|
|
|
|
* @code
|
|
|
|
|
* $pageSet->setRedirectMergePolicy( function( array $current, array $new ) {
|
|
|
|
|
* return $current + $new;
|
|
|
|
|
* } );
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
|
|
|
|
* @param callable|null $callable Recieves two array arguments, first the
|
|
|
|
|
* generator data for the redirect target and second the generator data
|
|
|
|
|
* for the redirect source. Returns the resulting generator data to use
|
|
|
|
|
* for the redirect target.
|
|
|
|
|
*/
|
|
|
|
|
public function setRedirectMergePolicy( $callable ) {
|
|
|
|
|
$this->mRedirectMergePolicy = $callable;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 23:03:44 +00:00
|
|
|
/**
|
|
|
|
|
* Resolve the title a redirect points to.
|
|
|
|
|
*
|
|
|
|
|
* Will follow sequential redirects to find the final page. In
|
|
|
|
|
* the case of a redirect cycle the original page will be returned.
|
|
|
|
|
* self::resolvePendingRedirects must be executed before calling
|
|
|
|
|
* this method.
|
|
|
|
|
*
|
|
|
|
|
* @param Title $titleFrom A title from $this->mResolvedRedirectTitles
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
|
|
|
|
private function resolveRedirectTitleDest( Title $titleFrom ): Title {
|
|
|
|
|
$seen = [];
|
|
|
|
|
$dest = $titleFrom;
|
|
|
|
|
while ( isset( $this->mRedirectTitles[$dest->getPrefixedText()] ) ) {
|
|
|
|
|
$dest = $this->mRedirectTitles[$dest->getPrefixedText()];
|
|
|
|
|
if ( isset( $seen[$dest->getPrefixedText()] ) ) {
|
|
|
|
|
return $titleFrom;
|
|
|
|
|
}
|
|
|
|
|
$seen[$dest->getPrefixedText()] = true;
|
|
|
|
|
}
|
|
|
|
|
return $dest;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-24 21:21:49 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
2014-12-10 05:09:35 +00:00
|
|
|
* @return bool Whether the data fit
|
2014-11-24 21:21:49 +00:00
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public function populateGeneratorData( &$result, array $path = [] ) {
|
2014-11-24 21:21:49 +00:00
|
|
|
if ( $result instanceof ApiResult ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$data = $result->getResultData( $path );
|
|
|
|
|
if ( $data === null ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-11-24 21:21:49 +00:00
|
|
|
} else {
|
|
|
|
|
$data = &$result;
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
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];
|
2014-11-24 21:21:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach ( $this->mGeneratorData as $ns => $dbkeys ) {
|
2017-04-29 20:50:33 +00:00
|
|
|
if ( $ns === NS_SPECIAL ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$pages = [];
|
2014-11-24 21:21:49 +00:00
|
|
|
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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$path2 = array_merge( $path, [ $pageId ] );
|
2014-11-24 21:21:49 +00:00
|
|
|
foreach ( $genData as $key => $value ) {
|
|
|
|
|
if ( !$result->addValue( $path2, $key, $value ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$data[$pageId] = array_merge( $data[$pageId], $genData );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-07 21:03:15 +00:00
|
|
|
|
|
|
|
|
// Merge data generated about redirect titles into the redirect destination
|
|
|
|
|
if ( $this->mRedirectMergePolicy ) {
|
|
|
|
|
foreach ( $this->mResolvedRedirectTitles as $titleFrom ) {
|
2020-10-06 23:03:44 +00:00
|
|
|
$dest = $this->resolveRedirectTitleDest( $titleFrom );
|
2015-10-07 21:03:15 +00:00
|
|
|
$fromNs = $titleFrom->getNamespace();
|
|
|
|
|
$fromDBkey = $titleFrom->getDBkey();
|
|
|
|
|
$toPageId = $dest->getArticleID();
|
|
|
|
|
if ( isset( $data[$toPageId] ) &&
|
|
|
|
|
isset( $this->mGeneratorData[$fromNs][$fromDBkey] )
|
|
|
|
|
) {
|
2018-08-15 23:33:12 +00:00
|
|
|
// It is necessary to set both $data and add to $result, if an ApiResult,
|
2015-10-07 21:03:15 +00:00
|
|
|
// to ensure multiple redirects to the same destination are all merged.
|
|
|
|
|
$data[$toPageId] = call_user_func(
|
|
|
|
|
$this->mRedirectMergePolicy,
|
|
|
|
|
$data[$toPageId],
|
|
|
|
|
$this->mGeneratorData[$fromNs][$fromDBkey]
|
|
|
|
|
);
|
2019-03-29 20:12:24 +00:00
|
|
|
if ( $result instanceof ApiResult &&
|
|
|
|
|
!$result->addValue( $path, $toPageId, $data[$toPageId], ApiResult::OVERRIDE )
|
|
|
|
|
) {
|
|
|
|
|
return false;
|
2015-10-07 21:03:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-24 21:21:49 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get the database connection (read-only)
|
2023-04-24 10:45:42 +00:00
|
|
|
* @return \Wikimedia\Rdbms\IReadableDatabase
|
2013-02-08 20:39:40 +00:00
|
|
|
*/
|
|
|
|
|
protected function getDB() {
|
|
|
|
|
return $this->mDbSource->getDB();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAllowedParams( $flags = 0 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [
|
|
|
|
|
'titles' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-pageset-param-titles',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'pageids' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'integer',
|
|
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-pageset-param-pageids',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'revids' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'integer',
|
|
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-pageset-param-revids',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'generator' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => null,
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-pageset-param-generator',
|
2022-06-06 01:24:41 +00:00
|
|
|
SubmoduleDef::PARAM_SUBMODULE_PARAM_PREFIX => 'g',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'redirects' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => false,
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => $this->mAllowGenerator
|
|
|
|
|
? 'api-pageset-param-redirects-generator'
|
|
|
|
|
: 'api-pageset-param-redirects-nogenerator',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'converttitles' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => [
|
2014-09-18 17:38:23 +00:00
|
|
|
'api-pageset-param-converttitles',
|
2024-08-16 19:29:07 +00:00
|
|
|
Message::listParam( LanguageConverter::$languagesWithVariants, 'text' ),
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2014-09-18 17:38:23 +00:00
|
|
|
|
|
|
|
|
if ( !$this->mAllowGenerator ) {
|
|
|
|
|
unset( $result['generator'] );
|
|
|
|
|
} elseif ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
|
2022-06-05 23:18:50 +00:00
|
|
|
$result['generator'][ParamValidator::PARAM_TYPE] = 'submodule';
|
2022-06-06 01:24:41 +00:00
|
|
|
$result['generator'][SubmoduleDef::PARAM_SUBMODULE_MAP] = $this->getGenerators();
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 19:53:53 +00:00
|
|
|
public function handleParamNormalization( $paramName, $value, $rawValue ) {
|
2016-08-24 18:07:43 +00:00
|
|
|
parent::handleParamNormalization( $paramName, $value, $rawValue );
|
|
|
|
|
|
|
|
|
|
if ( $paramName === 'titles' ) {
|
|
|
|
|
// For the 'titles' parameter, we want to split it like ApiBase would
|
|
|
|
|
// and add any changed titles to $this->mNormalizedTitles
|
2019-08-21 19:53:53 +00:00
|
|
|
$value = ParamValidator::explodeMultiValue( $value, self::LIMIT_SML2 + 1 );
|
2016-08-24 18:07:43 +00:00
|
|
|
$l = count( $value );
|
2019-08-21 19:53:53 +00:00
|
|
|
$rawValue = ParamValidator::explodeMultiValue( $rawValue, $l );
|
2016-08-24 18:07:43 +00:00
|
|
|
for ( $i = 0; $i < $l; $i++ ) {
|
|
|
|
|
if ( $value[$i] !== $rawValue[$i] ) {
|
|
|
|
|
$this->mNormalizedTitles[$rawValue[$i]] = $value[$i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get an array of all available generators
|
2024-07-02 09:57:44 +00:00
|
|
|
* @return array<string,string>
|
2013-02-08 20:39:40 +00:00
|
|
|
*/
|
|
|
|
|
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' );
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$gens = [];
|
2015-05-07 16:39:55 +00:00
|
|
|
$prefix = $query->getModulePath() . '+';
|
2013-02-08 23:43:25 +00:00
|
|
|
$mgr = $query->getModuleManager();
|
|
|
|
|
foreach ( $mgr->getNamesWithClasses() as $name => $class ) {
|
2018-01-13 00:02:09 +00:00
|
|
|
if ( is_subclass_of( $class, ApiQueryGeneratorBase::class ) ) {
|
2015-05-07 16:39:55 +00:00
|
|
|
$gens[$name] = $prefix . $name;
|
2013-02-08 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-05-07 16:39:55 +00:00
|
|
|
ksort( $gens );
|
2013-02-08 20:39:40 +00:00
|
|
|
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
|
|
|
}
|
2024-09-25 16:17:29 +00:00
|
|
|
|
|
|
|
|
/** @deprecated class alias since 1.43 */
|
|
|
|
|
class_alias( ApiPageSet::class, 'ApiPageSet' );
|