MediaWiki REL1_30
Interwiki_hooks.php
Go to the documentation of this file.
1<?php
2
4 public static function onExtensionFunctions() {
5 global $wgInterwikiViewOnly;
6
7 if ( $wgInterwikiViewOnly === false ) {
9
10 // New user right, required to modify the interwiki table through Special:Interwiki
11 $wgAvailableRights[] = 'interwiki';
12
13 // Set up the new log type - interwiki actions are logged to this new log
14 $wgLogTypes[] = 'interwiki';
15 // interwiki, iw_add, iw_delete, iw_edit
16 $wgLogActionsHandlers['interwiki/*'] = 'InterwikiLogFormatter';
17 }
18
19 return true;
20 }
21
22 public static function onInterwikiLoadPrefix( $prefix, &$iwData ) {
23 global $wgInterwikiCentralDB;
24 // docs/hooks.txt says: Return true without providing an interwiki to continue interwiki search.
25 if ( $wgInterwikiCentralDB === null || $wgInterwikiCentralDB === wfWikiID() ) {
26 // No global set or this is global, nothing to add
27 return true;
28 }
29 if ( !Language::fetchLanguageName( $prefix ) ) {
30 // Check if prefix exists locally and skip
31 foreach ( Interwiki::getAllPrefixes( null ) as $id => $localPrefixInfo ) {
32 if ( $prefix === $localPrefixInfo['iw_prefix'] ) {
33 return true;
34 }
35 }
36 $dbr = wfGetDB( DB_SLAVE, [], $wgInterwikiCentralDB );
37 $res = $dbr->selectRow(
38 'interwiki',
39 '*',
40 [ 'iw_prefix' => $prefix ],
41 __METHOD__
42 );
43 if ( !$res ) {
44 return true;
45 }
46 // Excplicitly make this an array since it's expected to be one
47 $iwData = (array)$res;
48 // At this point, we can safely return false because we know that we have something
49 return false;
50 }
51 return true;
52 }
53
54}
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
$wgAvailableRights
A list of available rights, in addition to the ones defined by the core.
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
const DB_SLAVE
Definition Defines.php:37
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
static onInterwikiLoadPrefix( $prefix, &$iwData)
static onExtensionFunctions()
static getAllPrefixes( $local=null)
Returns all interwiki prefix definitions.
if(! $regexes) $dbr
Definition cleanup.php:94
$res
Definition database.txt:21
the array() calling protocol came about after MediaWiki 1.4rc1.