Update Codex from v1.20.0 to v1.20.1
[mediawiki.git] / includes / api / ApiQueryPagePropNames.php
blob5b7960d1fccff29f5ef389cf84f6317346146c6c
1 <?php
2 /**
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
20 * @file
21 * @since 1.21
24 namespace MediaWiki\Api;
26 use Wikimedia\ParamValidator\ParamValidator;
27 use Wikimedia\ParamValidator\TypeDef\IntegerDef;
29 /**
30 * A query module to list used page props
32 * @ingroup API
33 * @since 1.21
35 class ApiQueryPagePropNames extends ApiQueryBase {
37 public function __construct( ApiQuery $query, string $moduleName ) {
38 parent::__construct( $query, $moduleName, 'ppn' );
41 public function getCacheMode( $params ) {
42 return 'public';
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' ] );
55 // Add a WHERE clause
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();
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;
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;
85 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
88 public function getAllowedParams() {
89 return [
90 'continue' => [
91 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
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
103 protected function getExamplesMessages() {
104 return [
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' );