Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5967893
PageTranslationHookHandler.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
PageTranslationHookHandler.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\PageTranslation
;
use
MediaWiki\Context\IContextSource
;
use
MediaWiki\Hook\LonelyPagesQueryHook
;
use
MediaWiki\Hook\SpecialPrefixIndexGetFormFiltersHook
;
use
MediaWiki\Hook\SpecialPrefixIndexQueryHook
;
use
MediaWiki\Hook\SpecialWhatLinksHereQueryHook
;
use
MediaWiki\HTMLForm\Field\HTMLCheckField
;
use
MediaWiki\SpecialPage\Hook\SpecialPageBeforeFormDisplayHook
;
use
Wikimedia\Rdbms\SelectQueryBuilder
;
class
PageTranslationHookHandler
implements
SpecialPrefixIndexGetFormFiltersHook
,
SpecialPrefixIndexQueryHook
,
LonelyPagesQueryHook
,
SpecialPageBeforeFormDisplayHook
,
SpecialWhatLinksHereQueryHook
{
public
function
onSpecialPrefixIndexGetFormFilters
(
IContextSource
$contextSource
,
array
&
$filters
)
{
$filters
[
'translate-hidetranslations'
]
=
[
'class'
=>
HTMLCheckField
::
class
,
'name'
=>
'translate-hidetranslations'
,
'label-message'
=>
'translate-hidetranslations'
,
];
}
public
function
onSpecialPrefixIndexQuery
(
array
$fieldData
,
SelectQueryBuilder
$queryBuilder
)
{
if
(
$fieldData
[
'translate-hidetranslations'
]
===
true
)
{
$queryBuilder
->
leftJoin
(
'page_props'
,
'translate_pp'
,
[
'translate_pp.pp_page=page_id'
,
'translate_pp.pp_propname'
=>
'translate-is-translation'
]
)->
andWhere
(
[
'translate_pp.pp_value'
=>
null
]
);
}
}
public
function
onLonelyPagesQuery
(
&
$tables
,
&
$conds
,
&
$joinConds
)
{
$tables
[
'translate_pp'
]
=
'page_props'
;
$joinConds
[
'translate_pp'
]
=
[
'LEFT JOIN'
,
[
'translate_pp.pp_page=page_id'
,
'translate_pp.pp_propname'
=>
'translate-is-translation'
]
];
$conds
[
'translate_pp.pp_value'
]
=
null
;
}
public
function
onSpecialPageBeforeFormDisplay
(
$name
,
$form
):
void
{
if
(
$name
===
'Whatlinkshere'
)
{
$form
->
addFields
(
[
'translate-hidetranslations'
=>
[
'type'
=>
'check'
,
'name'
=>
'translate-hidetranslations'
,
'label-message'
=>
'translate-hidetranslations'
,
'section'
=>
'whatlinkshere-filter'
,
]
]
);
}
}
public
function
onSpecialWhatLinksHereQuery
(
$table
,
$data
,
$queryBuilder
)
{
$isSupportedTable
=
in_array
(
$table
,
[
'pagelinks'
,
'templatelinks'
,
'imagelinks'
]
);
if
(
$data
[
'translate-hidetranslations'
]
&&
$isSupportedTable
)
{
$queryBuilder
->
leftJoin
(
'page_props'
,
'translate_pp'
,
[
'translate_pp.pp_page=page_id'
,
'translate_pp.pp_propname'
=>
'translate-is-translation'
,
]
)
->
andWhere
(
[
'translate_pp.pp_value'
=>
null
]
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 12:42 (3 d, 2 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
fc/b6/4f6dde04f7c89433a4798bc6b591
Default Alt Text
PageTranslationHookHandler.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment