Rename WikiMap DB domain ID methods to reduce confusion with web domains
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 6 Feb 2019 20:28:45 +0000 (12:28 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 6 Feb 2019 20:28:45 +0000 (12:28 -0800)
Those added in this same release do not need alias methods.

Change-Id: I05feeb9b0b13afe43aea1f95551965489cdbe094

17 files changed:
includes/WikiMap.php
includes/debug/logger/LegacyLogger.php
includes/debug/logger/monolog/WikiProcessor.php
includes/deferred/LinksDeletionUpdate.php
includes/deferred/LinksUpdate.php
includes/filebackend/lockmanager/LockManagerGroup.php
includes/interwiki/ClassicInterwikiLookup.php
includes/jobqueue/JobQueue.php
includes/jobqueue/JobQueueGroup.php
includes/jobqueue/JobQueueRedis.php
includes/mail/UserMailer.php
includes/objectcache/ObjectCache.php
includes/page/WikiPage.php
includes/profiler/Profiler.php
includes/rcfeed/MachineReadableRCFeedFormatter.php
includes/user/User.php
tests/phpunit/includes/WikiMapTest.php

index 3305f9f..628fbc0 100644 (file)
@@ -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 );
        }
 }
index 9f63ede..bbcd33a 100644 (file)
@@ -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;
index cb95be6..dc3c1f2 100644 (file)
@@ -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'] ) ) {
index 5ab83c6..0743dbe 100644 (file)
@@ -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 ],
index b4863f8..937196d 100644 (file)
@@ -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',
                                [
index b8fb7fd..aa955d0 100644 (file)
@@ -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] ) ) {
index f6265f7..7a8e64f 100644 (file)
@@ -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 {
index 4f4728d..0ca272c 100644 (file)
@@ -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] ) ) {
index 4853c4a..328f298 100644 (file)
@@ -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 ),
index a1ef28b..5e7a115 100644 (file)
@@ -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 ];
 
index 63a3eb0..5d7030b 100644 (file)
@@ -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'];
index cb6249c..14d63a1 100644 (file)
@@ -154,7 +154,7 @@ class ObjectCache {
                        return $keyspace;
                }
 
-               return WikiMap::getCurrentWikiDomain()->getId();
+               return WikiMap::getCurrentWikiDbDomain()->getId();
        }
 
        /**
index 728f2ce..add76db 100644 (file)
@@ -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()
                                )
                        );
index 5c38159..455130c 100644 (file)
@@ -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;
                }
index 71f6854..3736d6d 100644 (file)
@@ -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 );
        }
index f23c8ee..73c12de 100644 (file)
@@ -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
                        ]
index 1fb8aff..e87e434 100644 (file)
@@ -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(