Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
QueryGroupSyncCacheMaintenanceScript.php
1<?php
2declare( strict_types = 1 );
3
5
8use MediaWiki\MediaWikiServices;
9
17 public function __construct() {
18 parent::__construct();
19 $this->addDescription( 'Query the contents of the group synchronization cache' );
20
21 $this->addOption(
22 'group',
23 '(optional) Group Id being queried',
24 self::OPTIONAL,
25 self::HAS_ARG
26 );
27
28 $this->requireExtension( 'Translate' );
29 }
30
31 public function execute() {
32 $config = MediaWikiServices::getInstance()->getMainConfig();
33
34 if ( !$config->get( 'TranslateGroupSynchronizationCache' ) ) {
35 $this->fatalError( 'GroupSynchronizationCache is not enabled' );
36 }
37
38 $groupSyncCache = Services::getInstance()->getGroupSynchronizationCache();
39
40 $groupId = $this->getOption( 'group' );
41 if ( $groupId ) {
42 $groupMessages = $groupSyncCache->getGroupMessages( $groupId );
43 $this->displayGroupMessages( $groupId, $groupMessages );
44 } else {
45 $groups = $groupSyncCache->getGroupsInSync();
46 $this->displayGroups( $groups );
47 }
48 }
49
50 private function displayGroups( array $groupIds ): void {
51 if ( !$groupIds ) {
52 $this->output( "No groups found in synchronization\n" );
53 return;
54 }
55
56 $this->output( "Groups found in sync:\n" );
57 foreach ( $groupIds as $groupId ) {
58 $this->output( "\t- $groupId\n" );
59 }
60 }
61
66 private function displayGroupMessages( string $groupId, array $groupMessages ): void {
67 if ( !$groupMessages ) {
68 $this->output( "No messages found for group $groupId\n" );
69 return;
70 }
71
72 $this->output( "Messages in group $groupId:\n" );
73 foreach ( $groupMessages as $message ) {
74 $this->displayMessageDetails( $message );
75 }
76 }
77
78 private function displayMessageDetails( MessageUpdateParameter $messageParam ): void {
79 $tags = [];
80 if ( $messageParam->isRename() ) {
81 $tags[] = 'rename';
82 }
83
84 if ( $messageParam->isFuzzy() ) {
85 $tags[] = 'fuzzy';
86 }
87
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" );
95 }
96 }
97}
Minimal service container.
Definition Services.php:59
Base maintenance script containing constants and methods used in multiple scripts Hopefully the const...
Finds external changes for file based message groups.