$row = self::fetchFromConds( $db, $conditions, $flags );
if ( $row ) {
$rev = new Revision( $row );
- $rev->mWiki = $db->getWikiID();
+ $rev->mWiki = $db->getDomainID();
return $rev;
}
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return $cache->getWithSetCallback(
// Page/rev IDs passed in from DB to reflect history merges
- $cache->makeGlobalKey( 'revision', $db->getWikiID(), $pageId, $revId ),
+ $cache->makeGlobalKey( 'revision', $db->getDomainID(), $pageId, $revId ),
$cache::TTL_WEEK,
function ( $curValue, &$ttl, array &$setOpts ) use ( $db, $pageId, $revId ) {
$setOpts += Database::getCacheSetOptions( $db );
);
if ( count( $watchersChunks ) > 1 ) {
$factory->commitAndWaitForReplication(
- __METHOD__, $ticket, [ 'wiki' => $dbw->getWikiID() ]
+ __METHOD__, $ticket, [ 'domain' => $dbw->getDomainID() ]
);
}
}
*/
use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\DatabaseDomain;
/**
* Helper tools for dealing with other locally-hosted wikis.
return false;
}
+
+ /**
+ * Get the wiki ID of a database domain
+ *
+ * This is like DatabaseDomain::getId() without encoding (for legacy reasons)
+ *
+ * @param string|DatabaseDomain $domain
+ * @return string
+ */
+ public static function getWikiIdFromDomain( $domain ) {
+ if ( !( $domain instanceof DatabaseDomain ) ) {
+ $domain = DatabaseDomain::newFromId( $domain );
+ }
+
+ return strlen( $domain->getTablePrefix() )
+ ? "{$domain->getDatabase()}-{$domain->getTablePrefix()}"
+ : $domain->getDatabase();
+ }
}
$this->page->updateCategoryCounts( [], $catBatch, $id );
if ( count( $catBatches ) > 1 ) {
$lbFactory->commitAndWaitForReplication(
- __METHOD__, $this->ticket, [ 'wiki' => $dbw->getWikiID() ]
+ __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
);
}
}
$dbw->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ );
if ( count( $rcIdBatches ) > 1 ) {
$lbFactory->commitAndWaitForReplication(
- __METHOD__, $this->ticket, [ 'wiki' => $dbw->getWikiID() ]
+ __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
);
}
}
if ( count( $pkDeleteConds ) >= $bSize ) {
$dbw->delete( $table, $dbw->makeList( $pkDeleteConds, LIST_OR ), __METHOD__ );
$lbFactory->commitAndWaitForReplication(
- __METHOD__, $this->ticket, [ 'wiki' => $dbw->getWikiID() ]
+ __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
);
$pkDeleteConds = [];
}
public function getAsJobSpecification() {
return [
- 'wiki' => $this->getDB()->getWikiID(),
+ 'wiki' => WikiMap::getWikiIdFromDomain( $this->getDB()->getDomainID() ),
'job' => new JobSpecification(
'deleteLinks',
[ 'pageId' => $this->pageId, 'timestamp' => $this->timestamp ],
return;
}
- $wikiId = $this->getDB()->getWikiID();
+ $domainId = $this->getDB()->getDomainID();
$wp = WikiPage::factory( $this->mTitle );
$lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
// T163801: try to release any row locks to reduce contention
- $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] );
+ $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'domain' => $domainId ] );
foreach ( array_chunk( array_keys( $added ), $wgUpdateRowsPerQuery ) as $addBatch ) {
$wp->updateCategoryCounts( $addBatch, [], $this->mId );
- $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] );
+ $lbf->commitAndWaitForReplication(
+ __METHOD__, $this->ticket, [ 'domain' => $domainId ] );
}
foreach ( array_chunk( array_keys( $deleted ), $wgUpdateRowsPerQuery ) as $deleteBatch ) {
$wp->updateCategoryCounts( [], $deleteBatch, $this->mId );
- $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] );
+ $lbf->commitAndWaitForReplication(
+ __METHOD__, $this->ticket, [ 'domain' => $domainId ] );
}
}
}
}
+ $domainId = $this->getDB()->getDomainID();
+
foreach ( $deleteWheres as $deleteWhere ) {
$this->getDB()->delete( $table, $deleteWhere, __METHOD__ );
$lbf->commitAndWaitForReplication(
- __METHOD__, $this->ticket, [ 'wiki' => $this->getDB()->getWikiID() ]
+ __METHOD__, $this->ticket, [ 'domain' => $domainId ]
);
}
foreach ( $insertBatches as $insertBatch ) {
$this->getDB()->insert( $table, $insertBatch, __METHOD__, 'IGNORE' );
$lbf->commitAndWaitForReplication(
- __METHOD__, $this->ticket, [ 'wiki' => $this->getDB()->getWikiID() ]
+ __METHOD__, $this->ticket, [ 'domain' => $domainId ]
);
}
}
return [
- 'wiki' => $this->getDB()->getWikiID(),
+ 'wiki' => WikiMap::getWikiIdFromDomain( $this->getDB()->getDomainID() ),
'job' => new JobSpecification(
'refreshLinksPrioritized',
[
[ $this, 'getTitleChangeEvents' ],
[ $this, 'getEventAffectedKeys' ],
[
- 'channel' => 'table:recentchanges:' . $this->db->getWikiID(),
+ 'channel' => 'table:recentchanges:' . $this->db->getDomainID(),
'logger' => $this->logger
]
);
* Alias for getDomainID()
*
* @return string
+ * @deprecated 1.30
*/
public function getWikiID();
if ( $module instanceof self ) {
$mDB = $module->getDB();
// Subclasses may disable getDB and implement getTitleInfo differently
- if ( $mDB && $mDB->getWikiID() === $db->getWikiID() ) {
+ if ( $mDB && $mDB->getDomainID() === $db->getDomainID() ) {
$wikiModules[] = $module;
$allPages += $module->getPages( $context );
}
$cache = ObjectCache::getMainWANInstance();
$allInfo = $cache->getWithSetCallback(
- $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getWikiID(), $hash ),
+ $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID(), $hash ),
$cache::TTL_HOUR,
function ( $curVal, &$ttl, array &$setOpts ) use ( $func, $pageNames, $db, $fname ) {
$setOpts += Database::getCacheSetOptions( $db );
return call_user_func( $func, $db, $pageNames, $fname );
},
- [ 'checkKeys' => [ $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getWikiID() ) ] ]
+ [
+ 'checkKeys' => [
+ $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID() ) ]
+ ]
);
foreach ( $wikiModules as $wikiModule ) {
__METHOD__
);
- $wikiId = $this->db->getWikiID();
+ $domainId = $this->db->getDomainID();
$userId = $this->id;
$this->db->onTransactionPreCommitOrIdle(
- function () use ( $wikiId, $userId ) {
- User::purge( $wikiId, $userId );
+ function () use ( $domainId, $userId ) {
+ User::purge( $domainId, $userId );
},
__METHOD__
);
require_once __DIR__ . '/Maintenance.php';
use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\MediaWikiServices;
/**
* Usage:
public function execute() {
$dbw = $this->getDB( DB_MASTER );
- $this->wikiId = $dbw->getWikiID();
-
- $this->wanCache = ObjectCache::getMainWANInstance();
+ $this->wikiId = $dbw->getDomainID();
+ $this->wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$ns = $this->getOption( 'ns' );
if ( !ctype_digit( $ns ) && $ns !== 'all' ) {
<?php
+use Wikimedia\Rdbms\DatabaseDomain;
/**
* @covers WikiMap
public function testGetWikiFromUrl( $url, $wiki ) {
$this->assertEquals( $wiki, WikiMap::getWikiFromUrl( $url ) );
}
+
+ /**
+ * @dataProvider provideGetWikiIdFromDomain
+ * @covers WikiMap::getWikiIdFromDomain()
+ */
+ public function testGetWikiIdFromDomain( $domain, $wikiId ) {
+ $this->assertEquals( $wikiId, WikiMap::getWikiIdFromDomain( $domain ) );
+ }
+
+ public function provideGetWikiIdFromDomain() {
+ return [
+ [ 'db-prefix', 'db-prefix' ],
+ [ wfWikiID(), wfWikiID() ],
+ [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ]
+ ];
+ }
}