17 public function __construct() {
18 parent::__construct();
19 $this->addDescription(
'Query the contents of the group synchronization cache' );
23 '(optional) Group Id being queried',
28 $this->requireExtension(
'Translate' );
31 public function execute() {
32 $config = MediaWikiServices::getInstance()->getMainConfig();
34 if ( !$config->get(
'TranslateGroupSynchronizationCache' ) ) {
35 $this->fatalError(
'GroupSynchronizationCache is not enabled' );
38 $groupSyncCache = Services::getInstance()->getGroupSynchronizationCache();
40 $groupId = $this->getOption(
'group' );
42 $groupMessages = $groupSyncCache->getGroupMessages( $groupId );
43 $this->displayGroupMessages( $groupId, $groupMessages );
45 $groups = $groupSyncCache->getGroupsInSync();
46 $this->displayGroups( $groups );
50 private function displayGroups( array $groupIds ):
void {
52 $this->output(
"No groups found in synchronization\n" );
56 $this->output(
"Groups found in sync:\n" );
57 foreach ( $groupIds as $groupId ) {
58 $this->output(
"\t- $groupId\n" );
66 private function displayGroupMessages(
string $groupId, array $groupMessages ):
void {
67 if ( !$groupMessages ) {
68 $this->output(
"No messages found for group $groupId\n" );
72 $this->output(
"Messages in group $groupId:\n" );
73 foreach ( $groupMessages as $message ) {
74 $this->displayMessageDetails( $message );
80 if ( $messageParam->isRename() ) {
84 if ( $messageParam->isFuzzy() ) {
88 $otherLangs = $messageParam->getOtherLangs() ?: [
'N/A' ];
89 $this->output(
"\t- Title: " . $messageParam->getPageName() .
"\n" );
90 $this->output(
"\t Tags: " . ( $tags ? implode(
', ', $tags ) :
'N/A' ) .
"\n" );
91 if ( $messageParam->isRename() ) {
92 $this->output(
"\t Target: " . $messageParam->getTargetValue() .
"\n" );
93 $this->output(
"\t Replacement: " . $messageParam->getReplacementValue() .
"\n" );
94 $this->output(
"\t Other languages: " . ( implode(
', ', $otherLangs ) ) .
"\n" );