28 private $hookContainer;
30 public function __construct(
33 HookContainer $hookContainer
35 parent::__construct( $query, $moduleName,
'mg' );
36 $this->hookContainer = $hookContainer;
39 public function execute():
void {
40 $params = $this->extractRequestParams();
41 $filter = $params[
'filter'];
44 $props = array_flip( $params[
'prop'] );
46 $needsMetadata = isset( $props[
'prioritylangs'] ) || isset( $props[
'priorityforce'] );
49 if ( $params[
'root'] ===
'all' ) {
50 $allGroups = MessageGroups::getAllGroups();
51 foreach ( $allGroups as $id => $group ) {
53 $groups[$id] = $group;
56 } elseif ( $params[
'format'] ===
'flat' ) {
57 if ( $params[
'root'] !==
'' ) {
58 $group = MessageGroups::getGroup( $params[
'root'] );
60 $groups[$params[
'root']] = $group;
63 $groups = MessageGroups::getAllGroups();
64 usort( $groups, [
'MessageGroups',
'groupLabelSort' ] );
66 TranslateMetadata::preloadGroups( array_keys( $groups ), __METHOD__ );
67 } elseif ( $params[
'root'] !==
'' ) {
69 $group = MessageGroups::getGroup( $params[
'root'] );
72 $groups = MessageGroups::subGroups( $group, $childIds );
74 array_shift( $groups );
77 $groups = MessageGroups::getGroupStructure();
80 if ( $needsMetadata && $groups ) {
81 TranslateMetadata::preloadGroups( array_keys( $groups ), __METHOD__ );
84 if ( $params[
'root'] ===
'' ) {
86 foreach ( array_keys( MessageGroups::getDynamicGroups() ) as $id ) {
87 $dynamicGroups[$id] = MessageGroups::getGroup( $id );
90 $groups = $dynamicGroups + $groups;
92 '@phan-var (MessageGroup|array)[] $groups';
96 if ( isset( $groups[
'!sandbox'] ) ) {
97 unset( $groups[
'!sandbox'] );
100 $result = $this->getResult();
103 foreach ( $groups as $mixed ) {
105 $group = is_array( $mixed ) ? reset( $mixed ) : $mixed;
106 if ( $filter !== [] && !$matcher->matches( $group->getId() ) ) {
111 $params[
'languageFilter'] !==
'' &&
112 TranslateMetadata::isExcluded( $group->getId(), $params[
'languageFilter'] )
119 $result->setIndexedTagName( $a,
'group' );
122 $fit = $result->addValue( [
'query', $this->getModuleName() ],
null, $a );
130 $result->addIndexedTagName( [
'query', $this->getModuleName() ],
'group' );
137 protected function formatGroup( $mixed, array $props,
int $depth = 0 ): array {
138 $params = $this->extractRequestParams();
139 $context = $this->getContext();
146 if ( is_array( $mixed ) ) {
147 $g = array_shift( $mixed );
153 $groupId = $g->getId();
155 if ( isset( $props[
'id'] ) ) {
159 if ( isset( $props[
'label'] ) ) {
160 $a[
'label'] = $g->getLabel( $context );
163 if ( isset( $props[
'description'] ) ) {
164 $a[
'description'] = $g->getDescription( $context );
167 if ( isset( $props[
'class'] ) ) {
168 $a[
'class'] = get_class( $g );
171 if ( isset( $props[
'namespace'] ) ) {
172 $a[
'namespace'] = $g->getNamespace();
175 if ( isset( $props[
'exists'] ) ) {
176 $a[
'exists'] = $g->exists();
179 if ( isset( $props[
'icon'] ) ) {
182 $a[
'icon'] = $formats;
186 if ( isset( $props[
'priority'] ) ) {
188 $a[
'priority'] = $priority ?:
'default';
191 if ( isset( $props[
'prioritylangs'] ) ) {
193 $a[
'prioritylangs'] = $prioritylangs ? explode(
',', $prioritylangs ) : false;
196 if ( isset( $props[
'priorityforce'] ) ) {
200 if ( isset( $props[
'workflowstates'] ) ) {
201 $a[
'workflowstates'] = $this->getWorkflowStates( $g );
204 if ( isset( $props[
'sourcelanguage'] ) ) {
205 $a[
'sourcelanguage'] = $g->getSourceLanguage();
208 $this->hookContainer->run(
209 'TranslateProcessAPIMessageGroupsProperties',
210 [ &$a, $props, $params, $g ]
214 if ( $depth >= $params[
'depth'] && $params[
'format'] ===
'tree' ) {
215 $a[
'groupcount'] = count( $subgroups );
222 if ( $subgroups !== [] ) {
223 foreach ( $subgroups as $sg ) {
224 $a[
'groups'][] = $this->
formatGroup( $sg, $props );
226 $result = $this->getResult();
228 $result->setIndexedTagName( $a[
'groups'],
'group' );
239 private function getWorkflowStates(
MessageGroup $group ) {
240 if ( MessageGroups::isDynamic( $group ) ) {
246 if ( !is_array( $stateConfig ) || $stateConfig === [] ) {
250 $user = $this->getUser();
252 foreach ( $stateConfig as $state => $config ) {
253 if ( is_array( $config ) ) {
255 $allowed = $user->isAllowed(
'translate-groupreview' );
257 if ( $allowed && isset( $config[
'right'] ) ) {
258 $allowed = $user->isAllowed( $config[
'right'] );
262 $stateConfig[$state][
'canchange'] = 1;
265 $stateConfig[$state][
'name'] =
266 $this->msg(
"translate-workflow-state-$state" )->text();
273 protected function getAllowedParams(): array {
276 ParamValidator::PARAM_TYPE =>
'integer',
277 ParamValidator::PARAM_DEFAULT => 100,
280 ParamValidator::PARAM_TYPE =>
'string',
281 ParamValidator::PARAM_DEFAULT =>
'',
282 ParamValidator::PARAM_ISMULTI => true,
285 ParamValidator::PARAM_TYPE => [
'flat',
'tree' ],
286 ParamValidator::PARAM_DEFAULT =>
'flat',
289 ParamValidator::PARAM_TYPE =>
'integer',
290 ParamValidator::PARAM_DEFAULT => 64,
293 ParamValidator::PARAM_TYPE => array_keys( $this->getPropertyList() ),
294 ParamValidator::PARAM_DEFAULT =>
'id|label|description|class|exists',
295 ParamValidator::PARAM_ISMULTI => true,
298 ParamValidator::PARAM_TYPE =>
'string',
299 ParamValidator::PARAM_DEFAULT =>
'',
301 'languageFilter' => [
302 ParamValidator::PARAM_TYPE =>
'string',
303 ParamValidator::PARAM_DEFAULT =>
'',
306 $this->hookContainer->run(
'TranslateGetAPIMessageGroupsParameterList', [ &$allowedParams ] );
308 return $allowedParams;
316 private function getPropertyList(): array {
317 $properties = array_flip( [
332 $this->hookContainer->run(
'TranslateGetAPIMessageGroupsPropertyDescs', [ &$properties ] );
337 protected function getExamplesMessages(): array {
339 'action=query&meta=messagegroups' =>
'apihelp-query+messagegroups-example-1',
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
Wraps the translatable page sections into a message group.