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
24 * A query module to show basic page information.
28 class ApiQueryPageProps
extends ApiQueryBase
{
32 public function __construct( ApiQuery
$query, $moduleName ) {
33 parent
::__construct( $query, $moduleName, 'pp' );
36 public function execute() {
37 # Only operate on existing pages
38 $pages = $this->getPageSet()->getGoodTitles();
40 $this->params
= $this->extractRequestParams();
41 if ( $this->params
['continue'] ) {
42 $continueValue = intval( $this->params
['continue'] );
43 $this->dieContinueUsageIf( strval( $continueValue ) !== $this->params
['continue'] );
45 foreach ( $pages as $id => $page ) {
46 if ( $id >= $continueValue ) {
47 $filteredPages[$id] = $page;
50 $pages = $filteredPages;
53 if ( !count( $pages ) ) {
58 $pageProps = PageProps
::getInstance();
59 $result = $this->getResult();
60 if ( $this->params
['prop'] ) {
61 $propnames = $this->params
['prop'];
62 $properties = $pageProps->getProperties( $pages, $propnames );
64 $properties = $pageProps->getAllProperties( $pages );
69 foreach ( $properties as $page => $props ) {
70 if ( !$this->addPageProps( $result, $page, $props ) ) {
77 * Add page properties to an ApiResult, adding a continue
78 * parameter if it doesn't fit.
80 * @param ApiResult $result
83 * @return bool True if it fits in the result
85 private function addPageProps( $result, $page, $props ) {
86 ApiResult
::setArrayType( $props, 'assoc' );
87 $fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props );
90 $this->setContinueEnumParameter( 'continue', $page );
96 public function getCacheMode( $params ) {
100 public function getAllowedParams() {
103 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
106 ApiBase
::PARAM_ISMULTI
=> true,
111 protected function getExamplesMessages() {
113 'action=query&prop=pageprops&titles=Main%20Page|MediaWiki'
114 => 'apihelp-query+pageprops-example-simple',
118 public function getHelpUrls() {
119 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops';