Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5986553
Hooks.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 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
{
public
function
__construct
(
private
readonly
Config
$config
,
private
readonly
UserIdentityLookup
$userIdentityLookup
,
private
readonly
CentralIdLookupFactory
$centralIdLookupFactory
,
private
readonly
WANObjectCache
$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
Sun, Oct 4, 00:08 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
dc/da/86ff9a8fbc1c50ce5ea38903c77d
Default Alt Text
Hooks.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment