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 EditPage;
8use MediaWiki\Diff\Hook\ArticleContentOnDiffHook;
9use MediaWiki\Hook\AlternateEditHook;
10use MediaWiki\Hook\EditPage__showEditForm_initialHook;
11use MediaWiki\Languages\LanguageFactory;
13use OutputPage;
14
21 implements AlternateEditHook, ArticleContentOnDiffHook, EditPage__showEditForm_initialHook
22{
24 private $languageFactory;
25
26 public function __construct( LanguageFactory $languageFactory ) {
27 $this->languageFactory = $languageFactory;
28 }
29
34 public function onAlternateEdit( $editPage ): void {
35 $handle = new MessageHandle( $editPage->getTitle() );
36 if ( $handle->isValid() ) {
37 $editPage->suppressIntro = true;
38 }
39 }
40
46 // phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
47 public function onEditPage__showEditForm_initial( $editPage, $out ): void {
48 // phpcs:enable
49 $handle = new MessageHandle( $editPage->getTitle() );
50 if ( !$handle->isValid() ) {
51 return;
52 }
53
54 $context = $out->getContext();
55 $request = $context->getRequest();
56
57 if ( $editPage->firsttime && !$request->getCheck( 'oldid' ) &&
58 !$request->getCheck( 'undo' ) ) {
59 if ( $handle->isFuzzy() ) {
60 $editPage->textbox1 = TRANSLATE_FUZZY . $editPage->textbox1;
61 }
62 }
63
64 $th = new LegacyTranslationAids( $handle, $context, $this->languageFactory );
65 $editPage->editFormTextTop .= $th->getBoxes();
66 }
67
73 public function onArticleContentOnDiff( $diffEngine, $output ): void {
74 $title = $diffEngine->getTitle();
75 $handle = new MessageHandle( $title );
76
77 if ( !$handle->isValid() ) {
78 return;
79 }
80
81 $th = new LegacyTranslationAids( $handle, $diffEngine->getContext(), $this->languageFactory );
82 $output->addHTML( $th->getBoxes() );
83 }
84}
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.
Provides minimal translation aids which integrate with the edit page and on diffs for translatable me...
Class for pointing to messages, like Title class is for titles.