]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - extensions/Interwiki/Interwiki_hooks.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / extensions / Interwiki / Interwiki_hooks.php
1 <?php
2
3 class InterwikiHooks {
4         public static function onExtensionFunctions() {
5                 global $wgInterwikiViewOnly;
6
7                 if ( $wgInterwikiViewOnly === false ) {
8                         global $wgAvailableRights, $wgLogTypes, $wgLogActionsHandlers;
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 }