Disable $wgServer autodetection to prevent cache poisoning attacks
[lhc/web/wiklou.git] / includes / search / SearchSqlite.php
index 3646b27..84e6edd 100644 (file)
@@ -22,7 +22,6 @@
  */
 
 use MediaWiki\MediaWikiServices;
-use Wikimedia\Rdbms\DatabaseSqlite;
 
 /**
  * Search engine hook for SQLite
@@ -33,11 +32,16 @@ class SearchSqlite extends SearchDatabase {
         * Whether fulltext search is supported by current schema
         * @return bool
         */
-       function fulltextSearchSupported() {
-               /** @var DatabaseSqlite $dbr */
-               $dbr = $this->lb->getConnection( DB_REPLICA );
+       private function fulltextSearchSupported() {
+               $dbr = $this->lb->getMaintenanceConnectionRef( DB_REPLICA );
+               $sql = (string)$dbr->selectField(
+                       $dbr->addIdentifierQuotes( 'sqlite_master' ),
+                       'sql',
+                       [ 'tbl_name' => $dbr->tableName( 'searchindex', 'raw' ) ],
+                       __METHOD__
+               );
 
-               return $dbr->checkForEnabledSearch();
+               return ( stristr( $sql, 'fts' ) !== false );
        }
 
        /**
@@ -161,7 +165,7 @@ class SearchSqlite extends SearchDatabase {
         * Perform a full text search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return SqlSearchResultSet
+        * @return SqlSearchResultSet|null
         */
        protected function doSearchTextInDB( $term ) {
                return $this->searchInternal( $term, true );
@@ -171,7 +175,7 @@ class SearchSqlite extends SearchDatabase {
         * Perform a title-only search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return SqlSearchResultSet
+        * @return SqlSearchResultSet|null
         */
        protected function doSearchTitleInDB( $term ) {
                return $this->searchInternal( $term, false );
@@ -285,7 +289,7 @@ class SearchSqlite extends SearchDatabase {
         * @param string $title
         * @param string $text
         */
-       function update( $id, $title, $text ) {
+       public function update( $id, $title, $text ) {
                if ( !$this->fulltextSearchSupported() ) {
                        return;
                }
@@ -308,7 +312,7 @@ class SearchSqlite extends SearchDatabase {
         * @param int $id
         * @param string $title
         */
-       function updateTitle( $id, $title ) {
+       public function updateTitle( $id, $title ) {
                if ( !$this->fulltextSearchSupported() ) {
                        return;
                }