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
This commit is contained in:
Aaron Schulz 2019-02-06 12:28:45 -08:00
parent 52fbe64ef3
commit 5196ac32c6
17 changed files with 47 additions and 37 deletions

View 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 );
}
}

View 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;

View 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'] ) ) {

View 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 ],

View 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',
[

View 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] ) ) {

View 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 {

View 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] ) ) {

View 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 ),

View 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 ];

View 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'];

View file

@ -154,7 +154,7 @@ class ObjectCache {
return $keyspace;
}
return WikiMap::getCurrentWikiDomain()->getId();
return WikiMap::getCurrentWikiDbDomain()->getId();
}
/**

View 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()
)
);

View 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;
}

View 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 );
}

View 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
]

View 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(