Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryWikimediaEditorTasksCounts | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| isInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | * @file |
| 18 | */ |
| 19 | |
| 20 | namespace MediaWiki\Extension\WikimediaEditorTasks\Api; |
| 21 | |
| 22 | use MediaWiki\Api\ApiQuery; |
| 23 | use MediaWiki\Api\ApiQueryBase; |
| 24 | use MediaWiki\Config\Config; |
| 25 | use MediaWiki\Extension\WikimediaEditorTasks\CounterDao; |
| 26 | use MediaWiki\Extension\WikimediaEditorTasks\Utils; |
| 27 | |
| 28 | class ApiQueryWikimediaEditorTasksCounts extends ApiQueryBase { |
| 29 | |
| 30 | /** @var bool */ |
| 31 | private $editStreaksEnabled; |
| 32 | |
| 33 | /** @var bool */ |
| 34 | private $revertCountsEnabled; |
| 35 | |
| 36 | public function __construct( |
| 37 | ApiQuery $queryModule, |
| 38 | string $moduleName, |
| 39 | private readonly CounterDao $counterDao, |
| 40 | Config $extensionConfig, |
| 41 | ) { |
| 42 | parent::__construct( $queryModule, $moduleName, 'wmetc' ); |
| 43 | $this->editStreaksEnabled = $extensionConfig->get( 'WikimediaEditorTasksEnableEditStreaks' ); |
| 44 | $this->revertCountsEnabled = $extensionConfig->get( 'WikimediaEditorTasksEnableRevertCounts' ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Entry point for executing the module |
| 49 | * @inheritDoc |
| 50 | */ |
| 51 | public function execute() { |
| 52 | if ( $this->getUser()->isAnon() ) { |
| 53 | $this->dieWithError( [ 'apierror-mustbeloggedin', |
| 54 | $this->msg( 'action-viewmyprivateinfo' ) ], 'notloggedin' ); |
| 55 | } |
| 56 | $this->checkUserRightsAny( 'viewmyprivateinfo' ); |
| 57 | |
| 58 | $dao = $this->counterDao; |
| 59 | $centralId = Utils::getCentralId( $this->getUser() ); |
| 60 | |
| 61 | $result = [ 'counts' => $dao->getAllEditCounts( $centralId ) ]; |
| 62 | if ( $this->editStreaksEnabled ) { |
| 63 | $result['edit_streak'] = $dao->getEditStreak( $centralId ); |
| 64 | } |
| 65 | if ( $this->revertCountsEnabled ) { |
| 66 | $result['revert_counts'] = $dao->getAllRevertCounts( $centralId ); |
| 67 | } |
| 68 | $this->getResult()->addValue( 'query', 'wikimediaeditortaskscounts', $result ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @inheritDoc |
| 73 | * @return array |
| 74 | */ |
| 75 | protected function getExamplesMessages() { |
| 76 | return [ |
| 77 | "action=query&formatversion=2&meta=wikimediaeditortaskscounts" => |
| 78 | 'apihelp-query+wikimediaeditortaskscounts-example', |
| 79 | ]; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @inheritDoc |
| 84 | * @return bool |
| 85 | */ |
| 86 | public function isInternal() { |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | } |