31 private $linkRenderer;
33 private $configHelper;
35 private $messageLocalizer;
39 protected $mainColumnHeader;
41 protected $extraColumns = [];
43 public function __construct(
44 LinkRenderer $linkRenderer,
46 MessageLocalizer $messageLocalizer,
49 $this->translate = SpecialPage::getTitleValueFor(
'Translate' );
50 $this->linkRenderer = $linkRenderer;
51 $this->configHelper = $configHelper;
52 $this->messageLocalizer = $messageLocalizer;
53 $this->language = $language;
63 public function element(
string $in,
string $bgcolor =
'',
string $sort =
'' ): string {
67 $attributes[
'data-sort-value'] = $sort;
71 $attributes[
'style'] =
'background-color: #' . $bgcolor;
74 $element = Html::element(
'td', $attributes, $in );
79 public function getBackgroundColor(
float $percentage,
bool $fuzzy =
false ): string {
83 $index = min( 7, ceil( 50 * $percentage ) );
85 '',
'fedbd7',
'fecec8',
'fec1b9',
86 'fcb5ab',
'fba89d',
'f89b8f',
'f68d81'
88 return $colors[ $index ];
93 $index = floor( $percentage * 10 );
95 'eaf3ff',
'e2ebfc',
'dae3fa',
'd2dbf7',
'c9d4f5',
96 'c1ccf2',
'b8c4ef',
'b1bced',
'a8b4ea',
'9fade8',
100 return $colors[ $index ];
103 private function getMainColumnHeader(): string {
104 return $this->mainColumnHeader;
107 public function setMainColumnHeader( Message $msg ): void {
108 $this->mainColumnHeader = $this->createColumnHeader( $msg );
112 private function createColumnHeader( Message $msg ): string {
113 return Html::element(
'th', [], $msg->text() );
116 public function addExtraColumn( Message $column ): void {
117 $this->extraColumns[] = $column;
121 private function getOtherColumnHeaders(): array {
123 $this->messageLocalizer->msg(
'translate-total' ),
124 $this->messageLocalizer->msg(
'translate-untranslated' ),
125 $this->messageLocalizer->msg(
'translate-percentage-complete' ),
126 $this->messageLocalizer->msg(
'translate-percentage-proofread' ),
127 $this->messageLocalizer->msg(
'translate-percentage-fuzzy' ),
128 ], $this->extraColumns );
134 $out = Html::openElement(
136 [
'class' =>
'statstable' ]
139 $out .=
"\n\t" . Html::openElement(
'thead' );
140 $out .=
"\n\t" . Html::openElement(
'tr' );
142 $out .=
"\n\t\t" . $this->getMainColumnHeader();
143 foreach ( $this->getOtherColumnHeaders() as $label ) {
144 $out .=
"\n\t\t" . $this->createColumnHeader( $label );
146 $out .=
"\n\t" . Html::closeElement(
'tr' );
147 $out .=
"\n\t" . Html::closeElement(
'thead' );
148 $out .=
"\n\t" . Html::openElement(
'tbody' );
159 public function makeTotalRow( Message $message, array $stats ): string {
160 $out =
"\t" . Html::openElement(
'tr' );
161 $out .=
"\n\t\t" . Html::element(
'td', [], $message->text() );
162 $out .= $this->makeNumberColumns( $stats );
163 $out .=
"\n\t" . Xml::closeElement(
'tr' ) .
"\n";
174 $translated = $stats[MessageGroupStats::TRANSLATED];
175 $fuzzy = $stats[MessageGroupStats::FUZZY];
176 $proofread = $stats[MessageGroupStats::PROOFREAD];
178 if ( $total ===
null ) {
179 $na =
"\n\t\t" . Html::element(
'td', [
'data-sort-value' => -1 ],
'...' );
180 $nap =
"\n\t\t" . $this->element(
'...',
'AFAFAF',
'-1' );
181 $out = $na . $na . $nap . $nap;
186 $out =
"\n\t\t" . Html::element(
'td',
187 [
'data-sort-value' => $total ],
188 $this->language->formatNum( $total ) );
190 $out .=
"\n\t\t" . Html::element(
'td',
191 [
'data-sort-value' => $total - $translated ],
192 $this->language->formatNum( $total - $translated ) );
194 if ( $total === 0 ) {
199 $transRatio = $translated / $total;
200 $fuzzyRatio = $fuzzy / $total;
201 $proofRatio = $translated === 0 ? 0 : $proofread / $translated;
204 $out .=
"\n\t\t" . $this->element( $this->formatPercentage( $transRatio,
'floor' ),
205 $this->getBackgroundColor( $transRatio ),
206 sprintf(
'%1.5f', $transRatio ) );
208 $out .=
"\n\t\t" . $this->element( $this->formatPercentage( $proofRatio,
'floor' ),
209 $this->getBackgroundColor( $proofRatio ),
210 sprintf(
'%1.5f', $proofRatio ) );
212 $out .=
"\n\t\t" . $this->element( $this->formatPercentage( $fuzzyRatio,
'ceil' ),
213 $this->getBackgroundColor( $fuzzyRatio,
true ),
214 sprintf(
'%1.5f', $fuzzyRatio ) );
219 public function makeWorkflowStateCell( ?
string $state,
MessageGroup $group,
string $language ): string {
220 if ( $state === null ) {
221 return "\n\t\t" . $this->element(
'',
'',
'-1' );
224 if ( $group->getSourceLanguage() === $language ) {
225 return "\n\t\t" . $this->element(
'',
'',
'-1' );
228 $stateConfig = $group->getMessageGroupStates()->getStates();
231 if ( isset( $stateConfig[$state] ) ) {
232 $sortIndex = array_flip( array_keys( $stateConfig ) );
233 $sortValue = $sortIndex[$state] + 1;
235 if ( is_string( $stateConfig[$state] ) ) {
237 $stateColor = $stateConfig[$state];
238 } elseif ( isset( $stateConfig[$state][
'color'] ) ) {
239 $stateColor = $stateConfig[$state][
'color'];
243 $stateMessage = $this->messageLocalizer->msg(
"translate-workflow-state-$state" );
244 $stateText = $stateMessage->isBlank() ? $state : $stateMessage->text();
246 return "\n\t\t" . $this->element(
260 $num = $to ===
'floor' ? floor( 100 * $num ) : ceil( 100 * $num );
261 $fmt = $this->language->formatNum( $num );
263 return $this->messageLocalizer->msg(
'percent', $fmt )->text();
270 private function getGroupLabel(
MessageGroup $group ): string {
271 $groupLabel = htmlspecialchars( $group->getLabel() );
275 $groupLabel = Html::rawElement(
'b', [], $groupLabel );
289 $queryParameters = $params + [
290 'group' => $group->getId(),
294 return $this->linkRenderer->makeLink(
296 new HtmlArmor( $this->getGroupLabel( $group ) ),
308 public function isExcluded(
string $groupId,
string $code ): bool {
313 strtok( $groupId,
'-' ),
317 $disabledLanguages = $this->configHelper->getDisabledTargetLanguages();
319 foreach ( $checks as $check ) {
320 if ( isset( $disabledLanguages[$check] ) && isset( $disabledLanguages[$check][$code] ) ) {
321 $excluded = $disabledLanguages[$check][$code];
324 if ( $excluded !==
null ) {
329 $group = MessageGroups::getGroup( $groupId );
331 if ( $languages !==
null && !isset( $languages[$code] ) ) {
335 if ( TranslateMetadata::isExcluded( $groupId, $code ) ) {
339 return (
bool)$excluded;
return[ 'Translate:ConfigHelper'=> static function():ConfigHelper { return new ConfigHelper();}, 'Translate:CsvTranslationImporter'=> static function(MediaWikiServices $services):CsvTranslationImporter { return new CsvTranslationImporter( $services->getWikiPageFactory());}, 'Translate:EntitySearch'=> static function(MediaWikiServices $services):EntitySearch { return new EntitySearch($services->getMainWANObjectCache(), $services->getCollationFactory() ->makeCollation( 'uca-default-u-kn'), MessageGroups::singleton(), $services->getNamespaceInfo(), $services->get( 'Translate:MessageIndex'), $services->getTitleParser(), $services->getTitleFormatter());}, 'Translate:ExternalMessageSourceStateImporter'=> static function(MediaWikiServices $services):ExternalMessageSourceStateImporter { return new ExternalMessageSourceStateImporter($services->getMainConfig(), $services->get( 'Translate:GroupSynchronizationCache'), $services->getJobQueueGroup(), LoggerFactory::getInstance( 'Translate.GroupSynchronization'), MessageIndex::singleton());}, 'Translate:GroupSynchronizationCache'=> static function(MediaWikiServices $services):GroupSynchronizationCache { return new GroupSynchronizationCache( $services->get( 'Translate:PersistentCache'));}, 'Translate:MessageBundleStore'=> static function(MediaWikiServices $services):MessageBundleStore { return new MessageBundleStore(new RevTagStore(), $services->getJobQueueGroup(), $services->getLanguageNameUtils(), $services->get( 'Translate:MessageIndex'));}, 'Translate:MessageGroupReview'=> static function(MediaWikiServices $services):MessageGroupReview { return new MessageGroupReview($services->getDBLoadBalancer(), $services->getHookContainer());}, 'Translate:MessageIndex'=> static function(MediaWikiServices $services):MessageIndex { $params=$services->getMainConfig() ->get( 'TranslateMessageIndex');if(is_string( $params)) { $params=(array) $params;} $class=array_shift( $params);return new $class( $params);}, 'Translate:ParsingPlaceholderFactory'=> static function():ParsingPlaceholderFactory { return new ParsingPlaceholderFactory();}, 'Translate:PersistentCache'=> static function(MediaWikiServices $services):PersistentCache { return new PersistentDatabaseCache($services->getDBLoadBalancer(), $services->getJsonCodec());}, 'Translate:ProgressStatsTableFactory'=> static function(MediaWikiServices $services):ProgressStatsTableFactory { return new ProgressStatsTableFactory($services->getLinkRenderer(), $services->get( 'Translate:ConfigHelper'));}, 'Translate:SubpageListBuilder'=> static function(MediaWikiServices $services):SubpageListBuilder { return new SubpageListBuilder($services->get( 'Translate:TranslatableBundleFactory'), $services->getLinkBatchFactory());}, 'Translate:TranslatableBundleFactory'=> static function(MediaWikiServices $services):TranslatableBundleFactory { return new TranslatableBundleFactory($services->get( 'Translate:TranslatablePageStore'), $services->get( 'Translate:MessageBundleStore'));}, 'Translate:TranslatableBundleMover'=> static function(MediaWikiServices $services):TranslatableBundleMover { return new TranslatableBundleMover($services->getMovePageFactory(), $services->getJobQueueGroup(), $services->getLinkBatchFactory(), $services->get( 'Translate:TranslatableBundleFactory'), $services->get( 'Translate:SubpageListBuilder'), $services->getMainConfig() ->get( 'TranslatePageMoveLimit'));}, 'Translate:TranslatablePageParser'=> static function(MediaWikiServices $services):TranslatablePageParser { return new TranslatablePageParser($services->get( 'Translate:ParsingPlaceholderFactory'));}, 'Translate:TranslatablePageStore'=> static function(MediaWikiServices $services):TranslatablePageStore { return new TranslatablePageStore($services->get( 'Translate:MessageIndex'), $services->getJobQueueGroup(), new RevTagStore(), $services->getDBLoadBalancer());}, 'Translate:TranslationStashReader'=> static function(MediaWikiServices $services):TranslationStashReader { $db=$services->getDBLoadBalancer() ->getConnectionRef(DB_REPLICA);return new TranslationStashStorage( $db);}, 'Translate:TranslationStatsDataProvider'=> static function(MediaWikiServices $services):TranslationStatsDataProvider { return new TranslationStatsDataProvider(new ServiceOptions(TranslationStatsDataProvider::CONSTRUCTOR_OPTIONS, $services->getMainConfig()), $services->getObjectFactory());}, 'Translate:TranslationUnitStoreFactory'=> static function(MediaWikiServices $services):TranslationUnitStoreFactory { return new TranslationUnitStoreFactory( $services->getDBLoadBalancer());}, 'Translate:TranslatorActivity'=> static function(MediaWikiServices $services):TranslatorActivity { $query=new TranslatorActivityQuery($services->getMainConfig(), $services->getDBLoadBalancer());return new TranslatorActivity($services->getMainObjectStash(), $query, $services->getJobQueueGroup());}, 'Translate:TtmServerFactory'=> static function(MediaWikiServices $services):TtmServerFactory { $config=$services->getMainConfig();$default=$config->get( 'TranslateTranslationDefaultService');if( $default===false) { $default=null;} return new TtmServerFactory( $config->get( 'TranslateTranslationServices'), $default);}]
@phpcs-require-sorted-array