Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryContentTranslationStats | |
0.00% |
0 / 27 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Api module for querying Content translations for stats. |
4 | * |
5 | * @copyright See AUTHORS.txt |
6 | * @license GPL-2.0-or-later |
7 | */ |
8 | |
9 | namespace ContentTranslation\ActionApi; |
10 | |
11 | use ContentTranslation\Translation; |
12 | use ContentTranslation\Translator; |
13 | use MediaWiki\Api\ApiQuery; |
14 | use MediaWiki\Api\ApiQueryBase; |
15 | use MediaWiki\MediaWikiServices; |
16 | use Wikimedia\LightweightObjectStore\ExpirationAwareness; |
17 | |
18 | /** |
19 | * Api module for querying ContentTranslation stats. |
20 | */ |
21 | class ApiQueryContentTranslationStats extends ApiQueryBase { |
22 | |
23 | public function __construct( ApiQuery $query, string $moduleName ) { |
24 | parent::__construct( $query, $moduleName ); |
25 | } |
26 | |
27 | public function execute() { |
28 | $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
29 | $translationStats = $cache->getWithSetCallback( |
30 | $cache->makeGlobalKey( 'cx-api-stats-translation' ), |
31 | ExpirationAwareness::TTL_DAY, |
32 | fn () => Translation::getStats() |
33 | ); |
34 | $translatorStats = $cache->getWithSetCallback( |
35 | $cache->makeGlobalKey( 'cx-api-stats-translator' ), |
36 | ExpirationAwareness::TTL_DAY, |
37 | fn () => Translator::getStats() |
38 | ); |
39 | |
40 | $result = $this->getResult(); |
41 | $result->addValue( |
42 | [ 'query', 'contenttranslationstats' ], |
43 | 'pages', |
44 | $translationStats |
45 | ); |
46 | $result->addValue( |
47 | [ 'query', 'contenttranslationstats' ], |
48 | 'translators', |
49 | $translatorStats |
50 | ); |
51 | } |
52 | |
53 | protected function getExamplesMessages() { |
54 | return [ |
55 | 'action=query&list=contenttranslationstats' => |
56 | 'apihelp-query+contenttranslationstats-example-1', |
57 | ]; |
58 | } |
59 | } |