[MediaWiki-commits] [Gerrit] mediawiki...Echo[master]: Replace EchoDiscussionParser::htmlToText with Sanitizer::str...

2017-07-07 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/363993 )

Change subject: Replace EchoDiscussionParser::htmlToText with 
Sanitizer::stripAllTags()
..


Replace EchoDiscussionParser::htmlToText with Sanitizer::stripAllTags()

The latter doesn't trim(), so add trim() calls in some cases.
User input is trimmed, parsed i18n messages are not.

Change-Id: I933a6a929bf7d3e2d1623ea537227dc8c731cb6f
---
M includes/DiscussionParser.php
M includes/formatters/EchoPlainTextDigestEmailFormatter.php
M includes/formatters/EchoPlainTextEmailFormatter.php
3 files changed, 6 insertions(+), 14 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified
  Jforrester: Looks good to me, but someone else must approve



diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php
index eba108f..a1b1ea8 100644
--- a/includes/DiscussionParser.php
+++ b/includes/DiscussionParser.php
@@ -1155,7 +1155,7 @@
static function getTextSnippet( $text, Language $lang, $length = 150, 
$title = null ) {
// Parse wikitext
$html = MessageCache::singleton()->parse( $text, $title 
)->getText();
-   $plaintext = self::htmlToText( $html );
+   $plaintext = trim( Sanitizer::stripAllTags( $html ) );
return $lang->truncate( $plaintext, $length );
}
 
@@ -1169,16 +1169,8 @@
static function getTextSnippetFromSummary( $text, Language $lang, 
$length = 150 ) {
// Parse wikitext with summary parser
$html = Linker::formatLinksInComment( 
Sanitizer::escapeHtmlAllowEntities( $text ) );
-   $plaintext = self::htmlToText( $html );
+   $plaintext = trim( Sanitizer::stripAllTags( $html ) );
return $lang->truncate( $plaintext, $length );
-   }
-
-   /**
-* @param string $html
-* @return string text version of the given html string
-*/
-   public static function htmlToText( $html ) {
-   return trim( html_entity_decode( strip_tags( $html ), 
ENT_QUOTES ) );
}
 
/**
diff --git a/includes/formatters/EchoPlainTextDigestEmailFormatter.php 
b/includes/formatters/EchoPlainTextDigestEmailFormatter.php
index e6d4b7e..88d9c5f 100644
--- a/includes/formatters/EchoPlainTextDigestEmailFormatter.php
+++ b/includes/formatters/EchoPlainTextDigestEmailFormatter.php
@@ -21,7 +21,7 @@
protected function formatModels( array $models ) {
$content = [];
foreach ( $models as $model ) {
-   $content[$model->getCategory()][] = 
EchoDiscussionParser::htmlToText( $model->getHeaderMessage()->parse() );
+   $content[$model->getCategory()][] = 
Sanitizer::stripAllTags( $model->getHeaderMessage()->parse() );
}
 
ksort( $content );
diff --git a/includes/formatters/EchoPlainTextEmailFormatter.php 
b/includes/formatters/EchoPlainTextEmailFormatter.php
index 6e1e03a..34fdc7d 100644
--- a/includes/formatters/EchoPlainTextEmailFormatter.php
+++ b/includes/formatters/EchoPlainTextEmailFormatter.php
@@ -2,15 +2,15 @@
 
 class EchoPlainTextEmailFormatter extends EchoEventFormatter {
protected function formatModel( EchoEventPresentationModel $model ) {
-   $subject = EchoDiscussionParser::htmlToText( 
$model->getSubjectMessage()->parse() );
+   $subject = Sanitizer::stripAllTags( 
$model->getSubjectMessage()->parse() );
 
-   $text = EchoDiscussionParser::htmlToText( 
$model->getHeaderMessage()->parse() );
+   $text = Sanitizer::stripAllTags( 
$model->getHeaderMessage()->parse() );
 
$text .= "\n\n";
 
$bodyMsg = $model->getBodyMessage();
if ( $bodyMsg ) {
-   $text .= EchoDiscussionParser::htmlToText( 
$bodyMsg->parse() );
+   $text .= Sanitizer::stripAllTags( $bodyMsg->parse() );
}
 
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I933a6a929bf7d3e2d1623ea537227dc8c731cb6f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Catrope 
Gerrit-Reviewer: Jforrester 
Gerrit-Reviewer: Krinkle 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki...Echo[master]: Replace EchoDiscussionParser::htmlToText with Sanitizer::str...

2017-07-07 Thread Catrope (Code Review)
Catrope has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/363993 )

Change subject: Replace EchoDiscussionParser::htmlToText with 
Sanitizer::stripAllTags()
..

Replace EchoDiscussionParser::htmlToText with Sanitizer::stripAllTags()

The latter doesn't trim(), so add trim() calls in some cases.
User input is trimmed, parsed i18n messages are not.

Change-Id: I933a6a929bf7d3e2d1623ea537227dc8c731cb6f
---
M includes/DiscussionParser.php
M includes/formatters/EchoPlainTextDigestEmailFormatter.php
M includes/formatters/EchoPlainTextEmailFormatter.php
3 files changed, 6 insertions(+), 14 deletions(-)


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

diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php
index eba108f..a1b1ea8 100644
--- a/includes/DiscussionParser.php
+++ b/includes/DiscussionParser.php
@@ -1155,7 +1155,7 @@
static function getTextSnippet( $text, Language $lang, $length = 150, 
$title = null ) {
// Parse wikitext
$html = MessageCache::singleton()->parse( $text, $title 
)->getText();
-   $plaintext = self::htmlToText( $html );
+   $plaintext = trim( Sanitizer::stripAllTags( $html ) );
return $lang->truncate( $plaintext, $length );
}
 
@@ -1169,16 +1169,8 @@
static function getTextSnippetFromSummary( $text, Language $lang, 
$length = 150 ) {
// Parse wikitext with summary parser
$html = Linker::formatLinksInComment( 
Sanitizer::escapeHtmlAllowEntities( $text ) );
-   $plaintext = self::htmlToText( $html );
+   $plaintext = trim( Sanitizer::stripAllTags( $html ) );
return $lang->truncate( $plaintext, $length );
-   }
-
-   /**
-* @param string $html
-* @return string text version of the given html string
-*/
-   public static function htmlToText( $html ) {
-   return trim( html_entity_decode( strip_tags( $html ), 
ENT_QUOTES ) );
}
 
