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