API: Added filter by namespace to links & templates query - bug 10275
[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);
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 $pageSet = $this->getPageSet();
54 $titles = $pageSet->getGoodTitles();
55 $result = $this->getResult();
56
57 $pageIsRedir = $pageSet->getCustomField('page_is_redirect');
58 $pageIsNew = $pageSet->getCustomField('page_is_new');
59 $pageCounter = $pageSet->getCustomField('page_counter');
60 $pageTouched = $pageSet->getCustomField('page_touched');
61 $pageLatest = $pageSet->getCustomField('page_latest');
62 $pageLength = $pageSet->getCustomField('page_len');
63
64 foreach ( $titles as $pageid => $unused ) {
65 $pageInfo = array (
66 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
67 'lastrevid' => intval($pageLatest[$pageid]),
68 'counter' => intval($pageCounter[$pageid]),
69 'length' => intval($pageLength[$pageid]),
70 );
71
72 if ($pageIsRedir[$pageid])
73 $pageInfo['redirect'] = '';
74
75 if ($pageIsNew[$pageid])
76 $pageInfo['new'] = '';
77
78 $result->addValue(array (
79 'query',
80 'pages'
81 ), $pageid, $pageInfo);
82 }
83 }
84
85 protected function getDescription() {
86 return 'Get basic page information such as namespace, title, last touched date, ...';
87 }
88
89 protected function getExamples() {
90 return array (
91 'api.php?action=query&prop=info&titles=Main%20Page'
92 );
93 }
94
95 public function getVersion() {
96 return __CLASS__ . ': $Id$';
97 }
98 }
99 ?>