MediaWiki REL1_30
ApiQueryPageProps.php
Go to the documentation of this file.
1<?php
33
34 private $params;
35
36 public function __construct( ApiQuery $query, $moduleName ) {
37 parent::__construct( $query, $moduleName, 'pp' );
38 }
39
40 public function execute() {
41 # Only operate on existing pages
42 $pages = $this->getPageSet()->getGoodTitles();
43
44 $this->params = $this->extractRequestParams();
45 if ( $this->params['continue'] ) {
46 $continueValue = intval( $this->params['continue'] );
47 $this->dieContinueUsageIf( strval( $continueValue ) !== $this->params['continue'] );
48 $filteredPages = [];
49 foreach ( $pages as $id => $page ) {
50 if ( $id >= $continueValue ) {
51 $filteredPages[$id] = $page;
52 }
53 }
54 $pages = $filteredPages;
55 }
56
57 if ( !count( $pages ) ) {
58 # Nothing to do
59 return;
60 }
61
62 $pageProps = PageProps::getInstance();
63 $result = $this->getResult();
64 if ( $this->params['prop'] ) {
65 $propnames = $this->params['prop'];
66 $properties = $pageProps->getProperties( $pages, $propnames );
67 } else {
68 $properties = $pageProps->getAllProperties( $pages );
69 }
70
71 ksort( $properties );
72
73 foreach ( $properties as $page => $props ) {
74 if ( !$this->addPageProps( $result, $page, $props ) ) {
75 break;
76 }
77 }
78 }
79
89 private function addPageProps( $result, $page, $props ) {
90 ApiResult::setArrayType( $props, 'assoc' );
91 $fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props );
92
93 if ( !$fit ) {
94 $this->setContinueEnumParameter( 'continue', $page );
95 }
96
97 return $fit;
98 }
99
100 public function getCacheMode( $params ) {
101 return 'public';
102 }
103
104 public function getAllowedParams() {
105 return [
106 'continue' => [
107 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
108 ],
109 'prop' => [
111 ],
112 ];
113 }
114
115 protected function getExamplesMessages() {
116 return [
117 'action=query&prop=pageprops&titles=Main%20Page|MediaWiki'
118 => 'apihelp-query+pageprops-example-simple',
119 ];
120 }
121
122 public function getHelpUrls() {
123 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops';
124 }
125}
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:2026
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:740
getResult()
Get the result object.
Definition ApiBase.php:632
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:128
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:55
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:40
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:1610