time need to follow RFC 822 format ( "r" )
[lhc/web/wiklou.git] / includes / Feed.php
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.
11 #
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.
16 #
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
21
22 $wgFeedClasses = array(
23 "rss" => "RSSFeed",
24 # "atom" => "AtomFeed",
25 );
26
27 class FeedItem {
28 var $Title = "Wiki";
29 var $Description = "";
30 var $Url = "";
31 var $Date = "";
32 var $Author = "";
33
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;
40 }
41
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 );
48 }
49 return htmlspecialchars( $string );
50 }
51 function getTitle() {
52 return $this->xmlEncode( $this->Title );
53 }
54 function getUrl() {
55 return $this->xmlEncode( $this->Url );
56 }
57 function getDescription() {
58 return $this->xmlEncode( $this->Description );
59 }
60 function getLanguage() {
61 global $wgLanguageCode;
62 return $wgLanguageCode;
63 }
64 function getDate() {
65 return $this->Date;
66 }
67 function getAuthor() {
68 return $this->xmlEncode( $this->Author );
69 }
70 }
71
72 class ChannelFeed extends FeedItem {
73 /* Abstract functions, override! */
74 function outHeader() {
75 # print "<feed>";
76 }
77 function outItem( $item ) {
78 # print "<item>...</item>";
79 }
80 function outFooter() {
81 # print "</feed>";
82 }
83 }
84
85 class RSSFeed extends ChannelFeed {
86 function formatTime( $ts ) {
87 // need to use RFC 822 time format
88 return gmdate( "r", wfTimestamp2Unix( $ts ) );
89 }
90
91 function outHeader() {
92 global $wgVersion, $wgOut;
93
94 # We take over from $wgOut, excepting its cache header info
95 $wgOut->disable();
96 header( "Content-type: application/xml; charset=UTF-8" );
97 $wgOut->sendCacheControl();
98
99 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
100 ?><rss version="2.0">
101 <channel>
102 <title><?php print $this->getTitle() ?></title>
103 <link><?php print $this->getUrl() ?></link>
104 <description><?php print $this->getDescription() ?></description>
105 <language><?php print $this->getLanguage() ?></language>
106 <generator>MediaWiki <?php print $wgVersion ?></generator>
107 <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
108 <?php
109 }
110
111 function outItem( $item ) {
112 ?>
113 <item>
114 <title><?php print $item->getTitle() ?></title>
115 <link><?php print $item->getUrl() ?></link>
116 <description><?php print $item->getDescription() ?></description>
117 <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?>
118 <?php if( $item->getAuthor() ) { ?><author><?php print $item->getAuthor() ?></author><?php }?>
119
120 </item>
121 <?php
122 }
123
124 function outFooter() {
125 ?>
126 </channel>
127 </rss><?php
128 }
129 }
130
131 ?>