40 public function __construct(
47 $this->groupId = $groupId;
49 $this->pageId = $pageId;
50 $this->revisionId = $revisionId;
51 $this->description = $description;
55 public static function getGroupId(
string $name ): string {
56 return "messagebundle-$name";
59 private function getData(): array {
61 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
62 $revision = $revisionStore->getRevisionById( $this->revisionId );
64 if ( $revision ===
null ) {
65 throw new LogicException(
"Could not find revision id $this->revisionId" );
68 $content = $revision->getContent( SlotRecord::MAIN );
69 if ( !$content instanceof MessageBundleContent ) {
70 throw new LogicException(
71 "Content with revision id $this->revisionId has wrong content format"
75 $data = json_decode( $content->getText(),
true );
77 throw new LogicException(
78 "Content with revision id $this->revisionId is not valid JSON"
88 private function prefixKeys( array $keys ): array {
90 foreach ( $keys as $key ) {
91 $result[] =
"$this->name/$key";
97 public function getId(): string {
102 public function getLabel( IContextSource $context =
null ): string {
108 $titleText = Title::newFromID( $this->pageId )->getPrefixedText();
109 $linkTargetText =
":$titleText";
111 $message = $context->msg(
'translate-messagebundle-group-description' );
113 $message = wfMessage(
'translate-messagebundle-group-description' )
114 ->inContentLanguage();
117 $plainMessage = $message->params( $titleText, $linkTargetText )->plain();
119 if ( $this->description ===
null ) {
120 return $plainMessage;
123 return $plainMessage .
' ' . $this->description;
159 $collection = MessageCollection::newFromDefinitions( $defs, $code );
161 foreach ( $this->getTags() as $type => $tags ) {
162 $collection->setTags( $type, $tags );
169 public function load( $code ): array {
175 $data = $this->getData();
176 unset( $data[
'@metadata'] );
178 return array_combine(
179 $this->prefixKeys( array_keys( $data ) ),
180 array_values( $data )
186 return array_keys( $this->getDefinitions() );
190 public function getTags( $type =
null ): array {
196 if ( $code === $this->getSourceLanguage() ) {
197 return $this->getData()[$key] ??
null;
205 return Title::newFromText( $this->name )->getPageLanguage()->getCode();
210 global $wgTranslateWorkflowStates;
211 $conf = $wgTranslateWorkflowStates ?: [];
213 MediaWikiHooks::run(
'Translate:modifyMessageGroupStates', [ $this->getId(), &$conf ] );
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