5 * Created on Oct 13, 2006
7 * API for MediaWiki 1.8+
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
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.
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.
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
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ("ApiBase.php");
32 class ApiFeedWatchlist
extends ApiBase
{
34 public function __construct($main, $action) {
35 parent
:: __construct($main, $action);
38 public function getCustomPrinter() {
39 return new ApiFormatFeedWrapper($this->getMain());
42 public function execute() {
44 extract($this->extractRequestParams());
46 // Prepare nested request
47 $params = new FauxRequest(array (
50 'siprop' => 'general',
51 'list' => 'watchlist',
52 'wlprop' => 'user|comment|timestamp',
53 'wlstart' => wfTimestamp(TS_MW
, time() - intval( 1 * 86400 )), // limit to 1 day
58 $module = new ApiMain($params);
62 $data = & $module->getResultData();
64 $feedItems = array ();
65 foreach ($data['query']['watchlist'] as $index => $info) {
66 $title = $info['title'];
67 $titleUrl = Title
:: newFromText($title)->getFullUrl();
68 $feedItems[] = new FeedItem($title, $info['comment'], $titleUrl, $info['timestamp'], $info['user']);
71 global $wgFeedClasses, $wgSitename, $wgContLanguageCode;
72 $feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgContLanguageCode . ']';
73 $feedUrl = Title
:: makeTitle(NS_SPECIAL
, 'Watchlist')->getFullUrl();
74 $feed = new $wgFeedClasses[$feedformat] ($feedTitle, '!Watchlist (TODO)!', $feedUrl);
76 ApiFormatFeedWrapper
:: setResult($this->getResult(), $feed, $feedItems);
79 protected function GetAllowedParams() {
80 global $wgFeedClasses;
81 $feedFormatNames = array_keys($wgFeedClasses);
83 'feedformat' => array (
84 ApiBase
:: PARAM_DFLT
=> 'rss',
85 ApiBase
:: PARAM_TYPE
=> $feedFormatNames
90 protected function GetParamDescription() {
92 'feedformat' => 'The format of the feed'
96 protected function GetDescription() {
97 return 'This module returns a watchlist feed';
100 protected function GetExamples() {
102 'api.php?action=feedwatchlist'
106 public function getVersion() {
107 return __CLASS__
. ': $Id$';