Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4121027
Hooks.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
Hooks.php
View Options
<?php
namespace
MediaWiki\Extension\Interwiki
;
use
MediaWiki\MediaWikiServices
;
use
MediaWiki\Permissions\Hook\UserGetAllRightsHook
;
use
MediaWiki\WikiMap\WikiMap
;
class
Hooks
implements
UserGetAllRightsHook
{
/** @var bool */
private
static
$shouldSkipIWCheck
=
false
;
/** @var bool */
private
static
$shouldSkipILCheck
=
false
;
public
static
function
onExtensionFunctions
()
{
global
$wgInterwikiViewOnly
;
if
(
!
$wgInterwikiViewOnly
)
{
global
$wgLogTypes
;
// Set up the new log type - interwiki actions are logged to this new log
// TODO: Move this out of an extension function once T200385 is implemented.
$wgLogTypes
[]
=
'interwiki'
;
}
// Register the (deprecated) InterwikiLoadPrefix hook only if one
// of the wgInterwiki*CentralDB globals is set.
global
$wgInterwikiCentralDB
,
$wgInterwikiCentralInterlanguageDB
;
self
::
$shouldSkipIWCheck
=
(
$wgInterwikiCentralDB
===
null
||
$wgInterwikiCentralDB
===
WikiMap
::
getCurrentWikiId
()
);
self
::
$shouldSkipILCheck
=
(
$wgInterwikiCentralInterlanguageDB
===
null
||
$wgInterwikiCentralInterlanguageDB
===
WikiMap
::
getCurrentWikiId
()
);
if
(
self
::
$shouldSkipIWCheck
&&
self
::
$shouldSkipILCheck
)
{
// Bail out early if _neither_ $wgInterwiki*CentralDB
// global is set; if one or both are set, we gotta register
// the InterwikiLoadPrefix hook.
return
;
}
// This will trigger a deprecation warning in MW 1.36+
MediaWikiServices
::
getInstance
()->
getHookContainer
()->
register
(
'InterwikiLoadPrefix'
,
'MediaWiki
\E
xtension
\I
nterwiki
\H
ooks::onInterwikiLoadPrefix'
);
}
/**
* @param array &$rights
*/
public
function
onUserGetAllRights
(
&
$rights
)
{
global
$wgInterwikiViewOnly
;
if
(
!
$wgInterwikiViewOnly
)
{
// New user right, required to modify the interwiki table through Special:Interwiki
$rights
[]
=
'interwiki'
;
}
}
public
static
function
onInterwikiLoadPrefix
(
$prefix
,
&
$iwData
)
{
global
$wgInterwikiCentralDB
,
$wgInterwikiCentralInterlanguageDB
;
$services
=
MediaWikiServices
::
getInstance
();
$connectionProvider
=
$services
->
getConnectionProvider
();
$isInterlanguageLink
=
$services
->
getLanguageNameUtils
()->
getLanguageName
(
$prefix
);
if
(
!
$isInterlanguageLink
&&
!
self
::
$shouldSkipIWCheck
)
{
// Check if prefix exists locally and skip
$lookup
=
$services
->
getInterwikiLookup
();
foreach
(
$lookup
->
getAllPrefixes
(
null
)
as
$id
=>
$localPrefixInfo
)
{
if
(
$prefix
===
$localPrefixInfo
[
'iw_prefix'
]
)
{
return
true
;
}
}
$dbrCentralDB
=
$connectionProvider
->
getReplicaDatabase
(
$wgInterwikiCentralDB
??
false
);
$res
=
$dbrCentralDB
->
newSelectQueryBuilder
()
->
select
(
'*'
)
->
from
(
'interwiki'
)
->
where
(
[
'iw_prefix'
=>
$prefix
]
)
->
caller
(
__METHOD__
)
->
fetchRow
();
if
(
!
$res
)
{
return
true
;
}
// Explicitly 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
;
}
elseif
(
$isInterlanguageLink
&&
!
self
::
$shouldSkipILCheck
)
{
// Global interlanguage link? Whoo!
$dbrCentralLangDB
=
$connectionProvider
->
getReplicaDatabase
(
$wgInterwikiCentralInterlanguageDB
??
false
);
$res
=
$dbrCentralLangDB
->
newSelectQueryBuilder
()
->
select
(
'*'
)
->
from
(
'interwiki'
)
->
where
(
[
'iw_prefix'
=>
$prefix
]
)
->
caller
(
__METHOD__
)
->
fetchRow
();
if
(
!
$res
)
{
return
false
;
}
// Explicitly 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
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 04:22 (2 d, 8 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
46/b9/1b2d33884fb326144dd6a7103d61
Default Alt Text
Hooks.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment