MediaWiki REL1_32
InterwikiHooks.php
Go to the documentation of this file.
1<?php
2
4
6 public static function onExtensionFunctions() {
7 global $wgInterwikiViewOnly;
8
9 if ( !$wgInterwikiViewOnly ) {
10 global $wgLogTypes;
11
12 // Set up the new log type - interwiki actions are logged to this new log
13 // TODO: Move this out of an extension function once T200385 is implemented.
14 $wgLogTypes[] = 'interwiki';
15 }
16 }
17
21 public static function onUserGetAllRights( array &$rights ) {
22 global $wgInterwikiViewOnly;
23 if ( !$wgInterwikiViewOnly ) {
24 // New user right, required to modify the interwiki table through Special:Interwiki
25 $rights[] = 'interwiki';
26 }
27 }
28
29 public static function onInterwikiLoadPrefix( $prefix, &$iwData ) {
30 global $wgInterwikiCentralDB;
31 // docs/hooks.txt says: Return true without providing an interwiki to continue interwiki search.
32 if ( $wgInterwikiCentralDB === null || $wgInterwikiCentralDB === wfWikiID() ) {
33 // No global set or this is global, nothing to add
34 return true;
35 }
36 if ( !Language::fetchLanguageName( $prefix ) ) {
37 // Check if prefix exists locally and skip
38 $lookup = MediaWikiServices::getInstance()->getInterwikiLookup();
39 foreach ( $lookup->getAllPrefixes( null ) as $id => $localPrefixInfo ) {
40 if ( $prefix === $localPrefixInfo['iw_prefix'] ) {
41 return true;
42 }
43 }
44 $dbr = wfGetDB( DB_REPLICA, [], $wgInterwikiCentralDB );
45 $res = $dbr->selectRow(
46 'interwiki',
47 '*',
48 [ 'iw_prefix' => $prefix ],
49 __METHOD__
50 );
51 if ( !$res ) {
52 return true;
53 }
54 // Excplicitly make this an array since it's expected to be one
55 $iwData = (array)$res;
56 // At this point, we can safely return false because we know that we have something
57 return false;
58 }
59 return true;
60 }
61
62}
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
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 onUserGetAllRights(array &$rights)
static onInterwikiLoadPrefix( $prefix, &$iwData)
static onExtensionFunctions()
MediaWikiServices is the service locator for the application scope of MediaWiki.
$res
Definition database.txt:21
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
const DB_REPLICA
Definition defines.php:25