Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 106 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryConfiguredpages | |
0.00% |
0 / 106 |
|
0.00% |
0 / 7 |
342 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
executeGenerator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 62 |
|
0.00% |
0 / 1 |
156 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Created on April 8, 2011 |
5 | * |
6 | * API module for MediaWiki's FlaggedRevs extension |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; if not, write to the Free Software Foundation, Inc., |
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
21 | * http://www.gnu.org/copyleft/gpl.html |
22 | */ |
23 | |
24 | use MediaWiki\Api\ApiBase; |
25 | use MediaWiki\Api\ApiPageSet; |
26 | use MediaWiki\Api\ApiQuery; |
27 | use MediaWiki\Api\ApiQueryGeneratorBase; |
28 | use MediaWiki\Title\Title; |
29 | use Wikimedia\ParamValidator\ParamValidator; |
30 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
31 | |
32 | /** |
33 | * Query module to list pages with custom review configurations |
34 | * |
35 | * @ingroup FlaggedRevs |
36 | */ |
37 | class ApiQueryConfiguredpages extends ApiQueryGeneratorBase { |
38 | |
39 | public function __construct( ApiQuery $query, string $moduleName ) { |
40 | parent::__construct( $query, $moduleName, 'cp' ); |
41 | } |
42 | |
43 | /** |
44 | * @inheritDoc |
45 | */ |
46 | public function execute() { |
47 | $this->run(); |
48 | } |
49 | |
50 | /** |
51 | * @param ApiPageSet $resultPageSet |
52 | */ |
53 | public function executeGenerator( $resultPageSet ) { |
54 | $this->run( $resultPageSet ); |
55 | } |
56 | |
57 | /** |
58 | * @param ApiPageSet|null $resultPageSet |
59 | */ |
60 | private function run( $resultPageSet = null ) { |
61 | $params = $this->extractRequestParams(); |
62 | |
63 | // Construct SQL Query |
64 | $this->addTables( [ 'page', 'flaggedpage_config', 'flaggedpages' ] ); |
65 | if ( isset( $params['namespace'] ) ) { |
66 | $this->addWhereFld( 'page_namespace', $params['namespace'] ); |
67 | } |
68 | if ( isset( $params['default'] ) ) { |
69 | // Convert readable 'stable'/'latest' to 0/1 (DB format) |
70 | $override = ( $params['default'] === 'stable' ) ? 1 : 0; |
71 | $this->addWhereFld( 'fpc_override', $override ); |
72 | } |
73 | if ( isset( $params['autoreview'] ) ) { |
74 | // Convert readable 'none' to '' (DB format) |
75 | $level = ( $params['autoreview'] === 'none' ) ? '' : $params['autoreview']; |
76 | $this->addWhereFld( 'fpc_level', $level ); |
77 | } |
78 | |
79 | $this->addWhereRange( |
80 | 'fpc_page_id', |
81 | $params['dir'], |
82 | $params['start'], |
83 | $params['end'] |
84 | ); |
85 | $this->addJoinConds( [ |
86 | 'flaggedpage_config' => [ 'INNER JOIN', 'page_id=fpc_page_id' ], |
87 | 'flaggedpages' => [ 'LEFT JOIN', 'page_id=fp_page_id' ] |
88 | ] ); |
89 | |
90 | if ( $resultPageSet === null ) { |
91 | $this->addFields( [ |
92 | 'page_id', |
93 | 'page_namespace', |
94 | 'page_title', |
95 | 'page_len', |
96 | 'page_latest', |
97 | 'fpc_page_id', |
98 | 'fpc_override', |
99 | 'fpc_level', |
100 | 'fpc_expiry', |
101 | 'fp_stable' |
102 | ] ); |
103 | } else { |
104 | $this->addFields( $resultPageSet->getPageTableFields() ); |
105 | $this->addFields( 'fpc_page_id' ); |
106 | } |
107 | |
108 | $limit = $params['limit']; |
109 | $this->addOption( 'LIMIT', $limit + 1 ); |
110 | $res = $this->select( __METHOD__ ); |
111 | |
112 | $data = []; |
113 | $count = 0; |
114 | foreach ( $res as $row ) { |
115 | if ( ++$count > $limit ) { |
116 | // We've reached the one extra which shows that there are |
117 | // additional pages to be had. Stop here... |
118 | $this->setContinueEnumParameter( 'start', $row->fpc_page_id ); |
119 | break; |
120 | } |
121 | |
122 | if ( $resultPageSet === null ) { |
123 | $title = Title::newFromRow( $row ); |
124 | $data[] = [ |
125 | 'pageid' => intval( $row->page_id ), |
126 | 'ns' => intval( $row->page_namespace ), |
127 | 'title' => $title->getPrefixedText(), |
128 | 'last_revid' => intval( $row->page_latest ), |
129 | 'stable_revid' => intval( $row->fp_stable ), |
130 | 'stable_is_default' => intval( $row->fpc_override ), |
131 | 'autoreview' => $row->fpc_level, |
132 | 'expiry' => ( $row->fpc_expiry === 'infinity' ) ? |
133 | 'infinity' : wfTimestamp( TS_ISO_8601, $row->fpc_expiry ), |
134 | ]; |
135 | } else { |
136 | $resultPageSet->processDbRow( $row ); |
137 | } |
138 | } |
139 | |
140 | if ( $resultPageSet === null ) { |
141 | $result = $this->getResult(); |
142 | $result->setIndexedTagName( $data, 'p' ); |
143 | $result->addValue( 'query', $this->getModuleName(), $data ); |
144 | } |
145 | } |
146 | |
147 | /** |
148 | * @inheritDoc |
149 | */ |
150 | public function getCacheMode( $params ) { |
151 | return 'public'; |
152 | } |
153 | |
154 | /** |
155 | * @inheritDoc |
156 | */ |
157 | protected function getAllowedParams() { |
158 | // Replace '' with more readable 'none' in autoreview restiction levels |
159 | $autoreviewLevels = [ ...FlaggedRevs::getRestrictionLevels(), 'none' ]; |
160 | return [ |
161 | 'start' => [ |
162 | ParamValidator::PARAM_TYPE => 'integer' |
163 | ], |
164 | 'end' => [ |
165 | ParamValidator::PARAM_TYPE => 'integer' |
166 | ], |
167 | 'dir' => [ |
168 | ParamValidator::PARAM_DEFAULT => 'newer', |
169 | ParamValidator::PARAM_TYPE => [ 'newer', 'older' ], |
170 | ApiBase::PARAM_HELP_MSG => 'api-help-param-direction', |
171 | ], |
172 | 'namespace' => [ |
173 | ParamValidator::PARAM_DEFAULT => null, |
174 | ParamValidator::PARAM_TYPE => 'namespace', |
175 | ParamValidator::PARAM_ISMULTI => true, |
176 | ], |
177 | 'default' => [ |
178 | ParamValidator::PARAM_DEFAULT => null, |
179 | ParamValidator::PARAM_TYPE => [ 'latest', 'stable' ], |
180 | ], |
181 | 'autoreview' => [ |
182 | ParamValidator::PARAM_DEFAULT => null, |
183 | ParamValidator::PARAM_TYPE => $autoreviewLevels, |
184 | ], |
185 | 'limit' => [ |
186 | ParamValidator::PARAM_DEFAULT => 10, |
187 | ParamValidator::PARAM_TYPE => 'limit', |
188 | IntegerDef::PARAM_MIN => 1, |
189 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
190 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
191 | ] |
192 | ]; |
193 | } |
194 | |
195 | /** |
196 | * @inheritDoc |
197 | */ |
198 | protected function getExamplesMessages() { |
199 | return [ |
200 | 'action=query&list=configuredpages&cpnamespace=0' |
201 | => 'apihelp-query+configuredpages-example-1', |
202 | 'action=query&generator=configuredpages&gcplimit=4&prop=info' |
203 | => 'apihelp-query+configuredpages-example-2', |
204 | ]; |
205 | } |
206 | } |