From cc554b12306fa65d4d07728dab49fdf45bcf6695 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 19 Nov 2008 00:11:14 +0000 Subject: [PATCH] Add FeedItem::stripComment() and remove duplication --- includes/Feed.php | 39 +++++++++++++++++----- includes/PageHistory.php | 9 +---- includes/specials/SpecialContributions.php | 9 +---- includes/specials/SpecialNewpages.php | 9 +---- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/includes/Feed.php b/includes/Feed.php index b702f8683a..fe6d8febd6 100644 --- a/includes/Feed.php +++ b/includes/Feed.php @@ -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 ); + } /**#@-*/ } diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 628cbb9784..b01b485e68 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -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 ); - } } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 4755e33be5..bca2f57eb1 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -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 '

' . htmlspecialchars( $revision->getUserText() ) . ': ' . - htmlspecialchars( $this->stripComment( $revision->getComment() ) ) . + htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . "

\n
\n
" . nl2br( htmlspecialchars( $revision->getText() ) ) . "
"; } diff --git a/includes/specials/SpecialNewpages.php b/includes/specials/SpecialNewpages.php index ed40ef0eb0..0f5cfe4e9a 100644 --- a/includes/specials/SpecialNewpages.php +++ b/includes/specials/SpecialNewpages.php @@ -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 '

' . htmlspecialchars( $revision->getUserText() ) . ': ' . - htmlspecialchars( $this->stripComment( $revision->getComment() ) ) . + htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . "

\n
\n
" . nl2br( htmlspecialchars( $revision->getText() ) ) . "
"; } -- 2.20.1