X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fsearch%2FSearchHighlighter.php;h=d0e3a240d6dfd19f8adce6d646056ea9fc7ecbe0;hb=d114089171aff655b11c762d55baa39b3c354dce;hp=2bd19558a229fd98170268fb89f00aad90335ca4;hpb=2a1fcd27c19913394c179cbe8be1a9e981d7f81b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchHighlighter.php b/includes/search/SearchHighlighter.php index 2bd19558a2..d0e3a240d6 100644 --- a/includes/search/SearchHighlighter.php +++ b/includes/search/SearchHighlighter.php @@ -34,10 +34,11 @@ class SearchHighlighter { } /** - * Default implementation of wikitext highlighting + * Wikitext highlighting when $wgAdvancedSearchHighlighting = true * * @param string $text - * @param array $terms Terms to highlight (unescaped) + * @param array $terms Terms to highlight (not html escaped but + * regex escaped via SearchDatabase::regexTerm()) * @param int $contextlines * @param int $contextchars * @return string @@ -74,10 +75,10 @@ class SearchHighlighter { if ( preg_match( $spat, $text, $matches, PREG_OFFSET_CAPTURE, $start ) ) { $epat = ''; foreach ( $matches as $key => $val ) { - if ( $key > 0 && $val[1] != - 1 ) { + if ( $key > 0 && $val[1] != -1 ) { if ( $key == 2 ) { // see if this is an image link - $ns = substr( $val[0], 2, - 1 ); + $ns = substr( $val[0], 2, -1 ); if ( $wgContLang->getNsIndex( $ns ) != NS_FILE ) { break; } @@ -145,7 +146,6 @@ class SearchHighlighter { } $anyterm = implode( '|', $terms ); $phrase = implode( "$wgSearchHighlightBoundaries+", $terms ); - // @todo FIXME: A hack to scale contextchars, a correct solution // would be to have contextchars actually be char and not byte // length, and do proper utf-8 substrings and lengths everywhere, @@ -252,10 +252,10 @@ class SearchHighlighter { // $snippets = array_map( 'htmlspecialchars', $extended ); $snippets = $extended; - $last = - 1; + $last = -1; $extract = ''; foreach ( $snippets as $index => $line ) { - if ( $last == - 1 ) { + if ( $last == -1 ) { $extract .= $line; // first line } elseif ( $last + 1 == $index && $offsets[$last] + strlen( $snippets[$last] ) >= strlen( $all[$last] ) @@ -485,8 +485,10 @@ class SearchHighlighter { * Simple & fast snippet extraction, but gives completely unrelevant * snippets * + * Used when $wgAdvancedSearchHighlighting is false. + * * @param string $text - * @param array $terms + * @param array $terms Escaped for regex by SearchDatabase::regexTerm() * @param int $contextlines * @param int $contextchars * @return string