22 private LinkBatchFactory $linkBatchFactory;
25 private TemplateParser $templateParser;
27 public function __construct(
28 LinkBatchFactory $linkBatchFactory,
32 parent::__construct(
'AggregateGroups',
'translate-manage' );
33 $this->linkBatchFactory = $linkBatchFactory;
34 $this->messageGroupMetadata = $messageGroupMetadata;
35 $this->aggregateGroupManager = $aggregateGroupManager;
36 $this->templateParser =
new TemplateParser( __DIR__ .
'/templates' );
39 protected function getGroupName():
string {
44 public function execute( $parameters ): void {
46 $this->addHelpLink(
'Help:Extension:Translate/Page translation administration' );
49 $hasPermission = $this->getUser()->isAllowed(
'translate-manage' );
51 $out = $this->getOutput();
53 $out->addModuleStyles(
'ext.translate.specialpages.styles' );
54 $out->addModules(
'ext.translate.special.aggregategroups' );
60 'id' =>
'ext-translate-aggregategroups',
61 'data-haspermission' => $hasPermission ?
'true' : null,
66 $aggregateGroups = $this->aggregateGroupManager->getAll();
67 if ( $aggregateGroups === [] ) {
70 $this->msg(
'tpt-aggregategroup-no-groups' )->escaped(),
71 'tpt-aggregategroup-nogroups'
77 'editLabel' => $this->msg(
'tpt-aggregategroup-edit' )->text(),
78 'deleteLabel' => $this->msg(
'tpt-aggregategroup-delete' )->text(),
79 'removeItemLabel' => $this->msg(
'tpt-aggregategroup-remove-item' )->text(),
81 foreach ( $aggregateGroups as $aggregateGroup ) {
82 $subGroupIds = $this->messageGroupMetadata->getSubgroups( $aggregateGroup->getId() );
84 $html = $this->templateParser->processTemplate(
'AggregateGroupTemplate', [
85 'id' => $aggregateGroup->getId(),
86 'name' => $aggregateGroup->getLabel(),
87 'description' => $aggregateGroup->getDescription(),
88 'subGroups' => $this->getSubGroupInfoForTemplate( $subGroupIds ),
89 'shouldExpand' => count( $subGroupIds ) <= 3,
90 'editLabel' => $msgCache[
'editLabel'],
91 'deleteLabel' => $msgCache[
'deleteLabel'],
92 'removeItemLabel' => $msgCache[
'removeItemLabel'],
93 'hasManageRights' => $hasPermission,
96 $this->getOutput()->addHTML( $html );
100 private function getSubGroupInfoForTemplate( array $subGroupIds ): array {
101 $subGroups = MessageGroups::getGroupsById( $subGroupIds );
102 uasort( $subGroups, [ MessageGroups::class,
'groupLabelSort' ] );
104 $groupCache = $this->getGroupCache( $subGroups );
107 foreach ( $subGroupIds as $id ) {
108 $group = $subGroups[$id] ??
null;
110 $text = $this->getLinkRenderer()->makeKnownLink( $groupCache[$group->getId()], $group->getLabel() );
113 $text = htmlspecialchars( $id );
114 $note = $this->msg(
'tpt-aggregategroup-invalid-group' )->escaped();
118 'labelHtml' => $text,
123 return $subGroupInfo;
130 private function getGroupCache( array $subGroups ): array {
132 $lb = $this->linkBatchFactory->newLinkBatch();
133 foreach ( $subGroups as $group ) {
134 $subGroupId = $group->getId();
135 $groupCache[$subGroupId] = $this->aggregateGroupManager->getTargetTitleByGroupId( $subGroupId );
136 $lb->addObj( $groupCache[$subGroupId] );
138 $lb->setCaller( __METHOD__ );