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