Add FeedItem::stripComment() and remove duplication
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 19 Nov 2008 00:11:14 +0000 (00:11 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 19 Nov 2008 00:11:14 +0000 (00:11 +0000)
includes/Feed.php
includes/PageHistory.php
includes/specials/SpecialContributions.php
includes/specials/SpecialNewpages.php

index b702f86..fe6d8fe 100644 (file)
@@ -52,22 +52,45 @@ class FeedItem {
                $this->Comments = $Comments;
        }
 
-       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 );
+       }
        /**#@-*/
 }
 
index 628cbb9..b01b485 100644 (file)
@@ -573,7 +573,7 @@ class PageHistory {
                        $rev->getUserText(),
                        $wgContLang->timeanddate( $rev->getTimestamp() ) );
                } else {
-                       $title = $rev->getUserText() . ": " . $this->stripComment( $rev->getComment() );
+                       $title = $rev->getUserText() . ": " . FeedItem::stripComment( $rev->getComment() );
                }
 
                return new FeedItem(
@@ -584,13 +584,6 @@ class PageHistory {
                        $rev->getUserText(),
                        $this->mTitle->getTalkPage()->getFullUrl() );
        }
-
-       /**
-        * Quickie hack... strip out wikilinks to more legible form from the comment.
-        */
-       function stripComment( $text ) {
-               return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
-       }
 }
 
 
index 4755e33..bca2f57 100644 (file)
@@ -347,13 +347,6 @@ class SpecialContributions extends SpecialPage {
                }
        }
 
-       /**
-        * Quickie hack... strip out wikilinks to more legible form from the comment.
-        */
-       protected function stripComment( $text ) {
-               return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
-       }
-
        protected function feedItemAuthor( $revision ) {
                return $revision->getUserText();
        }
@@ -361,7 +354,7 @@ class SpecialContributions extends SpecialPage {
        protected function feedItemDesc( $revision ) {
                if( $revision ) {
                        return '<p>' . htmlspecialchars( $revision->getUserText() ) . ': ' .
-                               htmlspecialchars( $this->stripComment( $revision->getComment() ) ) . 
+                               htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . 
                                "</p>\n<hr />\n<div>" .
                                nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
                }
index ed40ef0..0f5cfe4 100644 (file)
@@ -322,13 +322,6 @@ class SpecialNewpages extends SpecialPage {
                }
        }
 
-       /**
-        * Quickie hack... strip out wikilinks to more legible form from the comment.
-        */
-       protected function stripComment( $text ) {
-               return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
-       }
-
        protected function feedItemAuthor( $row ) {
                return isset( $row->rc_user_text ) ? $row->rc_user_text : '';
        }
@@ -337,7 +330,7 @@ class SpecialNewpages extends SpecialPage {
                $revision = Revision::newFromId( $row->rev_id );
                if( $revision ) {
                        return '<p>' . htmlspecialchars( $revision->getUserText() ) . ': ' .
-                               htmlspecialchars( $this->stripComment( $revision->getComment() ) ) . 
+                               htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . 
                                "</p>\n<hr />\n<div>" .
                                nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
                }