mediawiki logo instead of the wikipedia one
[mediawiki.git] / includes / Feed.php
blob590d9ca6cc01c0924f5e88abb14e72645ceb2766
1 <?php
2 # Basic support for outputting syndication feeds in RSS, other formats
3 #
4 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
6 #
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(
23 "rss" => "RSSFeed",
24 # "atom" => "AtomFeed",
27 class FeedItem {
28 var $Title = "Wiki";
29 var $Description = "";
30 var $Url = "";
31 var $Date = "";
32 var $Author = "";
34 function FeedItem( $Title, $Description, $Url, $Date = "", $Author = "" ) {
35 $this->Title = $Title;
36 $this->Description = $Description;
37 $this->Url = $Url;
38 $this->Date = $Date;
39 $this->Author = $Author;
42 /* Static... */
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 );
51 function getTitle() {
52 return $this->xmlEncode( $this->Title );
54 function getUrl() {
55 return $this->xmlEncode( $this->Url );
57 function getDescription() {
58 return $this->xmlEncode( $this->Description );
60 function getLanguage() {
61 global $wgLanguageCode;
62 return $wgLanguageCode;
64 function getDate() {
65 return $this->Date;
67 function getAuthor() {
68 return $this->xmlEncode( $this->Author );
72 class ChannelFeed extends FeedItem {
73 /* Abstract functions, override! */
74 function outHeader() {
75 # print "<feed>";
77 function outItem( $item ) {
78 # print "<item>...</item>";
80 function outFooter() {
81 # print "</feed>";
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() {
91 global $wgVersion, $wgOut;
93 # We take over from $wgOut, excepting its cache header info
94 $wgOut->disable();
95 header( "Content-type: application/xml; charset=UTF-8" );
96 $wgOut->sendCacheControl();
98 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
99 ?><rss version="2.0">
100 <channel>
101 <title><?php print $this->getTitle() ?></title>
102 <link><?php print $this->getUrl() ?></link>
103 <description><?php print $this->getDescription() ?></description>
104 <language><?php print $this->getLanguage() ?></language>
105 <generator>MediaWiki <?php print $wgVersion ?></generator>
106 <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
107 <?php
110 function outItem( $item ) {
112 <item>
113 <title><?php print $item->getTitle() ?></title>
114 <link><?php print $item->getUrl() ?></link>
115 <description><?php print $item->getDescription() ?></description>
116 <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?>
117 <?php if( $item->getAuthor() ) { ?><author><?php print $item->getAuthor() ?></author><?php }?>
119 </item>
120 <?php
123 function outFooter() {
125 </channel>
126 </rss><?php