Fix whitespace, documentation
[lhc/web/wiklou.git] / includes / search / SearchEngine.php
index ba203ca..1293353 100644 (file)
@@ -22,6 +22,9 @@ class SearchEngine {
        var $namespaces = array( NS_MAIN );
        var $showRedirects = false;
 
+       /// Feature values
+       protected $features = array();
+
        /**
         * @var DatabaseBase
         */
@@ -59,9 +62,38 @@ class SearchEngine {
                return null;
        }
 
-       /** If this search backend can list/unlist redirects */
+       /**
+        * If this search backend can list/unlist redirects
+        * @deprecated since 1.19 Call supports( 'list-redirects' );
+        */
        function acceptListRedirects() {
-               return true;
+               return $this->supports( 'list-redirects' );
+       }
+
+       /**
+        * @since 1.18
+        * @param $feature String
+        * @return Boolean
+        */
+       public function supports( $feature ) {
+               switch( $feature ) {
+               case 'list-redirects':
+                       return true;
+               case 'title-suffix-filter':
+               default:
+                       return false;
+               }
+       }
+
+       /**
+        * Way to pass custom data for engines
+        * @since 1.18
+        * @param $feature String
+        * @param $data Mixed
+        * @return Noolean
+        */
+       public function setFeatureData( $feature, $data ) {
+               $this->features[$feature] = $data;
        }
 
        /**
@@ -100,11 +132,11 @@ class SearchEngine {
                wfRunHooks( 'SearchGetNearMatchComplete', array( $searchterm, &$title ) );
                return $title;
        }
-       
+
        /**
-        * Do a near match (see SearchEngine::getNearMatch) and wrap it into a 
+        * Do a near match (see SearchEngine::getNearMatch) and wrap it into a
         * SearchResultSet.
-        * 
+        *
         * @param $searchterm string
         * @return SearchResultSet
         */
@@ -145,7 +177,7 @@ class SearchEngine {
 
                        # See if it still otherwise has content is some sane sense
                        $context->setTitle( $title );
-                       $article = MediaWiki::articleFromTitle( $title, $context );
+                       $article = Article::newFromTitle( $title, $context );
                        if ( $article->hasViewableContent() ) {
                                return $title;
                        }
@@ -268,7 +300,7 @@ class SearchEngine {
                if ( strncmp( $query, $allkeyword, strlen( $allkeyword ) ) == 0 ) {
                        $this->namespaces = null;
                        $parsed = substr( $query, strlen( $allkeyword ) );
-               } else if ( strpos( $query, ':' ) !== false ) {
+               } elseif ( strpos( $query, ':' ) !== false ) {
                        $prefix = substr( $query, 0, strpos( $query, ':' ) );
                        $index = $wgContLang->getNsIndex( $prefix );
                        if ( $index !== false ) {
@@ -330,14 +362,11 @@ class SearchEngine {
        }
 
        /**
-        * Find snippet highlight settings for a given user
+        * Find snippet highlight settings for all users
         *
-        * @param $user User
         * @return Array contextlines, contextchars
         */
-       public static function userHighlightPrefs( &$user ) {
-               // $contextlines = $user->getOption( 'contextlines',  5 );
-               // $contextchars = $user->getOption( 'contextchars', 50 );
+       public static function userHighlightPrefs() {
                $contextlines = 2; // Hardcode this. Old defaults sucked. :)
                $contextchars = 75; // same as above.... :P
                return array( $contextlines, $contextchars );
@@ -444,11 +473,13 @@ class SearchEngine {
         */
        public static function getOpenSearchTemplate() {
                global $wgOpenSearchTemplate, $wgServer;
-               if ( $wgOpenSearchTemplate )    {
+               if ( $wgOpenSearchTemplate ) {
                        return $wgOpenSearchTemplate;
                } else {
                        $ns = implode( '|', SearchEngine::defaultNamespaces() );
-                       if ( !$ns ) $ns = "0";
+                       if ( !$ns ) {
+                               $ns = "0";
+                       }
                        return $wgServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
                }
        }
@@ -584,6 +615,9 @@ class SearchResultSet {
  * This class is used for different SQL-based search engines shipped with MediaWiki
  */
 class SqlSearchResultSet extends SearchResultSet {
+
+       protected $mResultSet;
+
        function __construct( $resultSet, $terms ) {
                $this->mResultSet = $resultSet;
                $this->mTerms = $terms;
@@ -607,7 +641,7 @@ class SqlSearchResultSet extends SearchResultSet {
                $row = $this->mResultSet->fetchObject();
                if ( $row === false )
                        return false;
-                       
+
                return SearchResult::newFromRow( $row );
        }
 
@@ -628,7 +662,7 @@ class SearchResultTooMany {
 
 
 /**
- * @todo Fixme: This class is horribly factored. It would probably be better to
+ * @todo FIXME: This class is horribly factored. It would probably be better to
  * have a useful base class to which you pass some standard information, then
  * let the fancy self-highlighters extend that.
  * @ingroup Search
@@ -653,8 +687,8 @@ class SearchResult {
 
        /**
         * Return a new SearchResult and initializes it with a title.
-        * 
-        * @param $title Title 
+        *
+        * @param $title Title
         * @return SearchResult
         */
        public static function newFromTitle( $title ) {
@@ -664,7 +698,7 @@ class SearchResult {
        }
        /**
         * Return a new SearchResult and initializes it with a row.
-        * 
+        *
         * @param $row object
         * @return SearchResult
         */
@@ -673,28 +707,28 @@ class SearchResult {
                $result->initFromRow( $row );
                return $result;
        }
-       
+
        public function __construct( $row = null ) {
                if ( !is_null( $row ) ) {
                        // Backwards compatibility with pre-1.17 callers
                        $this->initFromRow( $row );
                }
        }
-       
+
        /**
         * Initialize from a database row. Makes a Title and passes that to
         * initFromTitle.
-        * 
+        *
         * @param $row object
         */
        protected function initFromRow( $row ) {
                $this->initFromTitle( Title::makeTitle( $row->page_namespace, $row->page_title ) );
        }
-       
+
        /**
         * Initialize from a Title and if possible initializes a corresponding
         * Revision and File.
-        * 
+        *
         * @param $title Title
         */
        protected function initFromTitle( $title ) {
@@ -811,7 +845,7 @@ class SearchResult {
        function getTimestamp() {
                if ( $this->mRevision )
                        return $this->mRevision->getTimestamp();
-               else if ( $this->mImage )
+               elseif ( $this->mImage )
                        return $this->mImage->getTimestamp();
                return '';
        }
@@ -909,7 +943,7 @@ class SearchHighlighter {
                        2 => '/(\[\[)|(\]\])/', // image
                        3 => "/(\n\\{\\|)|(\n\\|\\})/" ); // table
 
-               // FIXME: this should prolly be a hook or something
+               // @todo FIXME: This should prolly be a hook or something
                if ( function_exists( 'wfCite' ) ) {
                        $spat .= '|(<ref>)'; // references via cite extension
                        $endPatterns[4] = '/(<ref>)|(<\/ref>)/';
@@ -995,7 +1029,7 @@ class SearchHighlighter {
                $anyterm = implode( '|', $terms );
                $phrase = implode( "$wgSearchHighlightBoundaries+", $terms );
 
-               // FIXME: a hack to scale contextchars, a correct solution
+               // @todo FIXME: A hack to scale contextchars, a correct solution
                // would be to have contextchars actually be char and not byte
                // length, and do proper utf-8 substrings and lengths everywhere,
                // but PHP is making that very hard and unclean to implement :(
@@ -1368,7 +1402,7 @@ class SearchHighlighter {
 
 /**
  * Dummy class to be used when non-supported Database engine is present.
- * @todo Fixme: dummy class should probably try something at least mildly useful,
+ * @todo FIXME: Dummy class should probably try something at least mildly useful,
  * such as a LIKE search through titles.
  * @ingroup Search
  */