mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Interwiki
synced 2024-11-24 14:34:06 +00:00
55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
class InterwikiHooks {
|
||
|
public static function onExtensionFunctions() {
|
||
|
global $wgInterwikiViewOnly;
|
||
|
|
||
|
if ( $wgInterwikiViewOnly === false ) {
|
||
|
global $wgAvailableRights, $wgLogTypes, $wgLogActionsHandlers;
|
||
|
|
||
|
// New user right, required to modify the interwiki table through Special:Interwiki
|
||
|
$wgAvailableRights[] = 'interwiki';
|
||
|
|
||
|
// Set up the new log type - interwiki actions are logged to this new log
|
||
|
$wgLogTypes[] = 'interwiki';
|
||
|
// interwiki, iw_add, iw_delete, iw_edit
|
||
|
$wgLogActionsHandlers['interwiki/*'] = 'InterwikiLogFormatter';
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static function onInterwikiLoadPrefix( $prefix, &$iwData ) {
|
||
|
global $wgInterwikiCentralDB;
|
||
|
// docs/hooks.txt says: Return true without providing an interwiki to continue interwiki search.
|
||
|
if ( $wgInterwikiCentralDB === null || $wgInterwikiCentralDB === wfWikiId() ) {
|
||
|
// No global set or this is global, nothing to add
|
||
|
return true;
|
||
|
}
|
||
|
if ( !Language::fetchLanguageName( $prefix ) ) {
|
||
|
// Check if prefix exists locally and skip
|
||
|
foreach ( Interwiki::getAllPrefixes( null ) as $id => $localPrefixInfo ) {
|
||
|
if ( $prefix === $localPrefixInfo['iw_prefix'] ) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
$dbr = wfGetDB( DB_SLAVE, array(), $wgInterwikiCentralDB );
|
||
|
$res = $dbr->selectRow(
|
||
|
'interwiki',
|
||
|
'*',
|
||
|
array( 'iw_prefix' => $prefix ),
|
||
|
__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;
|
||
|
}
|
||
|
|
||
|
}
|