MediaWiki  1.34.0
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, $wgInterwikiCentralInterlanguageDB;
31 
32  // docs/hooks.txt says: Return true without providing an interwiki to continue interwiki search.
33  $shouldSkipIWCheck = ( $wgInterwikiCentralDB === null || $wgInterwikiCentralDB === wfWikiID() );
34  $shouldSkipILCheck = (
35  $wgInterwikiCentralInterlanguageDB === null ||
36  $wgInterwikiCentralInterlanguageDB === wfWikiID()
37  );
38  // Bail out early if _neither_ $wgInterwiki*CentralDB global is set; if one
39  // or both are set, we gotta do some more complex checking first
40  if ( $shouldSkipIWCheck && $shouldSkipILCheck ) {
41  // No global set or this is global, nothing to add
42  return true;
43  }
44 
45  $isInterlanguageLink = Language::fetchLanguageName( $prefix );
46  if ( !$isInterlanguageLink && !$shouldSkipIWCheck ) {
47  // Check if prefix exists locally and skip
48  $lookup = MediaWikiServices::getInstance()->getInterwikiLookup();
49  foreach ( $lookup->getAllPrefixes( null ) as $id => $localPrefixInfo ) {
50  if ( $prefix === $localPrefixInfo['iw_prefix'] ) {
51  return true;
52  }
53  }
54  $dbr = wfGetDB( DB_REPLICA, [], $wgInterwikiCentralDB );
55  $res = $dbr->selectRow(
56  'interwiki',
57  '*',
58  [ 'iw_prefix' => $prefix ],
59  __METHOD__
60  );
61  if ( !$res ) {
62  return true;
63  }
64  // Excplicitly make this an array since it's expected to be one
65  $iwData = (array)$res;
66  // At this point, we can safely return false because we know that we have something
67  return false;
68  } elseif ( $isInterlanguageLink && !$shouldSkipILCheck ) {
69  // Global interlanguage link? Whoo!
70  $dbr = wfGetDB( DB_REPLICA, [], $wgInterwikiCentralInterlanguageDB );
71  $res = $dbr->selectRow(
72  'interwiki',
73  '*',
74  [ 'iw_prefix' => $prefix ],
75  __METHOD__
76  );
77  if ( !$res ) {
78  return false;
79  }
80  // Excplicitly make this an array since it's expected to be one
81  $iwData = (array)$res;
82  // At this point, we can safely return false because we know that we have something
83  return false;
84  }
85  }
86 }
Language\fetchLanguageName
static fetchLanguageName( $code, $inLanguage=self::AS_AUTONYMS, $include=self::ALL)
Definition: Language.php:832
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
InterwikiHooks
Definition: InterwikiHooks.php:5
$res
$res
Definition: testCompression.php:52
InterwikiHooks\onInterwikiLoadPrefix
static onInterwikiLoadPrefix( $prefix, &$iwData)
Definition: InterwikiHooks.php:29
$dbr
$dbr
Definition: testCompression.php:50
InterwikiHooks\onUserGetAllRights
static onUserGetAllRights(array &$rights)
Definition: InterwikiHooks.php:21
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2575
$wgLogTypes
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
Definition: DefaultSettings.php:7694
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:2541
InterwikiHooks\onExtensionFunctions
static onExtensionFunctions()
Definition: InterwikiHooks.php:6