30 public function __construct(
37 parent::__construct( $query, $moduleName,
'mg' );
38 $this->hookRunner = $hookRunner;
39 $this->messageGroupMetadata = $messageGroupMetadata;
40 $this->groupSubscription = $groupSubscription;
43 public function execute():
void {
44 $params = $this->extractRequestParams();
45 $filter = $params[
'filter'];
48 $props = array_flip( $params[
'prop'] );
50 $needsMetadata = isset( $props[
'prioritylangs'] ) || isset( $props[
'priorityforce'] );
52 if ( $params[
'format'] ===
'flat' ) {
53 if ( $params[
'root'] !==
'' ) {
56 $groups[$params[
'root']] = $group;
60 usort( $groups, [ MessageGroups::class,
'groupLabelSort' ] );
62 } elseif ( $params[
'root'] !==
'' ) {
69 array_shift( $groups );
75 if ( $params[
'root'] ===
'' ) {
81 $groups = $dynamicGroups + $groups;
83 '@phan-var (MessageGroup|array)[] $groups';
87 if ( isset( $groups[
'!sandbox'] ) ) {
88 unset( $groups[
'!sandbox'] );
91 $result = $this->getResult();
94 foreach ( $groups as $index => $mixed ) {
96 $group = is_array( $mixed ) ? reset( $mixed ) : $mixed;
97 if ( $filter !== [] && !$matcher->matches( $group->getId() ) ) {
98 unset( $groups[$index] );
103 $params[
'languageFilter'] !==
'' &&
104 $this->messageGroupMetadata->isExcluded( $group->getId(), $params[
'languageFilter'] )
106 unset( $groups[$index] );
110 if ( $needsMetadata && $groups ) {
112 $this->messageGroupMetadata->preloadGroups( array_keys( $groups ), __METHOD__ );
116 foreach ( $groups as $index => $mixed ) {
119 $result->setIndexedTagName( $a,
'group' );
122 $fit = $result->addValue( [
'query', $this->getModuleName() ],
null, $a );
130 $result->addIndexedTagName( [
'query', $this->getModuleName() ],
'group' );
138 protected function formatGroup( $mixed, array $props,
int $depth = 0 ): array {
139 $params = $this->extractRequestParams();
140 $context = $this->getContext();
147 if ( is_array( $mixed ) ) {
148 $g = array_shift( $mixed );
154 $groupId = $g->getId();
156 if ( isset( $props[
'id'] ) ) {
160 if ( isset( $props[
'label'] ) ) {
161 $a[
'label'] = $g->getLabel( $context );
164 if ( isset( $props[
'description'] ) ) {
165 $a[
'description'] = $g->getDescription( $context );
168 if ( isset( $props[
'class'] ) ) {
169 $a[
'class'] = get_class( $g );
172 if ( isset( $props[
'namespace'] ) ) {
173 $a[
'namespace'] = $g->getNamespace();
176 if ( isset( $props[
'exists'] ) ) {
177 $a[
'exists'] = $g->exists();
180 if ( isset( $props[
'icon'] ) ) {
181 $formats = Utilities::getIcon( $g, $params[
'iconsize'] );
183 $a[
'icon'] = $formats;
187 if ( isset( $props[
'priority'] ) ) {
189 $a[
'priority'] = $priority ?:
'default';
192 if ( isset( $props[
'prioritylangs'] ) ) {
193 $prioritylangs = $this->messageGroupMetadata->get( $groupId,
'prioritylangs' );
194 $a[
'prioritylangs'] = $prioritylangs ? explode(
',', $prioritylangs ) : false;
197 if ( isset( $props[
'priorityforce'] ) ) {
198 $a[
'priorityforce'] = ( $this->messageGroupMetadata->get( $groupId,
'priorityforce' ) ===
'on' );
201 if ( isset( $props[
'workflowstates'] ) ) {
202 $a[
'workflowstates'] = $this->getWorkflowStates( $g );
205 if ( isset( $props[
'sourcelanguage'] ) ) {
206 $a[
'sourcelanguage'] = $g->getSourceLanguage();
210 isset( $props[
'subscription'] ) &&
211 $this->groupSubscription->canUserSubscribeToGroup( $g, $this->getUser() )->isOK()
213 $a[
'subscription'] = $this->groupSubscription->isUserSubscribedTo( $g, $this->getUser() );
216 $this->hookRunner->onTranslateProcessAPIMessageGroupsProperties( $a, $props, $params, $g );
219 if ( $depth >= $params[
'depth'] && $params[
'format'] ===
'tree' ) {
220 $a[
'groupcount'] = count( $subgroups );
227 if ( $subgroups !== [] ) {
228 foreach ( $subgroups as $sg ) {
229 $a[
'groups'][] = $this->
formatGroup( $sg, $props );
231 $result = $this->getResult();
232 $result->setIndexedTagName( $a[
'groups'],
'group' );
243 private function getWorkflowStates(
MessageGroup $group ) {
244 if ( MessageGroups::isDynamic( $group ) ) {
250 if ( !is_array( $stateConfig ) || $stateConfig === [] ) {
254 $user = $this->getUser();
256 foreach ( $stateConfig as $state => $config ) {
257 if ( is_array( $config ) ) {
259 $allowed = $user->isAllowed(
'translate-groupreview' );
261 if ( $allowed && isset( $config[
'right'] ) ) {
262 $allowed = $user->isAllowed( $config[
'right'] );
266 $stateConfig[$state][
'canchange'] = 1;
269 $stateConfig[$state][
'name'] =
270 $this->msg(
"translate-workflow-state-$state" )->text();
277 protected function getAllowedParams(): array {
280 ParamValidator::PARAM_TYPE =>
'integer',
281 ParamValidator::PARAM_DEFAULT => 100,
284 ParamValidator::PARAM_TYPE =>
'string',
285 ParamValidator::PARAM_DEFAULT =>
'',
286 ParamValidator::PARAM_ISMULTI => true,
289 ParamValidator::PARAM_TYPE => [
'flat',
'tree' ],
290 ParamValidator::PARAM_DEFAULT =>
'flat',
293 ParamValidator::PARAM_TYPE =>
'integer',
294 ParamValidator::PARAM_DEFAULT => 64,
297 ParamValidator::PARAM_TYPE => array_keys( $this->getPropertyList() ),
298 ParamValidator::PARAM_DEFAULT =>
'id|label|description|class|exists',
299 ParamValidator::PARAM_ISMULTI => true,
300 ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
303 ParamValidator::PARAM_TYPE =>
'string',
304 ParamValidator::PARAM_DEFAULT =>
'',
306 'languageFilter' => [
307 ParamValidator::PARAM_TYPE =>
'string',
308 ParamValidator::PARAM_DEFAULT =>
'',
312 return $allowedParams;
320 private function getPropertyList(): array {
321 $properties = array_flip( [
340 protected function getExamplesMessages(): array {
342 'action=query&meta=messagegroups' =>
'apihelp-query+messagegroups-example-1',
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