| 1 |
<?php |
| 2 |
|
| 3 |
s |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\Api; |
| 25 |
|
| 26 |
use Wikimedia\ParamValidator\ParamValidator; |
| 27 |
use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class ApiQueryPagePropNames extends ApiQueryBase { |
| 36 |
|
| 37 |
public function __construct( ApiQuery $query, string $moduleName ) { |
| 38 |
parent::__construct( $query, $moduleName, 'ppn' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function getCacheMode( $params ) { |
| 42 |
return 'public'; |
| 43 |
} |
| 44 |
|
| 45 |
public function execute() { |
| 46 |
$params = $this->extractRequestParams(); |
| 47 |
|
| 48 |
$this->addTables( 'page_props' ); |
| 49 |
$this->addFields( 'pp_propname' ); |
| 50 |
$this->addOption( 'DISTINCT' ); |
| 51 |
$this->addOption( 'ORDER BY', 'pp_propname' ); |
| 52 |
|
| 53 |
if ( $params['continue'] ) { |
| 54 |
$cont = $this->parseContinueParamOrDie( $params['continue'], [ 'string' ] ); |
| 55 |
|
| 56 |
$this->addWhereRange( 'pp_propname', 'newer', $cont[0], null ); |
| 57 |
} |
| 58 |
|
| 59 |
$limit = $params['limit']; |
| 60 |
|
| 61 |
|
| 62 |
if ( $this->getDB()->getType() !== 'mysql' ) { |
| 63 |
$this->addOption( 'LIMIT', $limit + 1 ); |
| 64 |
} |
| 65 |
|
| 66 |
$result = $this->getResult(); |
| 67 |
$count = 0; |
| 68 |
foreach ( $this->select( __METHOD__ ) as $row ) { |
| 69 |
if ( ++$count > $limit ) { |
| 70 |
|
| 71 |
|
| 72 |
$this->setContinueEnumParameter( 'continue', $row->pp_propname ); |
| 73 |
break; |
| 74 |
} |
| 75 |
|
| 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; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
$result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' ); |
| 86 |
} |
| 87 |
|
| 88 |
public function getAllowedParams() { |
| 89 |
return [ |
| 90 |
'continue' => [ |
| 91 |
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
| 92 |
], |
| 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 |
| 99 |
], |
| 100 |
]; |
| 101 |
} |
| 102 |
|
| 103 |
protected function getExamplesMessages() { |
| 104 |
return [ |
| 105 |
'action=query&list=pagepropnames' |
| 106 |
=> 'apihelp-query+pagepropnames-example-simple', |
| 107 |
]; |
| 108 |
} |
| 109 |
|
| 110 |
public function getHelpUrls() { |
| 111 |
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames'; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
class_alias( ApiQueryPagePropNames::class, 'ApiQueryPagePropNames' ); |