Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
QueryMessageGroupStatsActionApi.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Statistics;
5
6use ApiQuery;
7use IJobSpecification;
8use JobQueueGroup;
12use Wikimedia\ParamValidator\ParamValidator;
13
27 private $noComplete = false;
32 private $noEmpty = false;
33
34 public function __construct(
35 ApiQuery $query,
36 string $moduleName,
37 JobQueueGroup $jobQueueGroup
38 ) {
39 parent::__construct( $query, $moduleName, 'mgs', $jobQueueGroup );
40 }
41
42 // ApiStatsQuery methods
43
45 protected function validateTargetParamater( array $params ): string {
46 $group = MessageGroups::getGroup( $params['group'] );
47 if ( !$group ) {
48 $this->dieWithError( [ 'apierror-badparameter', 'mgsgroup' ] );
49 } elseif ( MessageGroups::isDynamic( $group ) ) {
50 $this->dieWithError( 'apierror-translate-nodynamicgroups', 'invalidparam' );
51 }
52
53 return $group->getId();
54 }
55
57 protected function loadStatistics( string $target, int $flags = 0 ): array {
58 return MessageGroupStats::forGroup( $target, $flags );
59 }
60
62 public function execute() {
63 $params = $this->extractRequestParams();
64
65 $this->noComplete = $params['suppresscomplete'];
66 $this->noEmpty = $params['suppressempty'];
67
68 parent::execute();
69 }
70
72 protected function makeStatsItem( string $item, array $stats ): ?array {
73 $data = $this->makeItem( $stats );
74
75 if ( $this->noComplete && $data['fuzzy'] === 0 && $data['translated'] === $data['total'] ) {
76 return null;
77 }
78
79 if ( $this->noEmpty && $data['translated'] === 0 && $data['fuzzy'] === 0 ) {
80 return null;
81 }
82
83 // Skip below 2% if "don't show without translations" is checked.
84 if ( $this->noEmpty && ( $data['translated'] / $data['total'] ) < 0.02 ) {
85 return null;
86 }
87
88 $data['code'] = $item; // For BC
89 $data['language'] = $item;
90
91 return $data;
92 }
93
95 protected function getCacheRebuildJob( string $target ): IJobSpecification {
96 return MessageGroupStatsRebuildJob::newJob( [ 'groupid' => $target ] );
97 }
98
99 // Api methods
100
102 protected function getAllowedParams(): array {
103 $params = parent::getAllowedParams();
104 $params['group'] = [
105 ParamValidator::PARAM_TYPE => 'string',
106 ParamValidator::PARAM_REQUIRED => true,
107 ];
108
109 $params['suppresscomplete'] = false;
110 $params['suppressempty'] = false;
111
112 return $params;
113 }
114
116 protected function getExamplesMessages(): array {
117 return [
118 'action=query&meta=messagegroupstats&mgsgroup=page-Example'
119 => 'apihelp-query+messagegroupstats-example-1',
120 ];
121 }
122}
return[ 'Translate:ConfigHelper'=> static function():ConfigHelper { return new ConfigHelper();}, 'Translate:CsvTranslationImporter'=> static function(MediaWikiServices $services):CsvTranslationImporter { return new CsvTranslationImporter( $services->getWikiPageFactory());}, 'Translate:EntitySearch'=> static function(MediaWikiServices $services):EntitySearch { return new EntitySearch($services->getMainWANObjectCache(), $services->getCollationFactory() ->makeCollation( 'uca-default-u-kn'), MessageGroups::singleton(), $services->getNamespaceInfo(), $services->get( 'Translate:MessageIndex'), $services->getTitleParser(), $services->getTitleFormatter());}, 'Translate:ExternalMessageSourceStateImporter'=> static function(MediaWikiServices $services):ExternalMessageSourceStateImporter { return new ExternalMessageSourceStateImporter($services->getMainConfig(), $services->get( 'Translate:GroupSynchronizationCache'), $services->getJobQueueGroup(), LoggerFactory::getInstance( 'Translate.GroupSynchronization'), MessageIndex::singleton());}, 'Translate:GroupSynchronizationCache'=> static function(MediaWikiServices $services):GroupSynchronizationCache { return new GroupSynchronizationCache( $services->get( 'Translate:PersistentCache'));}, 'Translate:MessageBundleStore'=> static function(MediaWikiServices $services):MessageBundleStore { return new MessageBundleStore(new RevTagStore(), $services->getJobQueueGroup(), $services->getLanguageNameUtils(), $services->get( 'Translate:MessageIndex'));}, 'Translate:MessageGroupReview'=> static function(MediaWikiServices $services):MessageGroupReview { return new MessageGroupReview($services->getDBLoadBalancer(), $services->getHookContainer());}, 'Translate:MessageIndex'=> static function(MediaWikiServices $services):MessageIndex { $params=$services->getMainConfig() ->get( 'TranslateMessageIndex');if(is_string( $params)) { $params=(array) $params;} $class=array_shift( $params);return new $class( $params);}, 'Translate:ParsingPlaceholderFactory'=> static function():ParsingPlaceholderFactory { return new ParsingPlaceholderFactory();}, 'Translate:PersistentCache'=> static function(MediaWikiServices $services):PersistentCache { return new PersistentDatabaseCache($services->getDBLoadBalancer(), $services->getJsonCodec());}, 'Translate:ProgressStatsTableFactory'=> static function(MediaWikiServices $services):ProgressStatsTableFactory { return new ProgressStatsTableFactory($services->getLinkRenderer(), $services->get( 'Translate:ConfigHelper'));}, 'Translate:SubpageListBuilder'=> static function(MediaWikiServices $services):SubpageListBuilder { return new SubpageListBuilder($services->get( 'Translate:TranslatableBundleFactory'), $services->getLinkBatchFactory());}, 'Translate:TranslatableBundleFactory'=> static function(MediaWikiServices $services):TranslatableBundleFactory { return new TranslatableBundleFactory($services->get( 'Translate:TranslatablePageStore'), $services->get( 'Translate:MessageBundleStore'));}, 'Translate:TranslatableBundleMover'=> static function(MediaWikiServices $services):TranslatableBundleMover { return new TranslatableBundleMover($services->getMovePageFactory(), $services->getJobQueueGroup(), $services->getLinkBatchFactory(), $services->get( 'Translate:TranslatableBundleFactory'), $services->get( 'Translate:SubpageListBuilder'), $services->getMainConfig() ->get( 'TranslatePageMoveLimit'));}, 'Translate:TranslatablePageParser'=> static function(MediaWikiServices $services):TranslatablePageParser { return new TranslatablePageParser($services->get( 'Translate:ParsingPlaceholderFactory'));}, 'Translate:TranslatablePageStore'=> static function(MediaWikiServices $services):TranslatablePageStore { return new TranslatablePageStore($services->get( 'Translate:MessageIndex'), $services->getJobQueueGroup(), new RevTagStore(), $services->getDBLoadBalancer());}, 'Translate:TranslationStashReader'=> static function(MediaWikiServices $services):TranslationStashReader { $db=$services->getDBLoadBalancer() ->getConnectionRef(DB_REPLICA);return new TranslationStashStorage( $db);}, 'Translate:TranslationStatsDataProvider'=> static function(MediaWikiServices $services):TranslationStatsDataProvider { return new TranslationStatsDataProvider(new ServiceOptions(TranslationStatsDataProvider::CONSTRUCTOR_OPTIONS, $services->getMainConfig()), $services->getObjectFactory());}, 'Translate:TranslationUnitStoreFactory'=> static function(MediaWikiServices $services):TranslationUnitStoreFactory { return new TranslationUnitStoreFactory( $services->getDBLoadBalancer());}, 'Translate:TranslatorActivity'=> static function(MediaWikiServices $services):TranslatorActivity { $query=new TranslatorActivityQuery($services->getMainConfig(), $services->getDBLoadBalancer());return new TranslatorActivity($services->getMainObjectStash(), $query, $services->getJobQueueGroup());}, 'Translate:TtmServerFactory'=> static function(MediaWikiServices $services):TtmServerFactory { $config=$services->getMainConfig();$default=$config->get( 'TranslateTranslationDefaultService');if( $default===false) { $default=null;} return new TtmServerFactory( $config->get( 'TranslateTranslationServices'), $default);}]
@phpcs-require-sorted-array
A base module for querying message group related stats.
Job for rebuilding message group stats.
This class abstract MessageGroup statistics calculation and storing.
Factory class for accessing message groups individually by id or all of them as an list.