3 * Copyright © 2004 Brion Vibber <brion@pobox.com>
4 * https://www.mediawiki.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
25 * Generate an RSS feed.
29 class RSSFeed
extends ChannelFeed
{
32 * Format a date given a timestamp. If a timestamp is not given, nothing is returned
34 * @param int|null $ts Timestamp
35 * @return string|null Date string
37 function formatTime( $ts ) {
39 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX
, $ts ) );
44 * Output an RSS 2.0 header
46 function outHeader() {
49 $this->outXmlHeader();
50 // Manually escaping rather than letting Mustache do it because Mustache
51 // uses htmlentities, which does not work with XML
53 'title' => $this->getTitle(),
54 'url' => $this->xmlEncode( wfExpandUrl( $this->getUrlUnescaped(), PROTO_CURRENT
) ),
55 'description' => $this->getDescription(),
56 'language' => $this->xmlEncode( $this->getLanguage() ),
57 'version' => $this->xmlEncode( $wgVersion ),
58 'timestamp' => $this->xmlEncode( $this->formatTime( wfTimestampNow() ) )
60 print $this->templateParser
->processTemplate( 'RSSHeader', $templateParams );
64 * Output an RSS 2.0 item
65 * @param FeedItem $item Item to be output
67 function outItem( $item ) {
68 // Manually escaping rather than letting Mustache do it because Mustache
69 // uses htmlentities, which does not work with XML
71 "title" => $item->getTitle(),
72 "url" => $this->xmlEncode( wfExpandUrl( $item->getUrlUnescaped(), PROTO_CURRENT
) ),
73 "permalink" => $item->rssIsPermalink
,
74 "uniqueID" => $item->getUniqueID(),
75 "description" => $item->getDescription(),
76 "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),
77 "author" => $item->getAuthor()
79 $comments = $item->getCommentsUnescaped();
81 $commentsEscaped = $this->xmlEncode( wfExpandUrl( $comments, PROTO_CURRENT
) );
82 $templateParams["comments"] = $commentsEscaped;
84 print $this->templateParser
->processTemplate( 'RSSItem', $templateParams );
88 * Output an RSS 2.0 footer
90 function outFooter() {
91 print "</channel></rss>";