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

This commit is contained in:
jenkins-bot 2017-07-08 00:13:22 +00:00 committed by Gerrit Code Review
commit fa37dac615
3 changed files with 6 additions and 14 deletions

View file

@ -1155,7 +1155,7 @@ abstract class EchoDiscussionParser {
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,18 +1169,10 @@ abstract class EchoDiscussionParser {
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 ) );
}
/**
* Extract an edit excerpt from a revision
*

View file

@ -21,7 +21,7 @@ class EchoPlainTextDigestEmailFormatter extends EchoEventDigestFormatter {
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 );

View file

@ -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();