2 # Basic support for outputting syndication feeds in RSS, other formats
4 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # http://www.gnu.org/copyleft/gpl.html
23 * Contain a feed class as well as classes to build rss / atom ... feeds
24 * Available feeds are defined in Defines.php
39 var $Description = '';
48 function FeedItem( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
49 $this->Title
= $Title;
50 $this->Description
= $Description;
53 $this->Author
= $Author;
54 $this->Comments
= $Comments;
61 function xmlEncode( $string ) {
62 global $wgInputEncoding, $wgContLang;
63 $string = str_replace( "\r\n", "\n", $string );
64 if( strcasecmp( $wgInputEncoding, 'utf-8' ) != 0 ) {
65 $string = $wgContLang->iconv( $wgInputEncoding, 'utf-8', $string );
67 return htmlspecialchars( $string );
73 function getTitle() { return $this->xmlEncode( $this->Title
); }
77 function getUrl() { return $this->xmlEncode( $this->Url
); }
81 function getDescription() { return $this->xmlEncode( $this->Description
); }
85 function getLanguage() {
86 global $wgContLanguageCode;
87 return $wgContLanguageCode;
92 function getDate() { return $this->Date
; }
96 function getAuthor() { return $this->xmlEncode( $this->Author
); }
100 function getComments() { return $this->xmlEncode( $this->Comments
); }
107 class ChannelFeed
extends FeedItem
{
109 * Abstract function, override!
114 * Generate Header of the feed
116 function outHeader() {
124 function outItem( $item ) {
125 # print "<item>...</item>";
129 * Generate Footer of the feed
131 function outFooter() {
138 * @param string $mimetype (optional) type of output
140 function outXmlHeader( $mimetype='application/xml' ) {
141 global $wgServer, $wgStylePath, $wgOut;
143 # We take over from $wgOut, excepting its cache header info
145 header( "Content-type: $mimetype; charset=UTF-8" );
146 $wgOut->sendCacheControl();
148 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
149 print '<' . '?xml-stylesheet type="text/css" href="' .
150 htmlspecialchars( "$wgServer$wgStylePath/feed.css" ) . '"?' . ">\n";
155 * Generate a RSS feed
159 class RSSFeed
extends ChannelFeed
{
162 * Format a date given a timestamp
163 * @param integer $ts Timestamp
164 * @return string Date string
166 function formatTime( $ts ) {
167 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX
, $ts ) );
171 * Ouput an RSS 2.0 header
173 function outHeader() {
176 $this->outXmlHeader();
177 ?
><rss version
="2.0" xmlns
:dc
="http://purl.org/dc/elements/1.1/">
179 <title
><?php
print $this->getTitle() ?
></title
>
180 <link
><?php
print $this->getUrl() ?
></link
>
181 <description
><?php
print $this->getDescription() ?
></description
>
182 <language
><?php
print $this->getLanguage() ?
></language
>
183 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
184 <lastBuildDate
><?php
print $this->formatTime( wfTimestampNow() ) ?
></lastBuildDate
>
189 * Output an RSS 2.0 item
190 * @param FeedItem item to be output
192 function outItem( $item ) {
195 <title
><?php
print $item->getTitle() ?
></title
>
196 <link
><?php
print $item->getUrl() ?
></link
>
197 <description
><?php
print $item->getDescription() ?
></description
>
198 <?php
if( $item->getDate() ) { ?
><pubDate
><?php
print $this->formatTime( $item->getDate() ) ?
></pubDate
><?php
} ?
>
199 <?php
if( $item->getAuthor() ) { ?
><dc
:creator
><?php
print $item->getAuthor() ?
></dc
:creator
><?php
}?
>
200 <?php
if( $item->getComments() ) { ?
><comments
><?php
print $item->getComments() ?
></comments
><?php
}?
>
206 * Ouput an RSS 2.0 footer
208 function outFooter() {
216 * Generate an Atom feed
220 class AtomFeed
extends ChannelFeed
{
224 function formatTime( $ts ) {
225 // need to use RFC 822 time format at least for rss2.0
226 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX
, $ts ) );
232 function outHeader() {
233 global $wgVersion, $wgOut;
235 $this->outXmlHeader();
236 ?
><feed version
="0.3" xml
:lang
="<?php print $this->getLanguage() ?>">
237 <title
><?php
print $this->getTitle() ?
></title
>
238 <link rel
="alternate" type
="text/html" href
="<?php print $this->getUrl() ?>"/>
239 <modified
><?php
print $this->formatTime( wfTimestampNow() ) ?
>Z
</modified
>
240 <tagline
><?php
print $this->getDescription() ?
></tagline
>
241 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
249 function outItem( $item ) {
253 <title
><?php
print $item->getTitle() ?
></title
>
254 <link rel
="alternate" type
="<?php print $wgMimeType ?>" href
="<?php print $item->getUrl() ?>"/>
255 <?php
if( $item->getDate() ) { ?
>
256 <modified
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</modified
>
257 <issued
><?php
print $this->formatTime( $item->getDate() ) ?
></issued
>
258 <created
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</created
><?php
} ?
>
260 <summary type
="text/plain"><?php
print $item->getDescription() ?
></summary
>
261 <?php
if( $item->getAuthor() ) { ?
><author
><name
><?php
print $item->getAuthor() ?
></name
><!-- <url
></url
><email
></email
> --></author
><?php
}?
>
262 <comment
>foobar
</comment
>
265 <?php
/* FIXME need to add comments
266 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
273 function outFooter() {?
>