From e68fdb4065a4822474f98f1c6bf2c77ef52e537b Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 12 Aug 2018 12:08:58 +0300 Subject: [PATCH] Mass conversion to SpecialPageFactory service Change-Id: Ia6e1e819ec6cbe8bf75b820109f51d47863e31fc --- includes/Linker.php | 3 ++- includes/MediaWiki.php | 13 ++++++++----- includes/OutputPage.php | 3 ++- includes/PrefixSearch.php | 7 ++++--- includes/Title.php | 16 +++++++++++----- includes/actions/SpecialPageAction.php | 5 ++++- includes/api/ApiPageSet.php | 5 +++-- includes/api/ApiQuerySiteinfo.php | 5 +++-- includes/changes/OldChangesList.php | 5 ++++- includes/logging/LogPage.php | 6 ++++-- includes/parser/CoreParserFunctions.php | 3 ++- includes/skins/Skin.php | 3 ++- includes/skins/SkinTemplate.php | 4 +++- includes/specialpage/SpecialPage.php | 9 ++++++--- includes/specials/SpecialSpecialpages.php | 5 ++++- maintenance/updateSpecialPages.php | 3 ++- .../includes/api/ApiQuerySiteinfoTest.php | 4 +++- .../specials/QueryAllSpecialPagesTest.php | 5 ++++- .../includes/specials/SpecialSearchTest.php | 2 +- tests/phpunit/structure/SpecialPageFatalTest.php | 7 +++++-- 20 files changed, 77 insertions(+), 36 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 56e377d838..08a57247a6 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -205,7 +205,8 @@ class Linker { */ public static function normaliseSpecialPage( LinkTarget $target ) { if ( $target->getNamespace() == NS_SPECIAL && !$target->isExternal() ) { - list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $target->getDBkey() ); + list( $name, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $target->getDBkey() ); if ( !$name ) { return $target; } diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 2a84556586..4636ba349e 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -250,14 +250,15 @@ class MediaWiki { // Redirect loops, titleless URL, $wgUsePathInfo URLs, and URLs with a variant } elseif ( !$this->tryNormaliseRedirect( $title ) ) { // Prevent information leak via Special:MyPage et al (T109724) + $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); if ( $title->isSpecialPage() ) { - $specialPage = SpecialPageFactory::getPage( $title->getDBkey() ); + $specialPage = $spFactory->getPage( $title->getDBkey() ); if ( $specialPage instanceof RedirectSpecialPage ) { $specialPage->setContext( $this->context ); if ( $this->config->get( 'HideIdentifiableRedirects' ) && $specialPage->personallyIdentifiableTarget() ) { - list( , $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() ); + list( , $subpage ) = $spFactory->resolveAlias( $title->getDBkey() ); $target = $specialPage->getRedirect( $subpage ); // target can also be true. We let that case fall through to normal processing. if ( $target instanceof Title ) { @@ -284,7 +285,7 @@ class MediaWiki { // Special pages ($title may have changed since if statement above) if ( $title->isSpecialPage() ) { // Actions that need to be made when we have a special pages - SpecialPageFactory::executePath( $title, $this->context ); + $spFactory->executePath( $title, $this->context ); } else { // ...otherwise treat it as an article view. The article // may still be a wikipage redirect to another article or URL. @@ -338,7 +339,8 @@ class MediaWiki { } if ( $title->isSpecialPage() ) { - list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() ); + list( $name, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $title->getDBkey() ); if ( $name ) { $title = SpecialPage::getTitleFor( $name, $subpage ); } @@ -1055,7 +1057,8 @@ class MediaWiki { $invokedWithSuccess = true; if ( $sock ) { - $special = SpecialPageFactory::getPage( 'RunJobs' ); + $special = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + getPage( 'RunJobs' ); $url = $special->getPageTitle()->getCanonicalURL( $query ); $req = ( "POST $url HTTP/1.1\r\n" . diff --git a/includes/OutputPage.php b/includes/OutputPage.php index f6d5dc9b98..20557e9965 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3075,7 +3075,8 @@ class OutputPage extends ContextSource { if ( $ns == NS_SPECIAL ) { list( $canonicalSpecialPageName, /*...*/ ) = - SpecialPageFactory::resolveAlias( $title->getDBkey() ); + MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $title->getDBkey() ); } elseif ( $this->canUseWikiPage() ) { $wikiPage = $this->getWikiPage(); $curRevisionId = $wikiPage->getLatest(); diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index e32b439755..7bc7a084a5 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -173,13 +173,14 @@ abstract class PrefixSearch { $subpageSearch = $searchParts[1] ?? null; // Handle subpage search separately. + $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); if ( $subpageSearch !== null ) { // Try matching the full search string as a page name $specialTitle = Title::makeTitleSafe( NS_SPECIAL, $searchKey ); if ( !$specialTitle ) { return []; } - $special = SpecialPageFactory::getPage( $specialTitle->getText() ); + $special = $spFactory->getPage( $specialTitle->getText() ); if ( $special ) { $subpages = $special->prefixSearchSubpages( $subpageSearch, $limit, $offset ); return array_map( function ( $sub ) use ( $specialTitle ) { @@ -198,12 +199,12 @@ abstract class PrefixSearch { // Unlike SpecialPage itself, we want the canonical forms of both // canonical and alias title forms... $keys = []; - foreach ( SpecialPageFactory::getNames() as $page ) { + foreach ( $spFactory->getNames() as $page ) { $keys[$contLang->caseFold( $page )] = [ 'page' => $page, 'rank' => 0 ]; } foreach ( $contLang->getSpecialPageAliases() as $page => $aliases ) { - if ( !in_array( $page, SpecialPageFactory::getNames() ) ) {# T22885 + if ( !in_array( $page, $spFactory->getNames() ) ) {# T22885 continue; } diff --git a/includes/Title.php b/includes/Title.php index 12186394c5..e74824c9b8 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1119,7 +1119,9 @@ class Title implements LinkTarget { */ public function isSpecial( $name ) { if ( $this->isSpecialPage() ) { - list( $thisName, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $this->mDbkeyform ); + list( $thisName, /* $subpage */ ) = + MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $this->mDbkeyform ); if ( $name == $thisName ) { return true; } @@ -1135,9 +1137,10 @@ class Title implements LinkTarget { */ public function fixSpecialName() { if ( $this->isSpecialPage() ) { - list( $canonicalName, $par ) = SpecialPageFactory::resolveAlias( $this->mDbkeyform ); + $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); + list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform ); if ( $canonicalName ) { - $localName = SpecialPageFactory::getLocalNameFor( $canonicalName, $par ); + $localName = $spFactory->getLocalNameFor( $canonicalName, $par ); if ( $localName != $this->mDbkeyform ) { return self::makeTitle( NS_SPECIAL, $localName ); } @@ -2705,7 +2708,9 @@ class Title implements LinkTarget { } elseif ( $this->isSpecialPage() ) { # If it's a special page, ditch the subpage bit and check again $name = $this->mDbkeyform; - list( $name, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $name ); + list( $name, /* $subpage */ ) = + MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $name ); if ( $name ) { $pure = SpecialPage::getTitleFor( $name )->getPrefixedText(); if ( in_array( $pure, $wgWhitelistRead, true ) ) { @@ -4678,7 +4683,8 @@ class Title implements LinkTarget { return (bool)wfFindFile( $this ); case NS_SPECIAL: // valid special page - return SpecialPageFactory::exists( $this->mDbkeyform ); + return MediaWikiServices::getInstance()->getSpecialPageFactory()-> + exists( $this->mDbkeyform ); case NS_MAIN: // selflink, possibly with fragment return $this->mDbkeyform == ''; diff --git a/includes/actions/SpecialPageAction.php b/includes/actions/SpecialPageAction.php index e59b6d61ad..8a231cbe5f 100644 --- a/includes/actions/SpecialPageAction.php +++ b/includes/actions/SpecialPageAction.php @@ -18,6 +18,8 @@ * @ingroup Actions */ +use MediaWiki\MediaWikiServices; + /** * An action that just passes the request to the relevant special page * @@ -92,6 +94,7 @@ class SpecialPageAction extends FormlessAction { } // map actions to (whitelisted) special pages - return SpecialPageFactory::getPage( self::$actionToSpecialPageMapping[$action] ); + return MediaWikiServices::getInstance()->getSpecialPageFactory()-> + getPage( self::$actionToSpecialPageMapping[$action] ); } } diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 3786e8d90c..41358cb0ac 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -1217,7 +1217,8 @@ class ApiPageSet extends ApiBase { $this->mAllSpecials[$ns][$dbkey] = $this->mFakePageId; $target = null; if ( $ns === NS_SPECIAL && $this->mResolveRedirects ) { - $special = SpecialPageFactory::getPage( $dbkey ); + $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); + $special = $spFactory->getPage( $dbkey ); if ( $special instanceof RedirectSpecialArticle ) { // Only RedirectSpecialArticle is intended to redirect to an article, other kinds of // RedirectSpecialPage are probably applying weird URL parameters we don't want to handle. @@ -1225,7 +1226,7 @@ class ApiPageSet extends ApiBase { $context->setTitle( $titleObj ); $context->setRequest( new FauxRequest ); $special->setContext( $context ); - list( /* $alias */, $subpage ) = SpecialPageFactory::resolveAlias( $dbkey ); + list( /* $alias */, $subpage ) = $spFactory->resolveAlias( $dbkey ); $target = $special->getRedirect( $subpage ); } } diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index eaa3bc12cc..697eab69ba 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -341,8 +341,9 @@ class ApiQuerySiteinfo extends ApiQueryBase { protected function appendSpecialPageAliases( $property ) { $data = []; - $aliases = MediaWikiServices::getInstance()->getContentLanguage()->getSpecialPageAliases(); - foreach ( SpecialPageFactory::getNames() as $specialpage ) { + $services = MediaWikiServices::getInstance(); + $aliases = $services->getContentLanguage()->getSpecialPageAliases(); + foreach ( $services->getSpecialPageFactory()->getNames() as $specialpage ) { if ( isset( $aliases[$specialpage] ) ) { $arr = [ 'realname' => $specialpage, 'aliases' => $aliases[$specialpage] ]; ApiResult::setIndexedTagName( $arr['aliases'], 'alias' ); diff --git a/includes/changes/OldChangesList.php b/includes/changes/OldChangesList.php index 7ba12fbddd..a2af01cc49 100644 --- a/includes/changes/OldChangesList.php +++ b/includes/changes/OldChangesList.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + class OldChangesList extends ChangesList { /** @@ -90,7 +92,8 @@ class OldChangesList extends ChangesList { } // Log entries (old format) or log targets, and special pages } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) { - list( $name, $htmlubpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] ); + list( $name, $htmlubpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $rc->mAttribs['rc_title'] ); if ( $name == 'Log' ) { $this->insertLog( $html, $rc->getTitle(), $htmlubpage ); } diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php index 673c9292fa..af99940cb1 100644 --- a/includes/logging/LogPage.php +++ b/includes/logging/LogPage.php @@ -294,9 +294,11 @@ class LogPage { return $title->getPrefixedText(); } - $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); + $services = MediaWikiServices::getInstance(); + $linkRenderer = $services->getLinkRenderer(); if ( $title->isSpecialPage() ) { - list( $name, $par ) = SpecialPageFactory::resolveAlias( $title->getDBkey() ); + list( $name, $par ) = $services->getSpecialPageFactory()-> + resolveAlias( $title->getDBkey() ); # Use the language name for log titles, rather than Log/X if ( $name == 'Log' ) { diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index ae7ca6d428..1f5308fbdc 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -950,7 +950,8 @@ class CoreParserFunctions { } public static function special( $parser, $text ) { - list( $page, $subpage ) = SpecialPageFactory::resolveAlias( $text ); + list( $page, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $text ); if ( $page ) { $title = SpecialPage::getTitleFor( $page, $subpage ); return $title->getPrefixedText(); diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 83d02a0fdd..69168c64ed 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -449,7 +449,8 @@ abstract class Skin extends ContextSource { if ( $title->isSpecialPage() ) { $type = 'ns-special'; // T25315: provide a class based on the canonical special page name without subpages - list( $canonicalName ) = SpecialPageFactory::resolveAlias( $title->getDBkey() ); + list( $canonicalName ) = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $title->getDBkey() ); if ( $canonicalName ) { $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" ); } else { diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php index ceebf12c36..b44d4096d5 100644 --- a/includes/skins/SkinTemplate.php +++ b/includes/skins/SkinTemplate.php @@ -659,7 +659,9 @@ class SkinTemplate extends Skin { # so it doesn't contain the original alias-with-subpage. $origTitle = Title::newFromText( $request->getText( 'title' ) ); if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) { - list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() ); + list( $spName, $spPar ) = + MediaWikiServices::getInstance()->getSpecialPageFactory()-> + resolveAlias( $origTitle->getText() ); $active = $spName == 'Contributions' && ( ( $spPar && $spPar == $this->username ) || $request->getText( 'target' ) == $this->username ); diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index 13287bde6d..e18eacc093 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -95,7 +95,8 @@ class SpecialPage implements MessageLocalizer { * @return TitleValue */ public static function getTitleValueFor( $name, $subpage = false, $fragment = '' ) { - $name = SpecialPageFactory::getLocalNameFor( $name, $subpage ); + $name = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + getLocalNameFor( $name, $subpage ); return new TitleValue( NS_SPECIAL, $name, $fragment ); } @@ -108,7 +109,8 @@ class SpecialPage implements MessageLocalizer { * @return Title|null Title object or null if the page doesn't exist */ public static function getSafeTitleFor( $name, $subpage = false ) { - $name = SpecialPageFactory::getLocalNameFor( $name, $subpage ); + $name = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + getLocalNameFor( $name, $subpage ); if ( $name ) { return Title::makeTitleSafe( NS_SPECIAL, $name ); } else { @@ -233,7 +235,8 @@ class SpecialPage implements MessageLocalizer { */ function getLocalName() { if ( !isset( $this->mLocalName ) ) { - $this->mLocalName = SpecialPageFactory::getLocalNameFor( $this->mName ); + $this->mLocalName = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + getLocalNameFor( $this->mName ); } return $this->mLocalName; diff --git a/includes/specials/SpecialSpecialpages.php b/includes/specials/SpecialSpecialpages.php index 4f29082227..00aa543a88 100644 --- a/includes/specials/SpecialSpecialpages.php +++ b/includes/specials/SpecialSpecialpages.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * A special page that lists special pages * @@ -50,7 +52,8 @@ class SpecialSpecialpages extends UnlistedSpecialPage { } private function getPageGroups() { - $pages = SpecialPageFactory::getUsablePages( $this->getUser() ); + $pages = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + getUsablePages( $this->getUser() ); if ( !count( $pages ) ) { # Yeah, that was pointless. Thanks for coming. diff --git a/maintenance/updateSpecialPages.php b/maintenance/updateSpecialPages.php index 01aace0738..12a454a255 100644 --- a/maintenance/updateSpecialPages.php +++ b/maintenance/updateSpecialPages.php @@ -66,7 +66,8 @@ class UpdateSpecialPages extends Maintenance { continue; } - $specialObj = SpecialPageFactory::getPage( $special ); + $specialObj = MediaWikiServices::getInstance()->getSpecialPageFactory()-> + getPage( $special ); if ( !$specialObj ) { $this->output( "No such special page: $special\n" ); exit; diff --git a/tests/phpunit/includes/api/ApiQuerySiteinfoTest.php b/tests/phpunit/includes/api/ApiQuerySiteinfoTest.php index fe2058fd18..129b7f9d6a 100644 --- a/tests/phpunit/includes/api/ApiQuerySiteinfoTest.php +++ b/tests/phpunit/includes/api/ApiQuerySiteinfoTest.php @@ -1,5 +1,7 @@ assertCount( - count( SpecialPageFactory::getNames() ), + count( MediaWikiServices::getInstance()->getSpecialPageFactory()->getNames() ), $this->doQuery( 'specialpagealiases' ) ); } diff --git a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php index d53a9b8f80..4a171dfac0 100644 --- a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php +++ b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php @@ -7,6 +7,8 @@ * @author Antoine Musso */ +use MediaWiki\MediaWikiServices; + /** * @group Database * @covers QueryPage @@ -43,7 +45,8 @@ class QueryAllSpecialPagesTest extends MediaWikiTestCase { $class = $page[0]; $name = $page[1]; if ( !in_array( $class, $this->manualTest ) ) { - $this->queryPages[$class] = SpecialPageFactory::getPage( $name ); + $this->queryPages[$class] = + MediaWikiServices::getInstance()->getSpecialPageFactory()->getPage( $name ); } } } diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php index 196321caed..6ff2110ee3 100644 --- a/tests/phpunit/includes/specials/SpecialSearchTest.php +++ b/tests/phpunit/includes/specials/SpecialSearchTest.php @@ -231,7 +231,7 @@ class SpecialSearchTest extends MediaWikiTestCase { $ctx = new RequestContext; $sp = Title::newFromText( 'Special:Search/foo_bar' ); - SpecialPageFactory::executePath( $sp, $ctx ); + MediaWikiServices::getInstance()->getSpecialPageFactory()->executePath( $sp, $ctx ); $url = $ctx->getOutput()->getRedirect(); // some older versions of hhvm have a bug that doesn't parse relative // urls with a port, so help it out a little bit. diff --git a/tests/phpunit/structure/SpecialPageFatalTest.php b/tests/phpunit/structure/SpecialPageFatalTest.php index 47dbd2e02e..9d85fdebeb 100644 --- a/tests/phpunit/structure/SpecialPageFatalTest.php +++ b/tests/phpunit/structure/SpecialPageFatalTest.php @@ -1,5 +1,7 @@ getSpecialPageFactory(); + foreach ( $spf->getNames() as $name ) { + $specialPages[$name] = [ $spf->getPage( $name ) ]; } return $specialPages; } -- 2.20.1