search: make legalSearchChars() non-static
[lhc/web/wiklou.git] / includes / search / SearchHighlighter.php
index 2cec241..469502f 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup Search
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Highlight bits of wikitext
  *
@@ -49,7 +51,7 @@ class SearchHighlighter {
         * @return string
         */
        public function highlightText( $text, $terms, $contextlines, $contextchars ) {
-               global $wgContLang, $wgSearchHighlightBoundaries;
+               global $wgSearchHighlightBoundaries;
 
                if ( $text == '' ) {
                        return '';
@@ -84,7 +86,10 @@ class SearchHighlighter {
                                                if ( $key == 2 ) {
                                                        // see if this is an image link
                                                        $ns = substr( $val[0], 2, -1 );
-                                                       if ( $wgContLang->getNsIndex( $ns ) != NS_FILE ) {
+                                                       if (
+                                                               MediaWikiServices::getInstance()->getContentLanguage()->
+                                                               getNsIndex( $ns ) != NS_FILE
+                                                       ) {
                                                                break;
                                                        }
 
@@ -313,9 +318,10 @@ class SearchHighlighter {
         * @return string
         */
        function caseCallback( $matches ) {
-               global $wgContLang;
                if ( strlen( $matches[0] ) > 1 ) {
-                       return '[' . $wgContLang->lc( $matches[0] ) . $wgContLang->uc( $matches[0] ) . ']';
+                       $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+                       return '[' . $contLang->lc( $matches[0] ) .
+                               $contLang->uc( $matches[0] ) . ']';
                } else {
                        return $matches[0];
                }
@@ -480,9 +486,8 @@ class SearchHighlighter {
                if ( $colon === false ) {
                        return $matches[2]; // replace with caption
                }
-               global $wgContLang;
                $ns = substr( $matches[1], 0, $colon );
-               $index = $wgContLang->getNsIndex( $ns );
+               $index = MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $ns );
                if ( $index !== false && ( $index == NS_FILE || $index == NS_CATEGORY ) ) {
                        return $matches[0]; // return the whole thing
                } else {
@@ -503,8 +508,6 @@ class SearchHighlighter {
         * @return string
         */
        public function highlightSimple( $text, $terms, $contextlines, $contextchars ) {
-               global $wgContLang;
-
                $lines = explode( "\n", $text );
 
                $terms = implode( '|', $terms );
@@ -514,8 +517,9 @@ class SearchHighlighter {
                $lineno = 0;
 
                $extract = "";
+               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
                foreach ( $lines as $line ) {
-                       if ( 0 == $contextlines ) {
+                       if ( $contextlines == 0 ) {
                                break;
                        }
                        ++$lineno;
@@ -525,12 +529,12 @@ class SearchHighlighter {
                        }
                        --$contextlines;
                        // truncate function changes ... to relevant i18n message.
-                       $pre = $wgContLang->truncateForVisual( $m[1], - $contextchars, '...', false );
+                       $pre = $contLang->truncateForVisual( $m[1], - $contextchars, '...', false );
 
                        if ( count( $m ) < 3 ) {
                                $post = '';
                        } else {
-                               $post = $wgContLang->truncateForVisual( $m[3], $contextchars, '...', false );
+                               $post = $contLang->truncateForVisual( $m[3], $contextchars, '...', false );
                        }
 
                        $found = $m[2];