26 protected TitleValue $translate;
27 private LinkRenderer $linkRenderer;
29 private MessageLocalizer $messageLocalizer;
30 protected Language $language;
31 protected string $mainColumnHeader;
33 protected array $extraColumns = [];
36 public function __construct(
37 LinkRenderer $linkRenderer,
39 MessageLocalizer $messageLocalizer,
43 $this->translate = SpecialPage::getTitleValueFor(
'Translate' );
44 $this->linkRenderer = $linkRenderer;
45 $this->configHelper = $configHelper;
46 $this->messageLocalizer = $messageLocalizer;
47 $this->language = $language;
48 $this->messageGroupMetadata = $messageGroupMetadata;
58 public function element(
string $in,
string $bgcolor =
'',
string $sort =
'' ): string {
62 $attributes[
'data-sort-value'] = $sort;
66 $attributes[
'class'] =
'notheme skin-invert';
67 $attributes[
'style'] =
'background-color: #' . $bgcolor;
70 $element = Html::element(
'td', $attributes, $in );
76 public function getBackgroundColor(
float $percentage,
bool $fuzzy =
false ): string {
80 $index = min( 7, ceil( 50 * $percentage ) );
82 '',
'fedbd7',
'fecec8',
'fec1b9',
83 'fcb5ab',
'fba89d',
'f89b8f',
'f68d81'
85 return $colors[ $index ];
90 $index = (int)floor( $percentage * 10 );
92 'eaf3ff',
'e2ebfc',
'dae3fa',
'd2dbf7',
'c9d4f5',
93 'c1ccf2',
'b8c4ef',
'b1bced',
'a8b4ea',
'9fade8',
97 return $colors[ $index ];
100 private function getMainColumnHeader(): string {
101 return $this->mainColumnHeader;
104 public function setMainColumnHeader( Message $msg ): void {
105 $this->mainColumnHeader = $this->createColumnHeader( $msg );
109 private function createColumnHeader( Message $msg ): string {
110 return Html::element(
'th', [], $msg->text() );
113 public function addExtraColumn( Message $column ): void {
114 $this->extraColumns[] = $column;
118 private function getOtherColumnHeaders(): array {
120 $this->messageLocalizer->msg(
'translate-total' ),
121 $this->messageLocalizer->msg(
'translate-untranslated' ),
122 $this->messageLocalizer->msg(
'translate-percentage-complete' ),
123 $this->messageLocalizer->msg(
'translate-percentage-proofread' ),
124 $this->messageLocalizer->msg(
'translate-percentage-fuzzy' ),
125 ], $this->extraColumns );
131 $out = Html::openElement(
133 [
'class' =>
'statstable' ]
136 $out .=
"\n\t" . Html::openElement(
'thead' );
137 $out .=
"\n\t" . Html::openElement(
'tr' );
139 $out .=
"\n\t\t" . $this->getMainColumnHeader();
140 foreach ( $this->getOtherColumnHeaders() as $label ) {
141 $out .=
"\n\t\t" . $this->createColumnHeader( $label );
143 $out .=
"\n\t" . Html::closeElement(
'tr' );
144 $out .=
"\n\t" . Html::closeElement(
'thead' );
145 $out .=
"\n\t" . Html::openElement(
'tbody' );
156 public function makeTotalRow( Message $message, array $stats ): string {
157 $out =
"\t" . Html::openElement(
'tr' );
158 $out .=
"\n\t\t" . Html::element(
'td', [], $message->text() );
159 $out .= $this->makeNumberColumns( $stats );
160 $out .=
"\n\t" . Xml::closeElement(
'tr' ) .
"\n";
171 $translated = $stats[MessageGroupStats::TRANSLATED];
172 $fuzzy = $stats[MessageGroupStats::FUZZY];
173 $proofread = $stats[MessageGroupStats::PROOFREAD];
175 if ( $total ===
null ) {
176 $na =
"\n\t\t" . Html::element(
'td', [
'data-sort-value' => -1 ],
'...' );
177 $nap =
"\n\t\t" . $this->element(
'...',
'AFAFAF',
'-1' );
178 $out = $na . $na . $nap . $nap;
183 $out =
"\n\t\t" . Html::element(
'td',
184 [
'data-sort-value' => $total ],
185 $this->language->formatNum( $total ) );
187 $out .=
"\n\t\t" . Html::element(
'td',
188 [
'data-sort-value' => $total - $translated ],
189 $this->language->formatNum( $total - $translated ) );
191 if ( $total === 0 ) {
196 $transRatio = $translated / $total;
197 $fuzzyRatio = $fuzzy / $total;
198 $proofRatio = $translated ? $proofread / $translated : 0;
201 $out .=
"\n\t\t" . $this->element( $this->formatPercentage( $transRatio,
'floor' ),
202 $this->getBackgroundColor( $transRatio ),
203 sprintf(
'%1.5f', $transRatio ) );
205 $out .=
"\n\t\t" . $this->element( $this->formatPercentage( $proofRatio,
'floor' ),
206 $this->getBackgroundColor( $proofRatio ),
207 sprintf(
'%1.5f', $proofRatio ) );
209 $out .=
"\n\t\t" . $this->element( $this->formatPercentage( $fuzzyRatio,
'ceil' ),
210 $this->getBackgroundColor( $fuzzyRatio,
true ),
211 sprintf(
'%1.5f', $fuzzyRatio ) );
216 public function makeWorkflowStateCell( ?
string $state,
MessageGroup $group,
string $language ): string {
217 if ( $state === null || $group->getSourceLanguage() === $language ) {
218 return "\n\t\t" . $this->element(
'',
'',
'-1' );
221 $stateConfig = $group->getMessageGroupStates()->getStates();
224 if ( isset( $stateConfig[$state] ) ) {
225 $sortIndex = array_flip( array_keys( $stateConfig ) );
226 $sortValue = $sortIndex[$state] + 1;
228 if ( is_string( $stateConfig[$state] ) ) {
230 $stateColor = $stateConfig[$state];
231 } elseif ( isset( $stateConfig[$state][
'color'] ) ) {
232 $stateColor = $stateConfig[$state][
'color'];
236 $stateMessage = $this->messageLocalizer->msg(
"translate-workflow-state-$state" );
237 $stateText = $stateMessage->isBlank() ? $state : $stateMessage->text();
239 return "\n\t\t" . $this->element(
253 $num = $to ===
'floor' ? floor( 100 * $num ) : ceil( 100 * $num );
254 $fmt = $this->language->formatNum( $num );
256 return $this->messageLocalizer->msg(
'percent', $fmt )->text();
263 private function getGroupLabel(
MessageGroup $group ): string {
264 $groupLabel = htmlspecialchars( $group->getLabel() );
268 $groupLabel = Html::rawElement(
'b', [], $groupLabel );
282 $queryParameters = $params + [
283 'group' => $group->getId(),
287 return $this->linkRenderer->makeLink(
289 new HtmlArmor( $this->getGroupLabel( $group ) ),
303 $groupId = $group->
getId();
307 strtok( $groupId,
'-' ),
311 $disabledLanguages = $this->configHelper->getDisabledTargetLanguages();
313 foreach ( $checks as $check ) {
314 if ( isset( $disabledLanguages[$check] ) && isset( $disabledLanguages[$check][$code] ) ) {
315 $excluded = $disabledLanguages[$check][$code];
318 if ( $excluded !==
null ) {
324 if ( $languages !==
null && !isset( $languages[$code] ) ) {
328 if ( $this->messageGroupMetadata->isExcluded( $groupId, $code ) ) {
332 return (
bool)$excluded;
return[ 'Translate:AggregateGroupManager'=> static function(MediaWikiServices $services):AggregateGroupManager { return new AggregateGroupManager($services->getTitleFactory(), $services->get( 'Translate:MessageGroupMetadata'));}, 'Translate:AggregateGroupMessageGroupFactory'=> static function(MediaWikiServices $services):AggregateGroupMessageGroupFactory { return new AggregateGroupMessageGroupFactory($services->get( 'Translate:MessageGroupMetadata'));}, '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:ExternalMessageSourceStateComparator'=> static function(MediaWikiServices $services):ExternalMessageSourceStateComparator { return new ExternalMessageSourceStateComparator(new SimpleStringComparator(), $services->getRevisionLookup(), $services->getPageStore());}, 'Translate:ExternalMessageSourceStateImporter'=> static function(MediaWikiServices $services):ExternalMessageSourceStateImporter { return new ExternalMessageSourceStateImporter($services->get( 'Translate:GroupSynchronizationCache'), $services->getJobQueueGroup(), LoggerFactory::getInstance(LogNames::GROUP_SYNCHRONIZATION), $services->get( 'Translate:MessageIndex'), $services->getTitleFactory(), $services->get( 'Translate:MessageGroupSubscription'), new ServiceOptions(ExternalMessageSourceStateImporter::CONSTRUCTOR_OPTIONS, $services->getMainConfig()));}, 'Translate:FileBasedMessageGroupFactory'=> static function(MediaWikiServices $services):FileBasedMessageGroupFactory { return new FileBasedMessageGroupFactory(new MessageGroupConfigurationParser(), new ServiceOptions(FileBasedMessageGroupFactory::SERVICE_OPTIONS, $services->getMainConfig()),);}, 'Translate:FileFormatFactory'=> static function(MediaWikiServices $services):FileFormatFactory { return new FileFormatFactory( $services->getObjectFactory());}, 'Translate:GroupSynchronizationCache'=> static function(MediaWikiServices $services):GroupSynchronizationCache { return new GroupSynchronizationCache( $services->get( 'Translate:PersistentCache'));}, 'Translate:HookDefinedMessageGroupFactory'=> static function(MediaWikiServices $services):HookDefinedMessageGroupFactory { return new HookDefinedMessageGroupFactory( $services->get( 'Translate:HookRunner'));}, 'Translate:HookRunner'=> static function(MediaWikiServices $services):HookRunner { return new HookRunner( $services->getHookContainer());}, 'Translate:MessageBundleDependencyPurger'=> static function(MediaWikiServices $services):MessageBundleDependencyPurger { return new MessageBundleDependencyPurger( $services->get( 'Translate:TranslatableBundleFactory'));}, 'Translate:MessageBundleMessageGroupFactory'=> static function(MediaWikiServices $services):MessageBundleMessageGroupFactory { return new MessageBundleMessageGroupFactory($services->get( 'Translate:MessageGroupMetadata'), new ServiceOptions(MessageBundleMessageGroupFactory::SERVICE_OPTIONS, $services->getMainConfig()),);}, 'Translate:MessageBundleStore'=> static function(MediaWikiServices $services):MessageBundleStore { return new MessageBundleStore($services->get( 'Translate:RevTagStore'), $services->getJobQueueGroup(), $services->getLanguageNameUtils(), $services->get( 'Translate:MessageIndex'), $services->get( 'Translate:MessageGroupMetadata'));}, 'Translate:MessageBundleTranslationLoader'=> static function(MediaWikiServices $services):MessageBundleTranslationLoader { return new MessageBundleTranslationLoader( $services->getLanguageFallback());}, 'Translate:MessageGroupMetadata'=> static function(MediaWikiServices $services):MessageGroupMetadata { return new MessageGroupMetadata( $services->getConnectionProvider());}, 'Translate:MessageGroupReviewStore'=> static function(MediaWikiServices $services):MessageGroupReviewStore { return new MessageGroupReviewStore($services->getConnectionProvider(), $services->get( 'Translate:HookRunner'));}, 'Translate:MessageGroupStatsTableFactory'=> static function(MediaWikiServices $services):MessageGroupStatsTableFactory { return new MessageGroupStatsTableFactory($services->get( 'Translate:ProgressStatsTableFactory'), $services->getLinkRenderer(), $services->get( 'Translate:MessageGroupReviewStore'), $services->get( 'Translate:MessageGroupMetadata'), $services->getMainConfig() ->get( 'TranslateWorkflowStates') !==false);}, 'Translate:MessageGroupSubscription'=> static function(MediaWikiServices $services):MessageGroupSubscription { return new MessageGroupSubscription($services->get( 'Translate:MessageGroupSubscriptionStore'), $services->getJobQueueGroup(), $services->getUserIdentityLookup(), LoggerFactory::getInstance(LogNames::GROUP_SUBSCRIPTION), new ServiceOptions(MessageGroupSubscription::CONSTRUCTOR_OPTIONS, $services->getMainConfig()));}, 'Translate:MessageGroupSubscriptionHookHandler'=> static function(MediaWikiServices $services):MessageGroupSubscriptionHookHandler { return new MessageGroupSubscriptionHookHandler($services->get( 'Translate:MessageGroupSubscription'), $services->getUserFactory());}, 'Translate:MessageGroupSubscriptionStore'=> static function(MediaWikiServices $services):MessageGroupSubscriptionStore { return new MessageGroupSubscriptionStore( $services->getConnectionProvider());}, 'Translate:MessageIndex'=> static function(MediaWikiServices $services):MessageIndex { $params=(array) $services->getMainConfig() ->get( 'TranslateMessageIndex');$class=array_shift( $params);$implementationMap=['HashMessageIndex'=> HashMessageIndex::class, 'CDBMessageIndex'=> CDBMessageIndex::class, 'DatabaseMessageIndex'=> DatabaseMessageIndex::class, 'hash'=> HashMessageIndex::class, 'cdb'=> CDBMessageIndex::class, 'database'=> DatabaseMessageIndex::class,];$messageIndexStoreClass=$implementationMap[$class] ?? $implementationMap['database'];return new MessageIndex(new $messageIndexStoreClass, $services->getMainWANObjectCache(), $services->getJobQueueGroup(), $services->get( 'Translate:HookRunner'), LoggerFactory::getInstance(LogNames::MAIN), $services->getMainObjectStash(), $services->getConnectionProvider(), new ServiceOptions(MessageIndex::SERVICE_OPTIONS, $services->getMainConfig()),);}, 'Translate:MessagePrefixStats'=> static function(MediaWikiServices $services):MessagePrefixStats { return new MessagePrefixStats( $services->getTitleParser());}, 'Translate:ParsingPlaceholderFactory'=> static function():ParsingPlaceholderFactory { return new ParsingPlaceholderFactory();}, 'Translate:PersistentCache'=> static function(MediaWikiServices $services):PersistentCache { return new PersistentDatabaseCache($services->getConnectionProvider(), $services->getJsonCodec());}, 'Translate:ProgressStatsTableFactory'=> static function(MediaWikiServices $services):ProgressStatsTableFactory { return new ProgressStatsTableFactory($services->getLinkRenderer(), $services->get( 'Translate:ConfigHelper'), $services->get( 'Translate:MessageGroupMetadata'));}, 'Translate:RevTagStore'=> static function(MediaWikiServices $services):RevTagStore { return new RevTagStore( $services->getConnectionProvider());}, 'Translate:SubpageListBuilder'=> static function(MediaWikiServices $services):SubpageListBuilder { return new SubpageListBuilder($services->get( 'Translate:TranslatableBundleFactory'), $services->getLinkBatchFactory());}, 'Translate:TranslatableBundleDeleter'=> static function(MediaWikiServices $services):TranslatableBundleDeleter { return new TranslatableBundleDeleter($services->getMainObjectStash(), $services->getJobQueueGroup(), $services->get( 'Translate:SubpageListBuilder'), $services->get( 'Translate:TranslatableBundleFactory'));}, 'Translate:TranslatableBundleExporter'=> static function(MediaWikiServices $services):TranslatableBundleExporter { return new TranslatableBundleExporter($services->get( 'Translate:SubpageListBuilder'), $services->getWikiExporterFactory(), $services->getConnectionProvider());}, 'Translate:TranslatableBundleFactory'=> static function(MediaWikiServices $services):TranslatableBundleFactory { return new TranslatableBundleFactory($services->get( 'Translate:TranslatablePageStore'), $services->get( 'Translate:MessageBundleStore'));}, 'Translate:TranslatableBundleImporter'=> static function(MediaWikiServices $services):TranslatableBundleImporter { return new TranslatableBundleImporter($services->getWikiImporterFactory(), $services->get( 'Translate:TranslatablePageParser'), $services->getRevisionLookup(), $services->getNamespaceInfo(), $services->getTitleFactory(), $services->getFormatterFactory());}, '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->getConnectionProvider(), $services->getObjectCacheFactory(), $services->getMainConfig() ->get( 'TranslatePageMoveLimit'));}, 'Translate:TranslatableBundleStatusStore'=> static function(MediaWikiServices $services):TranslatableBundleStatusStore { return new TranslatableBundleStatusStore($services->getConnectionProvider() ->getPrimaryDatabase(), $services->getCollationFactory() ->makeCollation( 'uca-default-u-kn'), $services->getDBLoadBalancer() ->getMaintenanceConnectionRef(DB_PRIMARY));}, 'Translate:TranslatablePageMarker'=> static function(MediaWikiServices $services):TranslatablePageMarker { return new TranslatablePageMarker($services->getConnectionProvider(), $services->getJobQueueGroup(), $services->getLinkRenderer(), MessageGroups::singleton(), $services->get( 'Translate:MessageIndex'), $services->getTitleFormatter(), $services->getTitleParser(), $services->get( 'Translate:TranslatablePageParser'), $services->get( 'Translate:TranslatablePageStore'), $services->get( 'Translate:TranslatablePageStateStore'), $services->get( 'Translate:TranslationUnitStoreFactory'), $services->get( 'Translate:MessageGroupMetadata'), $services->getWikiPageFactory(), $services->get( 'Translate:TranslatablePageView'), $services->get( 'Translate:MessageGroupSubscription'), $services->getFormatterFactory());}, 'Translate:TranslatablePageMessageGroupFactory'=> static function(MediaWikiServices $services):TranslatablePageMessageGroupFactory { return new TranslatablePageMessageGroupFactory(new ServiceOptions(TranslatablePageMessageGroupFactory::SERVICE_OPTIONS, $services->getMainConfig()),);}, 'Translate:TranslatablePageParser'=> static function(MediaWikiServices $services):TranslatablePageParser { return new TranslatablePageParser($services->get( 'Translate:ParsingPlaceholderFactory'));}, 'Translate:TranslatablePageStateStore'=> static function(MediaWikiServices $services):TranslatablePageStateStore { return new TranslatablePageStateStore($services->get( 'Translate:PersistentCache'), $services->getPageStore());}, 'Translate:TranslatablePageStore'=> static function(MediaWikiServices $services):TranslatablePageStore { return new TranslatablePageStore($services->get( 'Translate:MessageIndex'), $services->getJobQueueGroup(), $services->get( 'Translate:RevTagStore'), $services->getConnectionProvider(), $services->get( 'Translate:TranslatableBundleStatusStore'), $services->get( 'Translate:TranslatablePageParser'), $services->get( 'Translate:MessageGroupMetadata'));}, 'Translate:TranslatablePageView'=> static function(MediaWikiServices $services):TranslatablePageView { return new TranslatablePageView($services->getConnectionProvider(), $services->get( 'Translate:TranslatablePageStateStore'), new ServiceOptions(TranslatablePageView::SERVICE_OPTIONS, $services->getMainConfig()));}, 'Translate:TranslateSandbox'=> static function(MediaWikiServices $services):TranslateSandbox { return new TranslateSandbox($services->getUserFactory(), $services->getConnectionProvider(), $services->getPermissionManager(), $services->getAuthManager(), $services->getUserGroupManager(), $services->getActorStore(), $services->getUserOptionsManager(), $services->getJobQueueGroup(), $services->get( 'Translate:HookRunner'), new ServiceOptions(TranslateSandbox::CONSTRUCTOR_OPTIONS, $services->getMainConfig()));}, 'Translate:TranslationStashReader'=> static function(MediaWikiServices $services):TranslationStashReader { return new TranslationStashStorage( $services->getConnectionProvider() ->getPrimaryDatabase());}, 'Translate:TranslationStatsDataProvider'=> static function(MediaWikiServices $services):TranslationStatsDataProvider { return new TranslationStatsDataProvider(new ServiceOptions(TranslationStatsDataProvider::CONSTRUCTOR_OPTIONS, $services->getMainConfig()), $services->getObjectFactory(), $services->getConnectionProvider());}, '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