X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fsearch%2FSearchEngine.php;h=4ef728a2e935de50b0efd063fe4d2ba49589a2c3;hb=ce597275536c68b1f1f64332a39dcb6d1550c0e6;hp=a62104f68a7901380727acfb1a2c36487abbfc6e;hpb=04f68827d0e3e53ba2924ff7e9f67f6a7e485656;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index a62104f68a..4ef728a2e9 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -1,11 +1,15 @@ db = $db; + } else { + $this->db = wfGetDB( DB_SLAVE ); + } + } + /** * Perform a full text search query and return a result set. * If title searches are not supported or disabled, return null. @@ -42,9 +62,38 @@ class SearchEngine { return null; } - /** If this search backend can list/unlist redirects */ + /** + * If this search backend can list/unlist redirects + * @deprecated 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; } /** @@ -104,26 +153,31 @@ class SearchEngine { $allSearchTerms = array( $searchterm ); if ( $wgContLang->hasVariants() ) { - $allSearchTerms = array_merge( $allSearchTerms, $wgContLang->convertLinkToAllVariants( $searchterm ) ); + $allSearchTerms = array_merge( $allSearchTerms, $wgContLang->autoConvertToAllVariants( $searchterm ) ); } + $titleResult = null; if ( !wfRunHooks( 'SearchGetNearMatchBefore', array( $allSearchTerms, &$titleResult ) ) ) { return $titleResult; } + $context = new RequestContext; + foreach ( $allSearchTerms as $term ) { # Exact match? No need to look further. $title = Title::newFromText( $term ); - if ( is_null( $title ) ) + if ( is_null( $title ) ){ return null; + } if ( $title->getNamespace() == NS_SPECIAL || $title->isExternal() || $title->exists() ) { return $title; } # See if it still otherwise has content is some sane sense - $article = MediaWiki::articleFromTitle( $title ); + $context->setTitle( $title ); + $article = MediaWiki::articleFromTitle( $title, $context ); if ( $article->hasViewableContent() ) { return $title; } @@ -378,10 +432,11 @@ class SearchEngine { */ public static function create() { global $wgSearchType; - $dbr = wfGetDB( DB_SLAVE ); + $dbr = null; if ( $wgSearchType ) { $class = $wgSearchType; } else { + $dbr = wfGetDB( DB_SLAVE ); $class = $dbr->getSearchEngine(); } $search = new $class( $dbr ); @@ -420,13 +475,13 @@ class SearchEngine { * @return String */ public static function getOpenSearchTemplate() { - global $wgOpenSearchTemplate, $wgServer, $wgScriptPath; + global $wgOpenSearchTemplate, $wgServer; if ( $wgOpenSearchTemplate ) { return $wgOpenSearchTemplate; } else { $ns = implode( '|', SearchEngine::defaultNamespaces() ); if ( !$ns ) $ns = "0"; - return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace=' . $ns; + return $wgServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns; } } @@ -436,11 +491,11 @@ class SearchEngine { * @return String */ public static function getMWSuggestTemplate() { - global $wgMWSuggestTemplate, $wgServer, $wgScriptPath; + global $wgMWSuggestTemplate, $wgServer; if ( $wgMWSuggestTemplate ) return $wgMWSuggestTemplate; else - return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace={namespaces}&suggest'; + return $wgServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace={namespaces}&suggest'; } } @@ -611,9 +666,23 @@ class SearchResultTooMany { * @ingroup Search */ class SearchResult { + + /** + * @var Revision + */ var $mRevision = null; var $mImage = null; + /** + * @var Title + */ + var $mTitle; + + /** + * @var String + */ + var $mText; + /** * Return a new SearchResult and initializes it with a title. * @@ -843,7 +912,7 @@ class SearchNearMatchResultSet extends SearchResultSet { class SearchHighlighter { var $mCleanWikitext = true; - function SearchHighlighter( $cleanupWikitext = true ) { + function __construct( $cleanupWikitext = true ) { $this->mCleanWikitext = $cleanupWikitext; } @@ -1304,12 +1373,13 @@ class SearchHighlighter { continue; } --$contextlines; - $pre = $wgContLang->truncate( $m[1], - $contextchars ); + // truncate function changes ... to relevant i18n message. + $pre = $wgContLang->truncate( $m[1], - $contextchars, '...', false ); if ( count( $m ) < 3 ) { $post = ''; } else { - $post = $wgContLang->truncate( $m[3], $contextchars ); + $post = $wgContLang->truncate( $m[3], $contextchars, '...', false ); } $found = $m[2];