715c4a204e616c189aeeaabd8ec87c1e125fa134
4 * Created on Sep 25, 2006
6 * API for MediaWiki 1.8+
8 * Copyright (C) 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ApiQueryInfo
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'in');
42 public function requestExtraData($pageSet) {
43 $pageSet->requestField('page_is_redirect');
44 $pageSet->requestField('page_is_new');
45 $pageSet->requestField('page_counter');
46 $pageSet->requestField('page_touched');
47 $pageSet->requestField('page_latest');
48 $pageSet->requestField('page_len');
51 public function execute() {
53 $params = $this->extractRequestParams();
54 $fld_protection = false;
55 if(!is_null($params['prop'])) {
56 $prop = array_flip($params['prop']);
57 $fld_protection = isset($prop['protection']);
60 $pageSet = $this->getPageSet();
61 $titles = $pageSet->getGoodTitles();
62 $result = $this->getResult();
64 $pageIsRedir = $pageSet->getCustomField('page_is_redirect');
65 $pageIsNew = $pageSet->getCustomField('page_is_new');
66 $pageCounter = $pageSet->getCustomField('page_counter');
67 $pageTouched = $pageSet->getCustomField('page_touched');
68 $pageLatest = $pageSet->getCustomField('page_latest');
69 $pageLength = $pageSet->getCustomField('page_len');
71 if ($fld_protection) {
72 $this->addTables('page_restrictions');
73 $this->addFields(array('pr_page', 'pr_type', 'pr_level', 'pr_expiry'));
74 $this->addWhereFld('pr_page', array_keys($titles));
77 $res = $this->select(__METHOD__
);
78 while($row = $db->fetchObject($res)) {
79 $protections[$row->pr_page
][] = array(
80 'type' => $row->pr_type
,
81 'level' => $row->pr_level
,
82 'expiry' => Block
::decodeExpiry( $row->pr_expiry
, TS_ISO_8601
)
85 $db->freeResult($res);
88 foreach ( $titles as $pageid => $unused ) {
90 'touched' => wfTimestamp(TS_ISO_8601
, $pageTouched[$pageid]),
91 'lastrevid' => intval($pageLatest[$pageid]),
92 'counter' => intval($pageCounter[$pageid]),
93 'length' => intval($pageLength[$pageid]),
96 if ($pageIsRedir[$pageid])
97 $pageInfo['redirect'] = '';
99 if ($pageIsNew[$pageid])
100 $pageInfo['new'] = '';
102 if($fld_protection) {
103 if (isset($protections[$pageid])) {
104 $pageInfo['protection'] = $protections[$pageid];
105 $result->setIndexedTagName($pageInfo['protection'], 'pr');
107 $pageInfo['protection'] = array();
111 $result->addValue(array (
114 ), $pageid, $pageInfo);
118 protected function getAllowedParams() {
121 ApiBase
:: PARAM_DFLT
=> NULL,
122 ApiBase
:: PARAM_ISMULTI
=> true,
123 ApiBase
:: PARAM_TYPE
=> array (
129 protected function getParamDescription() {
132 'Which additional properties to get:',
133 ' "protection" - List the protection level of each page'
139 protected function getDescription() {
140 return 'Get basic page information such as namespace, title, last touched date, ...';
143 protected function getExamples() {
145 'api.php?action=query&prop=info&titles=Main%20Page',
146 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
150 public function getVersion() {
151 return __CLASS__
. ': $Id$';