+
+ /**
+ * @return DatabaseDomain Database domain of the current wiki
+ * @since 1.33
+ */
+ public static function getCurrentWikiDomain() {
+ global $wgDBname, $wgDBmwschema, $wgDBprefix;
+ // Avoid invoking LBFactory to avoid any chance of recursion
+ return new DatabaseDomain( $wgDBname, $wgDBmwschema, (string)$wgDBprefix );
+ }
+
+ /**
+ * @param DatabaseDomain|string $domain
+ * @return bool Whether $domain has the same DB/prefix as the current wiki
+ * @since 1.33
+ */
+ public static function isCurrentWikiDomain( $domain ) {
+ $domain = DatabaseDomain::newFromId( $domain );
+ $curDomain = self::getCurrentWikiDomain();
+
+ return (
+ $curDomain->getDatabase() === $domain->getDatabase() &&
+ // @TODO: check schema instead of assuming it's ""/"mediawiki" and never collides
+ $curDomain->getTablePrefix() === $domain->getTablePrefix()
+ );
+ }
+
+ /**
+ * @param string $wikiId
+ * @return bool Whether $wikiId has the same DB/prefix as the current wiki
+ * @since 1.33
+ */
+ public static function isCurrentWikiId( $wikiId ) {
+ return ( self::getWikiIdFromDomain( self::getCurrentWikiDomain() ) === $wikiId );
+ }