Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4097749
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
/**
* @file
* @author Robert Leverington
* @license GPL-2.0-or-later
*/
declare
(
strict_types
=
1
);
namespace
MediaWiki\Babel
;
use
MediaWiki\Config\Config
;
use
MediaWiki\Deferred\LinksUpdate\LinksUpdate
;
use
MediaWiki\Hook\LinksUpdateHook
;
use
MediaWiki\Hook\ParserFirstCallInitHook
;
use
MediaWiki\Parser\Parser
;
use
MediaWiki\User\CentralId\CentralIdLookupFactory
;
use
MediaWiki\User\Hook\UserGetReservedNamesHook
;
use
MediaWiki\User\UserIdentityLookup
;
use
MediaWiki\WikiMap\WikiMap
;
use
Wikimedia\ObjectCache\WANObjectCache
;
/**
* Hook handler functions for Babel extension.
*/
class
Hooks
implements
ParserFirstCallInitHook
,
LinksUpdateHook
,
UserGetReservedNamesHook
{
private
Config
$config
;
private
UserIdentityLookup
$userIdentityLookup
;
private
CentralIdLookupFactory
$centralIdLookupFactory
;
private
WANObjectCache
$mainWANObjectCache
;
public
function
__construct
(
Config
$config
,
UserIdentityLookup
$userIdentityLookup
,
CentralIdLookupFactory
$centralIdLookupFactory
,
WANObjectCache
$mainWANObjectCache
)
{
$this
->
config
=
$config
;
$this
->
userIdentityLookup
=
$userIdentityLookup
;
$this
->
centralIdLookupFactory
=
$centralIdLookupFactory
;
$this
->
mainWANObjectCache
=
$mainWANObjectCache
;
}
/**
* Registers the parser function hook.
*
* @param Parser $parser
*/
public
function
onParserFirstCallInit
(
$parser
):
void
{
$parser
->
setFunctionHook
(
'babel'
,
[
Babel
::
class
,
'render'
]
);
}
/**
* @param LinksUpdate $linksUpdate
*/
public
function
onLinksUpdate
(
$linksUpdate
):
void
{
$title
=
$linksUpdate
->
getTitle
();
$toCreate
=
$linksUpdate
->
getParserOutput
()->
getExtensionData
(
'babel-tocreate'
)
?:
[];
// Create categories
foreach
(
$toCreate
as
$category
=>
$value
)
{
$text
=
$linksUpdate
->
getParserOutput
()->
getExtensionData
(
"babel-category-text-{$category}"
);
BabelAutoCreate
::
create
(
$category
,
$text
);
}
// Has to be a root userpage
if
(
!
$title
->
inNamespace
(
NS_USER
)
||
!
$title
->
getRootTitle
()->
equals
(
$title
)
)
{
return
;
}
// And the user has to exist
$userIdentity
=
$this
->
userIdentityLookup
->
getUserIdentityByName
(
$title
->
getText
()
);
if
(
$userIdentity
===
null
||
!
$userIdentity
->
isRegistered
()
)
{
return
;
}
$babelDB
=
new
Database
();
$data
=
$linksUpdate
->
getParserOutput
()->
getExtensionData
(
'babel'
)
?:
[];
$changed
=
$babelDB
->
setForUser
(
$userIdentity
->
getId
(),
$data
);
if
(
$changed
)
{
$localLangKey
=
$this
->
mainWANObjectCache
->
makeKey
(
'babel-local-languages'
,
$userIdentity
->
getId
()
);
$this
->
mainWANObjectCache
->
touchCheckKey
(
$localLangKey
);
if
(
$this
->
config
->
get
(
'BabelCentralDb'
)
===
WikiMap
::
getCurrentWikiId
()
)
{
// If this is the central wiki, invalidate all of the local caches
$centralId
=
$this
->
centralIdLookupFactory
->
getLookup
()->
centralIdFromLocalUser
(
$userIdentity
);
if
(
$centralId
)
{
$centralLangKey
=
$this
->
mainWANObjectCache
->
makeGlobalKey
(
'babel-central-languages'
,
$centralId
);
$this
->
mainWANObjectCache
->
touchCheckKey
(
$centralLangKey
);
}
}
}
}
/**
* @param array &$names
*/
public
function
onUserGetReservedNames
(
&
$names
):
void
{
$names
[]
=
'msg:'
.
BabelAutoCreate
::
MSG_USERNAME
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 15:02 (3 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
aa/ff/d2292f9db2499eaa1a203a0dae8f
Default Alt Text
Hooks.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment