2006-10-16 00:08:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Created on Oct 13, 2006
|
|
|
|
|
*
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!defined('MEDIAWIKI')) {
|
|
|
|
|
// Eclipse helper - will be ignored in production
|
|
|
|
|
require_once ("ApiBase.php");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ApiFeedWatchlist extends ApiBase {
|
|
|
|
|
|
|
|
|
|
public function __construct($main, $action) {
|
|
|
|
|
parent :: __construct($main, $action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCustomPrinter() {
|
|
|
|
|
return new ApiFormatFeedWrapper($this->getMain());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$feedformat = null;
|
|
|
|
|
extract($this->extractRequestParams());
|
|
|
|
|
|
2006-10-18 23:49:09 +00:00
|
|
|
// limit to 1 day
|
|
|
|
|
$startTime = wfTimestamp(TS_MW, time() - intval(1 * 86400));
|
|
|
|
|
|
2006-10-16 00:08:03 +00:00
|
|
|
// Prepare nested request
|
|
|
|
|
$params = new FauxRequest(array (
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'meta' => 'siteinfo',
|
|
|
|
|
'siprop' => 'general',
|
|
|
|
|
'list' => 'watchlist',
|
2006-10-18 05:27:43 +00:00
|
|
|
'wlprop' => 'user|comment|timestamp',
|
2006-10-18 23:49:09 +00:00
|
|
|
'wlstart' => $startTime,
|
2006-10-16 00:08:03 +00:00
|
|
|
'wllimit' => 50
|
|
|
|
|
));
|
2006-10-18 23:49:09 +00:00
|
|
|
|
2006-10-16 00:08:03 +00:00
|
|
|
// Execute
|
|
|
|
|
$module = new ApiMain($params);
|
|
|
|
|
$module->execute();
|
|
|
|
|
|
2006-10-18 05:27:43 +00:00
|
|
|
// Get data array
|
2006-10-25 03:54:56 +00:00
|
|
|
$data = $module->getResultData();
|
2006-10-16 00:08:03 +00:00
|
|
|
|
|
|
|
|
$feedItems = array ();
|
2006-11-23 08:25:56 +00:00
|
|
|
foreach ($data['query']['watchlist'] as $info) {
|
2006-10-18 23:49:09 +00:00
|
|
|
$feedItems[] = $this->createFeedItem($info);
|
2006-10-16 00:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
global $wgFeedClasses, $wgSitename, $wgContLanguageCode;
|
|
|
|
|
$feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgContLanguageCode . ']';
|
2006-10-30 06:25:31 +00:00
|
|
|
$feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullUrl();
|
2006-10-18 23:49:09 +00:00
|
|
|
|
|
|
|
|
$feed = new $wgFeedClasses[$feedformat] ($feedTitle, htmlspecialchars(wfMsgForContent('watchlist')), $feedUrl);
|
2006-10-16 00:08:03 +00:00
|
|
|
|
|
|
|
|
ApiFormatFeedWrapper :: setResult($this->getResult(), $feed, $feedItems);
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-18 23:49:09 +00:00
|
|
|
private function createFeedItem($info) {
|
|
|
|
|
$titleStr = $info['title'];
|
|
|
|
|
$title = Title :: newFromText($titleStr);
|
|
|
|
|
$titleUrl = $title->getFullUrl();
|
|
|
|
|
$comment = $info['comment'];
|
|
|
|
|
$timestamp = $info['timestamp'];
|
|
|
|
|
$user = $info['user'];
|
|
|
|
|
|
|
|
|
|
$completeText = "$comment ($user)";
|
|
|
|
|
|
|
|
|
|
return new FeedItem($titleStr, $completeText, $titleUrl, $timestamp, $user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getAllowedParams() {
|
2006-10-16 00:08:03 +00:00
|
|
|
global $wgFeedClasses;
|
|
|
|
|
$feedFormatNames = array_keys($wgFeedClasses);
|
|
|
|
|
return array (
|
|
|
|
|
'feedformat' => array (
|
|
|
|
|
ApiBase :: PARAM_DFLT => 'rss',
|
|
|
|
|
ApiBase :: PARAM_TYPE => $feedFormatNames
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-18 23:49:09 +00:00
|
|
|
protected function getParamDescription() {
|
2006-10-16 00:08:03 +00:00
|
|
|
return array (
|
|
|
|
|
'feedformat' => 'The format of the feed'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-18 23:49:09 +00:00
|
|
|
protected function getDescription() {
|
2006-10-16 00:08:03 +00:00
|
|
|
return 'This module returns a watchlist feed';
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-18 23:49:09 +00:00
|
|
|
protected function getExamples() {
|
2006-10-16 00:08:03 +00:00
|
|
|
return array (
|
|
|
|
|
'api.php?action=feedwatchlist'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
2006-10-16 05:53:07 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2006-10-16 00:08:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-10-30 06:25:31 +00:00
|
|
|
?>
|