Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryPagePropNames | |
0.00% |
0 / 43 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
42 | |||
getAllowedParams | |
0.00% |
0 / 12 |
|
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 Wikimedia Foundation and contributors |
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 | * @since 1.21 |
22 | */ |
23 | |
24 | use Wikimedia\ParamValidator\ParamValidator; |
25 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
26 | |
27 | /** |
28 | * A query module to list used page props |
29 | * |
30 | * @ingroup API |
31 | * @since 1.21 |
32 | */ |
33 | class ApiQueryPagePropNames extends ApiQueryBase { |
34 | |
35 | public function __construct( ApiQuery $query, $moduleName ) { |
36 | parent::__construct( $query, $moduleName, 'ppn' ); |
37 | } |
38 | |
39 | public function getCacheMode( $params ) { |
40 | return 'public'; |
41 | } |
42 | |
43 | public function execute() { |
44 | $params = $this->extractRequestParams(); |
45 | |
46 | $this->addTables( 'page_props' ); |
47 | $this->addFields( 'pp_propname' ); |
48 | $this->addOption( 'DISTINCT' ); |
49 | $this->addOption( 'ORDER BY', 'pp_propname' ); |
50 | |
51 | if ( $params['continue'] ) { |
52 | $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'string' ] ); |
53 | // Add a WHERE clause |
54 | $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null ); |
55 | } |
56 | |
57 | $limit = $params['limit']; |
58 | |
59 | // mysql has issues with limit in loose index T115825 |
60 | if ( $this->getDB()->getType() !== 'mysql' ) { |
61 | $this->addOption( 'LIMIT', $limit + 1 ); |
62 | } |
63 | |
64 | $result = $this->getResult(); |
65 | $count = 0; |
66 | foreach ( $this->select( __METHOD__ ) as $row ) { |
67 | if ( ++$count > $limit ) { |
68 | // We've reached the one extra which shows that there are |
69 | // additional pages to be had. Stop here... |
70 | $this->setContinueEnumParameter( 'continue', $row->pp_propname ); |
71 | break; |
72 | } |
73 | |
74 | $vals = []; |
75 | $vals['propname'] = $row->pp_propname; |
76 | $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals ); |
77 | if ( !$fit ) { |
78 | $this->setContinueEnumParameter( 'continue', $row->pp_propname ); |
79 | break; |
80 | } |
81 | } |
82 | |
83 | $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' ); |
84 | } |
85 | |
86 | public function getAllowedParams() { |
87 | return [ |
88 | 'continue' => [ |
89 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
90 | ], |
91 | 'limit' => [ |
92 | ParamValidator::PARAM_TYPE => 'limit', |
93 | ParamValidator::PARAM_DEFAULT => 10, |
94 | IntegerDef::PARAM_MIN => 1, |
95 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
96 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
97 | ], |
98 | ]; |
99 | } |
100 | |
101 | protected function getExamplesMessages() { |
102 | return [ |
103 | 'action=query&list=pagepropnames' |
104 | => 'apihelp-query+pagepropnames-example-simple', |
105 | ]; |
106 | } |
107 | |
108 | public function getHelpUrls() { |
109 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames'; |
110 | } |
111 | } |