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(
24 # "atom" => "AtomFeed",
29 var $Description = "";
34 function FeedItem( $Title, $Description, $Url, $Date = "", $Author = "" ) {
35 $this->Title
= $Title;
36 $this->Description
= $Description;
39 $this->Author
= $Author;
43 function xmlEncode( $string ) {
44 global $wgInputEncoding, $wgLang;
45 $string = str_replace( "\r\n", "\n", $string );
46 if( strcasecmp( $wgInputEncoding, "utf-8" ) != 0 ) {
47 $string = $wgLang->iconv( $wgInputEncoding, "utf-8", $string );
49 return htmlspecialchars( $string );
52 return $this->xmlEncode( $this->Title
);
55 return $this->xmlEncode( $this->Url
);
57 function getDescription() {
58 return $this->xmlEncode( $this->Description
);
60 function getLanguage() {
61 global $wgLanguageCode;
62 return $wgLanguageCode;
67 function getAuthor() {
68 return $this->xmlEncode( $this->Author
);
72 class ChannelFeed
extends FeedItem
{
73 /* Abstract functions, override! */
74 function outHeader() {
77 function outItem( $item ) {
78 # print "<item>...</item>";
80 function outFooter() {
85 class RSSFeed
extends ChannelFeed
{
86 function formatTime( $ts ) {
87 return gmdate( "D, d M Y H:i:s T", wfTimestamp2Unix( $ts ) );
90 function outHeader() {
93 header( "Content-type: application/xml; charset=UTF-8" );
94 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
97 <title
><?php
print $this->getTitle() ?
></title
>
98 <link
><?php
print $this->getUrl() ?
></link
>
99 <description
><?php
print $this->getDescription() ?
></description
>
100 <language
><?php
print $this->getLanguage() ?
></language
>
101 <generator
>MediaWiki
<?php
print $wgVersion ?
></generator
>
102 <lastBuildDate
><?php
print $this->formatTime( wfTimestampNow() ) ?
></lastBuildDate
>
106 function outItem( $item ) {
109 <title
><?php
print $item->getTitle() ?
></title
>
110 <link
><?php
print $item->getUrl() ?
></link
>
111 <description
><?php
print $item->getDescription() ?
></description
>
112 <?php
if( $item->getDate() ) { ?
><pubDate
><?php
print $this->formatTime( $item->getDate() ) ?
></pubDate
><?php
} ?
>
113 <?php
if( $item->getAuthor() ) { ?
><author
><?php
print $item->getAuthor() ?
></author
><?php
}?
>
119 function outFooter() {