2010-08-07 18:50:23 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2010-08-07 18:50:23 +00:00
|
|
|
*
|
2010-10-23 18:53:39 +00:00
|
|
|
* Created on Aug 7, 2010
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
2010-10-23 18:53:39 +00:00
|
|
|
* Copyright © 2010 soxred93, Bryan Tong Minh
|
2010-08-07 18:50:23 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2010-08-07 18:50:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A query module to show basic page information.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiQueryPageProps extends ApiQueryBase {
|
|
|
|
|
|
2010-10-26 16:37:15 +00:00
|
|
|
private $params;
|
2010-10-06 21:18:55 +00:00
|
|
|
|
2014-03-25 17:22:11 +00:00
|
|
|
public function __construct( ApiQuery $query, $moduleName ) {
|
2010-08-07 18:50:23 +00:00
|
|
|
parent::__construct( $query, $moduleName, 'pp' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2010-10-26 19:31:47 +00:00
|
|
|
# Only operate on existing pages
|
2010-10-23 18:53:39 +00:00
|
|
|
$pages = $this->getPageSet()->getGoodTitles();
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2011-01-05 21:59:05 +00:00
|
|
|
$this->params = $this->extractRequestParams();
|
2010-10-23 18:53:39 +00:00
|
|
|
if ( $this->params['continue'] ) {
|
2016-02-14 21:58:46 +00:00
|
|
|
$continueValue = intval( $this->params['continue'] );
|
|
|
|
|
$this->dieContinueUsageIf( strval( $continueValue ) !== $this->params['continue'] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$filteredPages = [];
|
2016-02-14 21:58:46 +00:00
|
|
|
foreach ( $pages as $id => $page ) {
|
|
|
|
|
if ( $id >= $continueValue ) {
|
|
|
|
|
$filteredPages[$id] = $page;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$pages = $filteredPages;
|
2016-01-19 17:49:01 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-14 21:58:46 +00:00
|
|
|
if ( !count( $pages ) ) {
|
|
|
|
|
# Nothing to do
|
|
|
|
|
return;
|
2012-12-31 19:15:50 +00:00
|
|
|
}
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2016-02-14 21:58:46 +00:00
|
|
|
$pageProps = PageProps::getInstance();
|
2010-08-07 18:50:23 +00:00
|
|
|
$result = $this->getResult();
|
2016-02-14 21:58:46 +00:00
|
|
|
if ( $this->params['prop'] ) {
|
|
|
|
|
$propnames = $this->params['prop'];
|
|
|
|
|
$properties = $pageProps->getProperties( $pages, $propnames );
|
|
|
|
|
} else {
|
|
|
|
|
$properties = $pageProps->getAllProperties( $pages );
|
|
|
|
|
}
|
2016-01-19 17:49:01 +00:00
|
|
|
|
2016-02-14 21:58:46 +00:00
|
|
|
ksort( $properties );
|
2016-01-19 17:49:01 +00:00
|
|
|
|
2016-02-14 21:58:46 +00:00
|
|
|
foreach ( $properties as $page => $props ) {
|
|
|
|
|
if ( !$this->addPageProps( $result, $page, $props ) ) {
|
|
|
|
|
break;
|
2010-08-07 18:50:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-12-30 17:06:09 +00:00
|
|
|
* Add page properties to an ApiResult, adding a continue
|
2010-10-23 18:53:39 +00:00
|
|
|
* parameter if it doesn't fit.
|
|
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiResult $result
|
|
|
|
|
* @param int $page
|
|
|
|
|
* @param array $props
|
2010-10-23 18:53:39 +00:00
|
|
|
* @return bool True if it fits in the result
|
2010-08-07 18:50:23 +00:00
|
|
|
*/
|
2010-10-23 18:53:39 +00:00
|
|
|
private function addPageProps( $result, $page, $props ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
ApiResult::setArrayType( $props, 'assoc' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props );
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2010-10-23 18:53:39 +00:00
|
|
|
if ( !$fit ) {
|
|
|
|
|
$this->setContinueEnumParameter( 'continue', $page );
|
2010-08-07 18:50:23 +00:00
|
|
|
}
|
2013-11-14 12:56:06 +00:00
|
|
|
|
2010-10-23 18:53:39 +00:00
|
|
|
return $fit;
|
2010-08-07 18:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 16:26:35 +00:00
|
|
|
public function getCacheMode( $params ) {
|
2010-08-07 18:50:23 +00:00
|
|
|
return 'public';
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-30 17:06:09 +00:00
|
|
|
public function getAllowedParams() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
'continue' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'prop' => [
|
2012-12-31 19:15:50 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2010-08-07 18:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-04-07 10:31:43 +00:00
|
|
|
'action=query&prop=pageprops&titles=Main%20Page|MediaWiki'
|
2014-09-18 17:38:23 +00:00
|
|
|
=> 'apihelp-query+pageprops-example-simple',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-08-07 18:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:51:11 +00:00
|
|
|
public function getHelpUrls() {
|
2015-04-07 09:55:31 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/API:Pageprops';
|
2011-07-17 16:51:11 +00:00
|
|
|
}
|
2010-08-07 18:50:23 +00:00
|
|
|
}
|