fixed a couple of minor bugs
[mediawiki.git] / includes / Feed.php
blob248ba620e791c8e72a904b3ea1ff0246e66d0141
1 <?php
3 $wgFeedClasses = array(
4 "rss" => "RSSFeed",
5 # "atom" => "AtomFeed",
6 );
8 class FeedItem {
9 var $Title = "Wiki";
10 var $Description = "";
11 var $Url = "";
12 var $Date = "";
14 function FeedItem( $Title, $Description, $Url, $Date = "" ) {
15 $this->Title = $Title;
16 $this->Description = $Description;
17 $this->Url = $Url;
18 $this->Date = $Date;
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" );
28 return htmlspecialchars( $string );
30 function getTitle() {
31 return $this->xmlEncode( $this->Title );
33 function getUrl() {
34 return $this->xmlEncode( $this->Url );
36 function getDescription() {
37 return $this->xmlEncode( $this->Description );
39 function getLanguage() {
40 global $wgLanguageCode;
41 return $wgLanguageCode;
43 function getDate() {
44 return $this->Date;
48 class ChannelFeed extends FeedItem {
49 /* Abstract functions, override! */
50 function outHeader() {
51 # print "<feed>";
53 function outItem( $item ) {
54 # print "<item>...</item>";
56 function outFooter() {
57 # print "</feed>";
61 class RSSFeed extends ChannelFeed {
62 function formatTime( $ts ) {
63 return gmdate( "D, d M Y H:i:s T", wfTimestamp2Unix( $ts ) );
66 function outHeader() {
67 global $wgVersion;
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
81 function outItem( $item ) {
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 } ?>
89 </item>
90 <?php
93 function outFooter() {
95 </channel>
96 </rss><?php