Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
LegacyInterfaceHookHandler.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface;
5
6use DifferenceEngine;
7use MediaWiki\Context\RequestContext;
8use MediaWiki\Diff\Hook\ArticleContentOnDiffHook;
9use MediaWiki\EditPage\EditPage;
11use MediaWiki\Hook\AlternateEditHook;
12use MediaWiki\Hook\EditPage__showEditForm_initialHook;
13use MediaWiki\Hook\SidebarBeforeOutputHook;
14use MediaWiki\Hook\TitleGetEditNoticesHook;
15use MediaWiki\Languages\LanguageFactory;
16use MediaWiki\Output\OutputPage;
17use MediaWiki\Skin\SkinComponentUtils;
18
25 implements
26 AlternateEditHook,
27 ArticleContentOnDiffHook,
28 EditPage__showEditForm_initialHook,
29 TitleGetEditNoticesHook,
30 SidebarBeforeOutputHook
31{
32 private LanguageFactory $languageFactory;
33
34 public function __construct( LanguageFactory $languageFactory ) {
35 $this->languageFactory = $languageFactory;
36 }
37
42 public function onAlternateEdit( $editPage ): void {
43 $handle = new MessageHandle( $editPage->getTitle() );
44 if ( $handle->isValid() ) {
45 $editPage->suppressIntro = true;
46 }
47 }
48
54 public function onEditPage__showEditForm_initial( $editPage, $out ): void {
55 // phpcs:enable
56 $handle = new MessageHandle( $editPage->getTitle() );
57 if ( !$handle->isValid() ) {
58 return;
59 }
60
61 $context = $out->getContext();
62 $request = $context->getRequest();
63
64 if ( $editPage->firsttime && !$request->getCheck( 'oldid' ) &&
65 !$request->getCheck( 'undo' ) ) {
66 if ( $handle->isFuzzy() ) {
67 $editPage->textbox1 = MessageHandle::makeFuzzyString( $editPage->textbox1 );
68 }
69 }
70 }
71
73 public function onTitleGetEditNotices( $title, $oldid, &$notices ) {
74 $handle = new MessageHandle( $title );
75 if ( !$handle->isValid() ) {
76 return;
77 }
78
79 // The context is required for loading style modules. This won't work in
80 // an API context e.g. when loading VisualEditor.
81 $context = RequestContext::getMain();
82
83 $th = new LegacyTranslationAids( $handle, $context, $this->languageFactory );
84 $notices[] = $th->getBoxes();
85 }
86
92 public function onArticleContentOnDiff( $diffEngine, $output ): void {
93 $title = $diffEngine->getTitle();
94 $handle = new MessageHandle( $title );
95
96 if ( !$handle->isValid() ) {
97 return;
98 }
99
100 $th = new LegacyTranslationAids( $handle, $diffEngine->getContext(), $this->languageFactory );
101 $output->addHTML( $th->getBoxes() );
102 }
103
111 public function onSidebarBeforeOutput( $skin, &$sidebar ): void {
112 $title = $skin->getTitle();
113 $handle = new MessageHandle( $title );
114
115 if ( !$handle->isValid() ) {
116 return;
117 }
118
119 $message = $title->getNsText() . ':' . $handle->getKey();
120 $url = SkinComponentUtils::makeSpecialUrl( 'Translations', [ 'message' => $message ] );
121
122 // Add the actual toolbox entry.
123 $sidebar['TOOLBOX'][ 'alltrans' ] = [
124 'href' => $url,
125 'id' => 't-alltrans',
126 'msg' => 'translate-sidebar-alltrans',
127 ];
128 }
129}
Class for pointing to messages, like Title class is for titles.
Integration point to MediaWiki for the legacy translation aids.
onEditPage__showEditForm_initial( $editPage, $out)
Enhances the action=edit view for wikitext editor with some translation aids.
onArticleContentOnDiff( $diffEngine, $output)
Enhances the action=diff view with some translations aids.
onAlternateEdit( $editPage)
Do not show the usual introductory messages on edit page for messages.
onSidebarBeforeOutput( $skin, &$sidebar)
Adds toolbox menu item to pages, showing all other available translations for a message.
Provides minimal translation aids which integrate with the edit page and on diffs for translatable me...