Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
PageTranslationHookHandler.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\PageTranslation;
5
6use MediaWiki\Context\IContextSource;
7use MediaWiki\Hook\LonelyPagesQueryHook;
8use MediaWiki\Hook\SpecialPrefixIndexGetFormFiltersHook;
9use MediaWiki\Hook\SpecialPrefixIndexQueryHook;
10use MediaWiki\Hook\SpecialWhatLinksHereQueryHook;
11use MediaWiki\HTMLForm\Field\HTMLCheckField;
12use MediaWiki\SpecialPage\Hook\SpecialPageBeforeFormDisplayHook;
13use Wikimedia\Rdbms\SelectQueryBuilder;
14
16 SpecialPrefixIndexGetFormFiltersHook,
17 SpecialPrefixIndexQueryHook,
18 LonelyPagesQueryHook,
19 SpecialPageBeforeFormDisplayHook,
20 SpecialWhatLinksHereQueryHook
21{
23 public function onSpecialPrefixIndexGetFormFilters( IContextSource $contextSource, array &$filters ) {
24 $filters[ 'translate-hidetranslations' ] = [
25 'class' => HTMLCheckField::class,
26 'name' => 'translate-hidetranslations',
27 'label-message' => 'translate-hidetranslations',
28 ];
29 }
30
32 public function onSpecialPrefixIndexQuery( array $fieldData, SelectQueryBuilder $queryBuilder ) {
33 if ( $fieldData[ 'translate-hidetranslations' ] === true ) {
34 $queryBuilder->leftJoin(
35 'page_props',
36 'translate_pp',
37 [
38 'translate_pp.pp_page=page_id',
39 'translate_pp.pp_propname' => 'translate-is-translation'
40 ]
41 )->andWhere( [ 'translate_pp.pp_value' => null ] );
42 }
43 }
44
46 public function onLonelyPagesQuery( &$tables, &$conds, &$joinConds ) {
47 $tables[ 'translate_pp' ] = 'page_props';
48 $joinConds['translate_pp'] = [
49 'LEFT JOIN', [
50 'translate_pp.pp_page=page_id',
51 'translate_pp.pp_propname' => 'translate-is-translation'
52 ]
53 ];
54 $conds['translate_pp.pp_value'] = null;
55 }
56
58 public function onSpecialPageBeforeFormDisplay( $name, $form ): void {
59 // Temporarily disabled: https://phabricator.wikimedia.org/T385139#10559646
60 if ( $name === 'Whatlinkshere' ) {
61 $form->addFields( [
62 'translate-hidetranslations' => [
63 'type' => 'check',
64 'name' => 'translate-hidetranslations',
65 'label-message' => 'translate-hidetranslations',
66 'section' => 'whatlinkshere-filter',
67 ]
68 ] );
69 }
70 }
71
73 public function onSpecialWhatLinksHereQuery( $table, $data, $queryBuilder ) {
74 // Temporarily disabled: https://phabricator.wikimedia.org/T385139#10559646
75 $isSupportedTable = in_array( $table, [ 'pagelinks', 'templatelinks', 'imagelinks' ] );
76
77 if ( $data[ 'translate-hidetranslations' ] && $isSupportedTable ) {
78 $queryBuilder->leftJoin(
79 'page_props',
80 'translate_pp',
81 [
82 'translate_pp.pp_page=page_id',
83 'translate_pp.pp_propname' => 'translate-is-translation',
84 ]
85 )
86 ->andWhere( [ 'translate_pp.pp_value' => null ] );
87 }
88 }
89}
onSpecialPrefixIndexQuery(array $fieldData, SelectQueryBuilder $queryBuilder)
@inheritDoc
onSpecialPrefixIndexGetFormFilters(IContextSource $contextSource, array &$filters)
@inheritDoc