diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php index a8f1a54ee..86bbd46fe 100644 --- a/includes/DiscussionParser.php +++ b/includes/DiscussionParser.php @@ -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 ) ); diff --git a/includes/formatters/PresentationModelSection.php b/includes/formatters/PresentationModelSection.php index 94ca5948e..4d55c001c 100644 --- a/includes/formatters/PresentationModelSection.php +++ b/includes/formatters/PresentationModelSection.php @@ -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; } diff --git a/tests/phpunit/DiscussionParserTest.php b/tests/phpunit/DiscussionParserTest.php index 97c4dced5..a2076ee93 100644 --- a/tests/phpunit/DiscussionParserTest.php +++ b/tests/phpunit/DiscussionParserTest.php @@ -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 + ) + ); } }