fixing long lines
[lhc/web/wiklou.git] / includes / search / SearchEngine.php
index b09373f..59dd7ab 100644 (file)
@@ -2,6 +2,21 @@
 /**
  * Basic search engine
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Search
  */
@@ -65,8 +80,10 @@ class SearchEngine {
        /**
         * If this search backend can list/unlist redirects
         * @deprecated since 1.18 Call supports( 'list-redirects' );
+        * @return bool
         */
        function acceptListRedirects() {
+               wfDeprecated( __METHOD__, '1.18' );
                return $this->supports( 'list-redirects' );
        }
 
@@ -90,7 +107,7 @@ class SearchEngine {
         * @since 1.18
         * @param $feature String
         * @param $data Mixed
-        * @return Noolean
+        * @return bool
         */
        public function setFeatureData( $feature, $data ) {
                $this->features[$feature] = $data;
@@ -146,6 +163,7 @@ class SearchEngine {
 
        /**
         * Really find the title match.
+        * @return null|\Title
         */
        private static function getNearMatchInternal( $searchterm ) {
                global $wgContLang, $wgEnableSearchContributorsByIP;
@@ -286,6 +304,7 @@ class SearchEngine {
         * or namespace names
         *
         * @param $query String
+        * @return string
         */
        function replacePrefixes( $query ) {
                global $wgContLang;
@@ -296,7 +315,7 @@ class SearchEngine {
                        return $parsed;
                }
 
-               $allkeyword = wfMsgForContent( 'searchall' ) . ":";
+               $allkeyword = wfMessage( 'searchall' )->inContentLanguage()->text() . ":";
                if ( strncmp( $query, $allkeyword, strlen( $allkeyword ) ) == 0 ) {
                        $this->namespaces = null;
                        $parsed = substr( $query, strlen( $allkeyword ) );
@@ -343,20 +362,22 @@ class SearchEngine {
        public static function userNamespaces( $user ) {
                global $wgSearchEverythingOnlyLoggedIn;
 
-               // get search everything preference, that can be set to be read for logged-in users
-               $searcheverything = false;
-               if ( ( $wgSearchEverythingOnlyLoggedIn && $user->isLoggedIn() )
-                       || !$wgSearchEverythingOnlyLoggedIn )
-                       $searcheverything = $user->getOption( 'searcheverything' );
-
-               // searcheverything overrides other options
-               if ( $searcheverything )
-                       return array_keys( SearchEngine::searchableNamespaces() );
-
-               $arr = Preferences::loadOldSearchNs( $user );
                $searchableNamespaces = SearchEngine::searchableNamespaces();
 
-               $arr = array_intersect( $arr, array_keys( $searchableNamespaces ) ); // Filter
+               // get search everything preference, that can be set to be read for logged-in users
+               // it overrides other options
+               if ( !$wgSearchEverythingOnlyLoggedIn || $user->isLoggedIn() ) {
+                       if ( $user->getOption( 'searcheverything' ) ) {
+                               return array_keys( $searchableNamespaces );
+                       }
+               }
+
+               $arr = array();
+               foreach ( $searchableNamespaces as $ns => $name ) {
+                       if ( $user->getOption( 'searchNs' . $ns ) ) {
+                               $arr[] = $ns;
+                       }
+               }
 
                return $arr;
        }
@@ -388,6 +409,7 @@ class SearchEngine {
         * and preferences
         *
         * @param $namespaces Array
+        * @return array
         */
        public static function namespacesAsText( $namespaces ) {
                global $wgContLang;
@@ -395,7 +417,7 @@ class SearchEngine {
                $formatted = array_map( array( $wgContLang, 'getFormattedNsText' ), $namespaces );
                foreach ( $formatted as $key => $ns ) {
                        if ( empty( $ns ) )
-                               $formatted[$key] = wfMsg( 'blanknamespace' );
+                               $formatted[$key] = wfMessage( 'blanknamespace' )->text();
                }
                return $formatted;
        }
@@ -734,7 +756,8 @@ class SearchResult {
        protected function initFromTitle( $title ) {
                $this->mTitle = $title;
                if ( !is_null( $this->mTitle ) ) {
-                       $this->mRevision = Revision::newFromTitle( $this->mTitle );
+                       $this->mRevision = Revision::newFromTitle(
+                               $this->mTitle, false, Revision::READ_NORMAL );
                        if ( $this->mTitle->getNamespace() === NS_FILE )
                                $this->mImage = wfFindFile( $this->mTitle );
                }
@@ -768,7 +791,7 @@ class SearchResult {
        }
 
        /**
-        * @return Double or null if not supported
+        * @return float|null if not supported
         */
        function getScore() {
                return null;
@@ -779,11 +802,13 @@ class SearchResult {
         */
        protected function initText() {
                if ( !isset( $this->mText ) ) {
-                       if ( $this->mRevision != null )
-                               $this->mText = $this->mRevision->getText();
-                       else // TODO: can we fetch raw wikitext for commons images?
+                       if ( $this->mRevision != null ) {
+                               //TODO: don't use the text, but the content object!
+                               $content = $this->mRevision->getContent();
+                               $this->mText = $content->getTextForSearchIndex();
+                       } else { // TODO: can we fetch raw wikitext for commons images?
                                $this->mText = '';
-
+                       }
                }
        }
 
@@ -794,6 +819,8 @@ class SearchResult {
        function getTextSnippet( $terms ) {
                global $wgUser, $wgAdvancedSearchHighlighting;
                $this->initText();
+
+               // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter.
                list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs( $wgUser );
                $h = new SearchHighlighter();
                if ( $wgAdvancedSearchHighlighting )
@@ -1182,6 +1209,7 @@ class SearchHighlighter {
         * Do manual case conversion for non-ascii chars
         *
         * @param $matches Array
+        * @return string
         */
        function caseCallback( $matches ) {
                global $wgContLang;
@@ -1302,6 +1330,7 @@ class SearchHighlighter {
        /**
         * Basic wikitext removal
         * @protected
+        * @return mixed
         */
        function removeWiki( $text ) {
                $fname = __METHOD__;