23 private TemplateParser $templateParser;
25 public function __construct(
26 private readonly LinkBatchFactory $linkBatchFactory,
30 parent::__construct(
'AggregateGroups' );
31 $this->templateParser =
new TemplateParser( __DIR__ .
'/templates' );
34 protected function getGroupName():
string {
39 public function execute( $parameters ): void {
41 $this->addHelpLink(
'Help:Extension:Translate/Page translation administration' );
44 $hasPermission = $this->getUser()->isAllowed(
'translate-manage' );
46 $out = $this->getOutput();
48 $out->addModuleStyles(
'ext.translate.specialpages.styles' );
49 $out->addModules(
'ext.translate.special.aggregategroups' );
55 'id' =>
'ext-translate-aggregategroups',
56 'data-haspermission' => $hasPermission ?
'true' : null,
61 $aggregateGroups = $this->aggregateGroupManager->getAll();
62 if ( $aggregateGroups === [] ) {
65 $this->msg(
'tpt-aggregategroup-no-groups' )->escaped(),
66 'tpt-aggregategroup-nogroups'
72 'editLabel' => $this->msg(
'tpt-aggregategroup-edit' )->text(),
73 'deleteLabel' => $this->msg(
'tpt-aggregategroup-delete' )->text(),
74 'removeItemLabel' => $this->msg(
'tpt-aggregategroup-remove-item' )->text(),
76 foreach ( $aggregateGroups as $aggregateGroup ) {
77 $subGroupIds = $this->messageGroupMetadata->getSubgroups( $aggregateGroup->getId() );
79 $html = $this->templateParser->processTemplate(
'AggregateGroupTemplate', [
80 'id' => $aggregateGroup->getId(),
81 'name' => $aggregateGroup->getLabel(),
82 'description' => $aggregateGroup->getDescription(),
83 'subGroups' => $this->getSubGroupInfoForTemplate( $subGroupIds ),
84 'shouldExpand' => count( $subGroupIds ) <= 3,
85 'editLabel' => $msgCache[
'editLabel'],
86 'deleteLabel' => $msgCache[
'deleteLabel'],
87 'removeItemLabel' => $msgCache[
'removeItemLabel'],
88 'hasManageRights' => $hasPermission,
91 $this->getOutput()->addHTML( $html );
95 private function getSubGroupInfoForTemplate( array $subGroupIds ): array {
96 $subGroups = MessageGroups::getGroupsById( $subGroupIds );
97 uasort( $subGroups, [ MessageGroups::class,
'groupLabelSort' ] );
99 $groupCache = $this->getGroupCache( $subGroups );
102 foreach ( $subGroupIds as $id ) {
103 $group = $subGroups[$id] ??
null;
105 $text = $this->getLinkRenderer()->makeKnownLink( $groupCache[$group->getId()], $group->getLabel() );
108 $text = htmlspecialchars( $id );
109 $note = $this->msg(
'tpt-aggregategroup-invalid-group' )->escaped();
113 'labelHtml' => $text,
118 return $subGroupInfo;
125 private function getGroupCache( array $subGroups ): array {
127 $lb = $this->linkBatchFactory->newLinkBatch();
128 foreach ( $subGroups as $group ) {
129 $subGroupId = $group->getId();
130 $groupCache[$subGroupId] = $this->aggregateGroupManager->getTargetTitleByGroupId( $subGroupId );
131 $lb->addObj( $groupCache[$subGroupId] );
133 $lb->setCaller( __METHOD__ );