X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fsearch%2FSearchHighlighter.php;h=8f0db447a15e62a39f04dc732616ebc343dd3a18;hb=7ff1a16397aad6b14a957d964e583c8a86a57f72;hp=6c01f799d5c8283f32df0204c04ed640ca171999;hpb=c99b4bd4e646c3911a4d8b26dc77fa5c89ee7f91;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchHighlighter.php b/includes/search/SearchHighlighter.php index 6c01f799d5..8f0db447a1 100644 --- a/includes/search/SearchHighlighter.php +++ b/includes/search/SearchHighlighter.php @@ -29,6 +29,9 @@ use MediaWiki\MediaWikiServices; * @ingroup Search */ class SearchHighlighter { + const DEFAULT_CONTEXT_LINES = 2; + const DEFAULT_CONTEXT_CHARS = 75; + protected $mCleanWikitext = true; /** @@ -50,7 +53,12 @@ class SearchHighlighter { * @param int $contextchars * @return string */ - public function highlightText( $text, $terms, $contextlines, $contextchars ) { + public function highlightText( + $text, + $terms, + $contextlines = self::DEFAULT_CONTEXT_LINES, + $contextchars = self::DEFAULT_CONTEXT_CHARS + ) { global $wgSearchHighlightBoundaries; if ( $text == '' ) { @@ -66,8 +74,8 @@ class SearchHighlighter { 3 => "/(\n\\{\\|)|(\n\\|\\})/" ]; // table // @todo FIXME: This should prolly be a hook or something - // instead of hardcoding a class name from the Cite extension - if ( class_exists( 'Cite' ) ) { + // instead of hardcoding the name of the Cite extension + if ( \ExtensionRegistry::getInstance()->isLoaded( 'Cite' ) ) { $spat .= '|()'; // references via cite extension $endPatterns[4] = '/()|(<\/ref>)/'; } @@ -507,7 +515,12 @@ class SearchHighlighter { * @param int $contextchars * @return string */ - public function highlightSimple( $text, $terms, $contextlines, $contextchars ) { + public function highlightSimple( + $text, + $terms, + $contextlines = self::DEFAULT_CONTEXT_LINES, + $contextchars = self::DEFAULT_CONTEXT_CHARS + ) { $lines = explode( "\n", $text ); $terms = implode( '|', $terms ); @@ -557,7 +570,11 @@ class SearchHighlighter { * @param int $contextchars Average number of characters per line * @return string */ - public function highlightNone( $text, $contextlines, $contextchars ) { + public function highlightNone( + $text, + $contextlines = self::DEFAULT_CONTEXT_LINES, + $contextchars = self::DEFAULT_CONTEXT_CHARS + ) { $match = []; $text = ltrim( $text ) . "\n"; // make sure the preg_match may find the last line $text = str_replace( "\n\n", "\n", $text ); // remove empty lines