[JobQueue] Made the maximum number of job attempts configurable.
[lhc/web/wiklou.git] / includes / search / SearchEngine.php
index ec542a6..5e5755c 100644 (file)
@@ -45,7 +45,7 @@ class SearchEngine {
         */
        protected $db;
 
-       function __construct($db = null) {
+       function __construct( $db = null ) {
                if ( $db ) {
                        $this->db = $db;
                } else {
@@ -183,10 +183,15 @@ class SearchEngine {
 
                        # Exact match? No need to look further.
                        $title = Title::newFromText( $term );
-                       if ( is_null( $title ) ){
+                       if ( is_null( $title ) ) {
                                return null;
                        }
 
+                       # Try files if searching in the Media: namespace
+                       if ( $title->getNamespace() == NS_MEDIA ) {
+                               $title = Title::makeTitle( NS_FILE, $title->getText() );
+                       }
+
                        if ( $title->isSpecialPage() || $title->isExternal() || $title->exists() ) {
                                return $title;
                        }
@@ -197,22 +202,23 @@ class SearchEngine {
                                return $title;
                        }
 
+                       if ( !wfRunHooks( 'SearchAfterNoDirectMatch', array( $term, &$title ) ) ) {
+                               return $title;
+                       }
+
                        # Now try all lower case (i.e. first letter capitalized)
-                       #
                        $title = Title::newFromText( $wgContLang->lc( $term ) );
                        if ( $title && $title->exists() ) {
                                return $title;
                        }
 
                        # Now try capitalized string
-                       #
                        $title = Title::newFromText( $wgContLang->ucwords( $term ) );
                        if ( $title && $title->exists() ) {
                                return $title;
                        }
 
                        # Now try all upper case
-                       #
                        $title = Title::newFromText( $wgContLang->uc( $term ) );
                        if ( $title && $title->exists() ) {
                                return $title;
@@ -1136,8 +1142,8 @@ class SearchHighlighter {
                                // add more lines
                                $add = $index + 1;
                                while ( $len < $targetchars - 20
-                                          && array_key_exists( $add, $all )
-                                          && !array_key_exists( $add, $snippets ) ) {
+                                               && array_key_exists( $add, $all )
+                                               && !array_key_exists( $add, $snippets ) ) {
                                        $offsets[$add] = 0;
                                        $tt = "\n" . $this->extract( $all[$add], 0, $targetchars - $len, $offsets[$add] );
                                        $extended[$add] = $tt;
@@ -1147,7 +1153,7 @@ class SearchHighlighter {
                        }
                }
 
-               // $snippets = array_map('htmlspecialchars', $extended);
+               // $snippets = array_map( 'htmlspecialchars', $extended );
                $snippets = $extended;
                $last = - 1;
                $extract = '';
@@ -1237,7 +1243,7 @@ class SearchHighlighter {
                        $posEnd = $end;
                }
 
-               if ( $end > $start )  {
+               if ( $end > $start ) {
                        return substr( $text, $start, $end - $start );
                } else {
                        return '';
@@ -1326,12 +1332,12 @@ class SearchHighlighter {
                $fname = __METHOD__;
                wfProfileIn( $fname );
 
-               // $text = preg_replace("/'{2,5}/", "", $text);
-               // $text = preg_replace("/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text);
-               // $text = preg_replace("/\[\[([^]|]+)\]\]/", "\\1", $text);
-               // $text = preg_replace("/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text);
-               // $text = preg_replace("/\\{\\|(.*?)\\|\\}/", "", $text);
-               // $text = preg_replace("/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text);
+               // $text = preg_replace( "/'{2,5}/", "", $text );
+               // $text = preg_replace( "/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text );
+               // $text = preg_replace( "/\[\[([^]|]+)\]\]/", "\\1", $text );
+               // $text = preg_replace( "/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text );
+               // $text = preg_replace( "/\\{\\|(.*?)\\|\\}/", "", $text );
+               // $text = preg_replace( "/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text );
                $text = preg_replace( "/\\{\\{([^|]+?)\\}\\}/", "", $text );
                $text = preg_replace( "/\\{\\{([^|]+\\|)(.*?)\\}\\}/", "\\2", $text );
                $text = preg_replace( "/\\[\\[([^|]+?)\\]\\]/", "\\1", $text );
@@ -1413,8 +1419,7 @@ class SearchHighlighter {
 
                        $line = htmlspecialchars( $pre . $found . $post );
                        $pat2 = '/(' . $terms . ")/i";
-                       $line = preg_replace( $pat2,
-                         "<span class='searchmatch'>\\1</span>", $line );
+                       $line = preg_replace( $pat2, "<span class='searchmatch'>\\1</span>", $line );
 
                        $extract .= "${line}\n";
                }