Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MessageTable | |
0.00% |
0 / 45 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
fullTable | |
0.00% |
0 / 40 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\TranslatorInterface; |
5 | |
6 | use ContextSource; |
7 | use IContextSource; |
8 | use MediaWiki\Extension\Translate\Services; |
9 | use MediaWiki\Html\Html; |
10 | use MediaWiki\MediaWikiServices; |
11 | use MessageGroup; |
12 | |
13 | /** |
14 | * Display messages for translation & review |
15 | * @author Niklas Laxström |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | class MessageTable extends ContextSource { |
19 | protected $group; |
20 | protected $language; |
21 | |
22 | public function __construct( IContextSource $context, MessageGroup $group, string $language ) { |
23 | $this->setContext( $context ); |
24 | $this->group = $group; |
25 | if ( MediaWikiServices::getInstance()->getLanguageNameUtils()->isKnownLanguageTag( $language ) ) { |
26 | $this->language = $language; |
27 | } else { |
28 | $this->language = $context->getLanguage()->getCode(); |
29 | } |
30 | } |
31 | |
32 | public function fullTable(): string { |
33 | $modules = []; |
34 | Services::getInstance()->getHookRunner()->onTranslateBeforeAddModules( $modules ); |
35 | $this->getOutput()->addModules( $modules ); |
36 | |
37 | $languageFactory = MediaWikiServices::getInstance()->getLanguageFactory(); |
38 | $sourceLang = $languageFactory->getLanguage( $this->group->getSourceLanguage() ); |
39 | $targetLang = $languageFactory->getLanguage( $this->language ); |
40 | $batchSize = 100; |
41 | |
42 | $list = Html::element( 'div', [ |
43 | 'class' => 'row tux-messagelist', |
44 | 'data-grouptype' => get_class( $this->group ), |
45 | 'data-sourcelangcode' => $sourceLang->getCode(), |
46 | 'data-sourcelangdir' => $sourceLang->getDir(), |
47 | 'data-targetlangcode' => $targetLang->getCode(), |
48 | 'data-targetlangdir' => $targetLang->getDir(), |
49 | ] ); |
50 | |
51 | $groupId = htmlspecialchars( $this->group->getId() ); |
52 | $msg = $this->msg( 'tux-messagetable-loading-messages' ) |
53 | ->numParams( $batchSize ) |
54 | ->escaped(); |
55 | |
56 | $loader = |
57 | <<<HTML |
58 | <div class="tux-messagetable-loader hide" data-messagegroup="$groupId" data-pagesize="$batchSize"> |
59 | <span class="tux-loading-indicator"></span> |
60 | <div class="tux-messagetable-loader-info">$msg</div> |
61 | </div> |
62 | HTML; |
63 | |
64 | $hideOwn = $this->msg( 'tux-editor-proofreading-hide-own-translations' )->escaped(); |
65 | $clearTranslated = $this->msg( 'tux-editor-clear-translated' )->escaped(); |
66 | $modeTranslate = $this->msg( 'tux-editor-translate-mode' )->escaped(); |
67 | $modePage = $this->msg( 'tux-editor-page-mode' )->escaped(); |
68 | $modeProofread = $this->msg( 'tux-editor-proofreading-mode' )->escaped(); |
69 | |
70 | $actionbar = |
71 | <<<HTML |
72 | <div class="tux-action-bar hide row"> |
73 | <div class="three columns tux-message-list-statsbar" data-messagegroup="$groupId"></div> |
74 | <div class="three columns text-center"> |
75 | <button class="toggle button tux-proofread-own-translations-button hide"> |
76 | $hideOwn |
77 | </button> |
78 | <button class="toggle button tux-editor-clear-translated hide">$clearTranslated</button> |
79 | </div> |
80 | <div class="six columns tux-view-switcher text-center"> |
81 | <button class="toggle down translate-mode-button">$modeTranslate |
82 | </button><button class="toggle down page-mode-button">$modePage |
83 | </button><button class="toggle hide proofread-mode-button">$modeProofread |
84 | </button> |
85 | </div> |
86 | </div> |
87 | HTML; |
88 | |
89 | // Actual message table is fetched and rendered at client side. This just provides |
90 | // the loader and action bar. |
91 | return $list . $loader . $actionbar; |
92 | } |
93 | } |