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
25 * A query module to list used page props
30 class ApiQueryPagePropNames
extends ApiQueryBase
{
32 public function __construct( ApiQuery
$query, $moduleName ) {
33 parent
::__construct( $query, $moduleName, 'ppn' );
36 public function getCacheMode( $params ) {
40 public function execute() {
41 $params = $this->extractRequestParams();
43 $this->addTables( 'page_props' );
44 $this->addFields( 'pp_propname' );
45 $this->addOption( 'DISTINCT' );
46 $this->addOption( 'ORDER BY', 'pp_propname' );
48 if ( $params['continue'] ) {
49 $cont = explode( '|', $params['continue'] );
50 $this->dieContinueUsageIf( count( $cont ) != 1 );
53 $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null );
56 $limit = $params['limit'];
58 // mysql has issues with limit in loose index T115825
59 if ( $this->getDB()->getType() !== 'mysql' ) {
60 $this->addOption( 'LIMIT', $limit +
1 );
63 $result = $this->getResult();
65 foreach ( $this->select( __METHOD__
) as $row ) {
66 if ( ++
$count > $limit ) {
67 // We've reached the one extra which shows that there are
68 // additional pages to be had. Stop here...
69 $this->setContinueEnumParameter( 'continue', $row->pp_propname
);
74 $vals['propname'] = $row->pp_propname
;
75 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
77 $this->setContinueEnumParameter( 'continue', $row->pp_propname
);
82 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
85 public function getAllowedParams() {
88 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
91 ApiBase
::PARAM_TYPE
=> 'limit',
92 ApiBase
::PARAM_DFLT
=> 10,
93 ApiBase
::PARAM_MIN
=> 1,
94 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
95 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
100 protected function getExamplesMessages() {
102 'action=query&list=pagepropnames'
103 => 'apihelp-query+pagepropnames-example-simple',
107 public function getHelpUrls() {
108 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames';