Merge "Typo fix"
[mediawiki.git] / includes / api / ApiQueryPagePropNames.php
blob08c883d8ebc88d7d87c76c131961fea9e5733c8b
1 <?php
2 /**
3 * Created on January 21, 2013
5 * Copyright © 2013 Brad Jorsch <bjorsch@wikimedia.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
23 * @since 1.21
24 * @author Brad Jorsch
27 /**
28 * A query module to list used page props
30 * @ingroup API
31 * @since 1.21
33 class ApiQueryPagePropNames extends ApiQueryBase {
35 public function __construct( $query, $moduleName ) {
36 parent::__construct( $query, $moduleName, 'ppn' );
39 public function getCacheMode( $params ) {
40 return 'public';
43 public function execute() {
44 $params = $this->extractRequestParams();
46 $this->addTables( 'page_props' );
47 $this->addFields( 'pp_propname' );
48 $this->addOption( 'DISTINCT' );
49 $this->addOption( 'ORDER BY', 'pp_propname' );
51 if ( $params['continue'] ) {
52 $cont = explode( '|', $params['continue'] );
53 $this->dieContinueUsageIf( count( $cont ) != 1 );
55 // Add a WHERE clause
56 $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null );
59 $limit = $params['limit'];
60 $this->addOption( 'LIMIT', $limit + 1 );
62 $result = $this->getResult();
63 $count = 0;
64 foreach ( $this->select( __METHOD__ ) as $row ) {
65 if ( ++$count > $limit ) {
66 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
67 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
68 break;
71 $vals = array();
72 $vals['propname'] = $row->pp_propname;
73 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
74 if ( !$fit ) {
75 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
76 break;
80 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'p' );
83 public function getAllowedParams() {
84 return array(
85 'continue' => null,
86 'limit' => array(
87 ApiBase::PARAM_TYPE => 'limit',
88 ApiBase::PARAM_DFLT => 10,
89 ApiBase::PARAM_MIN => 1,
90 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
91 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
96 public function getParamDescription() {
97 return array(
98 'continue' => 'When more results are available, use this to continue',
99 'limit' => 'The maximum number of pages to return',
103 public function getDescription() {
104 return 'List all page prop names in use on the wiki';
107 public function getExamples() {
108 return array(
109 'api.php?action=query&list=pagepropnames' => 'Get first 10 prop names',
113 public function getHelpUrls() {
114 return 'https://www.mediawiki.org/wiki/API:Pagepropnames';