Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryWikimediaEditorTasksCounts
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
20
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 isInternal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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
20namespace MediaWiki\Extension\WikimediaEditorTasks\Api;
21
22use ApiQuery;
23use ApiQueryBase;
24use MediaWiki\Config\Config;
25use MediaWiki\Extension\WikimediaEditorTasks\CounterDao;
26use MediaWiki\Extension\WikimediaEditorTasks\Utils;
27
28class ApiQueryWikimediaEditorTasksCounts extends ApiQueryBase {
29
30    /** @var CounterDao */
31    private $counterDao;
32
33    /** @var bool */
34    private $editStreaksEnabled;
35
36    /** @var bool */
37    private $revertCountsEnabled;
38
39    /**
40     * @param ApiQuery $queryModule
41     * @param string $moduleName
42     * @param CounterDao $counterDao
43     * @param Config $extensionConfig
44     */
45    public function __construct(
46        ApiQuery $queryModule,
47        string $moduleName,
48        CounterDao $counterDao,
49        Config $extensionConfig
50    ) {
51        parent::__construct( $queryModule, $moduleName, 'wmetc' );
52        $this->counterDao = $counterDao;
53        $this->editStreaksEnabled = $extensionConfig->get( 'WikimediaEditorTasksEnableEditStreaks' );
54        $this->revertCountsEnabled = $extensionConfig->get( 'WikimediaEditorTasksEnableRevertCounts' );
55    }
56
57    /**
58     * Entry point for executing the module
59     * @inheritDoc
60     */
61    public function execute() {
62        if ( $this->getUser()->isAnon() ) {
63            $this->dieWithError( [ 'apierror-mustbeloggedin',
64                $this->msg( 'action-viewmyprivateinfo' ) ], 'notloggedin' );
65        }
66        $this->checkUserRightsAny( 'viewmyprivateinfo' );
67
68        $dao = $this->counterDao;
69        $centralId = Utils::getCentralId( $this->getUser() );
70
71        $result = [ 'counts' => $dao->getAllEditCounts( $centralId ) ];
72        if ( $this->editStreaksEnabled ) {
73            $result['edit_streak'] = $dao->getEditStreak( $centralId );
74        }
75        if ( $this->revertCountsEnabled ) {
76            $result['revert_counts'] = $dao->getAllRevertCounts( $centralId );
77        }
78        $this->getResult()->addValue( 'query', 'wikimediaeditortaskscounts', $result );
79    }
80
81    /**
82     * @inheritDoc
83     * @return array
84     */
85    protected function getExamplesMessages() {
86        return [
87            "action=query&formatversion=2&meta=wikimediaeditortaskscounts" =>
88                'apihelp-query+wikimediaeditortaskscounts-example',
89        ];
90    }
91
92    /**
93     * @inheritDoc
94     * @return bool
95     */
96    public function isInternal() {
97        return true;
98    }
99
100}