Fix undefined $ok in DatabaseUpdater::migrateComments
[lhc/web/wiklou.git] / includes / WikiMap.php
index 4f3c461..8bb37b5 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\DatabaseDomain;
 
 /**
  * Helper tools for dealing with other locally-hosted wikis.
@@ -239,4 +240,22 @@ class WikiMap {
 
                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();
+       }
 }