3 * Copyright © 2013 Wikimedia Foundation and contributors
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.
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.
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
24 namespace MediaWiki\Api
;
26 use Wikimedia\ParamValidator\ParamValidator
;
27 use Wikimedia\ParamValidator\TypeDef\IntegerDef
;
30 * A query module to list used page props
35 class ApiQueryPagePropNames
extends ApiQueryBase
{
37 public function __construct( ApiQuery
$query, string $moduleName ) {
38 parent
::__construct( $query, $moduleName, 'ppn' );
41 public function getCacheMode( $params ) {
45 public function execute() {
46 $params = $this->extractRequestParams();
48 $this->addTables( 'page_props' );
49 $this->addFields( 'pp_propname' );
50 $this->addOption( 'DISTINCT' );
51 $this->addOption( 'ORDER BY', 'pp_propname' );
53 if ( $params['continue'] ) {
54 $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'string' ] );
56 $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null );
59 $limit = $params['limit'];
61 // mysql has issues with limit in loose index T115825
62 if ( $this->getDB()->getType() !== 'mysql' ) {
63 $this->addOption( 'LIMIT', $limit +
1 );
66 $result = $this->getResult();
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
);
77 $vals['propname'] = $row->pp_propname
;
78 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
80 $this->setContinueEnumParameter( 'continue', $row->pp_propname
);
85 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
88 public function getAllowedParams() {
91 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
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
103 protected function getExamplesMessages() {
105 'action=query&list=pagepropnames'
106 => 'apihelp-query+pagepropnames-example-simple',
110 public function getHelpUrls() {
111 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames';
115 /** @deprecated class alias since 1.43 */
116 class_alias( ApiQueryPagePropNames
::class, 'ApiQueryPagePropNames' );