Tweaking RSS; add dates, etc.
[lhc/web/wiklou.git] / includes / Feed.php
1 <?php
2
3 $wgFeedClasses = array(
4 "rss" => "RSSFeed",
5 # "atom" => "AtomFeed",
6 );
7
8 class FeedItem {
9 var $Title = "Wiki";
10 var $Description = "";
11 var $Url = "";
12 var $Date = "";
13
14 function FeedItem( $Title, $Description, $Url, $Date = "" ) {
15 $this->Title = $Title;
16 $this->Description = $Description;
17 $this->Url = $Url;
18 $this->Date = $Date;
19 }
20
21 /* Static... */
22 function xmlEncode( $string ) {
23 global $wgInputEncoding, $wgLang;
24 $string = str_replace( "\r\n", "\n", $string );
25 if( strcasecmp( $wgInputEncoding, "utf-8" ) != 0 ) {
26 $string = $wgLang->iconv( $wgInputEncoding, "utf-8" );
27 }
28 return htmlspecialchars( $string );
29 }
30 function getTitle() {
31 return $this->xmlEncode( $this->Title );
32 }
33 function getUrl() {
34 return $this->xmlEncode( $this->Url );
35 }
36 function getDescription() {
37 return $this->xmlEncode( $this->Description );
38 }
39 function getLanguage() {
40 global $wgLanguageCode;
41 return $wgLanguageCode;
42 }
43 function getDate() {
44 return $this->Date;
45 }
46 }
47
48 class ChannelFeed extends FeedItem {
49 /* Abstract functions, override! */
50 function outHeader() {
51 # print "<feed>";
52 }
53 function outItem( $item ) {
54 # print "<item>...</item>";
55 }
56 function outFooter() {
57 # print "</feed>";
58 }
59 }
60
61 class RSSFeed extends ChannelFeed {
62 function formatTime( $ts ) {
63 return gmdate( "D, d M Y H:i:s T", wfTimestamp2Unix( $ts ) );
64 }
65
66 function outHeader() {
67 global $wgVersion;
68
69 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
70 ?><rss version="2.0">
71 <channel>
72 <title><?php print $this->getTitle() ?></title>
73 <link><?php print $this->getUrl() ?></link>
74 <description><?php print $this->getDescription() ?></description>
75 <language><?php print $this->getLanguage() ?></language>
76 <generator>MediaWiki <?php print $wgVersion ?></generator>
77 <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
78 <?php
79 }
80
81 function outItem( $item ) {
82 ?>
83 <item>
84 <title><?php print $item->getTitle() ?></title>
85 <link><?php print $item->getUrl() ?></link>
86 <description><?php print $item->getDescription() ?></description>
87 <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?>
88
89 </item>
90 <?php
91 }
92
93 function outFooter() {
94 ?>
95 </channel>
96 </rss><?php
97 }
98 }
99
100 ?>