getHookContainer()->register( 'InterwikiLoadPrefix', 'MediaWiki\Extension\Interwiki\Hooks::onInterwikiLoadPrefix' ); } /** * @param array &$rights */ public function onUserGetAllRights( &$rights ) { global $wgInterwikiViewOnly; if ( !$wgInterwikiViewOnly ) { // New user right, required to modify the interwiki table through Special:Interwiki $rights[] = 'interwiki'; } } public static function onInterwikiLoadPrefix( $prefix, &$iwData ) { global $wgInterwikiCentralDB, $wgInterwikiCentralInterlanguageDB; $services = MediaWikiServices::getInstance(); $connectionProvider = $services->getConnectionProvider(); $isInterlanguageLink = $services->getLanguageNameUtils()->getLanguageName( $prefix ); if ( !$isInterlanguageLink && !self::$shouldSkipIWCheck ) { // Check if prefix exists locally and skip $lookup = $services->getInterwikiLookup(); foreach ( $lookup->getAllPrefixes( null ) as $id => $localPrefixInfo ) { if ( $prefix === $localPrefixInfo['iw_prefix'] ) { return true; } } $dbrCentralDB = $connectionProvider->getReplicaDatabase( $wgInterwikiCentralDB ?? false ); $res = $dbrCentralDB->selectRow( 'interwiki', '*', [ 'iw_prefix' => $prefix ], __METHOD__ ); if ( !$res ) { return true; } // Explicitly make this an array since it's expected to be one $iwData = (array)$res; // At this point, we can safely return false because we know that we have something return false; } elseif ( $isInterlanguageLink && !self::$shouldSkipILCheck ) { // Global interlanguage link? Whoo! $dbrCentralLangDB = $connectionProvider->getReplicaDatabase( $wgInterwikiCentralInterlanguageDB ?? false ); $res = $dbrCentralLangDB->selectRow( 'interwiki', '*', [ 'iw_prefix' => $prefix ], __METHOD__ ); if ( !$res ) { return false; } // Explicitly make this an array since it's expected to be one $iwData = (array)$res; // At this point, we can safely return false because we know that we have something return false; } } }