Require a Language object in DiscussionParser::getTextSnippet()

To avoid using $wgLang directly. We still have to use it in
detectSectionTitleAndText for now though.

Change-Id: Ic901ed05d4e8f6291caa55d866ce58f7300880f5
This commit is contained in:
Kunal Mehta 2015-09-02 11:09:11 -07:00
parent 4a5c99921d
commit 86da8324d5
3 changed files with 18 additions and 8 deletions

View file

@ -81,6 +81,7 @@ abstract class EchoDiscussionParser {
* @param Title $title
*/
public static function detectSectionTitleAndText( array $interpretation, Title $title = null ) {
global $wgLang;
$header = $snippet = '';
$found = false;
@ -88,11 +89,17 @@ abstract class EchoDiscussionParser {
switch( $action['type'] ) {
case 'add-comment':
$header = self::extractHeader( $action['full-section'] );
$snippet = self::getTextSnippet( self::stripSignature( self::stripHeader( $action['content'] ), $title ), 150 );
$snippet = self::getTextSnippet(
self::stripSignature( self::stripHeader( $action['content'] ), $title ),
$wgLang,
150 );
break;
case 'new-section-with-comment':
$header = self::extractHeader( $action['content'] );
$snippet = self::getTextSnippet( self::stripSignature( self::stripHeader( $action['content'] ), $title ), 150 );
$snippet = self::getTextSnippet(
self::stripSignature( self::stripHeader( $action['content'] ), $title ),
$wgLang,
150 );
break;
}
if ( $header ) {
@ -815,12 +822,11 @@ abstract class EchoDiscussionParser {
* This function returns plain text snippet, it also removes html tag,
* template from text content
* @param $text string
* @param Language $lang
* @param $length int default 150
* @return string
*/
static function getTextSnippet( $text, $length = 150 ) {
global $wgLang;
static function getTextSnippet( $text, Language $lang, $length = 150 ) {
$text = strip_tags( $text );
$attempt = 0;
@ -849,7 +855,7 @@ abstract class EchoDiscussionParser {
$text = trim( strip_tags( htmlspecialchars_decode( $text ) ) );
// strip out non-useful data for snippet
$text = str_replace( array( '{', '}' ), '', $text );
$text = $wgLang->truncate( $text, $length );
$text = $lang->truncate( $text, $length );
// Return empty string if there is undecoded char left
if ( strpos( $text, '&#' ) !== false ) {

View file

@ -405,7 +405,7 @@ class EchoBasicFormatter extends EchoNotificationFormatter {
$content = EchoDiscussionParser::stripHeader( $extra['content'] );
$content = EchoDiscussionParser::stripSignature( $content );
$content = EchoDiscussionParser::stripIndents( $content );
return EchoDiscussionParser::getTextSnippet( $content, 200 );
return EchoDiscussionParser::getTextSnippet( $content, $this->getLanguage(), 200 );
}
/**

View file

@ -64,7 +64,11 @@ class EchoEditFormatter extends EchoBasicFormatter {
if ( !empty( $extra['section-title'] ) ) {
if ( $event->userCan( Revision::DELETED_TEXT, $user ) ) {
return EchoDiscussionParser::getTextSnippet( $extra['section-title'], 30 );
return EchoDiscussionParser::getTextSnippet(
$extra['section-title'],
$this->getLanguage(),
30
);
} else {
return $this->getMessage( 'echo-rev-deleted-text-view' )->text();
}