* Made special page names case-insensitive and localisable. Care has been taken to...
[lhc/web/wiklou.git] / includes / api / ApiFeedWatchlist.php
1 <?php
2
3
4 /*
5 * Created on Oct 13, 2006
6 *
7 * API for MediaWiki 1.8+
8 *
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * http://www.gnu.org/copyleft/gpl.html
25 */
26
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ("ApiBase.php");
30 }
31
32 class ApiFeedWatchlist extends ApiBase {
33
34 public function __construct($main, $action) {
35 parent :: __construct($main, $action);
36 }
37
38 public function getCustomPrinter() {
39 return new ApiFormatFeedWrapper($this->getMain());
40 }
41
42 public function execute() {
43 $feedformat = null;
44 extract($this->extractRequestParams());
45
46 // limit to 1 day
47 $startTime = wfTimestamp(TS_MW, time() - intval(1 * 86400));
48
49 // Prepare nested request
50 $params = new FauxRequest(array (
51 'action' => 'query',
52 'meta' => 'siteinfo',
53 'siprop' => 'general',
54 'list' => 'watchlist',
55 'wlprop' => 'user|comment|timestamp',
56 'wlstart' => $startTime,
57 'wllimit' => 50
58 ));
59
60 // Execute
61 $module = new ApiMain($params);
62 $module->execute();
63
64 // Get data array
65 $data = $module->getResultData();
66
67 $feedItems = array ();
68 foreach ($data['query']['watchlist'] as $index => $info) {
69 $feedItems[] = $this->createFeedItem($info);
70 }
71
72 global $wgFeedClasses, $wgSitename, $wgContLanguageCode;
73 $feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgContLanguageCode . ']';
74 $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullUrl();
75
76 $feed = new $wgFeedClasses[$feedformat] ($feedTitle, htmlspecialchars(wfMsgForContent('watchlist')), $feedUrl);
77
78 ApiFormatFeedWrapper :: setResult($this->getResult(), $feed, $feedItems);
79 }
80
81 private function createFeedItem($info) {
82 global $wgUser;
83
84 $titleStr = $info['title'];
85 $title = Title :: newFromText($titleStr);
86 $titleUrl = $title->getFullUrl();
87 $comment = $info['comment'];
88 $timestamp = $info['timestamp'];
89 $user = $info['user'];
90
91 $completeText = "$comment ($user)";
92
93 return new FeedItem($titleStr, $completeText, $titleUrl, $timestamp, $user);
94 }
95
96 protected function getAllowedParams() {
97 global $wgFeedClasses;
98 $feedFormatNames = array_keys($wgFeedClasses);
99 return array (
100 'feedformat' => array (
101 ApiBase :: PARAM_DFLT => 'rss',
102 ApiBase :: PARAM_TYPE => $feedFormatNames
103 )
104 );
105 }
106
107 protected function getParamDescription() {
108 return array (
109 'feedformat' => 'The format of the feed'
110 );
111 }
112
113 protected function getDescription() {
114 return 'This module returns a watchlist feed';
115 }
116
117 protected function getExamples() {
118 return array (
119 'api.php?action=feedwatchlist'
120 );
121 }
122
123 public function getVersion() {
124 return __CLASS__ . ': $Id$';
125 }
126 }
127 ?>