3 # Basic support for outputting syndication feeds in RSS, other formats
5 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
6 # http://www.mediawiki.org/
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 # http://www.gnu.org/copyleft/gpl.html
24 * Contain a feed class as well as classes to build rss / atom ... feeds
29 * Available feeds objects
31 $wgFeedClasses = array(
46 var $Description = '';
55 function FeedItem( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
56 $this->Title
= $Title;
57 $this->Description
= $Description;
60 $this->Author
= $Author;
61 $this->Comments
= $Comments;
68 function xmlEncode( $string ) {
69 global $wgInputEncoding, $wgLang;
70 $string = str_replace( "\r\n", "\n", $string );
71 if( strcasecmp( $wgInputEncoding, 'utf-8' ) != 0 ) {
72 $string = $wgLang->iconv( $wgInputEncoding, 'utf-8', $string );
74 return htmlspecialchars( $string );
80 function getTitle() { return $this->xmlEncode( $this->Title
); }
84 function getUrl() { return $this->xmlEncode( $this->Url
); }
88 function getDescription() { return $this->xmlEncode( $this->Description
); }
92 function getLanguage() {
93 global $wgLanguageCode;
94 return $wgLanguageCode;
99 function getDate() { return $this->Date
; }
103 function getAuthor() { return $this->xmlEncode( $this->Author
); }
107 function getComments() { return $this->xmlEncode( $this->Comments
); }
114 class ChannelFeed
extends FeedItem
{
116 * Abstract function, override!
121 * Generate Header of the feed
123 function outHeader() {
131 function outItem( $item ) {
132 # print "<item>...</item>";
136 * Generate Footer of the feed
138 function outFooter() {
145 * @param string $mimetype (optional) type of output
147 function outXmlHeader( $mimetype='application/xml' ) {
148 global $wgServer, $wgStylePath, $wgOut;
150 # We take over from $wgOut, excepting its cache header info
152 header( "Content-type: $mimetype; charset=UTF-8" );
153 $wgOut->sendCacheControl();
155 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
156 print '<' . '?xml-stylesheet type="text/css" href="' .
157 htmlspecialchars( "$wgServer$wgStylePath/feed.css" ) . '"?' . ">\n";
162 * Generate a RSS feed
166 class RSSFeed
extends ChannelFeed
{
169 * Format a date given a timestamp
170 * @param integer $ts Timestamp
171 * @return string Date string
173 function formatTime( $ts ) {
174 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX
, $ts ) );
178 * Ouput an RSS 2.0 header
180 function outHeader() {
183 $this->outXmlHeader();
184 ?
><rss version
="2.0" xmlns
:dc
="http://purl.org/dc/elements/1.1/">
186 <title
><?php
print $this->getTitle() ?
></title
>
187 <link
><?php
print $this->getUrl() ?
></link
>
188 <description
><?php
print $this->getDescription() ?
></description
>
189 <language
><?php
print $this->getLanguage() ?
></language
>
190 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
191 <lastBuildDate
><?php
print $this->formatTime( wfTimestampNow() ) ?
></lastBuildDate
>
196 * Output an RSS 2.0 item
197 * @param FeedItem item to be output
199 function outItem( $item ) {
202 <title
><?php
print $item->getTitle() ?
></title
>
203 <link
><?php
print $item->getUrl() ?
></link
>
204 <description
><?php
print $item->getDescription() ?
></description
>
205 <?php
if( $item->getDate() ) { ?
><pubDate
><?php
print $this->formatTime( $item->getDate() ) ?
></pubDate
><?php
} ?
>
206 <?php
if( $item->getAuthor() ) { ?
><dc
:creator
><?php
print $item->getAuthor() ?
></dc
:creator
><?php
}?
>
207 <?php
if( $item->getComments() ) { ?
><comments
><?php
print $item->getComments() ?
></comments
><?php
}?
>
213 * Ouput an RSS 2.0 footer
215 function outFooter() {
223 * Generate an Atom feed
227 class AtomFeed
extends ChannelFeed
{
231 function formatTime( $ts ) {
232 // need to use RFC 822 time format at least for rss2.0
233 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX
, $ts ) );
239 function outHeader() {
240 global $wgVersion, $wgOut;
242 $this->outXmlHeader();
243 ?
><feed version
="0.3" xml
:lang
="<?php print $this->getLanguage() ?>">
244 <title
><?php
print $this->getTitle() ?
></title
>
245 <link rel
="alternate" type
="text/html" href
="<?php print $this->getUrl() ?>"/>
246 <modified
><?php
print $this->formatTime( wfTimestampNow() ) ?
>Z
</modified
>
247 <tagline
><?php
print $this->getDescription() ?
></tagline
>
248 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
256 function outItem( $item ) {
260 <title
><?php
print $item->getTitle() ?
></title
>
261 <link rel
="alternate" type
="<?php print $wgMimeType ?>" href
="<?php print $item->getUrl() ?>"/>
262 <?php
if( $item->getDate() ) { ?
>
263 <modified
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</modified
>
264 <issued
><?php
print $this->formatTime( $item->getDate() ) ?
></issued
>
265 <created
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</created
><?php
} ?
>
267 <summary type
="text/plain"><?php
print $item->getDescription() ?
></summary
>
268 <?php
if( $item->getAuthor() ) { ?
><author
><name
><?php
print $item->getAuthor() ?
></name
><!-- <url
></url
><email
></email
> --></author
><?php
}?
>
269 <comment
>foobar
</comment
>
272 <?php
/* FIXME need to add comments
273 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
280 function outFooter() {?
>