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