EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/159974

Change subject: Hygiene: Move duplicated code to getCleanTextSnippet()
......................................................................

Hygiene: Move duplicated code to getCleanTextSnippet()

Change-Id: Id66b060876c9e863da991655b4c64ee4589b9ec3
---
M formatters/BasicFormatter.php
M includes/DiscussionParser.php
M includes/WikiTextString.php
3 files changed, 18 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/74/159974/1

diff --git a/formatters/BasicFormatter.php b/formatters/BasicFormatter.php
index c9668e0..30df474 100644
--- a/formatters/BasicFormatter.php
+++ b/formatters/BasicFormatter.php
@@ -411,10 +411,8 @@
                if ( !isset( $extra['content'] ) ) {
                        return '';
                }
-               $content = EchoWikiTextString::stripHeader( $extra['content'] );
-               $content = EchoWikiTextString::stripSignature( $content );
-               $content = EchoWikiTextString::stripIndents( $content );
-               return EchoWikiTextString::getTextSnippet( $content, 200 );
+
+               return EchoWikiTextString::getCleanTextSnippet( $content, 200 );
        }
 
        /**
diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php
index 9e06b8f..dbe66ad 100644
--- a/includes/DiscussionParser.php
+++ b/includes/DiscussionParser.php
@@ -82,15 +82,11 @@
                        switch( $action['type'] ) {
                                case 'add-comment':
                                        $header  = 
EchoWikiTextString::extractHeader( $action['full-section'] );
-                                       $snippet = 
EchoWikiTextString::stripHeader( $action['content'] );
-                                       $snippet = 
EchoWikiTextString::stripSignature( $snippet );
-                                       $snippet = 
EchoWikiTextString::getTextSnippet( $snippet, 150 );
+                                       $snippet = 
EchoWikiTextString::getCleanTextSnippet( $action['content'] );
                                        break;
                                case 'new-section-with-comment':
                                        $header  = 
EchoWikiTextString::extractHeader( $action['content'] );
-                                       $snippet = 
EchoWikiTextString::stripHeader( $action['content'] );
-                                       $snippet = 
EchoWikiTextString::stripSignature( $snippet );
-                                       $snippet = 
EchoWikiTextString::getTextSnippet( $snippet, 150 );
+                                       $snippet = 
EchoWikiTextString::getCleanTextSnippet( $action['content'] );
                                        break;
                        }
                        if ( $header ) {
diff --git a/includes/WikiTextString.php b/includes/WikiTextString.php
index eb70710..d1ab3a3 100644
--- a/includes/WikiTextString.php
+++ b/includes/WikiTextString.php
@@ -432,6 +432,7 @@
                $text = strip_tags( $text );
                $attempt = 0;
 
+               // remove any wikitext transclusions.
                // 10 attempts at most, the logic here is to find the first }} 
and
                // find the matching {{ for that }}
                while ( $attempt < 10 ) {
@@ -467,4 +468,17 @@
                return $text;
        }
 
+       /**
+        * Strip a wikitext string representing the users complete content 
addition 
+        * down to a small plaintext snippet
+        *
+        * @param string $text
+        * @return string
+        */
+       static public function getCleanTextSnippet( $text, $length = 150 ) {
+               $text = self::stripHeader( $text );
+               $text = self::stripSignature( $text );
+               $text = self::stripIndents( $text );
+               return self::getTextSnippet( $text, $length );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/159974
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id66b060876c9e863da991655b4c64ee4589b9ec3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to