c6dd72d40444d3d3bda4dfb2fb530341bef90b33
[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 // Prepare nested request
47 $params = new FauxRequest(array (
48 'action' => 'query',
49 'meta' => 'siteinfo',
50 'siprop' => 'general',
51 'list' => 'watchlist',
52 'wlstart' => wfTimestamp(TS_MW, time() - intval( 3 * 86400 )), // limit to 3 days
53 'wllimit' => 50
54 ));
55
56 // Execute
57 $module = new ApiMain($params);
58 $module->execute();
59
60 // Get clean data
61 $result = & $module->getResult();
62 $result->SanitizeData();
63 $data = & $result->GetData();
64
65 $feedItems = array ();
66 foreach ($data['query']['watchlist'] as $index => $info) {
67 $title = $info['title'];
68 $titleUrl = Title :: newFromText($title)->getFullUrl();
69 $feedItems[] = new FeedItem($title, '', $titleUrl, $info['timestamp'], $info['user']);
70 }
71
72 global $wgFeedClasses, $wgSitename, $wgContLanguageCode;
73 $feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgContLanguageCode . ']';
74 $feedUrl = Title :: makeTitle(NS_SPECIAL, 'Watchlist')->getFullUrl();
75 $feed = new $wgFeedClasses[$feedformat] ($feedTitle, '!Watchlist!', $feedUrl);
76
77 ApiFormatFeedWrapper :: setResult($this->getResult(), $feed, $feedItems);
78 }
79
80 protected function GetAllowedParams() {
81 global $wgFeedClasses;
82 $feedFormatNames = array_keys($wgFeedClasses);
83 return array (
84 'feedformat' => array (
85 ApiBase :: PARAM_DFLT => 'rss',
86 ApiBase :: PARAM_TYPE => $feedFormatNames
87 )
88 );
89 }
90
91 protected function GetParamDescription() {
92 return array (
93 'feedformat' => 'The format of the feed'
94 );
95 }
96
97 protected function GetDescription() {
98 return 'This module returns a watchlist feed';
99 }
100
101 protected function GetExamples() {
102 return array (
103 'api.php?action=feedwatchlist'
104 );
105 }
106
107 public function getVersion() {
108 return __CLASS__ . ': $Id$';
109 }
110 }
111 ?>