2010-08-07 18:50:23 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
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
|
|
|
*/
|
|
|
|
|
|
2024-09-25 16:17:29 +00:00
|
|
|
namespace MediaWiki\Api;
|
|
|
|
|
|
2022-12-09 12:17:40 +00:00
|
|
|
use MediaWiki\Page\PageProps;
|
2019-11-30 11:55:36 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-06-05 23:18:50 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
|
|
|
|
|
2010-08-07 18:50:23 +00:00
|
|
|
/**
|
|
|
|
|
* A query module to show basic page information.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiQueryPageProps extends ApiQueryBase {
|
|
|
|
|
|
2023-08-28 15:32:58 +00:00
|
|
|
private PageProps $pageProps;
|
2010-10-06 21:18:55 +00:00
|
|
|
|
2021-06-28 20:44:34 +00:00
|
|
|
public function __construct(
|
|
|
|
|
ApiQuery $query,
|
2024-10-14 20:12:27 +00:00
|
|
|
string $moduleName,
|
2021-06-28 20:44:34 +00:00
|
|
|
PageProps $pageProps
|
|
|
|
|
) {
|
2010-08-07 18:50:23 +00:00
|
|
|
parent::__construct( $query, $moduleName, 'pp' );
|
2021-06-28 20:44:34 +00:00
|
|
|
$this->pageProps = $pageProps;
|
2010-08-07 18:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2010-10-26 19:31:47 +00:00
|
|
|
# Only operate on existing pages
|
2021-06-28 20:44:34 +00:00
|
|
|
$pages = $this->getPageSet()->getGoodPages();
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2021-06-28 20:44:34 +00:00
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
if ( $params['continue'] ) {
|
2022-09-16 14:38:10 +00:00
|
|
|
$cont = $this->parseContinueParamOrDie( $params['continue'], [ 'int' ] );
|
|
|
|
|
$continueValue = $cont[0];
|
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
|
|
|
}
|
|
|
|
|
|
2019-01-09 16:24:36 +00:00
|
|
|
if ( $pages === [] ) {
|
2016-02-14 21:58:46 +00:00
|
|
|
# Nothing to do
|
|
|
|
|
return;
|
2012-12-31 19:15:50 +00:00
|
|
|
}
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2021-06-28 20:44:34 +00:00
|
|
|
if ( $params['prop'] ) {
|
|
|
|
|
$properties = $this->pageProps->getProperties( $pages, $params['prop'] );
|
2016-02-14 21:58:46 +00:00
|
|
|
} else {
|
2021-06-28 20:44:34 +00:00
|
|
|
$properties = $this->pageProps->getAllProperties( $pages );
|
2016-02-14 21:58:46 +00:00
|
|
|
}
|
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
|
|
|
|
2021-06-28 20:44:34 +00:00
|
|
|
$result = $this->getResult();
|
|
|
|
|
foreach ( $properties as $pageid => $props ) {
|
|
|
|
|
if ( !$this->addPageProps( $result, $pageid, $props ) ) {
|
2016-02-14 21:58:46 +00:00
|
|
|
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' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::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() {
|
2019-11-30 11:55:36 +00:00
|
|
|
$title = Title::newMainPage()->getPrefixedText();
|
|
|
|
|
$mp = rawurlencode( $title );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2019-11-30 11:55:36 +00:00
|
|
|
"action=query&prop=pageprops&titles={$mp}|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() {
|
2017-04-04 22:52:57 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops';
|
2011-07-17 16:51:11 +00:00
|
|
|
}
|
2010-08-07 18:50:23 +00:00
|
|
|
}
|
2024-09-25 16:17:29 +00:00
|
|
|
|
|
|
|
|
/** @deprecated class alias since 1.43 */
|
|
|
|
|
class_alias( ApiQueryPageProps::class, 'ApiQueryPageProps' );
|