Revert r24105, r24106, r24107 'security fix' forbidden text/css and text/javascript...
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
1 <?php
2
3 /*
4 * Created on Sep 25, 2006
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9 *
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.
14 *
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.
19 *
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
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
29 }
30
31 /**
32 * A query module to show basic page information.
33 *
34 * @addtogroup API
35 */
36 class ApiQueryInfo extends ApiQueryBase {
37
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'in');
40 }
41
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');
49 }
50
51 public function execute() {
52
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']);
58 }
59
60 $pageSet = $this->getPageSet();
61 $titles = $pageSet->getGoodTitles();
62 $result = $this->getResult();
63
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');
70
71 if ($fld_protection && count($titles) > 0) {
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));
75
76 $db = $this->getDB();
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 )
83 );
84 }
85 $db->freeResult($res);
86 }
87
88 foreach ( $titles as $pageid => $unused ) {
89 $pageInfo = array (
90 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
91 'lastrevid' => intval($pageLatest[$pageid]),
92 'counter' => intval($pageCounter[$pageid]),
93 'length' => intval($pageLength[$pageid]),
94 );
95
96 if ($pageIsRedir[$pageid])
97 $pageInfo['redirect'] = '';
98
99 if ($pageIsNew[$pageid])
100 $pageInfo['new'] = '';
101
102 if($fld_protection) {
103 if (isset($protections[$pageid])) {
104 $pageInfo['protection'] = $protections[$pageid];
105 $result->setIndexedTagName($pageInfo['protection'], 'pr');
106 } else {
107 $pageInfo['protection'] = array();
108 }
109 }
110
111 $result->addValue(array (
112 'query',
113 'pages'
114 ), $pageid, $pageInfo);
115 }
116 }
117
118 protected function getAllowedParams() {
119 return array (
120 'prop' => array (
121 ApiBase :: PARAM_DFLT => NULL,
122 ApiBase :: PARAM_ISMULTI => true,
123 ApiBase :: PARAM_TYPE => array (
124 'protection'
125 ))
126 );
127 }
128
129 protected function getParamDescription() {
130 return array (
131 'prop' => array (
132 'Which additional properties to get:',
133 ' "protection" - List the protection level of each page'
134 )
135 );
136 }
137
138
139 protected function getDescription() {
140 return 'Get basic page information such as namespace, title, last touched date, ...';
141 }
142
143 protected function getExamples() {
144 return array (
145 'api.php?action=query&prop=info&titles=Main%20Page',
146 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
147 );
148 }
149
150 public function getVersion() {
151 return __CLASS__ . ': $Id$';
152 }
153 }
154