diff options
author | daniel <dkinzler@wikimedia.org> | 2021-04-30 16:41:54 +0200 |
---|---|---|
committer | daniel <dkinzler@wikimedia.org> | 2021-05-12 23:17:59 +0200 |
commit | 246c54373757dac8b17013243913d6961118428a (patch) | |
tree | bdf470bd35315107c36c5771b017593225c1e5b7 /includes/api | |
parent | 64b8677ca2c2a2e27872620cd8d9917b03fb0ca8 (diff) | |
download | mediawikicore-246c54373757dac8b17013243913d6961118428a.tar.gz mediawikicore-246c54373757dac8b17013243913d6961118428a.zip |
ApiPageSet: replace Title in method signatures
Bug: T278459
Change-Id: Ie817fd476d6236791431b5ba5ce557800ef5222d
Diffstat (limited to 'includes/api')
-rw-r--r-- | includes/api/ApiPageSet.php | 106 | ||||
-rw-r--r-- | includes/api/ApiQuery.php | 2 | ||||
-rw-r--r-- | includes/api/ApiQueryBacklinksprop.php | 4 | ||||
-rw-r--r-- | includes/api/ApiQueryCategoryInfo.php | 2 | ||||
-rw-r--r-- | includes/api/ApiQueryDeletedRevisions.php | 4 | ||||
-rw-r--r-- | includes/api/ApiQueryDeletedrevs.php | 2 | ||||
-rw-r--r-- | includes/api/ApiSetNotificationTimestamp.php | 6 |
7 files changed, 103 insertions, 23 deletions
diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index e8b0e13dc894..c0ca9ab2f9ee 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -20,7 +20,10 @@ * @file */ +use MediaWiki\Linker\LinkTarget; use MediaWiki\MediaWikiServices; +use MediaWiki\Page\PageIdentity; +use MediaWiki\Page\PageReference; use Wikimedia\ParamValidator\ParamValidator; use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\IResultWrapper; @@ -344,7 +347,11 @@ class ApiPageSet extends ApiBase { } /** - * All Title objects provided. + * 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. + * + * @deprecated since 1.37, use getPages() instead. * @return Title[] */ public function getTitles() { @@ -352,6 +359,18 @@ class ApiPageSet extends ApiBase { } /** + * 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; + } + + /** * Returns the number of unique pages (not revisions) in the set. * @return int */ @@ -368,7 +387,9 @@ class ApiPageSet extends ApiBase { } /** - * Title objects that were found in the database. + * Title objects that were found in the database, including redirects. + * If redirects are resolved, this will include existing redirect targets. + * @deprecated since 1.37, use getGoodPages() instead. * @return Title[] Array page_id (int) => Title (obj) */ public function getGoodTitles() { @@ -376,6 +397,16 @@ class ApiPageSet extends ApiBase { } /** + * Pages that were found in the database, including redirects. + * If redirects are resolved, this will include existing redirect targets. + * @since 1.37 + * @return PageIdentity[] Array page_id (int) => PageIdentity (obj) + */ + public function getGoodPages(): array { + return $this->mGoodTitles; + } + + /** * Returns the number of found unique pages (not revisions) in the set. * @return int */ @@ -394,7 +425,9 @@ class ApiPageSet extends ApiBase { /** * Title objects that were NOT found in the database. - * The array's index will be negative for each item + * The array's index will be negative for each item. + * If redirects are resolved, this will include missing redirect targets. + * @deprecated since 1.37, use getMissingPages instead. * @return Title[] */ public function getMissingTitles() { @@ -402,6 +435,17 @@ class ApiPageSet extends ApiBase { } /** + * 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; + } + + /** * Returns an array [ns][dbkey] => page_id for all good and missing titles. * @return array */ @@ -411,6 +455,7 @@ class ApiPageSet extends ApiBase { /** * Title objects for good and missing titles. + * @deprecated since 1.37, use getGoodAndMissingPages() instead. * @return Title[] */ public function getGoodAndMissingTitles() { @@ -418,6 +463,15 @@ class ApiPageSet extends ApiBase { } /** + * Pages for good and missing titles. + * @since 1.37 + * @return PageIdentity[] + */ + public function getGoodAndMissingPages(): array { + return $this->mGoodTitles + $this->mMissingTitles; + } + + /** * Titles that were deemed invalid by Title::newFromText() * The array's index will be unique and negative for each item * @return array[] Array of arrays with 'title' and 'invalidreason' properties @@ -436,7 +490,8 @@ class ApiPageSet extends ApiBase { /** * Get a list of redirect resolutions - maps a title to its redirect - * target, as an array of output-ready arrays + * target. + * @deprecated since 1.37, use getRedirectTargets instead. * @return Title[] */ public function getRedirectTitles() { @@ -445,6 +500,16 @@ class ApiPageSet extends ApiBase { /** * 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; + } + + /** + * Get a list of redirect resolutions - maps a title to its redirect * target. Includes generator data for redirect source when available. * @param ApiResult|null $result * @return string[][] @@ -697,6 +762,7 @@ class ApiPageSet extends ApiBase { /** * Get the list of titles with negative namespace + * @deprecated since 1.37, use getSpecialPages() instead. * @return Title[] */ public function getSpecialTitles() { @@ -704,6 +770,15 @@ class ApiPageSet extends ApiBase { } /** + * Get the list of pages with negative namespace + * @since 1.37 + * @return PageReference[] + */ + public function getSpecialPages(): array { + return $this->mSpecialTitles; + } + + /** * Returns the number of revisions (requested with revids= parameter). * @return int Number of revisions. */ @@ -712,8 +787,8 @@ class ApiPageSet extends ApiBase { } /** - * Populate this PageSet from a list of Titles - * @param array $titles Array of Title objects + * Populate this PageSet + * @param string[]|LinkTarget[]|PageReference[] $titles */ public function populateFromTitles( $titles ) { $this->initFromTitles( $titles ); @@ -790,7 +865,7 @@ class ApiPageSet extends ApiBase { * #5 Substitute the original LinkBatch object with the new list * #6 Repeat from step #1 * - * @param array $titles Array of Title objects or strings + * @param string[]|LinkTarget[]|PageReference[] $titles */ private function initFromTitles( $titles ) { // Get validated and normalized title objects @@ -1026,7 +1101,7 @@ class ApiPageSet extends ApiBase { while ( $this->mPendingRedirectIDs || $this->mPendingRedirectSpecialPages ) { // Resolve redirects by querying the pagelinks table, and repeat the process // Create a new linkBatch object for the next pass - $linkBatch = $this->getRedirectTargets(); + $linkBatch = $this->loadRedirectTargets(); if ( $linkBatch->isEmpty() ) { break; @@ -1053,7 +1128,7 @@ class ApiPageSet extends ApiBase { * have one. * @return LinkBatch */ - private function getRedirectTargets() { + private function loadRedirectTargets() { $titlesToResolve = []; $db = $this->getDB(); @@ -1156,7 +1231,7 @@ class ApiPageSet extends ApiBase { * This method validates access rights for the title, * and appends normalization values to the output. * - * @param array $titles Array of Title objects or strings + * @param string[]|LinkTarget[]|PageReference[] $titles * @return LinkBatch */ private function processTitlesArray( $titles ) { @@ -1167,6 +1242,9 @@ class ApiPageSet extends ApiBase { ->getLanguageConverterFactory() ->getLanguageConverter( $services->getContentLanguage() ); + $titleFactory = $services->getTitleFactory(); + + /** @var Title[] $titleObjects */ $titleObjects = []; foreach ( $titles as $index => $title ) { if ( is_string( $title ) ) { @@ -1185,8 +1263,10 @@ class ApiPageSet extends ApiBase { } continue; // There's nothing else we can do } + } elseif ( $title instanceof LinkTarget ) { + $titleObj = $titleFactory->castFromLinkTarget( $title ); } else { - $titleObj = $title; + $titleObj = $titleFactory->castFromPageReference( $title ); } $titleObjects[$index] = $titleObj; @@ -1284,10 +1364,10 @@ class ApiPageSet extends ApiBase { * specified, since in the case of multiple redirects we can't know which * source's data to use on the target. * - * @param Title $title + * @param PageReference|LinkTarget $title * @param array $data */ - public function setGeneratorData( Title $title, array $data ) { + public function setGeneratorData( $title, array $data ) { $ns = $title->getNamespace(); $dbkey = $title->getDBkey(); $this->mGeneratorData[$ns][$dbkey] = $data; diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index fb551ae75058..abfc7508a8b7 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -506,7 +506,7 @@ class ApiQuery extends ApiBase { */ private function doExport( $pageSet, $result ) { $exportTitles = []; - $titles = $pageSet->getGoodTitles(); + $titles = $pageSet->getGoodPages(); if ( count( $titles ) ) { /** @var Title $title */ foreach ( $titles as $title ) { diff --git a/includes/api/ApiQueryBacklinksprop.php b/includes/api/ApiQueryBacklinksprop.php index 29d0d7954ea4..af9b8f1aa991 100644 --- a/includes/api/ApiQueryBacklinksprop.php +++ b/includes/api/ApiQueryBacklinksprop.php @@ -103,12 +103,12 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { $emptyString = $db->addQuotes( '' ); $pageSet = $this->getPageSet(); - $titles = $pageSet->getGoodAndMissingTitles(); + $titles = $pageSet->getGoodAndMissingPages(); $map = $pageSet->getGoodAndMissingTitlesByNamespace(); // Add in special pages, they can theoretically have backlinks too. // (although currently they only do for prop=redirects) - foreach ( $pageSet->getSpecialTitles() as $id => $title ) { + foreach ( $pageSet->getSpecialPages() as $id => $title ) { $titles[] = $title; $map[$title->getNamespace()][$title->getDBkey()] = $id; } diff --git a/includes/api/ApiQueryCategoryInfo.php b/includes/api/ApiQueryCategoryInfo.php index b51a088b74f2..b03abc989955 100644 --- a/includes/api/ApiQueryCategoryInfo.php +++ b/includes/api/ApiQueryCategoryInfo.php @@ -40,7 +40,7 @@ class ApiQueryCategoryInfo extends ApiQueryBase { } $categories = $alltitles[NS_CATEGORY]; - $titles = $this->getPageSet()->getGoodAndMissingTitles(); + $titles = $this->getPageSet()->getGoodAndMissingPages(); $cattitles = []; foreach ( $categories as $c ) { /** @var Title $t */ diff --git a/includes/api/ApiQueryDeletedRevisions.php b/includes/api/ApiQueryDeletedRevisions.php index 0c3639a74815..9526cb25bdb9 100644 --- a/includes/api/ApiQueryDeletedRevisions.php +++ b/includes/api/ApiQueryDeletedRevisions.php @@ -48,7 +48,7 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase { $pageSet = $this->getPageSet(); $pageMap = $pageSet->getGoodAndMissingTitlesByNamespace(); - $pageCount = count( $pageSet->getGoodAndMissingTitles() ); + $pageCount = count( $pageSet->getGoodAndMissingPages() ); $revCount = $pageSet->getRevisionCount(); if ( $revCount === 0 && $pageCount === 0 ) { // Nothing to do @@ -116,7 +116,7 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase { } else { // We need a custom WHERE clause that matches all titles. $linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory(); - $lb = $linkBatchFactory->newLinkBatch( $pageSet->getGoodAndMissingTitles() ); + $lb = $linkBatchFactory->newLinkBatch( $pageSet->getGoodAndMissingPages() ); $where = $lb->constructSet( 'ar', $db ); $this->addWhere( $where ); } diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 7dc5e831d2bc..0407655107ee 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -89,7 +89,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $result = $this->getResult(); $pageSet = $this->getPageSet(); - $titles = $pageSet->getTitles(); + $titles = $pageSet->getPages(); // This module operates in three modes: // 'revs': List deleted revs for certain titles (1) diff --git a/includes/api/ApiSetNotificationTimestamp.php b/includes/api/ApiSetNotificationTimestamp.php index 789cb9b6b127..5867a71d1dcd 100644 --- a/includes/api/ApiSetNotificationTimestamp.php +++ b/includes/api/ApiSetNotificationTimestamp.php @@ -173,18 +173,18 @@ class ApiSetNotificationTimestamp extends ApiBase { $result[] = $rev; } - if ( $pageSet->getTitles() ) { + if ( $pageSet->getPages() ) { // Now process the valid titles $this->watchedItemStore->setNotificationTimestampsForUser( $user, $timestamp, - $pageSet->getTitles() + $pageSet->getPages() ); // Query the results of our update $timestamps = $this->watchedItemStore->getNotificationTimestampsBatch( $user, - $pageSet->getTitles() + $pageSet->getPages() ); // Now, put the valid titles into the result |