X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fsearch%2FSearchEngine.php;h=56bb0ac9ae789b413919b0864368147ee00f987d;hb=69ae6a4c96b37dbdf962be124f34ce20e2810b9c;hp=827d8c31d7ccf30983cf3f630b4c25736ed398b8;hpb=c0cdf0e91186728c8e283bbcc977d6831f4b93d1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 827d8c31d7..56bb0ac9ae 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -30,11 +30,22 @@ * @ingroup Search */ class SearchEngine { - var $limit = 10; - var $offset = 0; - var $prefix = ''; - var $searchTerms = array(); - var $namespaces = array( NS_MAIN ); + /** @var string */ + public $prefix = ''; + + /** @var int[] */ + public $namespaces = array( NS_MAIN ); + + /** @var int */ + protected $limit = 10; + + /** @var int */ + protected $offset = 0; + + /** @var array|string */ + protected $searchTerms = array(); + + /** @var bool */ protected $showSuggestion = true; /** @var array Feature values */ @@ -106,8 +117,9 @@ class SearchEngine { } /** - * Transform search term in cases when parts of the query came as different GET params (when supported) - * e.g. for prefix queries: search=test&prefix=Main_Page/Archive -> test prefix:Main Page/Archive + * Transform search term in cases when parts of the query came as different + * GET params (when supported), e.g. for prefix queries: + * search=test&prefix=Main_Page/Archive -> test prefix:Main Page/Archive */ function transformSearchTerm( $term ) { return $term; @@ -148,7 +160,10 @@ class SearchEngine { $allSearchTerms = array( $searchterm ); if ( $wgContLang->hasVariants() ) { - $allSearchTerms = array_merge( $allSearchTerms, $wgContLang->autoConvertToAllVariants( $searchterm ) ); + $allSearchTerms = array_merge( + $allSearchTerms, + $wgContLang->autoConvertToAllVariants( $searchterm ) + ); } $titleResult = null; @@ -303,7 +318,6 @@ class SearchEngine { $parsed = $query; if ( strpos( $query, ':' ) === false ) { // nothing to do - wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) ); return $parsed; } @@ -323,8 +337,6 @@ class SearchEngine { $parsed = $query; // prefix was the whole query } - wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) ); - return $parsed; } @@ -353,20 +365,8 @@ class SearchEngine { * @return array */ public static function userNamespaces( $user ) { - global $wgSearchEverythingOnlyLoggedIn; - - $searchableNamespaces = SearchEngine::searchableNamespaces(); - - // 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 ) { + foreach ( SearchEngine::searchableNamespaces() as $ns => $name ) { if ( $user->getOption( 'searchNs' . $ns ) ) { $arr[] = $ns; } @@ -416,28 +416,6 @@ class SearchEngine { return $formatted; } - /** - * Return the help namespaces to be shown on Special:Search - * - * @return array - */ - public static function helpNamespaces() { - global $wgNamespacesToBeSearchedHelp; - - return array_keys( $wgNamespacesToBeSearchedHelp, true ); - } - - /** - * Return a 'cleaned up' search string - * - * @param string $text - * @return string - */ - function filter( $text ) { - $lc = $this->legalSearchChars(); - return trim( preg_replace( "/[^{$lc}]/", " ", $text ) ); - } - /** * Load up the appropriate search engine class for the currently * active database backend, and return a configured instance. @@ -523,6 +501,7 @@ class SearchEngine { */ public static function getOpenSearchTemplate() { global $wgOpenSearchTemplate, $wgCanonicalServer; + if ( $wgOpenSearchTemplate ) { return $wgOpenSearchTemplate; } else { @@ -530,7 +509,9 @@ class SearchEngine { if ( !$ns ) { $ns = "0"; } - return $wgCanonicalServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns; + + return $wgCanonicalServer . wfScript( 'api' ) + . '?action=opensearch&search={searchTerms}&namespace=' . $ns; } } @@ -560,13 +541,6 @@ class SearchEngine { } } -/** - * @ingroup Search - */ -class SearchResultTooMany { - # # Some search engines may bail out if too many matches are found -} - /** * Dummy class to be used when non-supported Database engine is present. * @todo FIXME: Dummy class should probably try something at least mildly useful,