Small fixes
[lhc/web/wiklou.git] / includes / Feed.php
index 5c14865..fe6d8fe 100644 (file)
@@ -1,6 +1,5 @@
 <?php
-# Basic support for outputting syndication feeds in RSS, other formats
-#
+
 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
 # http://www.mediawiki.org/
 #
 # http://www.gnu.org/copyleft/gpl.html
 
 /**
+ * Basic support for outputting syndication feeds in RSS, other formats.
  * Contain a feed class as well as classes to build rss / atom ... feeds
  * Available feeds are defined in Defines.php
- * @package MediaWiki
  */
 
-
 /**
- * @todo document
- * @package MediaWiki
+ * A base class for basic support for outputting syndication feeds in RSS and other formats.
  */
 class FeedItem {
        /**#@+
@@ -44,8 +41,9 @@ class FeedItem {
 
        /**#@+
         * @todo document
+        * @param $Url URL uniquely designating the item.
         */
-       function FeedItem( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
+       function __construct( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
                $this->Title = $Title;
                $this->Description = $Description;
                $this->Url = $Url;
@@ -54,31 +52,50 @@ class FeedItem {
                $this->Comments = $Comments;
        }
 
-       /**
-        * @static
-        */
-       function xmlEncode( $string ) {
+       public function xmlEncode( $string ) {
                $string = str_replace( "\r\n", "\n", $string );
                $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
                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() {
+       public function getTitle() {
+               return $this->xmlEncode( $this->Title );
+       }
+
+       public function getUrl() {
+               return $this->xmlEncode( $this->Url );
+       }
+
+       public function getDescription() {
+               return $this->xmlEncode( $this->Description );
+       }
+
+       public function getLanguage() {
                global $wgContLanguageCode;
                return $wgContLanguageCode;
        }
-       function getDate() { return $this->Date; }
-       function getAuthor() { return $this->xmlEncode( $this->Author ); }
-       function getComments() { return $this->xmlEncode( $this->Comments ); }
+
+       public function getDate() {
+               return $this->Date;
+       }
+       public function getAuthor() {
+               return $this->xmlEncode( $this->Author );
+       }
+       public function getComments() {
+               return $this->xmlEncode( $this->Comments );
+       }
+       
+       /**
+        * Quickie hack... strip out wikilinks to more legible form from the comment.
+        */
+       public static function stripComment( $text ) {
+               return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
+       }
        /**#@-*/
 }
 
 /**
- * @todo document
- * @package MediaWiki
+ * @todo document (needs one-sentence top-level class description).
  */
 class ChannelFeed extends FeedItem {
        /**#@+
@@ -149,19 +166,18 @@ class ChannelFeed extends FeedItem {
         * @private
         */
        function outXmlHeader() {
-               global $wgServer, $wgStylePath, $wgStyleVersion;
+               global $wgStylePath, $wgStyleVersion;
 
                $this->httpHeaders();
-               echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
+               echo '<?xml version="1.0"?>' . "\n";
                echo '<?xml-stylesheet type="text/css" href="' .
-                       htmlspecialchars( "$wgServer$wgStylePath/common/feed.css?$wgStyleVersion" ) . '"?' . ">\n";
+                       htmlspecialchars( wfExpandUrl( "$wgStylePath/common/feed.css?$wgStyleVersion" ) ) .
+                       '"?' . ">\n";
        }
 }
 
 /**
  * Generate a RSS feed
- * @todo document
- * @package MediaWiki
  */
 class RSSFeed extends ChannelFeed {
 
@@ -221,8 +237,6 @@ class RSSFeed extends ChannelFeed {
 
 /**
  * Generate an Atom feed
- * @todo document
- * @package MediaWiki
  */
 class AtomFeed extends ChannelFeed {
        /**
@@ -306,5 +320,3 @@ class AtomFeed extends ChannelFeed {
        </feed><?php
        }
 }
-
-?>