Merge "Provide title when parsing wikitext"

This commit is contained in:
jenkins-bot 2016-09-02 01:48:33 +00:00 committed by Gerrit Code Review
commit cf7cf0dd66
4 changed files with 23 additions and 6 deletions

View file

@ -135,14 +135,16 @@ abstract class EchoDiscussionParser {
$snippet = self::getTextSnippet(
self::stripSignature( self::stripHeader( $action['content'] ), $title ),
$wgLang,
150 );
150,
$title );
break;
case 'new-section-with-comment':
$header = self::extractHeader( $action['content'] );
$snippet = self::getTextSnippet(
self::stripSignature( self::stripHeader( $action['content'] ), $title ),
$wgLang,
150 );
150,
$title );
break;
}
if ( $header ) {
@ -1170,11 +1172,12 @@ abstract class EchoDiscussionParser {
* @param string $text
* @param Language $lang
* @param int $length default 150
* @param Title|null $title Page from which the text snippet is being extracted
* @return string
*/
static function getTextSnippet( $text, Language $lang, $length = 150 ) {
static function getTextSnippet( $text, Language $lang, $length = 150, $title = null ) {
// Parse wikitext
$html = MessageCache::singleton()->parse( $text )->getText();
$html = MessageCache::singleton()->parse( $text, $title )->getText();
$plaintext = self::htmlToText( $html );
return $lang->truncate( $plaintext, $length );
}

View file

@ -507,7 +507,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable {
protected function getTruncatedSectionTitle( $section ) {
return $this->language->embedBidi( $this->language->truncate(
EchoDiscussionParser::getTextSnippet( $section, $this->language ),
EchoDiscussionParser::getTextSnippet( $section, $this->language, 150, $this->event->getTitle() ),
self::SECTION_TITLE_RECOMMENDED_LENGTH,
'...',
false

View file

@ -63,7 +63,9 @@ class EchoMentionPresentationModel extends EchoEventPresentationModel {
$msg->plaintextParams(
EchoDiscussionParser::getTextSnippet(
$content,
$this->language
$this->language,
150,
$this->event->getTitle()
)
);
return $msg;

View file

@ -1586,4 +1586,16 @@ TEXT
return "ParserFunctions not enabled";
}
}
public function testGetTextSnippet() {
$this->assertEquals(
'Page001',
EchoDiscussionParser::getTextSnippet(
'[[:{{BASEPAGENAME}}]]',
Language::factory( 'en' ),
150,
Title::newFromText( 'Page001' )
)
);
}
}