aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Feed.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@users.mediawiki.org>2004-03-05 10:16:46 +0000
committerBrion Vibber <brion@users.mediawiki.org>2004-03-05 10:16:46 +0000
commit361c83706363c10685dd4baccd24164886094994 (patch)
treecca7a6dfd5e80832721a1281f44857f00df0b215 /includes/Feed.php
parent4b7a8428dbd80362baf126c52899af0b5a72d176 (diff)
downloadmediawikicore-361c83706363c10685dd4baccd24164886094994.tar.gz
mediawikicore-361c83706363c10685dd4baccd24164886094994.zip
New RSS feed should be easier to integrate with any QueryPage. Sample for Newpages.
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/2615
Diffstat (limited to 'includes/Feed.php')
-rw-r--r--includes/Feed.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/includes/Feed.php b/includes/Feed.php
new file mode 100644
index 000000000000..e5c7c18bc161
--- /dev/null
+++ b/includes/Feed.php
@@ -0,0 +1,86 @@
+<?php
+
+$wgFeedClasses = array(
+ "rss" => "RSSFeed",
+ # "atom" => "AtomFeed",
+ );
+
+class FeedItem {
+ var $Title = "Wiki";
+ var $Description = "";
+ var $Url = "";
+
+ function FeedItem( $Title, $Description, $Url ) {
+ $this->Title = $Title;
+ $this->Description = $Description;
+ $this->Url = $Url;
+ }
+
+ /* Static... */
+ function xmlEncode( $string ) {
+ global $wgInputEncoding, $wgLang;
+ $string = str_replace( "\r\n", "\n", $string );
+ if( strcasecmp( $wgInputEncoding, "utf-8" ) != 0 ) {
+ $string = $wgLang->iconv( $wgInputEncoding, "utf-8" );
+ }
+ return htmlspecialchars( $string );
+ }
+ function getTitle() {
+ return $this->xmlEncode( $this->Title );
+ }
+ function getUrl() {
+ return $this->xmlEncode( $this->Url );
+ }
+ function getDescription() {
+ return $this->xmlEncode( $this->Description );
+ }
+ function getLanguage() {
+ global $wgLanguageCode;
+ return $wgLanguageCode;
+ }
+}
+
+class ChannelFeed extends FeedItem {
+ /* Abstract functions, override! */
+ function outHeader() {
+ # print "<feed>";
+ }
+ function outItem( $item ) {
+ # print "<item>...</item>";
+ }
+ function outFooter() {
+ # print "</feed>";
+ }
+}
+
+class RSSFeed extends ChannelFeed {
+ function outHeader() {
+ print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
+ ?><!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">
+<rss version="0.91">
+ <channel>
+ <title><?php print $this->getTitle() ?></title>
+ <link><?php print $this->getUrl() ?></link>
+ <description><?php print $this->getDescription() ?></description>
+ <language><?php print $this->getLanguage() ?></language>
+<?php
+ }
+
+ function outItem( $item ) {
+ ?>
+ <item>
+ <title><?php print $item->getTitle() ?></title>
+ <link><?php print $item->getUrl() ?></link>
+ <description><?php print $item->getDescription() ?></description>
+ </item>
+<?php
+ }
+
+ function outFooter() {
+ ?>
+ </channel>
+</rss><?php
+ }
+}
+
+?> \ No newline at end of file