New RSS feed should be easier to integrate with any QueryPage. Sample for Newpages.
[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
13 function FeedItem( $Title, $Description, $Url ) {
14 $this->Title = $Title;
15 $this->Description = $Description;
16 $this->Url = $Url;
17 }
18
19 /* Static... */
20 function xmlEncode( $string ) {
21 global $wgInputEncoding, $wgLang;
22 $string = str_replace( "\r\n", "\n", $string );
23 if( strcasecmp( $wgInputEncoding, "utf-8" ) != 0 ) {
24 $string = $wgLang->iconv( $wgInputEncoding, "utf-8" );
25 }
26 return htmlspecialchars( $string );
27 }
28 function getTitle() {
29 return $this->xmlEncode( $this->Title );
30 }
31 function getUrl() {
32 return $this->xmlEncode( $this->Url );
33 }
34 function getDescription() {
35 return $this->xmlEncode( $this->Description );
36 }
37 function getLanguage() {
38 global $wgLanguageCode;
39 return $wgLanguageCode;
40 }
41 }
42
43 class ChannelFeed extends FeedItem {
44 /* Abstract functions, override! */
45 function outHeader() {
46 # print "<feed>";
47 }
48 function outItem( $item ) {
49 # print "<item>...</item>";
50 }
51 function outFooter() {
52 # print "</feed>";
53 }
54 }
55
56 class RSSFeed extends ChannelFeed {
57 function outHeader() {
58 print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
59 ?><!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">
60 <rss version="0.91">
61 <channel>
62 <title><?php print $this->getTitle() ?></title>
63 <link><?php print $this->getUrl() ?></link>
64 <description><?php print $this->getDescription() ?></description>
65 <language><?php print $this->getLanguage() ?></language>
66 <?php
67 }
68
69 function outItem( $item ) {
70 ?>
71 <item>
72 <title><?php print $item->getTitle() ?></title>
73 <link><?php print $item->getUrl() ?></link>
74 <description><?php print $item->getDescription() ?></description>
75 </item>
76 <?php
77 }
78
79 function outFooter() {
80 ?>
81 </channel>
82 </rss><?php
83 }
84 }
85
86 ?>