Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
LegacyInterfaceHookHandler | |
0.00% |
0 / 38 |
|
0.00% |
0 / 6 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onAlternateEdit | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
onEditPage__showEditForm_initial | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
42 | |||
onTitleGetEditNotices | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
onArticleContentOnDiff | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
onSidebarBeforeOutput | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\TranslatorInterface; |
5 | |
6 | use DifferenceEngine; |
7 | use MediaWiki\Diff\Hook\ArticleContentOnDiffHook; |
8 | use MediaWiki\EditPage\EditPage; |
9 | use MediaWiki\Extension\Translate\MessageLoading\MessageHandle; |
10 | use MediaWiki\Hook\AlternateEditHook; |
11 | use MediaWiki\Hook\EditPage__showEditForm_initialHook; |
12 | use MediaWiki\Hook\SidebarBeforeOutputHook; |
13 | use MediaWiki\Hook\TitleGetEditNoticesHook; |
14 | use MediaWiki\Languages\LanguageFactory; |
15 | use MediaWiki\Skin\SkinComponentUtils; |
16 | use OutputPage; |
17 | use RequestContext; |
18 | |
19 | /** |
20 | * Integration point to MediaWiki for the legacy translation aids. |
21 | * @author Niklas Laxström |
22 | * @license GPL-2.0-or-later |
23 | */ |
24 | class LegacyInterfaceHookHandler |
25 | implements |
26 | AlternateEditHook, |
27 | ArticleContentOnDiffHook, |
28 | EditPage__showEditForm_initialHook, |
29 | TitleGetEditNoticesHook, |
30 | SidebarBeforeOutputHook |
31 | { |
32 | /** @var LanguageFactory */ |
33 | private $languageFactory; |
34 | |
35 | public function __construct( LanguageFactory $languageFactory ) { |
36 | $this->languageFactory = $languageFactory; |
37 | } |
38 | |
39 | /** |
40 | * Do not show the usual introductory messages on edit page for messages. |
41 | * @param EditPage $editPage |
42 | */ |
43 | public function onAlternateEdit( $editPage ): void { |
44 | $handle = new MessageHandle( $editPage->getTitle() ); |
45 | if ( $handle->isValid() ) { |
46 | $editPage->suppressIntro = true; |
47 | } |
48 | } |
49 | |
50 | /** |
51 | * Enhances the action=edit view for wikitext editor with some translation aids |
52 | * @param EditPage $editPage |
53 | * @param OutputPage $out |
54 | */ |
55 | // phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName |
56 | public function onEditPage__showEditForm_initial( $editPage, $out ): void { |
57 | // phpcs:enable |
58 | $handle = new MessageHandle( $editPage->getTitle() ); |
59 | if ( !$handle->isValid() ) { |
60 | return; |
61 | } |
62 | |
63 | $context = $out->getContext(); |
64 | $request = $context->getRequest(); |
65 | |
66 | if ( $editPage->firsttime && !$request->getCheck( 'oldid' ) && |
67 | !$request->getCheck( 'undo' ) ) { |
68 | if ( $handle->isFuzzy() ) { |
69 | $editPage->textbox1 = MessageHandle::makeFuzzyString( $editPage->textbox1 ); |
70 | } |
71 | } |
72 | } |
73 | |
74 | public function onTitleGetEditNotices( $title, $oldid, &$notices ) { |
75 | $handle = new MessageHandle( $title ); |
76 | if ( !$handle->isValid() ) { |
77 | return; |
78 | } |
79 | |
80 | // The context is required for loading style modules. This won't work in |
81 | // an API context e.g. when loading VisualEditor. |
82 | $context = RequestContext::getMain(); |
83 | |
84 | $th = new LegacyTranslationAids( $handle, $context, $this->languageFactory ); |
85 | $notices[] = $th->getBoxes(); |
86 | } |
87 | |
88 | /** |
89 | * Enhances the action=diff view with some translations aids |
90 | * @param DifferenceEngine $diffEngine |
91 | * @param OutputPage $output |
92 | */ |
93 | public function onArticleContentOnDiff( $diffEngine, $output ): void { |
94 | $title = $diffEngine->getTitle(); |
95 | $handle = new MessageHandle( $title ); |
96 | |
97 | if ( !$handle->isValid() ) { |
98 | return; |
99 | } |
100 | |
101 | $th = new LegacyTranslationAids( $handle, $diffEngine->getContext(), $this->languageFactory ); |
102 | $output->addHTML( $th->getBoxes() ); |
103 | } |
104 | |
105 | /** |
106 | * Adds toolbox menu item to pages, showing all other |
107 | * available translations for a message. Only shown when it |
108 | * actually is a translatable/translated message. |
109 | * |
110 | * @inheritDoc |
111 | */ |
112 | public function onSidebarBeforeOutput( $skin, &$sidebar ): void { |
113 | $title = $skin->getTitle(); |
114 | $handle = new MessageHandle( $title ); |
115 | |
116 | if ( !$handle->isValid() ) { |
117 | return; |
118 | } |
119 | |
120 | $message = $title->getNsText() . ':' . $handle->getKey(); |
121 | if ( method_exists( SkinComponentUtils::class, 'makeSpecialUrl' ) ) { |
122 | $url = SkinComponentUtils::makeSpecialUrl( 'Translations', [ 'message' => $message ] ); |
123 | } else { |
124 | // MW < 1.41 |
125 | $url = $skin::makeSpecialUrl( 'Translations', [ 'message' => $message ] ); |
126 | } |
127 | |
128 | // Add the actual toolbox entry. |
129 | $sidebar['TOOLBOX'][ 'alltrans' ] = [ |
130 | 'href' => $url, |
131 | 'id' => 't-alltrans', |
132 | 'msg' => 'translate-sidebar-alltrans', |
133 | ]; |
134 | } |
135 | } |