/**
diff --git a/includes/formatters/EchoPlainTextDigestEmailFormatter.php 
b/includes/formatters/EchoPlainTextDigestEmailFormatter.php
index e6d4b7e..88d9c5f 100644
--- a/includes/formatters/EchoPlainTextDigestEmailFormatter.php
+++ b/includes/formatters/EchoPlainTextDigestEmailFormatter.php
@@ -21,7 +21,7 @@
protected function formatModels( array $models ) {
$content = [];
foreach ( $models as $model ) {
-   $content[$model->getCategory()][] = 
EchoDiscussionParser::htmlToText( $model->getHeaderMessage()->parse() );
+   $content[$model->getCategory()][] = 
Sanitizer::stripAllTags( $model->getHeaderMessage()->parse() );
}
 
ksort( $content );
diff --git a/includes/formatters/EchoPlainTextEmailFormatter.php 
b/includes/formatters/EchoPlainTextEmailFormatter.php
index 6e1e03a..34fdc7d 100644
--- a/includes/formatters/EchoPlainTextEmailFormatter.php
+++ b/includes/formatters/EchoPlainTextEmailFormatter.php
@@ -2,15 +2,15 @@
 
 class EchoPlainTextEmailFormatter extends EchoEventFormatter {
protected function formatModel( EchoEventPresentationModel $model ) {
-   $subject = EchoDiscussionParser::htmlToText( 
$model->getSubjectMessage()->parse() );
+   $subject = Sanitizer::stripAllTags( 
$model->getSubjectMessage()->parse() );
 
-   $text = EchoDiscussionParser::htmlToText( 
$model->getHeaderMessage()->parse() );
+   $text = Sanitizer::stripAllTags( 
$model->getHeaderMessage()->parse() );
 
$text .= "\n\n";
 
$bodyMsg = $model->getBodyMessage();
if ( $bodyMsg ) {
-   $text .= EchoDiscussionParser::htmlToText( 
$bodyMsg->parse() );
+   $text .= Sanitizer::stripAllTags( $bodyMsg->parse() );
}
 
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I933a6a929bf7d3e2d1623ea537227dc8c731cb6f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Catrope 

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