X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSearchEngine.php;h=c22e58d72246518e3bbbbb7b91ce991f788fba76;hb=c07e337da68a87e7e877c65194778f4b098bf7c2;hp=dc10279f4d78148fe86da37971eb8f9c46ac9590;hpb=0b2f7f7ea4c0b72398741e0b0fe6f3db2b408136;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index dc10279f4d..c22e58d722 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -3,9 +3,6 @@ * Contain a class for special pages * @addtogroup Search */ - -/** - */ class SearchEngine { var $limit = 10; var $offset = 0; @@ -43,12 +40,10 @@ class SearchEngine { * If an exact title match can be find, or a very slightly close match, * return the title. If no match, returns NULL. * - * @static * @param string $term * @return Title - * @private */ - function getNearMatch( $searchterm ) { + public static function getNearMatch( $searchterm ) { global $wgContLang; $allSearchTerms = array($searchterm); @@ -56,7 +51,7 @@ class SearchEngine { if($wgContLang->hasVariants()){ $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm)); } - + foreach($allSearchTerms as $term){ # Exact match? No need to look further. @@ -107,6 +102,12 @@ class SearchEngine { return $title; } } + + // Give hooks a chance at better match variants + $title = null; + if( !wfRunHooks( 'SearchGetNearMatch', array( $term, &$title ) ) ) { + return $title; + } } $title = Title::newFromText( $searchterm ); @@ -114,7 +115,7 @@ class SearchEngine { # Entering an IP address goes to the contributions page if ( ( $title->getNamespace() == NS_USER && User::isIP($title->getText() ) ) || User::isIP( trim( $searchterm ) ) ) { - return SpecialPage::getTitleFor( 'Contributions', $title->getDbkey() ); + return SpecialPage::getTitleFor( 'Contributions', $title->getDBkey() ); } @@ -122,13 +123,29 @@ class SearchEngine { if ( $title->getNamespace() == NS_USER ) { return $title; } + + # Go to images that exist even if there's no local page. + # There may have been a funny upload, or it may be on a shared + # file repository such as Wikimedia Commons. + if( $title->getNamespace() == NS_IMAGE ) { + $image = wfFindFile( $title ); + if( $image ) { + return $title; + } + } + + # MediaWiki namespace? Page may be "implied" if not customized. + # Just return it, with caps forced as the message system likes it. + if( $title->getNamespace() == NS_MEDIAWIKI ) { + return Title::makeTitle( NS_MEDIAWIKI, $wgContLang->ucfirst( $title->getText() ) ); + } # Quoted term? Try without the quotes... $matches = array(); if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) { return SearchEngine::getNearMatch( $matches[1] ); } - + return NULL; } @@ -163,9 +180,8 @@ class SearchEngine { /** * Make a list of searchable namespaces and their canonical names. * @return array - * @access public */ - function searchableNamespaces() { + public static function searchableNamespaces() { global $wgContLang; $arr = array(); foreach( $wgContLang->getNamespaces() as $ns => $name ) { @@ -231,11 +247,15 @@ class SearchEngine { * @param string $title * @abstract */ - function updateTitle( $id, $title ) { + function updateTitle( $id, $title ) { // no-op - } + } } + +/** + * @addtogroup Search + */ class SearchResultSet { /** * Fetch an array of regular expression fragments for matching @@ -308,9 +328,30 @@ class SearchResultSet { function next() { return false; } + + /** + * Frees the result set, if applicable. + * @ access public + */ + function free() { + // ... + } } + +/** + * @addtogroup Search + */ +class SearchResultTooMany { + ## Some search engines may bail out if too many matches are found +} + + +/** + * @addtogroup Search + */ class SearchResult { + function SearchResult( $row ) { $this->mTitle = Title::makeTitle( $row->page_namespace, $row->page_title ); } @@ -332,6 +373,7 @@ class SearchResult { } /** + * @addtogroup Search */ class SearchEngineDummy { function search( $term ) { @@ -344,4 +386,4 @@ class SearchEngineDummy { function searchtitle() {} function searchtext() {} } -?> +