mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
Make default snippet length (150) a constant
Change-Id: Idb53b226618fa0d625c7e4713c780538bd6a76ea
This commit is contained in:
parent
b5c919db25
commit
1b40b69481
|
@ -7,6 +7,8 @@ use MediaWiki\Revision\SlotRecord;
|
||||||
abstract class EchoDiscussionParser {
|
abstract class EchoDiscussionParser {
|
||||||
const HEADER_REGEX = '^(==+)\h*([^=].*)\h*\1$';
|
const HEADER_REGEX = '^(==+)\h*([^=].*)\h*\1$';
|
||||||
|
|
||||||
|
const DEFAULT_SNIPPET_LENGTH = 150;
|
||||||
|
|
||||||
protected static $timestampRegex;
|
protected static $timestampRegex;
|
||||||
protected static $revisionInterpretationCache = [];
|
protected static $revisionInterpretationCache = [];
|
||||||
protected static $diffParser;
|
protected static $diffParser;
|
||||||
|
@ -161,7 +163,7 @@ abstract class EchoDiscussionParser {
|
||||||
$snippet = self::getTextSnippet(
|
$snippet = self::getTextSnippet(
|
||||||
self::stripSignature( self::stripHeader( $action['content'] ), $title ),
|
self::stripSignature( self::stripHeader( $action['content'] ), $title ),
|
||||||
RequestContext::getMain()->getLanguage(),
|
RequestContext::getMain()->getLanguage(),
|
||||||
150,
|
self::DEFAULT_SNIPPET_LENGTH,
|
||||||
$title );
|
$title );
|
||||||
break;
|
break;
|
||||||
case 'new-section-with-comment':
|
case 'new-section-with-comment':
|
||||||
|
@ -169,7 +171,7 @@ abstract class EchoDiscussionParser {
|
||||||
$snippet = self::getTextSnippet(
|
$snippet = self::getTextSnippet(
|
||||||
self::stripSignature( self::stripHeader( $action['content'] ), $title ),
|
self::stripSignature( self::stripHeader( $action['content'] ), $title ),
|
||||||
RequestContext::getMain()->getLanguage(),
|
RequestContext::getMain()->getLanguage(),
|
||||||
150,
|
self::DEFAULT_SNIPPET_LENGTH,
|
||||||
$title );
|
$title );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1180,11 +1182,13 @@ abstract class EchoDiscussionParser {
|
||||||
* Parse wikitext into truncated plain text.
|
* Parse wikitext into truncated plain text.
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param Language $lang
|
* @param Language $lang
|
||||||
* @param int $length Length in characters (not bytes); default 150
|
* @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 Title|null $title Page from which the text snippet is being extracted
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getTextSnippet( $text, Language $lang, $length = 150, $title = null ) {
|
public static function getTextSnippet(
|
||||||
|
$text, Language $lang, $length = self::DEFAULT_SNIPPET_LENGTH, $title = null
|
||||||
|
) {
|
||||||
// Parse wikitext
|
// Parse wikitext
|
||||||
$html = MediaWikiServices::getInstance()->getMessageCache()->parse( $text, $title )->getText( [
|
$html = MediaWikiServices::getInstance()->getMessageCache()->parse( $text, $title )->getText( [
|
||||||
'enableSectionEditLinks' => false
|
'enableSectionEditLinks' => false
|
||||||
|
@ -1197,10 +1201,10 @@ abstract class EchoDiscussionParser {
|
||||||
* Parse an edit summary into truncated plain text.
|
* Parse an edit summary into truncated plain text.
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param Language $lang
|
* @param Language $lang
|
||||||
* @param int $length Length in characters (not bytes); default 150
|
* @param int $length Length in characters (not bytes); default DEFAULT_SNIPPET_LENGTH
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getTextSnippetFromSummary( $text, Language $lang, $length = 150 ) {
|
public static function getTextSnippetFromSummary( $text, Language $lang, $length = self::DEFAULT_SNIPPET_LENGTH ) {
|
||||||
// Parse wikitext with summary parser
|
// Parse wikitext with summary parser
|
||||||
$html = Linker::formatLinksInComment( Sanitizer::escapeHtmlAllowEntities( $text ) );
|
$html = Linker::formatLinksInComment( Sanitizer::escapeHtmlAllowEntities( $text ) );
|
||||||
$plaintext = trim( Sanitizer::stripAllTags( $html ) );
|
$plaintext = trim( Sanitizer::stripAllTags( $html ) );
|
||||||
|
@ -1212,10 +1216,12 @@ abstract class EchoDiscussionParser {
|
||||||
*
|
*
|
||||||
* @param RevisionRecord $revision
|
* @param RevisionRecord $revision
|
||||||
* @param Language $lang
|
* @param Language $lang
|
||||||
* @param int $length Length in characters (not bytes); default 150
|
* @param int $length Length in characters (not bytes); default DEFAULT_SNIPPET_LENGTH
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getEditExcerpt( RevisionRecord $revision, Language $lang, $length = 150 ) {
|
public static function getEditExcerpt(
|
||||||
|
RevisionRecord $revision, Language $lang, $length = self::DEFAULT_SNIPPET_LENGTH
|
||||||
|
) {
|
||||||
$interpretation = self::getChangeInterpretationForRevision( $revision );
|
$interpretation = self::getChangeInterpretationForRevision( $revision );
|
||||||
$section = self::detectSectionTitleAndText( $interpretation );
|
$section = self::detectSectionTitleAndText( $interpretation );
|
||||||
return $lang->truncateForVisual( $section['section-title'] . ' ' . $section['section-text'], $length );
|
return $lang->truncateForVisual( $section['section-title'] . ' ' . $section['section-text'], $length );
|
||||||
|
|
|
@ -79,7 +79,7 @@ class EchoMentionPresentationModel extends EchoEventPresentationModel {
|
||||||
EchoDiscussionParser::getTextSnippet(
|
EchoDiscussionParser::getTextSnippet(
|
||||||
$content,
|
$content,
|
||||||
$this->language,
|
$this->language,
|
||||||
150,
|
EchoDiscussionParser::DEFAULT_SNIPPET_LENGTH,
|
||||||
$this->event->getTitle()
|
$this->event->getTitle()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -82,7 +82,7 @@ class EchoPresentationModelSection {
|
||||||
$this->parsedSectionTitle = EchoDiscussionParser::getTextSnippet(
|
$this->parsedSectionTitle = EchoDiscussionParser::getTextSnippet(
|
||||||
$rawSectionTitle,
|
$rawSectionTitle,
|
||||||
$this->language,
|
$this->language,
|
||||||
150,
|
EchoDiscussionParser::DEFAULT_SNIPPET_LENGTH,
|
||||||
$this->event->getTitle()
|
$this->event->getTitle()
|
||||||
);
|
);
|
||||||
return $this->parsedSectionTitle;
|
return $this->parsedSectionTitle;
|
||||||
|
|
|
@ -1795,7 +1795,7 @@ TEXT
|
||||||
EchoDiscussionParser::getTextSnippet(
|
EchoDiscussionParser::getTextSnippet(
|
||||||
'[[:{{BASEPAGENAME}}]]',
|
'[[:{{BASEPAGENAME}}]]',
|
||||||
Language::factory( 'en' ),
|
Language::factory( 'en' ),
|
||||||
150,
|
EchoDiscussionParser::DEFAULT_SNIPPET_LENGTH,
|
||||||
Title::newFromText( 'Page001' )
|
Title::newFromText( 'Page001' )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue