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 class to build rss / atom ... feeds
27 * Available feeds objects
29 $wgFeedClasses = array(
39 var $Description = '';
44 function FeedItem( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
45 $this->Title
= $Title;
46 $this->Description
= $Description;
49 $this->Author
= $Author;
50 $this->Comments
= $Comments;
54 function xmlEncode( $string ) {
55 global $wgInputEncoding, $wgLang;
56 $string = str_replace( "\r\n", "\n", $string );
57 if( strcasecmp( $wgInputEncoding, 'utf-8' ) != 0 ) {
58 $string = $wgLang->iconv( $wgInputEncoding, 'utf-8', $string );
60 return htmlspecialchars( $string );
63 return $this->xmlEncode( $this->Title
);
66 return $this->xmlEncode( $this->Url
);
68 function getDescription() {
69 return $this->xmlEncode( $this->Description
);
71 function getLanguage() {
72 global $wgLanguageCode;
73 return $wgLanguageCode;
78 function getAuthor() {
79 return $this->xmlEncode( $this->Author
);
81 function getComments() {
82 return $this->xmlEncode( $this->Comments
);
89 class ChannelFeed
extends FeedItem
{
90 /* Abstract functions, override! */
91 function outHeader() {
94 function outItem( $item ) {
95 # print "<item>...</item>";
97 function outFooter() {
101 function outXmlHeader( $mimetype='application/xml' ) {
102 global $wgServer, $wgStylePath, $wgOut;
104 # We take over from $wgOut, excepting its cache header info
106 header( "Content-type: $mimetype; charset=UTF-8" );
107 $wgOut->sendCacheControl();
109 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
110 print '<' . '?xml-stylesheet type="text/css" href="' .
111 htmlspecialchars( "$wgServer$wgStylePath/feed.css" ) . '"?' . ">\n";
116 * Generate a RSS feed
119 class RSSFeed
extends ChannelFeed
{
121 function formatTime( $ts ) {
122 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp2Unix( $ts ) );
125 function outHeader() {
128 $this->outXmlHeader();
129 ?
><rss version
="2.0" xmlns
:dc
="http://purl.org/dc/elements/1.1/">
131 <title
><?php
print $this->getTitle() ?
></title
>
132 <link
><?php
print $this->getUrl() ?
></link
>
133 <description
><?php
print $this->getDescription() ?
></description
>
134 <language
><?php
print $this->getLanguage() ?
></language
>
135 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
136 <lastBuildDate
><?php
print $this->formatTime( wfTimestampNow() ) ?
></lastBuildDate
>
140 function outItem( $item ) {
143 <title
><?php
print $item->getTitle() ?
></title
>
144 <link
><?php
print $item->getUrl() ?
></link
>
145 <description
><?php
print $item->getDescription() ?
></description
>
146 <?php
if( $item->getDate() ) { ?
><pubDate
><?php
print $this->formatTime( $item->getDate() ) ?
></pubDate
><?php
} ?
>
147 <?php
if( $item->getAuthor() ) { ?
><dc
:creator
><?php
print $item->getAuthor() ?
></dc
:creator
><?php
}?
>
148 <?php
if( $item->getComments() ) { ?
><comments
><?php
print $item->getComments() ?
></comments
><?php
}?
>
153 function outFooter() {
161 * Generate an Atom feed
164 class AtomFeed
extends ChannelFeed
{
165 function formatTime( $ts ) {
166 // need to use RFC 822 time format at least for rss2.0
167 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp2Unix( $ts ) );
170 function outHeader() {
171 global $wgVersion, $wgOut;
173 $this->outXmlHeader();
174 ?
><feed version
="0.3" xml
:lang
="<?php print $this->getLanguage() ?>">
175 <title
><?php
print $this->getTitle() ?
></title
>
176 <link rel
="alternate" type
="text/html" href
="<?php print $this->getUrl() ?>"/>
177 <modified
><?php
print $this->formatTime( wfTimestampNow() ) ?
>Z
</modified
>
178 <tagline
><?php
print $this->getDescription() ?
></tagline
>
179 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
184 function outItem( $item ) {
188 <title
><?php
print $item->getTitle() ?
></title
>
189 <link rel
="alternate" type
="<?php print $wgMimeType ?>" href
="<?php print $item->getUrl() ?>"/>
190 <?php
if( $item->getDate() ) { ?
>
191 <modified
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</modified
>
192 <issued
><?php
print $this->formatTime( $item->getDate() ) ?
></issued
>
193 <created
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</created
><?php
} ?
>
195 <summary type
="text/plain"><?php
print $item->getDescription() ?
></summary
>
196 <?php
if( $item->getAuthor() ) { ?
><author
><name
><?php
print $item->getAuthor() ?
></name
><!-- <url
></url
><email
></email
> --></author
><?php
}?
>
197 <comment
>foobar
</comment
>
200 <?php
/* FIXME need to add comments
201 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
205 function outFooter() {?
>