Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
AggregateGroupManager.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageGroupProcessing;
5
7use MediaWiki\Title\Title;
8use MediaWiki\Title\TitleFactory;
10use RuntimeException;
12
20 private TitleFactory $titleFactory;
21
22 public function __construct( TitleFactory $titleFactory ) {
23 $this->titleFactory = $titleFactory;
24 }
25
26 public function supportsAggregation( MessageGroup $group ): bool {
27 return $group instanceof WikiPageMessageGroup || $group instanceof MessageBundleMessageGroup;
28 }
29
30 public function getTargetTitleByGroupId( string $groupId ): Title {
31 $group = MessageGroups::getGroup( $groupId );
32 if ( $group ) {
33 return $this->getTargetTitleByGroup( $group );
34 } else {
35 /* To allow removing no longer existing groups from aggregate message groups,
36 * the message group object $group might not always be available.
37 * In this case we need to fake some title. */
38 return $this->titleFactory->newFromText( "Special:Translate/$groupId" );
39 }
40 }
41
43 public function getTargetTitleByGroup( MessageGroup $group ): Title {
44 $relatedGroupPage = $group->getRelatedPage();
45 if ( !$relatedGroupPage ) {
46 throw new RuntimeException( "No related page found for group " . $group->getId() );
47 }
48
49 return $this->titleFactory->newFromLinkTarget( $relatedGroupPage );
50 }
51}
Contains logic to store, validate, fetch aggregate groups created via Special:AggregateGroups.
static getGroup(string $id)
Fetch a message group by id.
Wraps the translatable page sections into a message group.
Interface for message groups.
getId()
Returns the unique identifier for this group.