Replace wfWiki() usage with WikiMap in some additional places
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 4 Jul 2019 08:28:18 +0000 (01:28 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 4 Jul 2019 21:58:42 +0000 (21:58 +0000)
Change-Id: Ide4518292bd9392d09f701b2c301673687d19f3b

maintenance/cleanupSpam.php
maintenance/clearInterwikiCache.php
maintenance/copyJobQueue.php
maintenance/generateSitemap.php
maintenance/includes/TextPassDumper.php
maintenance/storage/recompressTracked.php

index e1ea247..27ada59 100644 (file)
@@ -67,9 +67,9 @@ class CleanupSpam extends Maintenance {
                        // Clean up spam on all wikis
                        $this->output( "Finding spam on " . count( $wgLocalDatabases ) . " wikis\n" );
                        $found = false;
-                       foreach ( $wgLocalDatabases as $wikiID ) {
+                       foreach ( $wgLocalDatabases as $wikiId ) {
                                /** @var Database $dbr */
-                               $dbr = $this->getDB( DB_REPLICA, [], $wikiID );
+                               $dbr = $this->getDB( DB_REPLICA, [], $wikiId );
 
                                foreach ( $protConds as $conds ) {
                                        $count = $dbr->selectField(
@@ -82,9 +82,9 @@ class CleanupSpam extends Maintenance {
                                                $found = true;
                                                $cmd = wfShellWikiCmd(
                                                        "$IP/maintenance/cleanupSpam.php",
-                                                       [ '--wiki', $wikiID, $spec ]
+                                                       [ '--wiki', $wikiId, $spec ]
                                                );
-                                               passthru( "$cmd | sed 's/^/$wikiID:  /'" );
+                                               passthru( "$cmd | sed 's/^/$wikiId:  /'" );
                                        }
                                }
                        }
index 8579f0f..45c66ae 100644 (file)
@@ -44,10 +44,10 @@ class ClearInterwikiCache extends Maintenance {
                        $prefixes[] = $row->iw_prefix;
                }
 
-               foreach ( $wgLocalDatabases as $db ) {
-                       $this->output( "$db..." );
+               foreach ( $wgLocalDatabases as $wikiId ) {
+                       $this->output( "$wikiId..." );
                        foreach ( $prefixes as $prefix ) {
-                               $wgMemc->delete( "$db:interwiki:$prefix" );
+                               $wgMemc->delete( "$wikiId:interwiki:$prefix" );
                        }
                        $this->output( "done\n" );
                }
index dc70e9c..0e96142 100644 (file)
@@ -57,8 +57,9 @@ class CopyJobQueue extends Maintenance {
                        ? JobQueueGroup::singleton()->getQueueTypes()
                        : [ $this->getOption( 'type' ) ];
 
+               $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
                foreach ( $types as $type ) {
-                       $baseConfig = [ 'type' => $type, 'wiki' => wfWikiID() ];
+                       $baseConfig = [ 'type' => $type, 'domain' => $dbDomain ];
                        $src = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$srcKey] );
                        $dst = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$dstKey] );
 
index 05dd0d0..aef45bf 100644 (file)
@@ -188,18 +188,20 @@ class GenerateSitemap extends Maintenance {
                        $this->fatalError( "Can not create directory $fspath." );
                }
 
+               $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
                $this->fspath = realpath( $fspath ) . DIRECTORY_SEPARATOR;
                $this->urlpath = $this->getOption( 'urlpath', "" );
                if ( $this->urlpath !== "" && substr( $this->urlpath, -1 ) !== '/' ) {
                        $this->urlpath .= '/';
                }
-               $this->identifier = $this->getOption( 'identifier', wfWikiID() );
+               $this->identifier = $this->getOption( 'identifier', $dbDomain );
                $this->compress = $this->getOption( 'compress', 'yes' ) !== 'no';
                $this->skipRedirects = $this->hasOption( 'skip-redirects' );
                $this->dbr = $this->getDB( DB_REPLICA );
                $this->generateNamespaces();
                $this->timestamp = wfTimestamp( TS_ISO_8601, wfTimestampNow() );
-               $this->findex = fopen( "{$this->fspath}sitemap-index-{$this->identifier}.xml", 'wb' );
+               $encIdentifier = rawurlencode( $this->identifier );
+               $this->findex = fopen( "{$this->fspath}sitemap-index-{$encIdentifier}.xml", 'wb' );
                $this->main();
        }
 
index b37fec1..8bc393f 100644 (file)
@@ -757,6 +757,7 @@ TEXT
        function openSpawn() {
                global $IP;
 
+               $wiki = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() );
                if ( count( $this->php ) == 2 ) {
                        $mwscriptpath = $this->php[1];
                } else {
@@ -769,14 +770,14 @@ TEXT
                                                $this->php[0],
                                                $mwscriptpath,
                                                "fetchText.php",
-                                               '--wiki', wfWikiID() ] ) );
+                                               '--wiki', $wiki ] ) );
                } else {
                        $cmd = implode( " ",
                                array_map( [ Shell::class, 'escape' ],
                                        [
                                                $this->php[0],
                                                "$IP/maintenance/fetchText.php",
-                                               '--wiki', wfWikiID() ] ) );
+                                               '--wiki', $wiki ] ) );
                }
                $spec = [
                        0 => [ "pipe", "r" ],
index e6733a1..50a4667 100644 (file)
@@ -218,6 +218,8 @@ class RecompressTracked {
         * writing are all slow.
         */
        function startReplicaProcs() {
+               $wiki = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() );
+
                $cmd = 'php ' . Shell::escape( __FILE__ );
                foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) {
                        if ( $cmdOption == 'replica-id' ) {
@@ -229,7 +231,7 @@ class RecompressTracked {
                        }
                }
                $cmd .= ' --child' .
-                       ' --wiki ' . Shell::escape( wfWikiID() ) .
+                       ' --wiki ' . Shell::escape( $wiki ) .
                        ' ' . Shell::escape( ...$this->destClusters );
 
                $this->replicaPipes = $this->replicaProcs = [];