mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
Merge "Provide title when parsing wikitext"
This commit is contained in:
commit
cf7cf0dd66
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -63,7 +63,9 @@ class EchoMentionPresentationModel extends EchoEventPresentationModel {
|
|||
$msg->plaintextParams(
|
||||
EchoDiscussionParser::getTextSnippet(
|
||||
$content,
|
||||
$this->language
|
||||
$this->language,
|
||||
150,
|
||||
$this->event->getTitle()
|
||||
)
|
||||
);
|
||||
return $msg;
|
||||
|
|
|
@ -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' )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue