MediaWiki REL1_32
ApiQueryPageProps.php
Go to the documentation of this file.
1<?php
29
30 private $params;
31
32 public function __construct( ApiQuery $query, $moduleName ) {
33 parent::__construct( $query, $moduleName, 'pp' );
34 }
35
36 public function execute() {
37 # Only operate on existing pages
38 $pages = $this->getPageSet()->getGoodTitles();
39
40 $this->params = $this->extractRequestParams();
41 if ( $this->params['continue'] ) {
42 $continueValue = intval( $this->params['continue'] );
43 $this->dieContinueUsageIf( strval( $continueValue ) !== $this->params['continue'] );
44 $filteredPages = [];
45 foreach ( $pages as $id => $page ) {
46 if ( $id >= $continueValue ) {
47 $filteredPages[$id] = $page;
48 }
49 }
50 $pages = $filteredPages;
51 }
52
53 if ( !count( $pages ) ) {
54 # Nothing to do
55 return;
56 }
57
58 $pageProps = PageProps::getInstance();
59 $result = $this->getResult();
60 if ( $this->params['prop'] ) {
61 $propnames = $this->params['prop'];
62 $properties = $pageProps->getProperties( $pages, $propnames );
63 } else {
64 $properties = $pageProps->getAllProperties( $pages );
65 }
66
67 ksort( $properties );
68
69 foreach ( $properties as $page => $props ) {
70 if ( !$this->addPageProps( $result, $page, $props ) ) {
71 break;
72 }
73 }
74 }
75
85 private function addPageProps( $result, $page, $props ) {
86 ApiResult::setArrayType( $props, 'assoc' );
87 $fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props );
88
89 if ( !$fit ) {
90 $this->setContinueEnumParameter( 'continue', $page );
91 }
92
93 return $fit;
94 }
95
96 public function getCacheMode( $params ) {
97 return 'public';
98 }
99
100 public function getAllowedParams() {
101 return [
102 'continue' => [
103 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
104 ],
105 'prop' => [
107 ],
108 ];
109 }
110
111 protected function getExamplesMessages() {
112 return [
113 'action=query&prop=pageprops&titles=Main%20Page|MediaWiki'
114 => 'apihelp-query+pageprops-example-simple',
115 ];
116 }
117
118 public function getHelpUrls() {
119 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops';
120 }
121}
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:2155
getResult()
Get the result object.
Definition ApiBase.php:659
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:770
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
getPageSet()
Get the PageSet object to work on.
A query module to show basic page information.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName)
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
addPageProps( $result, $page, $props)
Add page properties to an ApiResult, adding a continue parameter if it doesn't fit.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
This is the main query class.
Definition ApiQuery.php:36
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
static getInstance()
Definition PageProps.php:66
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1656