Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiQuerySiteViews | |
0.00% |
0 / 20 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\PageViewInfo; |
4 | |
5 | use ApiQueryBase; |
6 | use ApiResult; |
7 | use MediaWiki\MediaWikiServices; |
8 | |
9 | /** |
10 | * Expose PageViewService::getSiteData(). |
11 | */ |
12 | class ApiQuerySiteViews extends ApiQueryBase { |
13 | public function __construct( $query, $moduleName ) { |
14 | parent::__construct( $query, $moduleName, 'pvis' ); |
15 | } |
16 | |
17 | public function execute() { |
18 | $params = $this->extractRequestParams(); |
19 | /** @var PageViewService $service */ |
20 | $service = MediaWikiServices::getInstance()->getService( 'PageViewService' ); |
21 | $metric = Hooks::getApiMetricsMap()[$params['metric']]; |
22 | $status = $service->getSiteData( $params['days'], $metric ); |
23 | if ( $status->isOK() ) { |
24 | $this->addMessagesFromStatus( Hooks::makeWarningsOnlyStatus( $status ) ); |
25 | $result = $this->getResult(); |
26 | $value = $status->getValue(); |
27 | ApiResult::setArrayType( $value, 'kvp', 'date' ); |
28 | ApiResult::setIndexedTagName( $value, 'count' ); |
29 | $result->addValue( 'query', $this->getModuleName(), $value ); |
30 | } else { |
31 | $this->dieStatus( $status ); |
32 | } |
33 | } |
34 | |
35 | public function getCacheMode( $params ) { |
36 | return 'public'; |
37 | } |
38 | |
39 | public function getAllowedParams() { |
40 | return Hooks::getApiMetricsHelp( PageViewService::SCOPE_SITE ) + Hooks::getApiDaysHelp(); |
41 | } |
42 | |
43 | protected function getExamplesMessages() { |
44 | return [ |
45 | 'action=query&meta=siteviews' => 'apihelp-query+siteviews-example', |
46 | 'action=query&meta=siteviews&pvismetric=uniques' => 'apihelp-query+siteviews-example2', |
47 | ]; |
48 | } |
49 | |
50 | public function getHelpUrls() { |
51 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:PageViewInfo'; |
52 | } |
53 | } |