Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 70 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryAllCampaigns | |
0.00% |
0 / 70 |
|
0.00% |
0 / 6 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
30 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 13 |
|
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 | * Copyright © 2013 Yuvi Panda <yuvipanda@gmail.com> |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | */ |
22 | |
23 | namespace MediaWiki\Extension\UploadWizard; |
24 | |
25 | use ApiBase; |
26 | use ApiQueryBase; |
27 | use Wikimedia\ParamValidator\ParamValidator; |
28 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
29 | |
30 | /** |
31 | * Query module to enumerate all registered campaigns |
32 | * |
33 | * @ingroup API |
34 | */ |
35 | class ApiQueryAllCampaigns extends ApiQueryBase { |
36 | public function __construct( $query, $moduleName ) { |
37 | parent::__construct( $query, $moduleName, 'uwc' ); |
38 | } |
39 | |
40 | public function execute() { |
41 | $params = $this->extractRequestParams(); |
42 | |
43 | $limit = $params['limit']; |
44 | |
45 | $this->addTables( 'uw_campaigns' ); |
46 | |
47 | $this->addWhereIf( [ 'campaign_enabled' => 1 ], $params['enabledonly'] ); |
48 | $this->addOption( 'LIMIT', $limit + 1 ); |
49 | $this->addOption( 'ORDER BY', 'campaign_id' ); // Not sure if required? |
50 | |
51 | $this->addFields( [ |
52 | 'campaign_id', |
53 | 'campaign_name', |
54 | 'campaign_enabled' |
55 | ] ); |
56 | |
57 | if ( $params['continue'] !== null ) { |
58 | $from_id = (int)$params['continue']; |
59 | $this->addWhere( $this->getDB()->expr( 'campaign_id', '>=', $from_id ) ); |
60 | } |
61 | |
62 | $res = $this->select( __METHOD__ ); |
63 | |
64 | $result = $this->getResult(); |
65 | |
66 | $count = 0; |
67 | |
68 | foreach ( $res as $row ) { |
69 | if ( ++$count > $limit ) { |
70 | // We have more results than $limit. Set continue |
71 | $this->setContinueEnumParameter( 'continue', $row->campaign_id ); |
72 | break; |
73 | } |
74 | |
75 | $campaign = Campaign::newFromName( $row->campaign_name ); |
76 | |
77 | $campaignPath = [ 'query', $this->getModuleName(), $row->campaign_id ]; |
78 | |
79 | $result->addValue( |
80 | $campaignPath, |
81 | '*', |
82 | json_encode( $campaign->getParsedConfig() ) |
83 | ); |
84 | $result->addValue( |
85 | $campaignPath, |
86 | 'name', |
87 | $campaign->getName() |
88 | ); |
89 | $result->addValue( |
90 | $campaignPath, |
91 | 'trackingCategory', |
92 | $campaign->getTrackingCategory()->getDBkey() |
93 | ); |
94 | $result->addValue( |
95 | $campaignPath, |
96 | 'totalUploads', |
97 | $campaign->getUploadedMediaCount() |
98 | ); |
99 | if ( Config::getSetting( 'campaignExpensiveStatsEnabled' ) === true ) { |
100 | $result->addValue( |
101 | $campaignPath, |
102 | 'totalContributors', |
103 | $campaign->getTotalContributorsCount() |
104 | ); |
105 | } |
106 | } |
107 | $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'campaign' ); |
108 | } |
109 | |
110 | public function getCacheMode( $params ) { |
111 | return 'public'; |
112 | } |
113 | |
114 | public function getAllowedParams() { |
115 | return [ |
116 | 'enabledonly' => false, |
117 | 'limit' => [ |
118 | ParamValidator::PARAM_DEFAULT => 50, |
119 | ParamValidator::PARAM_TYPE => 'limit', |
120 | IntegerDef::PARAM_MIN => 1, |
121 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
122 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
123 | ], |
124 | 'continue' => [ |
125 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
126 | ], |
127 | ]; |
128 | } |
129 | |
130 | /** |
131 | * @inheritDoc |
132 | */ |
133 | protected function getExamplesMessages() { |
134 | return [ |
135 | 'action=query&list=allcampaigns&uwcenabledonly=' |
136 | => 'apihelp-query+allcampaigns-example-1', |
137 | ]; |
138 | } |
139 | |
140 | public function getHelpUrls() { |
141 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:UploadWizard'; |
142 | } |
143 | } |