Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialAutomaticTranslation | |
0.00% |
0 / 28 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getInitialLanguagesData | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace ContentTranslation\Special; |
6 | |
7 | use ContentTranslation\SiteMapper; |
8 | use MediaWiki\Html\TemplateParser; |
9 | use MediaWiki\Languages\LanguageNameUtils; |
10 | use MediaWiki\SpecialPage\SpecialPage; |
11 | |
12 | /** |
13 | * A special page for translating Wikipedia pages using MinT. |
14 | * |
15 | * This page provides the user the capability to search for an Wikipedia |
16 | * article in any language, and get the automatic (machine) translation for |
17 | * this article, by the MinT translation service. |
18 | * |
19 | * @author Nik Gkountas |
20 | * @license GPL-2.0-or-later |
21 | */ |
22 | class SpecialAutomaticTranslation extends SpecialPage { |
23 | |
24 | private LanguageNameUtils $languageNameUtils; |
25 | |
26 | public function __construct( LanguageNameUtils $languageNameUtils ) { |
27 | parent::__construct( 'AutomaticTranslation' ); |
28 | $this->languageNameUtils = $languageNameUtils; |
29 | } |
30 | |
31 | /** @inheritDoc */ |
32 | public function execute( $subPage ) { |
33 | parent::execute( $subPage ); |
34 | |
35 | $this->setHeaders(); |
36 | $out = $this->getOutput(); |
37 | $targetLanguageCode = SiteMapper::getCurrentLanguageCode(); |
38 | $targetLanguage = $this->languageNameUtils->getLanguageName( $targetLanguageCode ); |
39 | $out->addHTML( $this->getHtml( $targetLanguage ) ); |
40 | |
41 | $out->addModuleStyles( 'mint.styles' ); |
42 | $out->addModules( 'mint.app' ); |
43 | |
44 | // TODO: is there a way to get URL params in "getInitialLanguagesData" hook? |
45 | $out->addJsConfigVars( 'mintUrlSourceLanguageCode', $out->getRequest()->getVal( 'from' ) ); |
46 | $out->addJsConfigVars( 'mintUrlTargetLanguageCode', $out->getRequest()->getVal( 'to' ) ); |
47 | } |
48 | |
49 | /** |
50 | * Callback used to share MinT initial languages JS code |
51 | */ |
52 | public static function getInitialLanguagesData(): array { |
53 | return [ |
54 | 'mintInitialSourceLanguageCode' => 'all', |
55 | 'mintInitialTargetLanguageCode' => SiteMapper::getCurrentLanguageCode() |
56 | ]; |
57 | } |
58 | |
59 | private function getHtml( string $targetLanguage ): string { |
60 | $templateParser = new TemplateParser( __DIR__ . '/../templates/minT' ); |
61 | $data = [ |
62 | 'headerTitle' => $this->msg( 'mint-home-header-title' )->text(), |
63 | 'inputPlaceholder' => $this->msg( 'mint-home-input-placeholder' )->text(), |
64 | 'sourceLanguage' => $this->msg( 'mint-translation-list-all-languages-option-label' )->text(), |
65 | 'sourceLanguageCode' => 'all', |
66 | 'targetLanguage' => $targetLanguage, |
67 | 'infoPanelText' => $this->msg( 'mint-home-info-panel-text', $targetLanguage )->text(), |
68 | 'randomTopicButtonLabel' => $this->msg( 'mint-home-random-topic-button-label' )->text(), |
69 | ]; |
70 | |
71 | return $templateParser->processTemplate( 'Home', $data ); |
72 | } |
73 | |
74 | /** @inheritDoc */ |
75 | public function getDescription() { |
76 | return $this->msg( 'automatic-translation-special-page-description' ); |
77 | } |
78 | } |