* The following public properties on DatabaseBlock are deprecated: $mAuto,
$mParentBlockId. To check for an autoblock use DatabaseBlock::getType; to
check for the parent ID, use DatabaseBlock::getParentBlockId.
+* SearchEngine::userHighlightPrefs() is deprecated, simply stop passing
+ $contextlines and $contextchars to the SearchHighlighter methods, they will
+ use proper defaults defined in SearchHighlighter::DEFAULT_CONTEXT_LINES and
+ DEFAULT_CONTEXT_CHARS.
=== Other changes in 1.34 ===
* …
/**
* Find snippet highlight settings for all users
* @return array Contextlines, contextchars
+ * @deprecated in 1.34 use the SearchHighlighter constants directly
+ * @see SearchHighlighter::DEFAULT_CONTEXT_CHARS
+ * @see SearchHighlighter::DEFAULT_CONTEXT_LINES
*/
public static function userHighlightPrefs() {
- $contextlines = 2; // Hardcode this. Old defaults sucked. :)
- $contextchars = 75; // same as above.... :P
+ $contextlines = SearchHighlighter::DEFAULT_CONTEXT_LINES;
+ $contextchars = SearchHighlighter::DEFAULT_CONTEXT_CHARS;
return [ $contextlines, $contextchars ];
}
* @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 == '' ) {
* @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
global $wgAdvancedSearchHighlighting;
$this->initText();
- // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter.
- list( $contextlines, $contextchars ) = $this->searchEngine->userHighlightPrefs();
-
$h = new SearchHighlighter();
if ( count( $this->terms ) > 0 ) {
if ( $wgAdvancedSearchHighlighting ) {
- return $h->highlightText( $this->mText, $this->terms, $contextlines, $contextchars );
+ return $h->highlightText( $this->mText, $this->terms );
} else {
- return $h->highlightSimple( $this->mText, $this->terms, $contextlines, $contextchars );
+ return $h->highlightSimple( $this->mText, $this->terms );
}
} else {
- return $h->highlightNone( $this->mText, $contextlines, $contextchars );
+ return $h->highlightNone( $this->mText );
}
}