Translate extension for MediaWiki
Loading...
Searching...
No Matches
MessageGroups.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageGroupProcessing;
5
6use InvalidArgumentException;
7use MediaWiki\Extension\Translate\MessageGroups\AggregateMessageGroup;
8use MediaWiki\Extension\Translate\MessageGroups\MessageGroup;
9use MediaWiki\Extension\Translate\MessageGroups\RecentAdditionsMessageGroup;
10use MediaWiki\Extension\Translate\MessageGroups\RecentMessageGroup;
11use MediaWiki\Extension\Translate\MessageGroups\SandboxMessageGroup;
12use MediaWiki\Extension\Translate\MessageLoading\MessageHandle;
13use MediaWiki\Extension\Translate\MessageProcessing\StringMatcher;
14use MediaWiki\Extension\Translate\Services;
15use MediaWiki\Extension\Translate\Utilities\Utilities;
16use MediaWiki\MediaWikiServices;
17use MediaWiki\Title\Title;
18use RuntimeException;
19use Wikimedia\ObjectCache\WANObjectCache;
20
33 private $groups;
35 private $groupLoaders;
36 private WANObjectCache $cache;
43 private const CACHE_VERSION = 4;
44
46 protected function init(): void {
47 if ( is_array( $this->groups ) ) {
48 return; // groups already initialized
49 }
50
51 $groups = [];
52 foreach ( $this->getGroupLoaders() as $loader ) {
53 $groups += $loader->getGroups();
54 }
55 $this->initGroupsFromDefinitions( $groups );
56 }
57
63 protected function initGroupsFromDefinitions( array $groups ): void {
64 foreach ( $groups as $id => $mixed ) {
65 if ( !is_object( $mixed ) ) {
66 $groups[$id] = $mixed( $id );
67 }
68 }
69
70 $this->groups = $groups;
71 }
72
74 public function recache(): void {
75 $cache = $this->getCache();
76 $cache->touchCheckKey( $this->getCacheKey() );
77
78 $groups = [];
79 foreach ( $this->getGroupLoaders() as $loader ) {
80 if ( $loader instanceof CachedMessageGroupLoader ) {
81 $groups += $loader->recache();
82 } else {
83 $groups += $loader->getGroups();
84 }
85 }
86 $this->initGroupsFromDefinitions( $groups );
87 }
88
95 public function clearProcessCache(): void {
96 $this->groups = null;
97 $this->groupLoaders = null;
98 }
99
100 protected function getCache(): WANObjectCache {
101 return $this->cache ?? MediaWikiServices::getInstance()->getMainWANObjectCache();
102 }
103
105 public function setCache( WANObjectCache $cache ) {
106 $this->cache = $cache;
107 }
108
110 public function getCacheKey(): string {
111 return $this->getCache()->makeKey( 'translate-groups', 'v' . self::CACHE_VERSION );
112 }
113
119 protected function getGroupLoaders(): array {
120 if ( $this->groupLoaders !== null ) {
121 return $this->groupLoaders;
122 }
123
124 $services = Services::getInstance();
125 $cache = $this->getCache();
126 $dbProvider = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
127
128 $groupLoaderInstances = $this->groupLoaders = [];
129
130 // Initialize the dependencies
131 $deps = [
132 'database' => Utilities::getSafeReadDB(),
133 'cache' => $cache
134 ];
135
136 $services->getHookRunner()->onTranslateInitGroupLoaders( $groupLoaderInstances, $deps );
137
138 foreach ( $groupLoaderInstances as $loader ) {
139 if ( !$loader instanceof MessageGroupLoader ) {
140 throw new InvalidArgumentException(
141 "MessageGroupLoader - $loader must implement the " .
142 'MessageGroupLoader interface.'
143 );
144 }
145
146 $this->groupLoaders[] = $loader;
147 }
148
149 $factories = [
150 $services->getAggregateGroupMessageGroupFactory(),
151 $services->getFileBasedMessageGroupFactory(),
152 $services->getHookDefinedMessageGroupFactory(),
153 $services->getMessageBundleMessageGroupFactory(),
154 $services->getTranslatablePageMessageGroupFactory()
155 ];
156
157 foreach ( $factories as $factory ) {
158 $this->groupLoaders[] = new CachedMessageGroupFactoryLoader(
159 $cache,
160 $dbProvider,
161 $factory
162 );
163 }
164
165 // TODO: To decide if we should load this like we load other message group factories.
166 // See Ie95f25e18816f48d1d663ae392ecf5f9bbcf0b56 for related discussion
167 $this->groupLoaders[] = $services->getWorkflowStatesMessageGroupLoader();
168
169 return $this->groupLoaders;
170 }
171
178 public static function getGroup( string $id ): ?MessageGroup {
179 $groups = self::singleton()->getGroups();
180 $id = self::normalizeId( $id );
181
182 if ( isset( $groups[$id] ) ) {
183 return $groups[$id];
184 }
185
186 if ( str_starts_with( $id, '!' ) ) {
187 $dynamic = self::getDynamicGroups();
188 if ( isset( $dynamic[$id] ) ) {
189 return new $dynamic[$id];
190 }
191 }
192
193 return null;
194 }
195
197 public static function normalizeId( ?string $id ): string {
198 /* Translatable pages use spaces, but MW occasionally likes to
199 * normalize spaces to underscores */
200 $id = (string)$id;
201
202 if ( str_starts_with( $id, 'page-' ) ) {
203 $id = strtr( $id, '_', ' ' );
204 }
205
206 global $wgTranslateGroupAliases;
207 if ( isset( $wgTranslateGroupAliases[$id] ) ) {
208 $id = $wgTranslateGroupAliases[$id];
209 }
210
211 return $id;
212 }
213
214 public static function exists( string $id ): bool {
215 return (bool)self::getGroup( $id );
216 }
217
219 public static function labelExists( string $name ): bool {
220 $groups = self::getAllGroups();
221 foreach ( $groups as $group ) {
222 if ( $group instanceof AggregateMessageGroup ) {
223 if ( $group->getLabel() === $name ) {
224 return true;
225 }
226 }
227
228 }
229
230 return false;
231 }
232
237 public static function getAllGroups(): array {
238 return self::singleton()->getGroups();
239 }
240
248 public static function getPriority( MessageGroup|string $group ): string {
249 if ( $group instanceof MessageGroup ) {
250 $id = $group->getId();
251 } else {
252 $id = self::normalizeId( $group );
253 }
254
255 return Services::getInstance()->getMessageGroupReviewStore()->getGroupPriority( $id ) ?? '';
256 }
257
264 public static function setPriority( MessageGroup|string $group, string $priority = '' ): void {
265 if ( $group instanceof MessageGroup ) {
266 $id = $group->getId();
267 } else {
268 $id = self::normalizeId( $group );
269 }
270
271 $priority = $priority === '' ? null : $priority;
272 Services::getInstance()->getMessageGroupReviewStore()->setGroupPriority( $id, $priority );
273 }
274
275 public static function isDynamic( MessageGroup $group ): bool {
276 $id = $group->getId();
277
278 return ( $id[0] ?? null ) === '!';
279 }
280
287 public static function getSharedGroups( MessageGroup $group ): array {
288 // Take the first message, get a handle for it and check
289 // if that message belongs to other groups. Those are the
290 // parent aggregate groups. Ideally we loop over all keys,
291 // but this should be enough.
292 $keys = array_keys( $group->getDefinitions() );
293 $title = Title::makeTitle( $group->getNamespace(), $keys[0] );
294 $handle = new MessageHandle( $title );
295 $ids = $handle->getGroupIds();
296 foreach ( $ids as $index => $id ) {
297 if ( $id === $group->getId() ) {
298 unset( $ids[$index] );
299 break;
300 }
301 }
302
303 return $ids;
304 }
305
312 public static function getParentGroups( MessageGroup $targetGroup ): array {
313 $ids = self::getSharedGroups( $targetGroup );
314 if ( $ids === [] ) {
315 return [];
316 }
317
318 $targetId = $targetGroup->getId();
319
320 /* Get the group structure. We will be using this to find which
321 * of our candidates are top-level groups. Prefilter it to only
322 * contain aggregate groups. */
323 $structure = self::getGroupStructure();
324 foreach ( $structure as $index => $group ) {
325 if ( $group instanceof MessageGroup ) {
326 unset( $structure[$index] );
327 } else {
328 $structure[$index] = array_shift( $group );
329 }
330 }
331
332 /* Now that we have all related groups, use them to find all paths
333 * from top-level groups to target group with any number of subgroups
334 * in between. */
335 $paths = [];
336
337 /* This function recursively finds paths to the target group */
338 $pathFinder = static function ( &$paths, $group, $targetId, $prefix = '' )
339 use ( &$pathFinder ) {
340 if ( $group instanceof AggregateMessageGroup ) {
341 foreach ( $group->getGroups() as $subgroup ) {
342 $subId = $subgroup->getId();
343 if ( $subId === $targetId ) {
344 $paths[] = $prefix;
345 continue;
346 }
347
348 $pathFinder( $paths, $subgroup, $targetId, "$prefix|$subId" );
349 }
350 }
351 };
352
353 // Iterate over the top-level groups only
354 foreach ( $ids as $id ) {
355 // First, find a top level groups
356 $group = self::getGroup( $id );
357
358 // Quick escape for leaf groups
359 if ( !$group instanceof AggregateMessageGroup ) {
360 continue;
361 }
362
363 foreach ( $structure as $rootGroup ) {
365 if ( $rootGroup->getId() === $group->getId() ) {
366 // Yay we found a top-level group
367 $pathFinder( $paths, $rootGroup, $targetId, $id );
368 break; // No we have one or more paths appended into $paths
369 }
370 }
371 }
372
373 // And finally explode the strings
374 return array_map( static function ( string $pathString ): array {
375 return explode( '|', $pathString );
376 }, $paths );
377 }
378
379 public static function singleton(): self {
380 static $instance;
381 if ( !$instance instanceof self ) {
382 $instance = new self();
383 }
384
385 return $instance;
386 }
387
393 public function getGroups(): array {
394 $this->init();
395
396 return $this->groups;
397 }
398
407 public static function getGroupsById( array $ids, bool $skipMeta = false ): array {
408 $groups = [];
409 foreach ( $ids as $id ) {
410 $group = self::getGroup( $id );
411
412 if ( $group !== null ) {
413 if ( $skipMeta && $group->isMeta() ) {
414 continue;
415 } else {
416 $groups[$id] = $group;
417 }
418 } else {
419 wfDebug( __METHOD__ . ": Invalid message group id: $id\n" );
420 }
421 }
422
423 return $groups;
424 }
425
433 public static function expandWildcards( $ids ): array {
434 $all = [];
435
436 $ids = (array)$ids;
437 foreach ( $ids as $index => $id ) {
438 // Fast path, no wildcards
439 if ( strcspn( $id, '*?' ) === strlen( $id ) ) {
440 $g = self::getGroup( $id );
441 if ( $g ) {
442 $all[] = $g->getId();
443 }
444 unset( $ids[$index] );
445 }
446 }
447
448 if ( $ids === [] ) {
449 return $all;
450 }
451
452 // Slow path for the ones with wildcards
453 $matcher = new StringMatcher( '', $ids );
454 foreach ( self::getAllGroups() as $id => $_ ) {
455 if ( $matcher->matches( $id ) ) {
456 $all[] = $id;
457 }
458 }
459
460 return $all;
461 }
462
468 public static function getDynamicGroups(): array {
469 return [
470 '!recent' => RecentMessageGroup::class,
471 '!additions' => RecentAdditionsMessageGroup::class,
472 '!sandbox' => SandboxMessageGroup::class,
473 ];
474 }
475
483 public static function getGroupsByType( string $type ): array {
484 $groups = self::getAllGroups();
485 foreach ( $groups as $id => $group ) {
486 if ( !$group instanceof $type ) {
487 unset( $groups[$id] );
488 }
489 }
490
491 // @phan-suppress-next-line PhanTypeMismatchReturn
492 return $groups;
493 }
494
504 public static function getGroupStructure(): array {
505 $groups = self::getAllGroups();
506
507 // Determine the top level groups of the tree
508 $tree = $groups;
509 foreach ( $groups as $id => $o ) {
510 if ( !$o->exists() ) {
511 unset( $groups[$id], $tree[$id] );
512 continue;
513 }
514
515 if ( $o instanceof AggregateMessageGroup ) {
516 foreach ( $o->getGroups() as $sid => $so ) {
517 unset( $tree[$sid] );
518 }
519 }
520 }
521
522 uasort( $tree, [ self::class, 'groupLabelSort' ] );
523
524 /* Now we have two things left in $tree array:
525 * - solitaries: top-level non-aggregate message groups
526 * - top-level aggregate message groups */
527 foreach ( $tree as $index => $group ) {
528 if ( $group instanceof AggregateMessageGroup ) {
529 $tree[$index] = self::subGroups( $group );
530 }
531 }
532
533 /* Essentially we are done now. Cyclic groups can cause part of the
534 * groups not be included at all, because they have all unset each
535 * other in the first loop. So now we check if there are groups left
536 * over. */
537 $used = [];
538 array_walk_recursive(
539 $tree,
540 static function ( MessageGroup $group ) use ( &$used ) {
541 $used[$group->getId()] = true;
542 }
543 );
544 $unused = array_diff_key( $groups, $used );
545 if ( $unused ) {
546 foreach ( $unused as $index => $group ) {
547 if ( !$group instanceof AggregateMessageGroup ) {
548 unset( $unused[$index] );
549 }
550 }
551
552 // Only list the aggregate groups, other groups cannot cause cycles
553 $participants = implode( ', ', array_keys( $unused ) );
554 throw new RuntimeException( "Found cyclic aggregate message groups: $participants" );
555 }
556
557 return $tree;
558 }
559
561 public static function groupLabelSort( MessageGroup $a, MessageGroup $b ): int {
562 $al = $a->getLabel();
563 $bl = $b->getLabel();
564
565 return strcasecmp( $al, $bl );
566 }
567
579 public static function subGroups(
580 AggregateMessageGroup $parent,
581 array &$childIds = [],
582 string $fname = 'caller'
583 ): array {
584 static $recursionGuard = [];
585
586 $pid = $parent->getId();
587 if ( isset( $recursionGuard[$pid] ) ) {
588 $tid = $pid;
589 $path = [ $tid ];
590 do {
591 $tid = $recursionGuard[$tid];
592 $path[] = $tid;
593 // Until we have gone full cycle
594 } while ( $tid !== $pid );
595 $path = implode( ' > ', $path );
596 throw new RuntimeException( "Found cyclic aggregate message groups: $path" );
597 }
598
599 // We don't care about the ids.
600 $tree = array_values( $parent->getGroups() );
601 usort( $tree, [ self::class, 'groupLabelSort' ] );
602 // Expand aggregate groups (if any left) after sorting to form a tree
603 foreach ( $tree as $index => $group ) {
604 if ( $group instanceof AggregateMessageGroup ) {
605 $sid = $group->getId();
606 $recursionGuard[$pid] = $sid;
607 $tree[$index] = self::subGroups( $group, $childIds, __METHOD__ );
608 unset( $recursionGuard[$pid] );
609
610 $childIds[$sid] = 1;
611 }
612 }
613
614 // Parent group must be first item in the array
615 array_unshift( $tree, $parent );
616
617 if ( $fname !== __METHOD__ ) {
618 // Move the IDs from the keys to the value for final return
619 $childIds = array_values( $childIds );
620 }
621
622 return $tree;
623 }
624
630 public static function haveSingleSourceLanguage( array $groups ): string {
631 $seen = '';
632
633 foreach ( $groups as $group ) {
634 $language = $group->getSourceLanguage();
635 if ( $seen === '' ) {
636 $seen = $language;
637 } elseif ( $language !== $seen ) {
638 return '';
639 }
640 }
641
642 return $seen;
643 }
644
653 public static function isTranslatableMessage( MessageHandle $handle, string $targetLanguage ): bool {
654 static $cache = [];
655
656 if ( !$handle->isValid() ) {
657 return false;
658 }
659
660 $group = $handle->getGroup();
661 $groupId = $group->getId();
662 $cacheKey = "$groupId:$targetLanguage";
663
664 if ( !isset( $cache[$cacheKey] ) ) {
665 $supportedLanguages = Utilities::getLanguageNames( 'en' );
666 $inclusionList = $group->getTranslatableLanguages() ?? $supportedLanguages;
667
668 $included = isset( $inclusionList[$targetLanguage] );
669 $excluded = Services::getInstance()->getMessageGroupMetadata()->isExcluded( $groupId, $targetLanguage );
670
671 $cache[$cacheKey] = [
672 'relevant' => $included && !$excluded,
673 'tags' => [],
674 ];
675
676 $groupTags = $group->getTags();
677 foreach ( [ 'ignored', 'optional' ] as $tag ) {
678 if ( isset( $groupTags[$tag] ) ) {
679 foreach ( $groupTags[$tag] as $key ) {
680 // TODO: ucfirst should not be here
681 $cache[$cacheKey]['tags'][ucfirst( $key )] = true;
682 }
683 }
684 }
685 }
686
687 return $cache[$cacheKey]['relevant'] &&
688 !isset( $cache[$cacheKey]['tags'][ucfirst( $handle->getKey() )] );
689 }
690
692 public function overrideGroupsForTesting( array $groups ): void {
693 $this->groups = $groups;
694 }
695}
696
698class_alias( MessageGroups::class, 'MessageGroups' );
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'), $services->get( 'Translate:MessageGroupFactory'),);}, '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(), $services->get( 'Translate:MessageGroupFactory'), $services->getContentLanguageCode() ->toString(), 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:MessageGroupFactory'=> static function(MediaWikiServices $services):MessageGroupFactory { return new MessageGroupFactory($services->get( 'Translate:MessageGroupTypeRegistry'));}, '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(), $services->getNotificationService(), LoggerFactory::getInstance(LogNames::GROUP_SUBSCRIPTION), new ServiceOptions(MessageGroupSubscription::CONSTRUCTOR_OPTIONS, $services->getMainConfig()));}, 'Translate:MessageGroupSubscriptionHookHandler'=> static function(MediaWikiServices $services):?MessageGroupSubscriptionHookHandler { if(! $services->getExtensionRegistry() ->isLoaded( 'Echo')) { return null;} return new MessageGroupSubscriptionHookHandler();}, 'Translate:MessageGroupSubscriptionStore'=> static function(MediaWikiServices $services):MessageGroupSubscriptionStore { return new MessageGroupSubscriptionStore( $services->getConnectionProvider());}, 'Translate:MessageGroupTypeRegistry'=> static function():MessageGroupTypeRegistry { return new MessageGroupTypeRegistry();}, '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(), $services->get( 'Translate:HookRunner'),);}, '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->getConnectionProvider());}, 'Translate:TranslatorActivity'=> static function(MediaWikiServices $services):TranslatorActivity { $query=new TranslatorActivityQuery($services->getMainConfig(), $services->getConnectionProvider());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);}, 'Translate:WorkflowStatesMessageGroupLoader'=> static function(MediaWikiServices $services):WorkflowStatesMessageGroupLoader { return new WorkflowStatesMessageGroupLoader(new ServiceOptions(WorkflowStatesMessageGroupLoader::CONSTRUCTOR_OPTIONS, $services->getMainConfig()),);},]
@phpcs-require-sorted-array
Factory class for accessing message groups individually by id or all of them as a list.
static getGroup(string $id)
Fetch a message group by id.
static getDynamicGroups()
Contents on these groups changes on a whim.
static getGroupsByType(string $type)
Get only groups of specific type (class).
static getSharedGroups(MessageGroup $group)
Returns a list of message groups that share (certain) messages with this group.
static getGroupsById(array $ids, bool $skipMeta=false)
Get message groups for corresponding message group ids.
static isTranslatableMessage(MessageHandle $handle, string $targetLanguage)
Filters out messages that should not be translated under normal conditions.
static getGroupStructure()
Returns a tree of message groups.
static normalizeId(?string $id)
Fixes the id and resolves aliases.
setCache(WANObjectCache $cache)
Override cache, for example during tests.
getGroups()
Get all enabled non-dynamic message groups.
static subGroups(AggregateMessageGroup $parent, array &$childIds=[], string $fname='caller')
Like getGroupStructure but start from one root which must be an AggregateMessageGroup.
static setPriority(MessageGroup|string $group, string $priority='')
Sets the message group priority.
static haveSingleSourceLanguage(array $groups)
Checks whether all the message groups have the same source language.
static labelExists(string $name)
Check if a particular aggregate group label exists.
static expandWildcards( $ids)
If the list of message group ids contains wildcards, this function will match them against the list o...
static getPriority(MessageGroup|string $group)
We want to de-emphasize time sensitive groups like news for 2009.
static groupLabelSort(MessageGroup $a, MessageGroup $b)
Sorts groups by label value.
initGroupsFromDefinitions(array $groups)
Expand process cached groups to objects.
recache()
Clear message group caches and populate message groups from uncached data.
static getParentGroups(MessageGroup $targetGroup)
Returns a list of parent message groups.
Groups multiple message groups together as one group.
getGroups()
Returns a list of message groups that this group consists of.
Class for pointing to messages, like Title class is for titles.
getKey()
Returns the identified or guessed message key.
getGroup()
Get the primary MessageGroup this message belongs to.
isValid()
Checks if the handle corresponds to a known message.
getNamespace()
Returns the namespace where messages are placed.
getId()
Returns the unique identifier for this group.
getLabel(?IContextSource $context=null)
Returns the human readable label (as plain text).