Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / api / ApiQueryPageProps.php
blob1ef6c84e4ecdad9a75266a345274b33ade2a7baf
1 <?php
2 /**
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
20 * @file
23 namespace MediaWiki\Api;
25 use MediaWiki\Page\PageProps;
26 use MediaWiki\Title\Title;
27 use Wikimedia\ParamValidator\ParamValidator;
29 /**
30 * A query module to show basic page information.
32 * @ingroup API
34 class ApiQueryPageProps extends ApiQueryBase {
36 private PageProps $pageProps;
38 public function __construct(
39 ApiQuery $query,
40 string $moduleName,
41 PageProps $pageProps
42 ) {
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];
55 $filteredPages = [];
56 foreach ( $pages as $id => $page ) {
57 if ( $id >= $continueValue ) {
58 $filteredPages[$id] = $page;
61 $pages = $filteredPages;
64 if ( $pages === [] ) {
65 # Nothing to do
66 return;
69 if ( $params['prop'] ) {
70 $properties = $this->pageProps->getProperties( $pages, $params['prop'] );
71 } else {
72 $properties = $this->pageProps->getAllProperties( $pages );
75 ksort( $properties );
77 $result = $this->getResult();
78 foreach ( $properties as $pageid => $props ) {
79 if ( !$this->addPageProps( $result, $pageid, $props ) ) {
80 break;
85 /**
86 * Add page properties to an ApiResult, adding a continue
87 * parameter if it doesn't fit.
89 * @param ApiResult $result
90 * @param int $page
91 * @param array $props
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 );
98 if ( !$fit ) {
99 $this->setContinueEnumParameter( 'continue', $page );
102 return $fit;
105 public function getCacheMode( $params ) {
106 return 'public';
109 public function getAllowedParams() {
110 return [
111 'continue' => [
112 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
114 'prop' => [
115 ParamValidator::PARAM_ISMULTI => true,
120 protected function getExamplesMessages() {
121 $title = Title::newMainPage()->getPrefixedText();
122 $mp = rawurlencode( $title );
124 return [
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' );