Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / includes / api / ApiQueryPageProps.php
blobde1df347701360d034f65f9046d867be60d91114
1 <?php
2 /**
5 * Created on Aug 7, 2010
7 * Copyright © 2010 soxred93, Bryan Tong Minh
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 /**
28 * A query module to show basic page information.
30 * @ingroup API
32 class ApiQueryPageProps extends ApiQueryBase {
34 private $params;
36 public function __construct( ApiQuery $query, $moduleName ) {
37 parent::__construct( $query, $moduleName, 'pp' );
40 public function execute() {
41 # Only operate on existing pages
42 $pages = $this->getPageSet()->getGoodTitles();
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;
54 $pages = $filteredPages;
57 if ( !count( $pages ) ) {
58 # Nothing to do
59 return;
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 );
71 ksort( $properties );
73 foreach ( $properties as $page => $props ) {
74 if ( !$this->addPageProps( $result, $page, $props ) ) {
75 break;
80 /**
81 * Add page properties to an ApiResult, adding a continue
82 * parameter if it doesn't fit.
84 * @param ApiResult $result
85 * @param int $page
86 * @param array $props
87 * @return bool True if it fits in the result
89 private function addPageProps( $result, $page, $props ) {
90 ApiResult::setArrayType( $props, 'assoc' );
91 $fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props );
93 if ( !$fit ) {
94 $this->setContinueEnumParameter( 'continue', $page );
97 return $fit;
100 public function getCacheMode( $params ) {
101 return 'public';
104 public function getAllowedParams() {
105 return [
106 'continue' => [
107 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
109 'prop' => [
110 ApiBase::PARAM_ISMULTI => true,
115 protected function getExamplesMessages() {
116 return [
117 'action=query&prop=pageprops&titles=Main%20Page|MediaWiki'
118 => 'apihelp-query+pageprops-example-simple',
122 public function getHelpUrls() {
123 return 'https://www.mediawiki.org/wiki/API:Pageprops';