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
22 $wgFeedClasses = array(
29 var $Description = '';
34 function FeedItem( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
35 $this->Title
= $Title;
36 $this->Description
= $Description;
39 $this->Author
= $Author;
40 $this->Comments
= $Comments;
44 function xmlEncode( $string ) {
45 global $wgInputEncoding, $wgLang;
46 $string = str_replace( "\r\n", "\n", $string );
47 if( strcasecmp( $wgInputEncoding, 'utf-8' ) != 0 ) {
48 $string = $wgLang->iconv( $wgInputEncoding, 'utf-8', $string );
50 return htmlspecialchars( $string );
53 return $this->xmlEncode( $this->Title
);
56 return $this->xmlEncode( $this->Url
);
58 function getDescription() {
59 return $this->xmlEncode( $this->Description
);
61 function getLanguage() {
62 global $wgLanguageCode;
63 return $wgLanguageCode;
68 function getAuthor() {
69 return $this->xmlEncode( $this->Author
);
71 function getComments() {
72 return $this->xmlEncode( $this->Comments
);
76 class ChannelFeed
extends FeedItem
{
77 /* Abstract functions, override! */
78 function outHeader() {
81 function outItem( $item ) {
82 # print "<item>...</item>";
84 function outFooter() {
88 function outXmlHeader( $mimetype='application/xml' ) {
89 global $wgServer, $wgStylePath, $wgOut;
91 # We take over from $wgOut, excepting its cache header info
93 header( "Content-type: $mimetype; charset=UTF-8" );
94 $wgOut->sendCacheControl();
96 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
97 print '<' . '?xml-stylesheet type="text/css" href="' .
98 htmlspecialchars( "$wgServer$wgStylePath/feed.css" ) . '"?' . ">\n";
102 class RSSFeed
extends ChannelFeed
{
104 function formatTime( $ts ) {
105 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp2Unix( $ts ) );
108 function outHeader() {
111 $this->outXmlHeader();
112 ?
><rss version
="2.0" xmlns
:dc
="http://purl.org/dc/elements/1.1/">
114 <title
><?php
print $this->getTitle() ?
></title
>
115 <link
><?php
print $this->getUrl() ?
></link
>
116 <description
><?php
print $this->getDescription() ?
></description
>
117 <language
><?php
print $this->getLanguage() ?
></language
>
118 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
119 <lastBuildDate
><?php
print $this->formatTime( wfTimestampNow() ) ?
></lastBuildDate
>
123 function outItem( $item ) {
126 <title
><?php
print $item->getTitle() ?
></title
>
127 <link
><?php
print $item->getUrl() ?
></link
>
128 <description
><?php
print $item->getDescription() ?
></description
>
129 <?php
if( $item->getDate() ) { ?
><pubDate
><?php
print $this->formatTime( $item->getDate() ) ?
></pubDate
><?php
} ?
>
130 <?php
if( $item->getAuthor() ) { ?
><dc
:creator
><?php
print $item->getAuthor() ?
></dc
:creator
><?php
}?
>
131 <?php
if( $item->getComments() ) { ?
><comments
><?php
print $item->getComments() ?
></comments
><?php
}?
>
136 function outFooter() {
143 class AtomFeed
extends ChannelFeed
{
144 function formatTime( $ts ) {
145 // need to use RFC 822 time format at least for rss2.0
146 return gmdate( 'Y-m-d\TH:i:s', wfTimestamp2Unix( $ts ) );
149 function outHeader() {
150 global $wgVersion, $wgOut;
152 $this->outXmlHeader();
153 ?
><feed version
="0.3" xml
:lang
="<?php print $this->getLanguage() ?>">
154 <title
><?php
print $this->getTitle() ?
></title
>
155 <link rel
="alternate" type
="text/html" href
="<?php print $this->getUrl() ?>"/>
156 <modified
><?php
print $this->formatTime( wfTimestampNow() ) ?
>Z
</modified
>
157 <tagline
><?php
print $this->getDescription() ?
></tagline
>
158 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
163 function outItem( $item ) {
167 <title
><?php
print $item->getTitle() ?
></title
>
168 <link rel
="alternate" type
="<?php print $wgMimeType ?>" href
="<?php print $item->getUrl() ?>"/>
169 <?php
if( $item->getDate() ) { ?
>
170 <modified
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</modified
>
171 <issued
><?php
print $this->formatTime( $item->getDate() ) ?
></issued
>
172 <created
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</created
><?php
} ?
>
174 <summary type
="text/plain"><?php
print $item->getDescription() ?
></summary
>
175 <?php
if( $item->getAuthor() ) { ?
><author
><name
><?php
print $item->getAuthor() ?
></name
><!-- <url
></url
><email
></email
> --></author
><?php
}?
>
176 <comment
>foobar
</comment
>
179 <?php
/* FIXME need to add comments
180 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
184 function outFooter() {?
>