3 * Copyright © 2010 soxred93, Bryan Tong Minh
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
23 namespace MediaWiki\Api
;
25 use MediaWiki\Page\PageProps
;
26 use MediaWiki\Title\Title
;
27 use Wikimedia\ParamValidator\ParamValidator
;
30 * A query module to show basic page information.
34 class ApiQueryPageProps
extends ApiQueryBase
{
36 private PageProps
$pageProps;
38 public function __construct(
43 parent
::__construct( $query, $moduleName, 'pp' );
44 $this->pageProps
= $pageProps;
47 public function execute() {
48 # Only operate on existing pages
49 $pages = $this->getPageSet()->getGoodPages();
51 $params = $this->extractRequestParams();
52 if ( $params['continue'] ) {
53 $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'int' ] );
54 $continueValue = $cont[0];
56 foreach ( $pages as $id => $page ) {
57 if ( $id >= $continueValue ) {
58 $filteredPages[$id] = $page;
61 $pages = $filteredPages;
64 if ( $pages === [] ) {
69 if ( $params['prop'] ) {
70 $properties = $this->pageProps
->getProperties( $pages, $params['prop'] );
72 $properties = $this->pageProps
->getAllProperties( $pages );
77 $result = $this->getResult();
78 foreach ( $properties as $pageid => $props ) {
79 if ( !$this->addPageProps( $result, $pageid, $props ) ) {
86 * Add page properties to an ApiResult, adding a continue
87 * parameter if it doesn't fit.
89 * @param ApiResult $result
92 * @return bool True if it fits in the result
94 private function addPageProps( $result, $page, $props ) {
95 ApiResult
::setArrayType( $props, 'assoc' );
96 $fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props );
99 $this->setContinueEnumParameter( 'continue', $page );
105 public function getCacheMode( $params ) {
109 public function getAllowedParams() {
112 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
115 ParamValidator
::PARAM_ISMULTI
=> true,
120 protected function getExamplesMessages() {
121 $title = Title
::newMainPage()->getPrefixedText();
122 $mp = rawurlencode( $title );
125 "action=query&prop=pageprops&titles={$mp}|MediaWiki"
126 => 'apihelp-query+pageprops-example-simple',
130 public function getHelpUrls() {
131 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops';
135 /** @deprecated class alias since 1.43 */
136 class_alias( ApiQueryPageProps
::class, 'ApiQueryPageProps' );