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() {
89 class RSSFeed
extends ChannelFeed
{
91 function formatTime( $ts ) {
92 return gmdate( "D, d M Y H:i:s \G\M\T", wfTimestamp2Unix( $ts ) );
95 function outHeader() {
96 global $wgVersion, $wgOut;
98 # We take over from $wgOut, excepting its cache header info
100 header( "Content-type: application/xml; charset=UTF-8" );
101 $wgOut->sendCacheControl();
103 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
104 ?
><rss version
="2.0">
106 <title
><?php
print $this->getTitle() ?
></title
>
107 <link
><?php
print $this->getUrl() ?
></link
>
108 <description
><?php
print $this->getDescription() ?
></description
>
109 <language
><?php
print $this->getLanguage() ?
></language
>
110 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
111 <lastBuildDate
><?php
print $this->formatTime( wfTimestampNow() ) ?
></lastBuildDate
>
115 function outItem( $item ) {
118 <title
><?php
print $item->getTitle() ?
></title
>
119 <link
><?php
print $item->getUrl() ?
></link
>
120 <description
><?php
print $item->getDescription() ?
></description
>
121 <?php
if( $item->getDate() ) { ?
><pubDate
><?php
print $this->formatTime( $item->getDate() ) ?
></pubDate
><?php
} ?
>
122 <?php
if( $item->getAuthor() ) { ?
><author
><?php
print $item->getAuthor() ?
></author
><?php
}?
>
123 <?php
if( $item->getComments() ) { ?
><comments
><?php
print $item->getComments() ?
></comments
><?php
}?
>
128 function outFooter() {
135 class AtomFeed
extends ChannelFeed
{
136 function formatTime( $ts ) {
137 // need to use RFC 822 time format at least for rss2.0
138 return gmdate( "Y-m-d\TH:i:s", wfTimestamp2Unix( $ts ) );
141 function outHeader() {
142 global $wgVersion, $wgOut;
144 # We take over from $wgOut, excepting its cache header info
146 header( "Content-type: application/xml; charset=UTF-8" );
147 $wgOut->sendCacheControl();
149 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
150 ?
><feed version
="0.3" xml
:lang
="<?php print $this->getLanguage() ?>">
151 <title
><?php
print $this->getTitle() ?
></title
>
152 <link rel
="alternate" type
="text/html" href
="<?php print $this->getUrl() ?>"/>
153 <modified
><?php
print $this->formatTime( wfTimestampNow() ) ?
>Z
</modified
>
154 <tagline
><?php
print $this->getDescription() ?
></tagline
>
155 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
160 function outItem( $item ) {
164 <title
><?php
print $item->getTitle() ?
></title
>
165 <link rel
="alternate" type
="<?php print $wgMimeType ?>" href
="<?php print $item->getUrl() ?>"/>
166 <?php
if( $item->getDate() ) { ?
>
167 <modified
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</modified
>
168 <issued
><?php
print $this->formatTime( $item->getDate() ) ?
></issued
>
169 <created
><?php
print $this->formatTime( $item->getDate() ) ?
>Z
</created
><?php
} ?
>
171 <summary type
="text/plain"><?php
print $item->getDescription() ?
></summary
>
172 <?php
if( $item->getAuthor() ) { ?
><author
><name
><?php
print $item->getAuthor() ?
></name
><!-- <url
></url
><email
></email
> --></author
><?php
}?
>
173 <comment
>foobar
</comment
>
176 <?php
/* FIXME need to add comments
177 <?php if( $item->getComments() ) { ?><dc:comment><?php print $item->getComments() ?></dc:comment><?php }?>
181 function outFooter() {?
>