* @ingroup Search
*/
class SearchHighlighter {
+ const DEFAULT_CONTEXT_LINES = 2;
+ const DEFAULT_CONTEXT_CHARS = 75;
+
protected $mCleanWikitext = true;
/**
* @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 == '' ) {
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 .= '|(<ref>)'; // references via cite extension
$endPatterns[4] = '/(<ref>)|(<\/ref>)/';
}
* @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 );
* @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