From 5196ac32c60bf370463135c14eed3bba0d361940 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 6 Feb 2019 12:28:45 -0800 Subject: [PATCH] Rename WikiMap DB domain ID methods to reduce confusion with web domains Those added in this same release do not need alias methods. Change-Id: I05feeb9b0b13afe43aea1f95551965489cdbe094 --- includes/WikiMap.php | 22 ++++++++++++++----- includes/debug/logger/LegacyLogger.php | 4 ++-- .../debug/logger/monolog/WikiProcessor.php | 2 +- includes/deferred/LinksDeletionUpdate.php | 2 +- includes/deferred/LinksUpdate.php | 2 +- .../lockmanager/LockManagerGroup.php | 2 +- includes/interwiki/ClassicInterwikiLookup.php | 4 ++-- includes/jobqueue/JobQueue.php | 2 +- includes/jobqueue/JobQueueGroup.php | 10 ++++----- includes/jobqueue/JobQueueRedis.php | 2 +- includes/mail/UserMailer.php | 2 +- includes/objectcache/ObjectCache.php | 2 +- includes/page/WikiPage.php | 2 +- includes/profiler/Profiler.php | 2 +- .../rcfeed/MachineReadableRCFeedFormatter.php | 2 +- includes/user/User.php | 2 +- tests/phpunit/includes/WikiMapTest.php | 20 ++++++++--------- 17 files changed, 47 insertions(+), 37 deletions(-) diff --git a/includes/WikiMap.php b/includes/WikiMap.php index 3305f9f7d3..628fbc0257 100644 --- a/includes/WikiMap.php +++ b/includes/WikiMap.php @@ -196,7 +196,7 @@ class WikiMap { $infoMap = []; // Make sure at least the current wiki is set, for simple configurations. // This also makes it the first in the map, which is useful for common cases. - $wikiId = self::getWikiIdFromDomain( self::getCurrentWikiDomain() ); + $wikiId = self::getWikiIdFromDbDomain( self::getCurrentWikiDbDomain() ); $infoMap[$wikiId] = [ 'url' => $wgCanonicalServer, 'parts' => wfParseUrl( $wgCanonicalServer ) @@ -250,8 +250,9 @@ class WikiMap { * * @param string|DatabaseDomain $domain * @return string + * @since 1.31 */ - public static function getWikiIdFromDomain( $domain ) { + public static function getWikiIdFromDbDomain( $domain ) { $domain = DatabaseDomain::newFromId( $domain ); if ( !in_array( $domain->getSchema(), [ null, 'mediawiki' ], true ) ) { @@ -269,11 +270,20 @@ class WikiMap { : (string)$domain->getDatabase(); } + /** + * @param string $domain + * @return string + * @deprecated Since 1.33; use getWikiIdFromDbDomain() + */ + public static function getWikiIdFromDomain( $domain ) { + return self::getWikiIdFromDbDomain( $domain ); + } + /** * @return DatabaseDomain Database domain of the current wiki * @since 1.33 */ - public static function getCurrentWikiDomain() { + public static function getCurrentWikiDbDomain() { global $wgDBname, $wgDBmwschema, $wgDBprefix; // Avoid invoking LBFactory to avoid any chance of recursion return new DatabaseDomain( $wgDBname, $wgDBmwschema, (string)$wgDBprefix ); @@ -284,9 +294,9 @@ class WikiMap { * @return bool Whether $domain has the same DB/prefix as the current wiki * @since 1.33 */ - public static function isCurrentWikiDomain( $domain ) { + public static function isCurrentWikiDbDomain( $domain ) { $domain = DatabaseDomain::newFromId( $domain ); - $curDomain = self::getCurrentWikiDomain(); + $curDomain = self::getCurrentWikiDbDomain(); if ( !in_array( $curDomain->getSchema(), [ null, 'mediawiki' ], true ) ) { // Include the schema if it is set and is not the default placeholder. @@ -308,6 +318,6 @@ class WikiMap { * @since 1.33 */ public static function isCurrentWikiId( $wikiId ) { - return ( self::getWikiIdFromDomain( self::getCurrentWikiDomain() ) === $wikiId ); + return ( self::getWikiIdFromDbDomain( self::getCurrentWikiDbDomain() ) === $wikiId ); } } diff --git a/includes/debug/logger/LegacyLogger.php b/includes/debug/logger/LegacyLogger.php index 9f63eded09..bbcd33ac75 100644 --- a/includes/debug/logger/LegacyLogger.php +++ b/includes/debug/logger/LegacyLogger.php @@ -327,7 +327,7 @@ class LegacyLogger extends AbstractLogger { $date = $d->format( 'D M j G:i:s T Y' ); $host = wfHostname(); - $wiki = WikiMap::getWikiIdFromDomain( WikiMap::getCurrentWikiDomain() ); + $wiki = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ); $text = "{$date}\t{$host}\t{$wiki}\t{$message}\n"; return $text; @@ -343,7 +343,7 @@ class LegacyLogger extends AbstractLogger { */ protected static function formatAsWfDebugLog( $channel, $message, $context ) { $time = wfTimestamp( TS_DB ); - $wiki = WikiMap::getWikiIdFromDomain( WikiMap::getCurrentWikiDomain() ); + $wiki = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ); $host = wfHostname(); $text = "{$time} {$host} {$wiki}: {$message}\n"; return $text; diff --git a/includes/debug/logger/monolog/WikiProcessor.php b/includes/debug/logger/monolog/WikiProcessor.php index cb95be63a1..dc3c1f249f 100644 --- a/includes/debug/logger/monolog/WikiProcessor.php +++ b/includes/debug/logger/monolog/WikiProcessor.php @@ -38,7 +38,7 @@ class WikiProcessor { public function __invoke( array $record ) { global $wgVersion; $record['extra']['host'] = wfHostname(); - $record['extra']['wiki'] = WikiMap::getWikiIdFromDomain( WikiMap::getCurrentWikiDomain() ); + $record['extra']['wiki'] = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ); $record['extra']['mwversion'] = $wgVersion; $record['extra']['reqId'] = \WebRequest::getRequestId(); if ( wfIsCLI() && isset( $_SERVER['argv'] ) ) { diff --git a/includes/deferred/LinksDeletionUpdate.php b/includes/deferred/LinksDeletionUpdate.php index 5ab83c62c6..0743dbec2f 100644 --- a/includes/deferred/LinksDeletionUpdate.php +++ b/includes/deferred/LinksDeletionUpdate.php @@ -225,7 +225,7 @@ class LinksDeletionUpdate extends DataUpdate implements EnqueueableDataUpdate { public function getAsJobSpecification() { return [ - 'wiki' => WikiMap::getWikiIdFromDomain( $this->getDB()->getDomainID() ), + 'wiki' => WikiMap::getWikiIdFromDbDomain( $this->getDB()->getDomainID() ), 'job' => new JobSpecification( 'deleteLinks', [ 'pageId' => $this->pageId, 'timestamp' => $this->timestamp ], diff --git a/includes/deferred/LinksUpdate.php b/includes/deferred/LinksUpdate.php index b4863f86c8..937196d943 100644 --- a/includes/deferred/LinksUpdate.php +++ b/includes/deferred/LinksUpdate.php @@ -1162,7 +1162,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { } return [ - 'wiki' => WikiMap::getWikiIdFromDomain( $this->getDB()->getDomainID() ), + 'wiki' => WikiMap::getWikiIdFromDbDomain( $this->getDB()->getDomainID() ), 'job' => new JobSpecification( 'refreshLinksPrioritized', [ diff --git a/includes/filebackend/lockmanager/LockManagerGroup.php b/includes/filebackend/lockmanager/LockManagerGroup.php index b8fb7fdf45..aa955d055c 100644 --- a/includes/filebackend/lockmanager/LockManagerGroup.php +++ b/includes/filebackend/lockmanager/LockManagerGroup.php @@ -51,7 +51,7 @@ class LockManagerGroup { */ public static function singleton( $domain = false ) { if ( $domain === false ) { - $domain = WikiMap::getCurrentWikiDomain()->getId(); + $domain = WikiMap::getCurrentWikiDbDomain()->getId(); } if ( !isset( self::$instances[$domain] ) ) { diff --git a/includes/interwiki/ClassicInterwikiLookup.php b/includes/interwiki/ClassicInterwikiLookup.php index f6265f787a..7a8e64f5ce 100644 --- a/includes/interwiki/ClassicInterwikiLookup.php +++ b/includes/interwiki/ClassicInterwikiLookup.php @@ -214,7 +214,7 @@ class ClassicInterwikiLookup implements InterwikiLookup { private function getInterwikiCacheEntry( $prefix ) { wfDebug( __METHOD__ . "( $prefix )\n" ); - $wikiId = WikiMap::getWikiIdFromDomain( WikiMap::getCurrentWikiDomain() ); + $wikiId = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ); $value = false; try { @@ -339,7 +339,7 @@ class ClassicInterwikiLookup implements InterwikiLookup { private function getAllPrefixesCached( $local ) { wfDebug( __METHOD__ . "()\n" ); - $wikiId = WikiMap::getWikiIdFromDomain( WikiMap::getCurrentWikiDomain() ); + $wikiId = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ); $data = []; try { diff --git a/includes/jobqueue/JobQueue.php b/includes/jobqueue/JobQueue.php index 4f4728d917..0ca272cfdd 100644 --- a/includes/jobqueue/JobQueue.php +++ b/includes/jobqueue/JobQueue.php @@ -366,7 +366,7 @@ abstract class JobQueue { global $wgJobClasses; $this->assertNotReadOnly(); - if ( !WikiMap::isCurrentWikiDomain( $this->domain ) ) { + if ( !WikiMap::isCurrentWikiDbDomain( $this->domain ) ) { throw new MWException( "Cannot pop '{$this->type}' job off foreign '{$this->domain}' wiki queue." ); } elseif ( !isset( $wgJobClasses[$this->type] ) ) { diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index 4853c4afff..328f2982f6 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -71,16 +71,16 @@ class JobQueueGroup { global $wgLocalDatabases; if ( $domain === false ) { - $domain = WikiMap::getCurrentWikiDomain()->getId(); + $domain = WikiMap::getCurrentWikiDbDomain()->getId(); } if ( !isset( self::$instances[$domain] ) ) { self::$instances[$domain] = new self( $domain, wfConfiguredReadOnlyReason() ); // Make sure jobs are not getting pushed to bogus wikis. This can confuse // the job runner system into spawning endless RPC requests that fail (T171371). - $wikiId = WikiMap::getWikiIdFromDomain( $domain ); + $wikiId = WikiMap::getWikiIdFromDbDomain( $domain ); if ( - !WikiMap::isCurrentWikiDomain( $domain ) && + !WikiMap::isCurrentWikiDbDomain( $domain ) && !in_array( $wikiId, $wgLocalDatabases ) ) { self::$instances[$domain]->invalidDomain = true; @@ -430,10 +430,10 @@ class JobQueueGroup { */ private function getCachedConfigVar( $name ) { // @TODO: cleanup this whole method with a proper config system - if ( WikiMap::isCurrentWikiDomain( $this->domain ) ) { + if ( WikiMap::isCurrentWikiDbDomain( $this->domain ) ) { return $GLOBALS[$name]; // common case } else { - $wiki = WikiMap::getWikiIdFromDomain( $this->domain ); + $wiki = WikiMap::getWikiIdFromDbDomain( $this->domain ); $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $value = $cache->getWithSetCallback( $cache->makeGlobalKey( 'jobqueue', 'configvalue', $this->domain, $name ), diff --git a/includes/jobqueue/JobQueueRedis.php b/includes/jobqueue/JobQueueRedis.php index a1ef28b1d2..5e7a11571a 100644 --- a/includes/jobqueue/JobQueueRedis.php +++ b/includes/jobqueue/JobQueueRedis.php @@ -811,7 +811,7 @@ LUA; $type = is_string( $type ) ? $type : $this->type; // Use wiki ID for b/c - $keyspace = WikiMap::getWikiIdFromDomain( $this->domain ); + $keyspace = WikiMap::getWikiIdFromDbDomain( $this->domain ); $parts = [ $keyspace, 'jobqueue', $type, $prop ]; diff --git a/includes/mail/UserMailer.php b/includes/mail/UserMailer.php index 63a3eb03eb..5d7030bb62 100644 --- a/includes/mail/UserMailer.php +++ b/includes/mail/UserMailer.php @@ -82,7 +82,7 @@ class UserMailer { static function makeMsgId() { global $wgSMTP, $wgServer; - $domainId = WikiMap::getCurrentWikiDomain()->getId(); + $domainId = WikiMap::getCurrentWikiDbDomain()->getId(); $msgid = uniqid( $domainId . ".", true /** for cygwin */ ); if ( is_array( $wgSMTP ) && isset( $wgSMTP['IDHost'] ) && $wgSMTP['IDHost'] ) { $domain = $wgSMTP['IDHost']; diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index cb6249c687..14d63a1fe0 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -154,7 +154,7 @@ class ObjectCache { return $keyspace; } - return WikiMap::getCurrentWikiDomain()->getId(); + return WikiMap::getCurrentWikiDbDomain()->getId(); } /** diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 728f2cefc6..add76db2c7 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -3506,7 +3506,7 @@ class WikiPage implements Page, IDBAccessObject { // means that some cache invalidations happen that are not strictly needed. $cache->makeGlobalKey( 'interwiki-page', - WikiMap::getCurrentWikiDomain()->getId(), + WikiMap::getCurrentWikiDbDomain()->getId(), $title->getDBkey() ) ); diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 5c38159483..455130cc05 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -115,7 +115,7 @@ abstract class Profiler { */ public function getProfileID() { if ( $this->profileID === false ) { - return WikiMap::getCurrentWikiDomain()->getId(); + return WikiMap::getCurrentWikiDbDomain()->getId(); } else { return $this->profileID; } diff --git a/includes/rcfeed/MachineReadableRCFeedFormatter.php b/includes/rcfeed/MachineReadableRCFeedFormatter.php index 71f6854bdb..3736d6d7bb 100644 --- a/includes/rcfeed/MachineReadableRCFeedFormatter.php +++ b/includes/rcfeed/MachineReadableRCFeedFormatter.php @@ -125,7 +125,7 @@ abstract class MachineReadableRCFeedFormatter implements RCFeedFormatter { $packet['server_name'] = $wgServerName; $packet['server_script_path'] = $wgScriptPath ?: '/'; - $packet['wiki'] = WikiMap::getWikiIdFromDomain( WikiMap::getCurrentWikiDomain() ); + $packet['wiki'] = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ); return $this->formatArray( $packet ); } diff --git a/includes/user/User.php b/includes/user/User.php index f23c8ee586..73c12de785 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -2652,7 +2652,7 @@ class User implements IDBAccessObject, UserIdentity { $rev = $timestamp ? Revision::loadFromTimestamp( $dbr, $utp, $timestamp ) : null; return [ [ - 'wiki' => WikiMap::getWikiIdFromDomain( WikiMap::getCurrentWikiDomain() ), + 'wiki' => WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ), 'link' => $utp->getLocalURL(), 'rev' => $rev ] diff --git a/tests/phpunit/includes/WikiMapTest.php b/tests/phpunit/includes/WikiMapTest.php index 1fb8affa39..e87e434f94 100644 --- a/tests/phpunit/includes/WikiMapTest.php +++ b/tests/phpunit/includes/WikiMapTest.php @@ -249,18 +249,18 @@ class WikiMapTest extends MediaWikiLangTestCase { /** * @dataProvider provideGetWikiIdFromDomain - * @covers WikiMap::getWikiIdFromDomain() + * @covers WikiMap::getWikiIdFromDbDomain() */ public function testGetWikiIdFromDomain( $domain, $wikiId ) { - $this->assertEquals( $wikiId, WikiMap::getWikiIdFromDomain( $domain ) ); + $this->assertEquals( $wikiId, WikiMap::getWikiIdFromDbDomain( $domain ) ); } /** - * @covers WikiMap::isCurrentWikiDomain() - * @covers WikiMap::getCurrentWikiDomain() + * @covers WikiMap::isCurrentWikiDbDomain() + * @covers WikiMap::getCurrentWikiDbDomain() */ public function testIsCurrentWikiDomain() { - $this->assertTrue( WikiMap::isCurrentWikiDomain( wfWikiID() ) ); + $this->assertTrue( WikiMap::isCurrentWikiDbDomain( wfWikiID() ) ); $localDomain = DatabaseDomain::newFromId( wfWikiID() ); $domain1 = new DatabaseDomain( @@ -268,10 +268,10 @@ class WikiMapTest extends MediaWikiLangTestCase { $domain2 = new DatabaseDomain( $localDomain->getDatabase(), null, $localDomain->getTablePrefix() ); - $this->assertTrue( WikiMap::isCurrentWikiDomain( $domain1 ), 'Schema ignored' ); - $this->assertTrue( WikiMap::isCurrentWikiDomain( $domain2 ), 'Schema ignored' ); + $this->assertTrue( WikiMap::isCurrentWikiDbDomain( $domain1 ), 'Schema ignored' ); + $this->assertTrue( WikiMap::isCurrentWikiDbDomain( $domain2 ), 'Schema ignored' ); - $this->assertTrue( WikiMap::isCurrentWikiDomain( WikiMap::getCurrentWikiDomain() ) ); + $this->assertTrue( WikiMap::isCurrentWikiDbDomain( WikiMap::getCurrentWikiDbDomain() ) ); } public function provideIsCurrentWikiId() { @@ -294,8 +294,8 @@ class WikiMapTest extends MediaWikiLangTestCase { /** * @dataProvider provideIsCurrentWikiId * @covers WikiMap::isCurrentWikiId() - * @covers WikiMap::getCurrentWikiDomain() - * @covers WikiMap::getWikiIdFromDomain() + * @covers WikiMap::getCurrentWikiDbDomain() + * @covers WikiMap::getWikiIdFromDbDomain() */ public function testIsCurrentWikiId( $wikiId, $db, $schema, $prefix ) { $this->setMwGlobals( -- 2.20.1