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\Diff\Hook\ArticleContentOnDiffHook;
8use MediaWiki\EditPage\EditPage;
10use MediaWiki\Hook\AlternateEditHook;
11use MediaWiki\Hook\EditPage__showEditForm_initialHook;
12use MediaWiki\Hook\SidebarBeforeOutputHook;
13use MediaWiki\Hook\TitleGetEditNoticesHook;
14use MediaWiki\Languages\LanguageFactory;
15use MediaWiki\Skin\SkinComponentUtils;
16use OutputPage;
17use RequestContext;
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 // phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
55 public function onEditPage__showEditForm_initial( $editPage, $out ): void {
56 // phpcs:enable
57 $handle = new MessageHandle( $editPage->getTitle() );
58 if ( !$handle->isValid() ) {
59 return;
60 }
61
62 $context = $out->getContext();
63 $request = $context->getRequest();
64
65 if ( $editPage->firsttime && !$request->getCheck( 'oldid' ) &&
66 !$request->getCheck( 'undo' ) ) {
67 if ( $handle->isFuzzy() ) {
68 $editPage->textbox1 = MessageHandle::makeFuzzyString( $editPage->textbox1 );
69 }
70 }
71 }
72
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...