Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialMinT | |
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 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 SpecialMinT extends SpecialPage { |
23 | |
24 | private LanguageNameUtils $languageNameUtils; |
25 | |
26 | public function __construct( LanguageNameUtils $languageNameUtils ) { |
27 | parent::__construct( 'MinT' ); |
28 | $this->languageNameUtils = $languageNameUtils; |
29 | } |
30 | |
31 | public function execute( $subPage ) { |
32 | parent::execute( $subPage ); |
33 | |
34 | $out = $this->getOutput(); |
35 | // Setting the page title to an empty string, leads to an empty title in the browser tab title. |
36 | // TODO: Check if this is acceptable and fix the page title if needed |
37 | $out->setPageTitle( '' ); |
38 | $targetLanguageCode = SiteMapper::getCurrentLanguageCode(); |
39 | $targetLanguage = $this->languageNameUtils->getLanguageName( $targetLanguageCode ); |
40 | $out->addHTML( $this->getHtml( $targetLanguage ) ); |
41 | |
42 | $out->addModuleStyles( "mint.styles" ); |
43 | $out->addModules( 'mint.app' ); |
44 | |
45 | // TODO: is there a way to get URL params in "getInitialLanguagesData" hook? |
46 | $out->addJsConfigVars( 'mintUrlSourceLanguageCode', $out->getRequest()->getVal( 'from' ) ); |
47 | $out->addJsConfigVars( 'mintUrlTargetLanguageCode', $out->getRequest()->getVal( 'to' ) ); |
48 | } |
49 | |
50 | /** |
51 | * Callback used to share MinT initial languages JS code |
52 | */ |
53 | public static function getInitialLanguagesData(): array { |
54 | return [ |
55 | 'mintInitialSourceLanguageCode' => 'all', |
56 | 'mintInitialTargetLanguageCode' => SiteMapper::getCurrentLanguageCode() |
57 | ]; |
58 | } |
59 | |
60 | private function getHtml( string $targetLanguage ): string { |
61 | $templateParser = new TemplateParser( __DIR__ . '/../templates/minT' ); |
62 | $data = [ |
63 | 'headerTitle' => $this->msg( 'mint-home-header-title' ), |
64 | 'inputPlaceholder' => $this->msg( 'mint-home-input-placeholder' ), |
65 | 'sourceLanguage' => $this->msg( 'mint-translation-list-all-languages-option-label' ), |
66 | 'sourceLanguageCode' => 'all', |
67 | 'targetLanguage' => $targetLanguage, |
68 | 'infoPanelText' => $this->msg( 'mint-home-info-panel-text', $targetLanguage ), |
69 | 'randomTopicButtonLabel' => $this->msg( 'mint-home-random-topic-button-label' ) |
70 | ]; |
71 | |
72 | return $templateParser->processTemplate( 'Home', $data ); |
73 | } |
74 | |
75 | public function getDescription() { |
76 | return $this->msg( 'mint' ); |
77 | } |
78 | } |