From 2e1ac38485b9c78890944413cba074474c06bd34 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 5 Aug 2018 20:58:51 +0300 Subject: [PATCH] Mass conversion to NamespaceInfo Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f --- includes/EditPage.php | 7 +- includes/Linker.php | 19 +++- includes/MovePage.php | 13 ++- includes/OutputPage.php | 5 +- includes/ProtectionForm.php | 11 +- includes/SiteStatsInit.php | 6 +- includes/Title.php | 102 ++++++++++++------ includes/TrackingCategories.php | 5 +- includes/actions/InfoAction.php | 11 +- includes/api/ApiBase.php | 4 +- includes/api/ApiHelp.php | 3 +- includes/api/ApiPageSet.php | 11 +- includes/api/ApiQueryAllDeletedRevisions.php | 6 +- includes/api/ApiQueryAllPages.php | 5 +- includes/api/ApiQueryAllRevisions.php | 5 +- includes/api/ApiQueryInfo.php | 13 +-- includes/api/ApiQuerySiteinfo.php | 13 +-- includes/changes/ChangesFeed.php | 5 +- includes/content/ContentHandler.php | 1 + includes/editpage/TextboxBuilder.php | 5 +- includes/export/DumpNotalkFilter.php | 5 +- includes/export/XmlDumpWriter.php | 4 +- includes/filerepo/FileRepo.php | 8 +- includes/gallery/TraditionalImageGallery.php | 3 +- includes/import/WikiImporter.php | 7 +- includes/page/Article.php | 7 +- .../ResourceLoaderStartUpModule.php | 7 +- includes/skins/Skin.php | 5 +- includes/skins/SkinTemplate.php | 11 +- .../specialpage/ChangesListSpecialPage.php | 6 +- includes/specials/SpecialAncientpages.php | 3 +- includes/specials/SpecialContributions.php | 4 +- includes/specials/SpecialDeadendpages.php | 9 +- .../specials/SpecialDeletedContributions.php | 5 +- includes/specials/SpecialEditWatchlist.php | 12 ++- includes/specials/SpecialFewestrevisions.php | 3 +- includes/specials/SpecialListGroupRights.php | 6 +- includes/specials/SpecialLonelypages.php | 9 +- includes/specials/SpecialMostcategories.php | 4 +- includes/specials/SpecialMostinterwikis.php | 4 +- includes/specials/SpecialMovepage.php | 16 +-- includes/specials/SpecialPasswordPolicies.php | 5 +- includes/specials/SpecialRandompage.php | 3 +- includes/specials/SpecialSearch.php | 4 +- includes/specials/SpecialShortpages.php | 6 +- includes/specials/SpecialStatistics.php | 6 +- .../specials/SpecialUncategorizedpages.php | 10 +- includes/specials/SpecialWithoutinterwiki.php | 5 +- includes/specials/forms/UploadForm.php | 3 +- includes/specials/pagers/ContribsPager.php | 2 +- includes/title/NaiveImportTitleFactory.php | 5 +- .../title/NamespaceImportTitleFactory.php | 4 +- includes/title/SubpageImportTitleFactory.php | 7 +- includes/user/ExternalUserNames.php | 6 +- includes/widget/search/SearchFormWidget.php | 4 +- languages/Language.php | 7 +- maintenance/cleanupCaps.php | 5 +- maintenance/cleanupTitles.php | 2 +- maintenance/generateSitemap.php | 2 +- maintenance/namespaceDupes.php | 15 ++- maintenance/rebuildFileCache.php | 5 +- tests/parser/ParserTestRunner.php | 3 +- tests/phpunit/MediaWikiTestCase.php | 9 +- tests/phpunit/includes/PagePropsTest.php | 5 +- tests/phpunit/includes/RevisionDbTestBase.php | 3 +- tests/phpunit/includes/api/ApiBaseTest.php | 5 +- .../includes/editpage/TextboxBuilderTest.php | 2 +- tests/phpunit/structure/ApiStructureTest.php | 4 +- 68 files changed, 360 insertions(+), 165 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 1d9ff05240..2d5b9e20b5 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2609,7 +2609,8 @@ ERROR; LogEventsList::showLogExtract( $out, 'block', - MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(), + MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( NS_USER ) . ':' . $block->getTarget(), '', [ 'lim' => 1, @@ -4451,7 +4452,9 @@ ERROR; protected function addPageProtectionWarningHeaders() { $out = $this->context->getOutput(); if ( $this->mTitle->isProtected( 'edit' ) && - MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ] + MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels( + $this->mTitle->getNamespace() + ) !== [ '' ] ) { # Is the title semi-protected? if ( $this->mTitle->isSemiProtected() ) { diff --git a/includes/Linker.php b/includes/Linker.php index 6acfda3121..ff4c786110 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -191,7 +191,7 @@ class Linker { */ public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) { // First we check whether the namespace exists or not. - if ( MWNamespace::exists( $namespace ) ) { + if ( MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $namespace ) ) { if ( $namespace == NS_MAIN ) { $name = $context->msg( 'blanknamespace' )->text(); } else { @@ -1302,7 +1302,12 @@ class Linker { ([^[]*) # 3. link trail (the text up until the next link) /x', function ( $match ) use ( $title, $local, $wikiId ) { - $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|'; + $services = MediaWikiServices::getInstance(); + + $medians = '(?:'; + $medians .= preg_quote( + $services->getNamespaceInfo()->getCanonicalName( NS_MEDIA ), '/' ); + $medians .= '|'; $medians .= preg_quote( MediaWikiServices::getInstance()->getContentLanguage()->getNsText( NS_MEDIA ), '/' @@ -1410,8 +1415,9 @@ class Linker { $wikiId, $linkTarget->getNamespace() === 0 ? $linkTarget->getDBkey() - : MWNamespace::getCanonicalName( $linkTarget->getNamespace() ) . ':' - . $linkTarget->getDBkey(), + : MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( $linkTarget->getNamespace() ) . + ':' . $linkTarget->getDBkey(), $linkTarget->getFragment() ), $text, @@ -1446,7 +1452,10 @@ class Linker { # Some namespaces don't allow subpages, # so only perform processing if subpages are allowed - if ( $contextTitle && MWNamespace::hasSubpages( $contextTitle->getNamespace() ) ) { + if ( + $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $contextTitle->getNamespace() ) + ) { $hash = strpos( $target, '#' ); if ( $hash !== false ) { $suffix = substr( $target, $hash ); diff --git a/includes/MovePage.php b/includes/MovePage.php index e49398a0f7..004ca07641 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -327,7 +327,8 @@ class MovePage { [ 'cl_from' => $pageid ], __METHOD__ ); - $type = MediaWikiServices::getInstance()->getNamespaceInfo()-> + $services = MediaWikiServices::getInstance(); + $type = $services->getNamespaceInfo()-> getCategoryLinkType( $this->newTitle->getNamespace() ); foreach ( $prefixes as $prefixRow ) { $prefix = $prefixRow->cl_sortkey_prefix; @@ -428,11 +429,13 @@ class MovePage { # Update watchlists $oldtitle = $this->oldTitle->getDBkey(); $newtitle = $this->newTitle->getDBkey(); - $oldsnamespace = MWNamespace::getSubject( $this->oldTitle->getNamespace() ); - $newsnamespace = MWNamespace::getSubject( $this->newTitle->getNamespace() ); + $oldsnamespace = $services->getNamespaceInfo()-> + getSubject( $this->oldTitle->getNamespace() ); + $newsnamespace = $services->getNamespaceInfo()-> + getSubject( $this->newTitle->getNamespace() ); if ( $oldsnamespace != $newsnamespace || $oldtitle != $newtitle ) { - $store = MediaWikiServices::getInstance()->getWatchedItemStore(); - $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle ); + $services->getWatchedItemStore()->duplicateAllAssociatedEntries( + $this->oldTitle, $this->newTitle ); } // If it is a file then move it last. diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 3e91fb346c..56e23707fc 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3430,8 +3430,9 @@ class OutputPage extends ContextSource { $title = $this->getTitle(); $ns = $title->getNamespace(); - $canonicalNamespace = MWNamespace::exists( $ns ) - ? MWNamespace::getCanonicalName( $ns ) + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + $canonicalNamespace = $nsInfo->exists( $ns ) + ? $nsInfo->getCanonicalName( $ns ) : $title->getNsText(); $sk = $this->getSkin(); diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 7972a1ebe4..2f1059886d 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -90,7 +90,7 @@ class ProtectionForm { * Loads the current state of protection into the object. */ function loadData() { - $levels = MWNamespace::getRestrictionLevels( + $levels = MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels( $this->mTitle->getNamespace(), $this->mContext->getUser() ); $this->mCascade = $this->mTitle->areRestrictionsCascading(); @@ -179,7 +179,11 @@ class ProtectionForm { * Main entry point for action=protect and action=unprotect */ function execute() { - if ( MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) === [ '' ] ) { + if ( + MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels( + $this->mTitle->getNamespace() + ) === [ '' ] + ) { throw new ErrorPageError( 'protect-badnamespace-title', 'protect-badnamespace-text' ); } @@ -581,7 +585,8 @@ class ProtectionForm { function buildSelector( $action, $selected ) { // If the form is disabled, display all relevant levels. Otherwise, // just show the ones this user can use. - $levels = MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace(), + $levels = MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels( + $this->mTitle->getNamespace(), $this->disabled ? null : $this->mContext->getUser() ); diff --git a/includes/SiteStatsInit.php b/includes/SiteStatsInit.php index 8adb2181ea..e97db2db04 100644 --- a/includes/SiteStatsInit.php +++ b/includes/SiteStatsInit.php @@ -68,15 +68,15 @@ class SiteStatsInit { * @return int */ public function articles() { - $config = MediaWikiServices::getInstance()->getMainConfig(); + $services = MediaWikiServices::getInstance(); $tables = [ 'page' ]; $conds = [ - 'page_namespace' => MWNamespace::getContentNamespaces(), + 'page_namespace' => $services->getNamespaceInfo()->getContentNamespaces(), 'page_is_redirect' => 0, ]; - if ( $config->get( 'ArticleCountMethod' ) == 'link' ) { + if ( $services->getMainConfig()->get( 'ArticleCountMethod' ) == 'link' ) { $tables[] = 'pagelinks'; $conds[] = 'pl_from=page_id'; } diff --git a/includes/Title.php b/includes/Title.php index ad6c167937..866f0415d8 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -618,7 +618,7 @@ class Title implements LinkTarget, IDBAccessObject { // NOTE: ideally, this would just call makeTitle() and then isValid(), // but presently, that means more overhead on a potential performance hotspot. - if ( !MWNamespace::exists( $ns ) ) { + if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) { return null; } @@ -820,7 +820,8 @@ class Title implements LinkTarget, IDBAccessObject { $canonicalNamespace = false ) { if ( $canonicalNamespace ) { - $namespace = MWNamespace::getCanonicalName( $ns ); + $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( $ns ); } else { $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns ); } @@ -862,13 +863,13 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isValid() { - if ( !MWNamespace::exists( $this->mNamespace ) ) { + $services = MediaWikiServices::getInstance(); + if ( !$services->getNamespaceInfo()->exists( $this->mNamespace ) ) { return false; } try { - $parser = MediaWikiServices::getInstance()->getTitleParser(); - $parser->parseTitle( $this->mDbkeyform, $this->mNamespace ); + $services->getTitleParser()->parseTitle( $this->mDbkeyform, $this->mNamespace ); return true; } catch ( MalformedTitleException $ex ) { return false; @@ -1086,7 +1087,8 @@ class Title implements LinkTarget, IDBAccessObject { if ( $this->isExternal() ) { // This probably shouldn't even happen, except for interwiki transclusion. // If possible, use the canonical name for the foreign namespace. - $nsText = MWNamespace::getCanonicalName( $this->mNamespace ); + $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( $this->mNamespace ); if ( $nsText !== false ) { return $nsText; } @@ -1107,8 +1109,9 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Namespace text */ public function getSubjectNsText() { - return MediaWikiServices::getInstance()->getContentLanguage()-> - getNsText( MWNamespace::getSubject( $this->mNamespace ) ); + $services = MediaWikiServices::getInstance(); + return $services->getContentLanguage()-> + getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) ); } /** @@ -1117,20 +1120,22 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Namespace text */ public function getTalkNsText() { - return MediaWikiServices::getInstance()->getContentLanguage()-> - getNsText( MWNamespace::getTalk( $this->mNamespace ) ); + $services = MediaWikiServices::getInstance(); + return $services->getContentLanguage()-> + getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) ); } /** * Can this title have a corresponding talk page? * - * @see MWNamespace::hasTalkNamespace + * @see NamespaceInfo::hasTalkNamespace * @since 1.30 * * @return bool True if this title either is a talk page or can have a talk page associated. */ public function canHaveTalkPage() { - return MWNamespace::hasTalkNamespace( $this->mNamespace ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasTalkNamespace( $this->mNamespace ); } /** @@ -1148,7 +1153,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isWatchable() { - return !$this->isExternal() && MWNamespace::isWatchable( $this->mNamespace ); + return !$this->isExternal() && MediaWikiServices::getInstance()->getNamespaceInfo()-> + isWatchable( $this->mNamespace ); } /** @@ -1209,7 +1215,8 @@ class Title implements LinkTarget, IDBAccessObject { * @since 1.19 */ public function inNamespace( $ns ) { - return MWNamespace::equals( $this->mNamespace, $ns ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + equals( $this->mNamespace, $ns ); } /** @@ -1248,7 +1255,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function hasSubjectNamespace( $ns ) { - return MWNamespace::subjectEquals( $this->mNamespace, $ns ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + subjectEquals( $this->mNamespace, $ns ); } /** @@ -1259,7 +1267,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isContentPage() { - return MWNamespace::isContent( $this->mNamespace ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + isContent( $this->mNamespace ); } /** @@ -1269,7 +1278,10 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isMovable() { - if ( !MWNamespace::isMovable( $this->mNamespace ) || $this->isExternal() ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + isMovable( $this->mNamespace ) || $this->isExternal() + ) { // Interwiki title or immovable namespace. Hooks don't get to override here return false; } @@ -1299,7 +1311,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isSubpage() { - return MWNamespace::hasSubpages( $this->mNamespace ) + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) ? strpos( $this->getText(), '/' ) !== false : false; } @@ -1495,7 +1508,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isTalkPage() { - return MWNamespace::isTalk( $this->mNamespace ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + isTalk( $this->mNamespace ); } /** @@ -1724,7 +1738,10 @@ class Title implements LinkTarget, IDBAccessObject { * @since 1.20 */ public function getRootText() { - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { return $this->getText(); } @@ -1760,7 +1777,10 @@ class Title implements LinkTarget, IDBAccessObject { */ public function getBaseText() { $text = $this->getText(); - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { return $text; } @@ -1801,7 +1821,10 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Subpage name */ public function getSubpageText() { - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { return $this->mTextform; } $parts = explode( '/', $this->mTextform ); @@ -2868,7 +2891,10 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function hasSubpages() { - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { # Duh return false; } @@ -2896,7 +2922,10 @@ class Title implements LinkTarget, IDBAccessObject { * doesn't allow subpages */ public function getSubpages( $limit = -1 ) { - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { return []; } @@ -3130,7 +3159,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Containing capitalized title */ public static function capitalize( $text, $ns = NS_MAIN ) { - if ( MWNamespace::isCapitalized( $ns ) ) { + $services = MediaWikiServices::getInstance(); + if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) { return MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $text ); } else { return $text; @@ -3472,14 +3502,15 @@ class Title implements LinkTarget, IDBAccessObject { ]; } // Do the source and target namespaces support subpages? - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + if ( !$nsInfo->hasSubpages( $this->mNamespace ) ) { return [ - [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $this->mNamespace ) ], + [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $this->mNamespace ) ], ]; } - if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) { + if ( !$nsInfo->hasSubpages( $nt->getNamespace() ) ) { return [ - [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $nt->getNamespace() ) ], + [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $nt->getNamespace() ) ], ]; } @@ -4293,9 +4324,10 @@ class Title implements LinkTarget, IDBAccessObject { */ public function getNamespaceKey( $prepend = 'nstab-' ) { // Gets the subject namespace of this title - $subjectNS = MWNamespace::getSubject( $this->mNamespace ); + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + $subjectNS = $nsInfo->getSubject( $this->mNamespace ); // Prefer canonical namespace name for HTML IDs - $namespaceKey = MWNamespace::getCanonicalName( $subjectNS ); + $namespaceKey = $nsInfo->getCanonicalName( $subjectNS ); if ( $namespaceKey === false ) { // Fallback to localised text $namespaceKey = $this->getSubjectNsText(); @@ -4391,7 +4423,8 @@ class Title implements LinkTarget, IDBAccessObject { public function canUseNoindex() { global $wgExemptFromUserRobotsControl; - $bannedNamespaces = $wgExemptFromUserRobotsControl ?? MWNamespace::getContentNamespaces(); + $bannedNamespaces = $wgExemptFromUserRobotsControl ?? + MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces(); return !in_array( $this->mNamespace, $bannedNamespaces ); } @@ -4558,7 +4591,10 @@ class Title implements LinkTarget, IDBAccessObject { } } - if ( MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { // Optional notice for page itself and any parent page $editnotice_base = $editnotice_ns; foreach ( explode( '/', $this->mDbkeyform ) as $part ) { diff --git a/includes/TrackingCategories.php b/includes/TrackingCategories.php index b3a49c71dd..ebdbc421d8 100644 --- a/includes/TrackingCategories.php +++ b/includes/TrackingCategories.php @@ -19,6 +19,8 @@ * @ingroup Categories */ +use MediaWiki\MediaWikiServices; + /** * This class performs some operations related to tracking categories, such as creating * a list of all such categories. @@ -80,6 +82,7 @@ class TrackingCategories { } $trackingCategories = []; + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); foreach ( $categories as $catMsg ) { /* * Check if the tracking category varies by namespace @@ -96,7 +99,7 @@ class TrackingCategories { // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}. // False positives are ok, this is just an efficiency shortcut if ( strpos( $msgObj->plain(), '{{' ) !== false ) { - $ns = MWNamespace::getValidNamespaces(); + $ns = $nsInfo->getValidNamespaces(); foreach ( $ns as $namesp ) { $tempTitle = Title::makeTitleSafe( $namesp, $catMsg ); if ( !$tempTitle ) { diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index 49a6bb5a5f..bfba59a02c 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -399,7 +399,7 @@ class InfoAction extends FormlessAction { } // Subpages of this page, if subpages are enabled for the current NS - if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) { + if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) { $prefixIndex = SpecialPage::getTitleFor( 'Prefixindex', $title->getPrefixedText() . '/' ); $pageInfo['header-basic'][] = [ @@ -730,12 +730,13 @@ class InfoAction extends FormlessAction { protected function pageCounts( Page $page ) { $fname = __METHOD__; $config = $this->context->getConfig(); - $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + $services = MediaWikiServices::getInstance(); + $cache = $services->getMainWANObjectCache(); return $cache->getWithSetCallback( self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ), WANObjectCache::TTL_WEEK, - function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) { + function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname, $services ) { global $wgActorTableSchemaMigrationStage; $title = $page->getTitle(); @@ -759,7 +760,7 @@ class InfoAction extends FormlessAction { $joins = []; } - $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore(); + $watchedItemStore = $services->getWatchedItemStore(); $result = []; $result['watchers'] = $watchedItemStore->countWatchers( $title ); @@ -824,7 +825,7 @@ class InfoAction extends FormlessAction { ); // Subpages (if enabled) - if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) { + if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) { $conds = [ 'page_namespace' => $title->getNamespace() ]; $conds[] = 'page_title ' . $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() ); diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 19d84f74b8..dbf72be290 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -20,6 +20,7 @@ * @file */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IDatabase; /** @@ -1198,7 +1199,8 @@ abstract class ApiBase extends ContextSource { $provided = $this->getMain()->getCheck( $encParamName ); if ( isset( $value ) && $type == 'namespace' ) { - $type = MWNamespace::getValidNamespaces(); + $type = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getValidNamespaces(); if ( isset( $paramSettings[self::PARAM_EXTRA_NAMESPACES] ) && is_array( $paramSettings[self::PARAM_EXTRA_NAMESPACES] ) ) { diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php index 1656e7ca29..78efe4191b 100644 --- a/includes/api/ApiHelp.php +++ b/includes/api/ApiHelp.php @@ -583,7 +583,8 @@ class ApiHelp extends ApiBase { break; case 'namespace': - $namespaces = MWNamespace::getValidNamespaces(); + $namespaces = MediaWikiServices::getInstance()-> + getNamespaceInfo()->getValidNamespaces(); if ( isset( $settings[ApiBase::PARAM_EXTRA_NAMESPACES] ) && is_array( $settings[ApiBase::PARAM_EXTRA_NAMESPACES] ) ) { diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index b321c7d14c..64c6f45971 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -866,6 +866,8 @@ class ApiPageSet extends ApiBase { ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' ); } + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + $usernames = []; if ( $res ) { foreach ( $res as $row ) { @@ -884,7 +886,7 @@ class ApiPageSet extends ApiBase { $this->processDbRow( $row ); // Need gender information - if ( MWNamespace::hasGenderDistinction( $row->page_namespace ) ) { + if ( $nsInfo->hasGenderDistinction( $row->page_namespace ) ) { $usernames[] = $row->page_title; } } @@ -907,7 +909,7 @@ class ApiPageSet extends ApiBase { $this->mTitles[] = $title; // need gender information - if ( MWNamespace::hasGenderDistinction( $ns ) ) { + if ( $nsInfo->hasGenderDistinction( $ns ) ) { $usernames[] = $dbkey; } } @@ -1249,7 +1251,10 @@ class ApiPageSet extends ApiBase { } // Need gender information - if ( MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) { + if ( + MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasGenderDistinction( $titleObj->getNamespace() ) + ) { $usernames[] = $titleObj->getText(); } } diff --git a/includes/api/ApiQueryAllDeletedRevisions.php b/includes/api/ApiQueryAllDeletedRevisions.php index bb50185444..beaad4336f 100644 --- a/includes/api/ApiQueryAllDeletedRevisions.php +++ b/includes/api/ApiQueryAllDeletedRevisions.php @@ -49,7 +49,8 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase { $user = $this->getUser(); $db = $this->getDB(); $params = $this->extractRequestParams( false ); - $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $services = MediaWikiServices::getInstance(); + $revisionStore = $services->getRevisionStore(); $result = $this->getResult(); @@ -156,7 +157,8 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase { $miser_ns = null; if ( $mode == 'all' ) { - $namespaces = $params['namespace'] ?? MWNamespace::getValidNamespaces(); + $namespaces = $params['namespace'] ?? + $services->getNamespaceInfo()->getValidNamespaces(); $this->addWhereFld( 'ar_namespace', $namespaces ); // For from/to/prefix, we have to consider the potential diff --git a/includes/api/ApiQueryAllPages.php b/includes/api/ApiQueryAllPages.php index 1940600e5e..08f3ea3f36 100644 --- a/includes/api/ApiQueryAllPages.php +++ b/includes/api/ApiQueryAllPages.php @@ -211,12 +211,13 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { $res = $this->select( __METHOD__ ); // Get gender information - if ( MWNamespace::hasGenderDistinction( $params['namespace'] ) ) { + $services = MediaWikiServices::getInstance(); + if ( $services->getNamespaceInfo()->hasGenderDistinction( $params['namespace'] ) ) { $users = []; foreach ( $res as $row ) { $users[] = $row->page_title; } - MediaWikiServices::getInstance()->getGenderCache()->doQuery( $users, __METHOD__ ); + $services->getGenderCache()->doQuery( $users, __METHOD__ ); $res->rewind(); // reset } diff --git a/includes/api/ApiQueryAllRevisions.php b/includes/api/ApiQueryAllRevisions.php index 58445a1faa..050bc0f81e 100644 --- a/includes/api/ApiQueryAllRevisions.php +++ b/includes/api/ApiQueryAllRevisions.php @@ -44,7 +44,8 @@ class ApiQueryAllRevisions extends ApiQueryRevisionsBase { $db = $this->getDB(); $params = $this->extractRequestParams( false ); - $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $services = MediaWikiServices::getInstance(); + $revisionStore = $services->getRevisionStore(); $result = $this->getResult(); @@ -70,7 +71,7 @@ class ApiQueryAllRevisions extends ApiQueryRevisionsBase { if ( $params['namespace'] !== null ) { $params['namespace'] = array_unique( $params['namespace'] ); sort( $params['namespace'] ); - if ( $params['namespace'] != MWNamespace::getValidNamespaces() ) { + if ( $params['namespace'] != $services->getNamespaceInfo()->getValidNamespaces() ) { $needPageTable = true; if ( $this->getConfig()->get( 'MiserMode' ) ) { $miser_ns = $params['namespace']; diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index a5437bae78..276aafbff0 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -708,10 +708,11 @@ class ApiQueryInfo extends ApiQueryBase { */ private function getTSIDs() { $getTitles = $this->talkids = $this->subjectids = []; + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); /** @var Title $t */ foreach ( $this->everything as $t ) { - if ( MWNamespace::isTalk( $t->getNamespace() ) ) { + if ( $nsInfo->isTalk( $t->getNamespace() ) ) { if ( $this->fld_subjectid ) { $getTitles[] = $t->getSubjectPage(); } @@ -734,12 +735,12 @@ class ApiQueryInfo extends ApiQueryBase { $this->addWhere( $lb->constructSet( 'page', $db ) ); $res = $this->select( __METHOD__ ); foreach ( $res as $row ) { - if ( MWNamespace::isTalk( $row->page_namespace ) ) { - $this->talkids[MWNamespace::getSubject( $row->page_namespace )][$row->page_title] = - (int)$row->page_id; + if ( $nsInfo->isTalk( $row->page_namespace ) ) { + $this->talkids[$nsInfo->getSubject( $row->page_namespace )][$row->page_title] = + (int)( $row->page_id ); } else { - $this->subjectids[MWNamespace::getTalk( $row->page_namespace )][$row->page_title] = - (int)$row->page_id; + $this->subjectids[$nsInfo->getTalk( $row->page_namespace )][$row->page_title] = + (int)( $row->page_id ); } } } diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 68ab725636..7e4a891adf 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -282,27 +282,28 @@ class ApiQuerySiteinfo extends ApiQueryBase { $data = [ ApiResult::META_TYPE => 'assoc', ]; + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); foreach ( MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces() as $ns => $title ) { $data[$ns] = [ 'id' => (int)$ns, - 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive', + 'case' => $nsInfo->isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive', ]; ApiResult::setContentValue( $data[$ns], 'name', $title ); - $canonical = MWNamespace::getCanonicalName( $ns ); + $canonical = $nsInfo->getCanonicalName( $ns ); - $data[$ns]['subpages'] = MWNamespace::hasSubpages( $ns ); + $data[$ns]['subpages'] = $nsInfo->hasSubpages( $ns ); if ( $canonical ) { $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' ); } - $data[$ns]['content'] = MWNamespace::isContent( $ns ); - $data[$ns]['nonincludable'] = MWNamespace::isNonincludable( $ns ); + $data[$ns]['content'] = $nsInfo->isContent( $ns ); + $data[$ns]['nonincludable'] = $nsInfo->isNonincludable( $ns ); - $contentmodel = MWNamespace::getNamespaceContentModel( $ns ); + $contentmodel = $nsInfo->getNamespaceContentModel( $ns ); if ( $contentmodel ) { $data[$ns]['defaultcontentmodel'] = $contentmodel; } diff --git a/includes/changes/ChangesFeed.php b/includes/changes/ChangesFeed.php index 4d00fbc543..bb9114aa62 100644 --- a/includes/changes/ChangesFeed.php +++ b/includes/changes/ChangesFeed.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * Feed to Special:RecentChanges and Special:RecentChangesLinked. * @@ -88,9 +90,10 @@ class ChangesFeed { } } + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); foreach ( $sorted as $obj ) { $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title ); - $talkpage = MWNamespace::hasTalkNamespace( $obj->rc_namespace ) + $talkpage = $nsInfo->hasTalkNamespace( $obj->rc_namespace ) ? $title->getTalkPage()->getFullURL() : ''; diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index decbb0c5d8..cc73dd2064 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -1,4 +1,5 @@ isProtected( 'edit' ) && - MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== [ '' ] + MediaWikiServices::getInstance()->getNamespaceInfo()-> + getRestrictionLevels( $title->getNamespace() ) !== [ '' ] ) { # Is the title semi-protected? if ( $title->isSemiProtected() ) { diff --git a/includes/export/DumpNotalkFilter.php b/includes/export/DumpNotalkFilter.php index c201c76b2f..6b2a22a080 100644 --- a/includes/export/DumpNotalkFilter.php +++ b/includes/export/DumpNotalkFilter.php @@ -23,6 +23,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * @ingroup Dump */ @@ -32,6 +34,7 @@ class DumpNotalkFilter extends DumpFilter { * @return bool */ protected function pass( $page ) { - return !MWNamespace::isTalk( $page->page_namespace ); + return !MediaWikiServices::getInstance()->getNamespaceInfo()-> + isTalk( $page->page_namespace ); } } diff --git a/includes/export/XmlDumpWriter.php b/includes/export/XmlDumpWriter.php index 54249a8b44..39153cf7c0 100644 --- a/includes/export/XmlDumpWriter.php +++ b/includes/export/XmlDumpWriter.php @@ -141,6 +141,7 @@ class XmlDumpWriter { */ function namespaces() { $spaces = "\n"; + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); foreach ( MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces() as $ns => $title @@ -149,7 +150,8 @@ class XmlDumpWriter { Xml::element( 'namespace', [ 'key' => $ns, - 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive', + 'case' => $nsInfo->isCapitalized( $ns ) + ? 'first-letter' : 'case-sensitive', ], $title ) . "\n"; } $spaces .= " "; diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 3a366c832c..3e11a48d7d 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -176,7 +176,8 @@ class FileRepo { } // Optional settings that have a default - $this->initialCapital = $info['initialCapital'] ?? MWNamespace::isCapitalized( NS_FILE ); + $this->initialCapital = $info['initialCapital'] ?? + MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized( NS_FILE ); $this->url = $info['url'] ?? false; // a subclass may set the URL (e.g. ForeignAPIRepo) if ( isset( $info['thumbUrl'] ) ) { $this->thumbUrl = $info['thumbUrl']; @@ -645,7 +646,10 @@ class FileRepo { * @return string */ public function getNameFromTitle( Title $title ) { - if ( $this->initialCapital != MWNamespace::isCapitalized( NS_FILE ) ) { + if ( + $this->initialCapital != + MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized( NS_FILE ) + ) { $name = $title->getUserCaseDBKey(); if ( $this->initialCapital ) { $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name ); diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index 9de7eb8408..4d5222cd79 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -169,7 +169,8 @@ class TraditionalImageGallery extends ImageGalleryBase { // @todo Code is incomplete. // $linkTarget = Title::newFromText( MediaWikiServices::getInstance()-> - // getContentLanguage()->getNsText( MWNamespace::getUser() ) . ":{$ut}" ); + // getContentLanguage()->getNsText( MediaWikiServices::getInstance()-> + // getNamespaceInfo()->getUser() ) . ":{$ut}" ); // $ul = Linker::link( $linkTarget, $ut ); $meta = []; diff --git a/includes/import/WikiImporter.php b/includes/import/WikiImporter.php index 466e3d873c..8f583442ce 100644 --- a/includes/import/WikiImporter.php +++ b/includes/import/WikiImporter.php @@ -257,7 +257,7 @@ class WikiImporter { return true; } elseif ( $namespace >= 0 && - MWNamespace::exists( intval( $namespace ) ) + MediaWikiServices::getInstance()->getNamespaceInfo()->exists( intval( $namespace ) ) ) { $namespace = intval( $namespace ); $this->setImportTitleFactory( new NamespaceImportTitleFactory( $namespace ) ); @@ -283,7 +283,10 @@ class WikiImporter { if ( !$title || $title->isExternal() ) { $status->fatal( 'import-rootpage-invalid' ); - } elseif ( !MWNamespace::hasSubpages( $title->getNamespace() ) ) { + } elseif ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $title->getNamespace() ) + ) { $displayNSText = $title->getNamespace() == NS_MAIN ? wfMessage( 'blanknamespace' )->text() : MediaWikiServices::getInstance()->getContentLanguage()-> diff --git a/includes/page/Article.php b/includes/page/Article.php index 124437ecb6..b20c83e269 100644 --- a/includes/page/Article.php +++ b/includes/page/Article.php @@ -1352,6 +1352,8 @@ class Article implements Page { $title = $this->getTitle(); + $services = MediaWikiServices::getInstance(); + # Show info in user (talk) namespace. Does the user exist? Is he blocked? if ( $title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK @@ -1374,7 +1376,8 @@ class Article implements Page { LogEventsList::showLogExtract( $outputPage, 'block', - MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(), + $services->getNamespaceInfo()->getCanonicalName( NS_USER ) . ':' . + $block->getTarget(), '', [ 'lim' => 1, @@ -1396,7 +1399,7 @@ class Article implements Page { # Show delete and move logs if there were any such events. # The logging query can DOS the site when bots/crawlers cause 404 floods, # so be careful showing this. 404 pages must be cheap as they are hard to cache. - $cache = MediaWikiServices::getInstance()->getMainObjectStash(); + $cache = $services->getMainObjectStash(); $key = $cache->makeKey( 'page-recent-delete', md5( $title->getPrefixedText() ) ); $loggedIn = $this->getContext()->getUser()->isLoggedIn(); $sessionExists = $this->getContext()->getRequest()->getSession()->isPersistent(); diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 69a6f5ff1a..8cbde09ff0 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -57,9 +57,10 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { $contLang = MediaWikiServices::getInstance()->getContentLanguage(); $namespaceIds = $contLang->getNamespaceIds(); $caseSensitiveNamespaces = []; - foreach ( MWNamespace::getCanonicalNamespaces() as $index => $name ) { + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + foreach ( $nsInfo->getCanonicalNamespaces() as $index => $name ) { $namespaceIds[$contLang->lc( $name )] = $index; - if ( !MWNamespace::isCapitalized( $index ) ) { + if ( !$nsInfo->isCapitalized( $index ) ) { $caseSensitiveNamespaces[] = $index; } } @@ -92,7 +93,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { 'wgEnableWriteAPI' => true, // Deprecated since MW 1.32 'wgFormattedNamespaces' => $contLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, - 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), + 'wgContentNamespaces' => $nsInfo->getContentNamespaces(), 'wgSiteName' => $conf->get( 'Sitename' ), 'wgDBname' => $conf->get( 'DBname' ), 'wgExtraSignatureNamespaces' => $conf->get( 'ExtraSignatureNamespaces' ), diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index ac41c466cd..420c4cbd14 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -755,7 +755,10 @@ abstract class Skin extends ContextSource { return $subpages; } - if ( $out->isArticle() && MWNamespace::hasSubpages( $title->getNamespace() ) ) { + if ( + $out->isArticle() && MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $title->getNamespace() ) + ) { $ptext = $title->getPrefixedText(); if ( strpos( $ptext, '/' ) !== false ) { $links = explode( '/', $ptext ); diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php index 25771bc952..ef45d15e2b 100644 --- a/includes/skins/SkinTemplate.php +++ b/includes/skins/SkinTemplate.php @@ -790,7 +790,8 @@ class SkinTemplate extends Skin { } } - $linkClass = MediaWikiServices::getInstance()->getLinkRenderer()->getLinkClasses( $title ); + $services = MediaWikiServices::getInstance(); + $linkClass = $services->getLinkRenderer()->getLinkClasses( $title ); // wfMessageFallback will nicely accept $message as an array of fallbacks // or just a single key @@ -802,8 +803,9 @@ class SkinTemplate extends Skin { if ( $msg->exists() ) { $text = $msg->text(); } else { - $text = MediaWikiServices::getInstance()->getContentLanguage()->getConverter()-> - convertNamespace( MWNamespace::getSubject( $title->getNamespace() ) ); + $text = $services->getContentLanguage()->getConverter()-> + convertNamespace( $services->getNamespaceInfo()-> + getSubject( $title->getNamespace() ) ); } // Avoid PHP 7.1 warning of passing $this by reference @@ -1086,7 +1088,8 @@ class SkinTemplate extends Skin { } if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() && - MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ] + MediaWikiServices::getInstance()->getNamespaceInfo()-> + getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ] ) { $mode = $title->isProtected() ? 'unprotect' : 'protect'; $content_navigation['actions'][$mode] = [ diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index dee31b21c3..f4b574be46 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -20,12 +20,13 @@ * @file * @ingroup SpecialPage */ + use MediaWiki\Logger\LoggerFactory; +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\DBQueryTimeoutError; use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\FakeResultWrapper; use Wikimedia\Rdbms\IDatabase; -use MediaWiki\MediaWikiServices; /** * Special page which uses a ChangesList to show query results. @@ -1451,7 +1452,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { if ( $opts[ 'associated' ] ) { $associatedNamespaces = array_map( function ( $ns ) { - return MWNamespace::getAssociated( $ns ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + getAssociated( $ns ); }, $namespaces ); diff --git a/includes/specials/SpecialAncientpages.php b/includes/specials/SpecialAncientpages.php index cea6d37506..a32393e56d 100644 --- a/includes/specials/SpecialAncientpages.php +++ b/includes/specials/SpecialAncientpages.php @@ -45,7 +45,8 @@ class AncientPagesPage extends QueryPage { public function getQueryInfo() { $tables = [ 'page', 'revision' ]; $conds = [ - 'page_namespace' => MWNamespace::getContentNamespaces(), + 'page_namespace' => + MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces(), 'page_is_redirect' => 0 ]; $joinConds = [ diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index dc4d1bd098..ce083928a7 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -21,6 +21,7 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; use MediaWiki\Widget\DateInputWidget; /** @@ -328,7 +329,8 @@ class SpecialContributions extends IncludableSpecialPage { if ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) { if ( $block->getType() == Block::TYPE_RANGE ) { - $nt = MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(); + $nt = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( NS_USER ) . ':' . $block->getTarget(); } $out = $this->getOutput(); // showLogExtract() wants first parameter by reference diff --git a/includes/specials/SpecialDeadendpages.php b/includes/specials/SpecialDeadendpages.php index f13f231dc4..2a967c588f 100644 --- a/includes/specials/SpecialDeadendpages.php +++ b/includes/specials/SpecialDeadendpages.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * A special page that list pages that contain no link to other pages * @@ -66,7 +68,8 @@ class DeadendPagesPage extends PageQueryPage { ], 'conds' => [ 'pl_from IS NULL', - 'page_namespace' => MWNamespace::getContentNamespaces(), + 'page_namespace' => MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces(), 'page_is_redirect' => 0 ], 'join_conds' => [ @@ -81,7 +84,9 @@ class DeadendPagesPage extends PageQueryPage { function getOrderFields() { // For some crazy reason ordering by a constant // causes a filesort - if ( count( MWNamespace::getContentNamespaces() ) > 1 ) { + if ( count( MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces() ) > 1 + ) { return [ 'page_namespace', 'page_title' ]; } else { return [ 'page_title' ]; diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index 65cf79ef56..73b438c28d 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * Implements Special:DeletedContributions to display archived revisions * @ingroup SpecialPage @@ -160,7 +162,8 @@ class DeletedContributionsPage extends SpecialPage { $block = Block::newFromTarget( $userObj, $userObj ); if ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) { if ( $block->getType() == Block::TYPE_RANGE ) { - $nt = MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(); + $nt = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( NS_USER ) . ':' . $block->getTarget(); } // LogEventsList::showLogExtract() wants the first parameter by ref diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index b05c81ab1a..480e81ae3e 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -380,8 +380,9 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { */ protected function getWatchlistInfo() { $titles = []; + $services = MediaWikiServices::getInstance(); - $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore() + $watchedItems = $services->getWatchedItemStore() ->getWatchedItemsForUser( $this->getUser(), [ 'sort' => WatchedItemStore::SORT_ASC ] ); $lb = new LinkBatch(); @@ -390,7 +391,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $namespace = $watchedItem->getLinkTarget()->getNamespace(); $dbKey = $watchedItem->getLinkTarget()->getDBkey(); $lb->add( $namespace, $dbKey ); - if ( !MWNamespace::isTalk( $namespace ) ) { + if ( !$services->getNamespaceInfo()->isTalk( $namespace ) ) { $titles[$namespace][$dbKey] = 1; } } @@ -511,6 +512,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { */ private function getExpandedTargets( array $targets ) { $expandedTargets = []; + $services = MediaWikiServices::getInstance(); foreach ( $targets as $target ) { if ( !$target instanceof LinkTarget ) { try { @@ -523,8 +525,10 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $ns = $target->getNamespace(); $dbKey = $target->getDBkey(); - $expandedTargets[] = new TitleValue( MWNamespace::getSubject( $ns ), $dbKey ); - $expandedTargets[] = new TitleValue( MWNamespace::getTalk( $ns ), $dbKey ); + $expandedTargets[] = + new TitleValue( $services->getNamespaceInfo()->getSubject( $ns ), $dbKey ); + $expandedTargets[] = + new TitleValue( $services->getNamespaceInfo()->getTalk( $ns ), $dbKey ); } return $expandedTargets; } diff --git a/includes/specials/SpecialFewestrevisions.php b/includes/specials/SpecialFewestrevisions.php index 84454e2e7b..c47d87be2e 100644 --- a/includes/specials/SpecialFewestrevisions.php +++ b/includes/specials/SpecialFewestrevisions.php @@ -52,7 +52,8 @@ class FewestrevisionsPage extends QueryPage { 'redirect' => 'page_is_redirect' ], 'conds' => [ - 'page_namespace' => MWNamespace::getContentNamespaces(), + 'page_namespace' => MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces(), 'page_id = rev_page' ], 'options' => [ 'GROUP BY' => [ 'page_namespace', 'page_title', 'page_is_redirect' ] diff --git a/includes/specials/SpecialListGroupRights.php b/includes/specials/SpecialListGroupRights.php index 1d10791363..ae4b090d94 100644 --- a/includes/specials/SpecialListGroupRights.php +++ b/includes/specials/SpecialListGroupRights.php @@ -84,7 +84,8 @@ class SpecialListGroupRights extends SpecialPage { $groupnameLocalized = UserGroupMembership::getGroupName( $groupname ); $grouppageLocalizedTitle = UserGroupMembership::getGroupPage( $groupname ) - ?: Title::newFromText( MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname ); + ?: Title::newFromText( MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( NS_PROJECT ) . ':' . $groupname ); if ( $group == '*' || !$grouppageLocalizedTitle ) { // Do not make a link for the generic * group or group with invalid group page @@ -162,7 +163,8 @@ class SpecialListGroupRights extends SpecialPage { ); $linkRenderer = $this->getLinkRenderer(); ksort( $namespaceProtection ); - $validNamespaces = MWNamespace::getValidNamespaces(); + $validNamespaces = + MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces(); $contLang = MediaWikiServices::getInstance()->getContentLanguage(); foreach ( $namespaceProtection as $namespace => $rights ) { if ( !in_array( $namespace, $validNamespaces ) ) { diff --git a/includes/specials/SpecialLonelypages.php b/includes/specials/SpecialLonelypages.php index ff76a4b47d..ca3f4dae8c 100644 --- a/includes/specials/SpecialLonelypages.php +++ b/includes/specials/SpecialLonelypages.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * A special page looking for articles with no article linking to them, * thus being lonely. @@ -52,7 +54,8 @@ class LonelyPagesPage extends PageQueryPage { $tables = [ 'page', 'pagelinks', 'templatelinks' ]; $conds = [ 'pl_namespace IS NULL', - 'page_namespace' => MWNamespace::getContentNamespaces(), + 'page_namespace' => MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces(), 'page_is_redirect' => 0, 'tl_namespace IS NULL' ]; @@ -89,7 +92,9 @@ class LonelyPagesPage extends PageQueryPage { function getOrderFields() { // For some crazy reason ordering by a constant // causes a filesort in MySQL 5 - if ( count( MWNamespace::getContentNamespaces() ) > 1 ) { + if ( count( MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces() ) > 1 + ) { return [ 'page_namespace', 'page_title' ]; } else { return [ 'page_title' ]; diff --git a/includes/specials/SpecialMostcategories.php b/includes/specials/SpecialMostcategories.php index 123c174080..0dd94372b6 100644 --- a/includes/specials/SpecialMostcategories.php +++ b/includes/specials/SpecialMostcategories.php @@ -24,6 +24,7 @@ * @author Ævar Arnfjörð Bjarmason */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\IDatabase; @@ -53,7 +54,8 @@ class MostcategoriesPage extends QueryPage { 'title' => 'page_title', 'value' => 'COUNT(*)' ], - 'conds' => [ 'page_namespace' => MWNamespace::getContentNamespaces() ], + 'conds' => [ 'page_namespace' => + MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces() ], 'options' => [ 'HAVING' => 'COUNT(*) > 1', 'GROUP BY' => [ 'page_namespace', 'page_title' ] diff --git a/includes/specials/SpecialMostinterwikis.php b/includes/specials/SpecialMostinterwikis.php index c963838462..0fcf8420b9 100644 --- a/includes/specials/SpecialMostinterwikis.php +++ b/includes/specials/SpecialMostinterwikis.php @@ -21,6 +21,7 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\IDatabase; @@ -52,7 +53,8 @@ class MostinterwikisPage extends QueryPage { 'title' => 'page_title', 'value' => 'COUNT(*)' ], 'conds' => [ - 'page_namespace' => MWNamespace::getContentNamespaces() + 'page_namespace' => + MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces() ], 'options' => [ 'HAVING' => 'COUNT(*) > 1', 'GROUP BY' => [ diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 39976c0d20..b561e5b61c 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * A special page that allows users to change page titles * @@ -297,7 +299,7 @@ class MovePageForm extends UnlistedSpecialPage { $immovableNamespaces = []; foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) { - if ( !MWNamespace::isMovable( $nsId ) ) { + if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->isMovable( $nsId ) ) { $immovableNamespaces[] = $nsId; } } @@ -664,11 +666,12 @@ class MovePageForm extends UnlistedSpecialPage { */ // @todo FIXME: Use Title::moveSubpages() here + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); $dbr = wfGetDB( DB_MASTER ); if ( $this->moveSubpages && ( - MWNamespace::hasSubpages( $nt->getNamespace() ) || ( + $nsInfo->hasSubpages( $nt->getNamespace() ) || ( $this->moveTalk - && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() ) + && $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() ) ) ) ) { $conds = [ @@ -676,11 +679,11 @@ class MovePageForm extends UnlistedSpecialPage { . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() ) ]; $conds['page_namespace'] = []; - if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) { + if ( $nsInfo->hasSubpages( $nt->getNamespace() ) ) { $conds['page_namespace'][] = $ot->getNamespace(); } if ( $this->moveTalk && - MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() ) + $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() ) ) { $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace(); } @@ -799,7 +802,8 @@ class MovePageForm extends UnlistedSpecialPage { * @param Title $title Page being moved. */ function showSubpages( $title ) { - $nsHasSubpages = MWNamespace::hasSubpages( $title->getNamespace() ); + $nsHasSubpages = MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $title->getNamespace() ); $subpages = $title->getSubpages(); $count = $subpages instanceof TitleArray ? $subpages->count() : 0; diff --git a/includes/specials/SpecialPasswordPolicies.php b/includes/specials/SpecialPasswordPolicies.php index d09deabf27..9bd855ac20 100644 --- a/includes/specials/SpecialPasswordPolicies.php +++ b/includes/specials/SpecialPasswordPolicies.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * This special page lists the defined password policies for user groups. * See also @ref $wgPasswordPolicy. @@ -84,7 +86,8 @@ class SpecialPasswordPolicies extends SpecialPage { $groupnameLocalized = UserGroupMembership::getGroupName( $group ); $grouppageLocalizedTitle = UserGroupMembership::getGroupPage( $group ) - ?: Title::newFromText( MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $group ); + ?: Title::newFromText( MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( NS_PROJECT ) . ':' . $group ); $grouppage = $linkRenderer->makeLink( $grouppageLocalizedTitle, diff --git a/includes/specials/SpecialRandompage.php b/includes/specials/SpecialRandompage.php index 7e5a73fb08..c4ea005a55 100644 --- a/includes/specials/SpecialRandompage.php +++ b/includes/specials/SpecialRandompage.php @@ -35,7 +35,8 @@ class RandomPage extends SpecialPage { protected $extra = []; // Extra SQL statements public function __construct( $name = 'Randompage' ) { - $this->namespaces = MWNamespace::getContentNamespaces(); + $this->namespaces = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces(); parent::__construct( $name ); } diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index c88fb2733b..4adc2475e1 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -647,7 +647,9 @@ class SpecialSearch extends SpecialPage { ) { // Reset namespace preferences: namespaces are not searched // when they're not mentioned in the URL parameters. - foreach ( MWNamespace::getValidNamespaces() as $n ) { + foreach ( MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces() + as $n + ) { $user->setOption( 'searchNs' . $n, false ); } // The request parameters include all the namespaces to be searched. diff --git a/includes/specials/SpecialShortpages.php b/includes/specials/SpecialShortpages.php index d90f72c2b9..94da25d172 100644 --- a/includes/specials/SpecialShortpages.php +++ b/includes/specials/SpecialShortpages.php @@ -21,6 +21,7 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\IDatabase; @@ -45,7 +46,10 @@ class ShortPagesPage extends QueryPage { $blacklist = $config->get( 'ShortPagesNamespaceBlacklist' ); $tables = [ 'page' ]; $conds = [ - 'page_namespace' => array_diff( MWNamespace::getContentNamespaces(), $blacklist ), + 'page_namespace' => array_diff( + MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces(), + $blacklist + ), 'page_is_redirect' => 0 ]; $joinConds = []; diff --git a/includes/specials/SpecialStatistics.php b/includes/specials/SpecialStatistics.php index d5e14d299b..eff8889f43 100644 --- a/includes/specials/SpecialStatistics.php +++ b/includes/specials/SpecialStatistics.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * Special page lists various statistics, including the contents of * `site_stats`, plus page view details if enabled @@ -207,8 +209,8 @@ class SpecialStatistics extends SpecialPage { } $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage(); if ( $msg->isBlank() ) { - $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . - ':' . $groupname; + $grouppageLocalized = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( NS_PROJECT ) . ':' . $groupname; } else { $grouppageLocalized = $msg->text(); } diff --git a/includes/specials/SpecialUncategorizedpages.php b/includes/specials/SpecialUncategorizedpages.php index 30b33cc697..9efa8032c8 100644 --- a/includes/specials/SpecialUncategorizedpages.php +++ b/includes/specials/SpecialUncategorizedpages.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * A special page looking for page without any category. * @@ -60,7 +62,8 @@ class UncategorizedPagesPage extends PageQueryPage { 'cl_from IS NULL', 'page_namespace' => $this->requestedNamespace !== false ? $this->requestedNamespace - : MWNamespace::getContentNamespaces(), + : MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces(), 'page_is_redirect' => 0 ], 'join_conds' => [ @@ -72,7 +75,10 @@ class UncategorizedPagesPage extends PageQueryPage { function getOrderFields() { // For some crazy reason ordering by a constant // causes a filesort - if ( $this->requestedNamespace === false && count( MWNamespace::getContentNamespaces() ) > 1 ) { + if ( $this->requestedNamespace === false && + count( MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces() ) > 1 + ) { return [ 'page_namespace', 'page_title' ]; } diff --git a/includes/specials/SpecialWithoutinterwiki.php b/includes/specials/SpecialWithoutinterwiki.php index a1e5156397..548e9212c3 100644 --- a/includes/specials/SpecialWithoutinterwiki.php +++ b/includes/specials/SpecialWithoutinterwiki.php @@ -22,6 +22,8 @@ * @author Rob Church */ +use MediaWiki\MediaWikiServices; + /** * Special page lists pages without language links * @@ -91,7 +93,8 @@ class WithoutInterwikiPage extends PageQueryPage { ], 'conds' => [ 'll_title IS NULL', - 'page_namespace' => MWNamespace::getContentNamespaces(), + 'page_namespace' => MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces(), 'page_is_redirect' => 0 ], 'join_conds' => [ 'langlinks' => [ 'LEFT JOIN', 'll_from = page_id' ] ] diff --git a/includes/specials/forms/UploadForm.php b/includes/specials/forms/UploadForm.php index 7a47edffd5..be2841749b 100644 --- a/includes/specials/forms/UploadForm.php +++ b/includes/specials/forms/UploadForm.php @@ -415,7 +415,8 @@ class UploadForm extends HTMLForm { 'wgCheckFileExtensions' => $config->get( 'CheckFileExtensions' ), 'wgStrictFileExtensions' => $config->get( 'StrictFileExtensions' ), 'wgFileExtensions' => array_values( array_unique( $config->get( 'FileExtensions' ) ) ), - 'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ), + 'wgCapitalizeUploads' => MediaWikiServices::getInstance()->getNamespaceInfo()-> + isCapitalized( NS_FILE ), 'wgMaxUploadSize' => $this->mMaxUploadSize, 'wgFileCanRotate' => SpecialUpload::rotationEnabled(), ]; diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index a187a44489..e0db715925 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -386,7 +386,7 @@ class ContribsPager extends RangeChronologicalPager { } $associatedNS = $this->mDb->addQuotes( - MWNamespace::getAssociated( $this->namespace ) + MediaWikiServices::getInstance()->getAssociated( $this->namespace ) ); return [ diff --git a/includes/title/NaiveImportTitleFactory.php b/includes/title/NaiveImportTitleFactory.php index 4da939511c..1a6ba72a80 100644 --- a/includes/title/NaiveImportTitleFactory.php +++ b/includes/title/NaiveImportTitleFactory.php @@ -46,7 +46,10 @@ class NaiveImportTitleFactory implements ImportTitleFactory { // For built-in namespaces (0 <= ID < 100), we try to find a local NS with // the same namespace ID - if ( $foreignNs < 100 && MWNamespace::exists( $foreignNs ) ) { + if ( + $foreignNs < 100 && + MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $foreignNs ) + ) { return Title::makeTitleSafe( $foreignNs, $foreignTitle->getText() ); } } diff --git a/includes/title/NamespaceImportTitleFactory.php b/includes/title/NamespaceImportTitleFactory.php index 7c756aa18f..7a44d0a377 100644 --- a/includes/title/NamespaceImportTitleFactory.php +++ b/includes/title/NamespaceImportTitleFactory.php @@ -18,6 +18,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * A class to convert page titles on a foreign wiki (ForeignTitle objects) into * page titles on the local wiki (Title objects), placing all pages in a fixed @@ -31,7 +33,7 @@ class NamespaceImportTitleFactory implements ImportTitleFactory { * @param int $ns The namespace to use for all pages */ public function __construct( $ns ) { - if ( !MWNamespace::exists( $ns ) ) { + if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) { throw new MWException( "Namespace $ns doesn't exist on this wiki" ); } $this->ns = $ns; diff --git a/includes/title/SubpageImportTitleFactory.php b/includes/title/SubpageImportTitleFactory.php index 4244350307..415196a5ef 100644 --- a/includes/title/SubpageImportTitleFactory.php +++ b/includes/title/SubpageImportTitleFactory.php @@ -18,6 +18,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * A class to convert page titles on a foreign wiki (ForeignTitle objects) into * page titles on the local wiki (Title objects), placing all pages as subpages @@ -32,7 +34,10 @@ class SubpageImportTitleFactory implements ImportTitleFactory { * created */ public function __construct( Title $rootPage ) { - if ( !MWNamespace::hasSubpages( $rootPage->getNamespace() ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $rootPage->getNamespace() ) + ) { throw new MWException( "The root page you specified, $rootPage, is in a " . "namespace where subpages are not allowed" ); } diff --git a/includes/user/ExternalUserNames.php b/includes/user/ExternalUserNames.php index 66674dca10..41facc707d 100644 --- a/includes/user/ExternalUserNames.php +++ b/includes/user/ExternalUserNames.php @@ -64,9 +64,11 @@ class ExternalUserNames { if ( $pos !== false ) { $iw = explode( ':', substr( $userName, 0, $pos ) ); $firstIw = array_shift( $iw ); - $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup(); + $services = MediaWikiServices::getInstance(); + $interwikiLookup = $services->getInterwikiLookup(); if ( $interwikiLookup->isValidInterwiki( $firstIw ) ) { - $title = MWNamespace::getCanonicalName( NS_USER ) . ':' . substr( $userName, $pos + 1 ); + $title = $services->getNamespaceInfo()->getCanonicalName( NS_USER ) . + ':' . substr( $userName, $pos + 1 ); if ( $iw ) { $title = implode( ':', $iw ) . ':' . $title; } diff --git a/includes/widget/search/SearchFormWidget.php b/includes/widget/search/SearchFormWidget.php index 5106c17762..66b65667c2 100644 --- a/includes/widget/search/SearchFormWidget.php +++ b/includes/widget/search/SearchFormWidget.php @@ -6,7 +6,6 @@ use Hooks; use Html; use MediaWiki\MediaWikiServices; use MediaWiki\Widget\SearchInputWidget; -use MWNamespace; use SearchEngineConfig; use SpecialSearch; use Xml; @@ -240,7 +239,8 @@ class SearchFormWidget { $activeNamespaces = $this->specialSearch->getNamespaces(); $langConverter = $this->specialSearch->getLanguage(); foreach ( $this->searchConfig->searchableNamespaces() as $namespace => $name ) { - $subject = MWNamespace::getSubject( $namespace ); + $subject = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getSubject( $namespace ); if ( !isset( $rows[$subject] ) ) { $rows[$subject] = ""; } diff --git a/languages/Language.php b/languages/Language.php index 539bdf4547..7b89a9c29f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -27,6 +27,7 @@ */ use CLDRPluralRuleParser\Evaluator; +use MediaWiki\MediaWikiServices; use Wikimedia\Assert\Assert; /** @@ -506,7 +507,8 @@ class Language { if ( is_null( $this->namespaceNames ) ) { global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces; - $validNamespaces = MWNamespace::getCanonicalNamespaces(); + $validNamespaces = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalNamespaces(); $this->namespaceNames = $wgExtraNamespaces + self::$dataCache->getItem( $this->mCode, 'namespaceNames' ); @@ -744,7 +746,8 @@ class Language { */ public function getNsIndex( $text ) { $lctext = $this->lc( $text ); - $ns = MWNamespace::getCanonicalIndex( $lctext ); + $ns = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalIndex( $lctext ); if ( $ns !== null ) { return $ns; } diff --git a/maintenance/cleanupCaps.php b/maintenance/cleanupCaps.php index 1b49f0e221..20be9fd1d7 100644 --- a/maintenance/cleanupCaps.php +++ b/maintenance/cleanupCaps.php @@ -55,7 +55,10 @@ class CleanupCaps extends TableCleanup { $this->namespace = intval( $this->getOption( 'namespace', 0 ) ); - if ( MWNamespace::isCapitalized( $this->namespace ) ) { + if ( + MediaWikiServices::getInstance()->getNamespaceInfo()-> + isCapitalized( $this->namespace ) + ) { $this->output( "Will be moving pages to first letter capitalized titles" ); $callback = 'processRowToUppercase'; } else { diff --git a/maintenance/cleanupTitles.php b/maintenance/cleanupTitles.php index 7f0e340a4a..cad612266b 100644 --- a/maintenance/cleanupTitles.php +++ b/maintenance/cleanupTitles.php @@ -152,7 +152,7 @@ class TitleCleanup extends TableCleanup { # Namespace which no longer exists. Put the page in the main namespace # since we don't have any idea of the old namespace name. See T70501. - if ( !MWNamespace::exists( $ns ) ) { + if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) { $ns = 0; } diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index af5373c2ef..7d43f218c8 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -290,7 +290,7 @@ class GenerateSitemap extends Maintenance { * @return string */ function guessPriority( $namespace ) { - return MWNamespace::isSubject( $namespace ) + return MediaWikiServices::getInstance()->getNamespaceInfo()->isSubject( $namespace ) ? $this->priorities[self::GS_MAIN] : $this->priorities[self::GS_TALK]; } diff --git a/maintenance/namespaceDupes.php b/maintenance/namespaceDupes.php index 075d6f27d6..3c73306eb6 100644 --- a/maintenance/namespaceDupes.php +++ b/maintenance/namespaceDupes.php @@ -117,7 +117,10 @@ class NamespaceDupes extends Maintenance { } // Now pull in all canonical and alias namespaces... - foreach ( MWNamespace::getCanonicalNamespaces() as $ns => $name ) { + foreach ( + MediaWikiServices::getInstance()->getNamespaceInfo()->getCanonicalNamespaces() + as $ns => $name + ) { // This includes $wgExtraNamespaces if ( $name !== '' ) { $spaces[$name] = $ns; @@ -429,7 +432,10 @@ class NamespaceDupes extends Maintenance { * @return ResultWrapper */ private function getTargetList( $ns, $name, $options ) { - if ( $options['move-talk'] && MWNamespace::isSubject( $ns ) ) { + if ( + $options['move-talk'] && + MediaWikiServices::getInstance()->getNamespaceInfo()->isSubject( $ns ) + ) { $checkNamespaces = [ NS_MAIN, NS_TALK ]; } else { $checkNamespaces = NS_MAIN; @@ -465,9 +471,10 @@ class NamespaceDupes extends Maintenance { $dbk = "$name-" . $dbk; } $destNS = $ns; - if ( $sourceNs == NS_TALK && MWNamespace::isSubject( $ns ) ) { + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + if ( $sourceNs == NS_TALK && $nsInfo->isSubject( $ns ) ) { // This is an associated talk page moved with the --move-talk feature. - $destNS = MWNamespace::getTalk( $destNS ); + $destNS = $nsInfo->getTalk( $destNS ); } $newTitle = Title::makeTitleSafe( $destNS, $dbk ); if ( !$newTitle || !$newTitle->canExist() ) { diff --git a/maintenance/rebuildFileCache.php b/maintenance/rebuildFileCache.php index cf398ff607..2cdf418b25 100644 --- a/maintenance/rebuildFileCache.php +++ b/maintenance/rebuildFileCache.php @@ -21,6 +21,8 @@ * @ingroup Maintenance */ +use MediaWiki\MediaWikiServices; + require_once __DIR__ . '/Maintenance.php'; /** @@ -102,7 +104,8 @@ class RebuildFileCache extends Maintenance { // Get the pages $res = $dbr->select( 'page', [ 'page_namespace', 'page_title', 'page_id' ], - [ 'page_namespace' => MWNamespace::getContentNamespaces(), + [ 'page_namespace' => MediaWikiServices::getInstance()->getNamespaceInfo()-> + getContentNamespaces(), "page_id BETWEEN " . (int)$blockStart . " AND " . (int)$blockEnd ], __METHOD__, [ 'ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY' ] diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index df897d9a1e..3b63c19a94 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -1080,7 +1080,8 @@ class ParserTestRunner { 'wgLanguageCode' => $langCode, 'wgRawHtml' => self::getOptionValue( 'wgRawHtml', $opts, false ), 'wgNamespacesWithSubpages' => array_fill_keys( - MWNamespace::getValidNamespaces(), isset( $opts['subpage'] ) + MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces(), + isset( $opts['subpage'] ) ), 'wgMaxTocLevel' => $maxtoclevel, 'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ), diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index ec61c23634..1e70c5788e 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -2244,18 +2244,19 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { } // NOTE: prefer content namespaces + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); $namespaces = array_unique( array_merge( - MWNamespace::getContentNamespaces(), + $nsInfo->getContentNamespaces(), [ NS_MAIN, NS_HELP, NS_PROJECT ], // prefer these - MWNamespace::getValidNamespaces() + $nsInfo->getValidNamespaces() ) ); $namespaces = array_diff( $namespaces, [ NS_FILE, NS_CATEGORY, NS_MEDIAWIKI, NS_USER // don't mess with magic namespaces ] ); - $talk = array_filter( $namespaces, function ( $ns ) { - return MWNamespace::isTalk( $ns ); + $talk = array_filter( $namespaces, function ( $ns ) use ( $nsInfo ) { + return $nsInfo->isTalk( $ns ); } ); // prefer non-talk pages diff --git a/tests/phpunit/includes/PagePropsTest.php b/tests/phpunit/includes/PagePropsTest.php index 646b487691..222b3e3a02 100644 --- a/tests/phpunit/includes/PagePropsTest.php +++ b/tests/phpunit/includes/PagePropsTest.php @@ -1,5 +1,7 @@ getDefaultWikitextNS(); - $page = MWNamespace::getCanonicalName( $ns ) . ':' . $page; + $page = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( $ns ) . ':' . $page; } $page = Title::newFromText( $page ); diff --git a/tests/phpunit/includes/RevisionDbTestBase.php b/tests/phpunit/includes/RevisionDbTestBase.php index 96e27668ec..7501167ebf 100644 --- a/tests/phpunit/includes/RevisionDbTestBase.php +++ b/tests/phpunit/includes/RevisionDbTestBase.php @@ -182,7 +182,8 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { ( $model === null || $model === CONTENT_MODEL_WIKITEXT ) ) { $ns = $this->getDefaultWikitextNS(); - $titleString = MWNamespace::getCanonicalName( $ns ) . ':' . $titleString; + $titleString = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( $ns ) . ':' . $titleString; } $title = Title::newFromText( $titleString ); diff --git a/tests/phpunit/includes/api/ApiBaseTest.php b/tests/phpunit/includes/api/ApiBaseTest.php index e02e8a4984..4e19822d94 100644 --- a/tests/phpunit/includes/api/ApiBaseTest.php +++ b/tests/phpunit/includes/api/ApiBaseTest.php @@ -1,5 +1,6 @@ true, ApiBase::PARAM_TYPE => 'namespace', ], - MWNamespace::getValidNamespaces(), + MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces(), [], ], // PARAM_ALL is ignored with namespace types. @@ -654,7 +655,7 @@ class ApiBaseTest extends ApiTestCase { ApiBase::PARAM_TYPE => 'namespace', ApiBase::PARAM_ALL => false, ], - MWNamespace::getValidNamespaces(), + MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces(), [], ], 'Namespace with wildcard "x"' => [ diff --git a/tests/phpunit/includes/editpage/TextboxBuilderTest.php b/tests/phpunit/includes/editpage/TextboxBuilderTest.php index 4195f968f5..a63521a74b 100644 --- a/tests/phpunit/includes/editpage/TextboxBuilderTest.php +++ b/tests/phpunit/includes/editpage/TextboxBuilderTest.php @@ -177,7 +177,7 @@ class TextboxBuilderTest extends MediaWikiTestCase { $expected ) { $this->setMwGlobals( [ - // set to trick MWNamespace::getRestrictionLevels + // set to trick NamespaceInfo::getRestrictionLevels 'wgRestrictionLevels' => $restrictionLevels ] ); diff --git a/tests/phpunit/structure/ApiStructureTest.php b/tests/phpunit/structure/ApiStructureTest.php index 2453353b85..0d10a20b22 100644 --- a/tests/phpunit/structure/ApiStructureTest.php +++ b/tests/phpunit/structure/ApiStructureTest.php @@ -1,5 +1,6 @@ getNamespaceInfo()-> + getValidNamespaces(); if ( isset( $config[ApiBase::PARAM_EXTRA_NAMESPACES] ) && is_array( $config[ApiBase::PARAM_EXTRA_NAMESPACES] ) -- 2.20.1