Merge "Parse section titles in notifs as if they weren't at the start of line"

This commit is contained in:
jenkins-bot 2022-01-24 05:43:44 +00:00 committed by Gerrit Code Review
commit a8af58f362
3 changed files with 27 additions and 3 deletions

View file

@ -1239,13 +1239,14 @@ abstract class EchoDiscussionParser {
* @param Language $lang
* @param int $length Length in characters (not bytes); default DEFAULT_SNIPPET_LENGTH
* @param Title|null $title Page from which the text snippet is being extracted
* @param bool $linestart Whether or not this is at the start of a line
* @return string
*/
public static function getTextSnippet(
$text, Language $lang, $length = self::DEFAULT_SNIPPET_LENGTH, $title = null
$text, Language $lang, $length = self::DEFAULT_SNIPPET_LENGTH, $title = null, $linestart = true
) {
// Parse wikitext
$html = MediaWikiServices::getInstance()->getMessageCache()->parse( $text, $title )->getText( [
$html = MediaWikiServices::getInstance()->getMessageCache()->parse( $text, $title, $linestart )->getText( [
'enableSectionEditLinks' => false
] );
$plaintext = trim( Sanitizer::stripAllTags( $html ) );

View file

@ -83,7 +83,10 @@ class EchoPresentationModelSection {
$rawSectionTitle,
$this->language,
EchoDiscussionParser::DEFAULT_SNIPPET_LENGTH,
$this->event->getTitle()
$this->event->getTitle(),
// linestart=false, because this wikitext was inside a heading like `== … ==`,
// so start-of-line markup like `*` should not be parsed (T299572)
false
);
return $this->parsedSectionTitle;
}

View file

@ -1816,5 +1816,25 @@ TEXT
Title::newFromText( 'Page001' )
)
);
$this->assertEquals(
'Hello',
EchoDiscussionParser::getTextSnippet(
'* Hello',
Language::factory( 'en' ),
EchoDiscussionParser::DEFAULT_SNIPPET_LENGTH,
null,
true
)
);
$this->assertEquals(
'* Hello',
EchoDiscussionParser::getTextSnippet(
'* Hello',
Language::factory( 'en' ),
EchoDiscussionParser::DEFAULT_SNIPPET_LENGTH,
null,
false
)
);
}
}