4 * Created on Sep 25, 2006
6 * API for MediaWiki 1.8+
8 * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if ( !defined( 'MEDIAWIKI' ) ) {
27 // Eclipse helper - will be ignored in production
28 require_once( 'ApiQueryBase.php' );
32 * A query module to show basic page information.
36 class ApiQueryPageProps
extends ApiQueryBase
{
38 public function __construct( $query, $moduleName ) {
39 parent
::__construct( $query, $moduleName, 'pp' );
42 public function execute() {
43 $this->params
= $this->extractRequestParams();
45 $pageSet = $this->getPageSet();
46 $this->titles
= $pageSet->getGoodTitles();
47 $this->missing
= $pageSet->getMissingTitles();
48 $this->everything
= $this->titles +
$this->missing
;
49 $result = $this->getResult();
51 uasort( $this->everything
, array( 'Title', 'compare' ) );
52 if ( !is_null( $this->params
['continue'] ) ) {
53 // Throw away any titles we're gonna skip so they don't
55 $cont = explode( '|', $this->params
['continue'] );
56 if ( count( $cont ) != 2 ) {
57 $this->dieUsage( 'Invalid continue param. You should pass the original ' .
58 'value returned by the previous query', '_badcontinue' );
60 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
61 foreach ( $this->everything
as $pageid => $title ) {
62 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
65 unset( $this->titles
[$pageid] );
66 unset( $this->missing
[$pageid] );
67 unset( $this->everything
[$pageid] );
73 foreach ( $this->everything
as $pageid => $title ) {
74 $pageInfo = $this->extractPageInfo( $pageid, $title );
75 $fit = $result->addValue( array(
78 ), $pageid, $pageInfo );
80 $this->setContinueEnumParameter( 'continue',
81 $title->getNamespace() . '|' .
89 * Get a result array with information about a title
90 * @param $pageid int Page ID (negative for missing titles)
91 * @param $title Title object
94 private function extractPageInfo( $pageid, $title ) {
98 if ( $title->exists() ) {
100 $dbr = wfGetDB( DB_SLAVE
);
104 array( 'pp_propname', 'pp_value' ),
105 array( 'pp_page' => $pageid ),
109 foreach( $res as $row ) {
110 if( isset( $wgPageProps[$row->pp_propname
] ) ) {
111 if( !is_null( $prop ) && !in_array( $row->pp_propname
, $prop ) ) {
114 $pageInfo[$row->pp_propname
] = $row->pp_value
;
123 public function getCacheMode( $params ) {
127 public function getAllowedParams() {
132 ApiBase
::PARAM_DFLT
=> null,
133 ApiBase
::PARAM_ISMULTI
=> true,
134 ApiBase
::PARAM_TYPE
=> array_keys( $wgPageProps )
140 public function getParamDescription() {
145 'Which additional properties to get:',
147 'continue' => 'When more results are available, use this to continue',
150 $maxLen = max( array_map( 'strlen', array_keys( $wgPageProps ) ) );
151 $matchLen = $maxLen +
2;
156 foreach( $wgPageProps as $propName => $desc ) {
157 $pretext = " $propName" . str_repeat( ' ', $matchLen - strlen( $propName ) );
159 $ret['prop'][] = "$pretext- $desc";
165 public function getDescription() {
166 return 'Get various properties about a page...';
169 public function getPossibleErrors() {
170 return array_merge( parent
::getPossibleErrors(), array(
171 array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
175 protected function getExamples() {
177 'api.php?action=query&prop=pageprops&titles=Category:Foo',
181 public function getVersion() {
182 return __CLASS__
. ': $Id$';