SpecialUploadStash: Convert form to OOUI
[lhc/web/wiklou.git] / includes / search / SearchSqlite.php
index 62fb236..b40e1aa 100644 (file)
@@ -38,21 +38,23 @@ class SearchSqlite extends SearchDatabase {
         * Parse the user's query and transform it into an SQL fragment which will
         * become part of a WHERE clause
         *
+        * @param string $filteredText
+        * @param bool $fulltext
         * @return string
         */
        function parseQuery( $filteredText, $fulltext ) {
                global $wgContLang;
                $lc = $this->legalSearchChars(); // Minus format chars
                $searchon = '';
-               $this->searchTerms = array();
+               $this->searchTerms = [];
 
-               $m = array();
+               $m = [];
                if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
                                $filteredText, $m, PREG_SET_ORDER ) ) {
                        foreach ( $m as $bits ) {
-                               wfSuppressWarnings();
+                               MediaWiki\suppressWarnings();
                                list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
-                               wfRestoreWarnings();
+                               MediaWiki\restoreWarnings();
 
                                if ( $nonQuoted != '' ) {
                                        $term = $nonQuoted;
@@ -72,7 +74,7 @@ class SearchSqlite extends SearchDatabase {
                                if ( is_array( $convertedVariants ) ) {
                                        $variants = array_unique( array_values( $convertedVariants ) );
                                } else {
-                                       $variants = array( $term );
+                                       $variants = [ $term ];
                                }
 
                                // The low-level search index does some processing on input to work
@@ -80,7 +82,7 @@ class SearchSqlite extends SearchDatabase {
                                // fulltext engine.
                                // For Chinese this also inserts spaces between adjacent Han characters.
                                $strippedVariants = array_map(
-                                       array( $wgContLang, 'normalizeForSearch' ),
+                                       [ $wgContLang, 'normalizeForSearch' ],
                                        $variants );
 
                                // Some languages such as Chinese force all variants to a canonical
@@ -115,9 +117,9 @@ class SearchSqlite extends SearchDatabase {
                        wfDebug( __METHOD__ . ": Can't understand search query '{$filteredText}'\n" );
                }
 
-               $searchon = $this->db->strencode( $searchon );
+               $searchon = $this->db->addQuotes( $searchon );
                $field = $this->getIndexField( $fulltext );
-               return " $field MATCH '$searchon' ";
+               return " $field MATCH $searchon ";
        }
 
        function regexTerm( $string, $wildcard ) {
@@ -164,7 +166,7 @@ class SearchSqlite extends SearchDatabase {
        }
 
        protected function searchInternal( $term, $fulltext ) {
-               global $wgCountTotalSearchHits, $wgContLang;
+               global $wgContLang;
 
                if ( !$this->fulltextSearchSupported() ) {
                        return null;
@@ -174,14 +176,12 @@ class SearchSqlite extends SearchDatabase {
                $resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) );
 
                $total = null;
-               if ( $wgCountTotalSearchHits ) {
-                       $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) );
-                       $row = $totalResult->fetchObject();
-                       if ( $row ) {
-                               $total = intval( $row->c );
-                       }
-                       $totalResult->free();
+               $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) );
+               $row = $totalResult->fetchObject();
+               if ( $row ) {
+                       $total = intval( $row->c );
                }
+               $totalResult->free();
 
                return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total );
        }
@@ -276,14 +276,14 @@ class SearchSqlite extends SearchDatabase {
                // couldn't do it so far due to typelessness of FTS3 tables.
                $dbw = wfGetDB( DB_MASTER );
 
-               $dbw->delete( 'searchindex', array( 'rowid' => $id ), __METHOD__ );
+               $dbw->delete( 'searchindex', [ 'rowid' => $id ], __METHOD__ );
 
                $dbw->insert( 'searchindex',
-                       array(
+                       [
                                'rowid' => $id,
                                'si_title' => $title,
                                'si_text' => $text
-                       ), __METHOD__ );
+                       ], __METHOD__ );
        }
 
        /**
@@ -300,8 +300,8 @@ class SearchSqlite extends SearchDatabase {
                $dbw = wfGetDB( DB_MASTER );
 
                $dbw->update( 'searchindex',
-                       array( 'si_title' => $title ),
-                       array( 'rowid' => $id ),
+                       [ 'si_title' => $title ],
+                       [ 'rowid' => $id ],
                        __METHOD__ );
        }
 }