2015-05-03 02:24:46 +00:00
|
|
|
<?php
|
|
|
|
|
2018-06-07 18:39:17 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2015-05-03 02:24:46 +00:00
|
|
|
class InterwikiHooks {
|
|
|
|
public static function onExtensionFunctions() {
|
|
|
|
global $wgInterwikiViewOnly;
|
|
|
|
|
2018-07-25 23:48:09 +00:00
|
|
|
if ( !$wgInterwikiViewOnly ) {
|
|
|
|
global $wgLogTypes;
|
2015-05-03 02:24:46 +00:00
|
|
|
|
|
|
|
// Set up the new log type - interwiki actions are logged to this new log
|
2018-07-25 23:48:09 +00:00
|
|
|
// TODO: Move this out of an extension function once T200385 is implemented.
|
2015-05-03 02:24:46 +00:00
|
|
|
$wgLogTypes[] = 'interwiki';
|
|
|
|
}
|
2018-07-25 23:48:09 +00:00
|
|
|
}
|
2015-05-03 02:24:46 +00:00
|
|
|
|
2018-07-25 23:48:09 +00:00
|
|
|
/**
|
|
|
|
* @param array &$rights
|
|
|
|
*/
|
|
|
|
public static function onUserGetAllRights( array &$rights ) {
|
|
|
|
global $wgInterwikiViewOnly;
|
|
|
|
if ( !$wgInterwikiViewOnly ) {
|
|
|
|
// New user right, required to modify the interwiki table through Special:Interwiki
|
|
|
|
$rights[] = 'interwiki';
|
|
|
|
}
|
2015-05-03 02:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function onInterwikiLoadPrefix( $prefix, &$iwData ) {
|
|
|
|
global $wgInterwikiCentralDB;
|
|
|
|
// docs/hooks.txt says: Return true without providing an interwiki to continue interwiki search.
|
2016-03-07 14:35:32 +00:00
|
|
|
if ( $wgInterwikiCentralDB === null || $wgInterwikiCentralDB === wfWikiID() ) {
|
2015-05-03 02:24:46 +00:00
|
|
|
// No global set or this is global, nothing to add
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ( !Language::fetchLanguageName( $prefix ) ) {
|
|
|
|
// Check if prefix exists locally and skip
|
2018-06-07 18:39:17 +00:00
|
|
|
$lookup = MediaWikiServices::getInstance()->getInterwikiLookup();
|
|
|
|
foreach ( $lookup->getAllPrefixes( null ) as $id => $localPrefixInfo ) {
|
2015-05-03 02:24:46 +00:00
|
|
|
if ( $prefix === $localPrefixInfo['iw_prefix'] ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-09-24 05:27:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA, [], $wgInterwikiCentralDB );
|
2015-05-03 02:24:46 +00:00
|
|
|
$res = $dbr->selectRow(
|
|
|
|
'interwiki',
|
|
|
|
'*',
|
2016-03-07 14:41:22 +00:00
|
|
|
[ 'iw_prefix' => $prefix ],
|
2015-05-03 02:24:46 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
if ( !$res ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Excplicitly 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;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|