<?php
/**
* Contain a class for special pages
- * @package MediaWiki
- * @subpackage Search
- */
-
-/**
- * @package MediaWiki
+ * @addtogroup Search
*/
class SearchEngine {
var $limit = 10;
* 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);
if($wgContLang->hasVariants()){
$allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm));
}
-
+
foreach($allSearchTerms as $term){
# Exact match? No need to look further.
return $title;
}
}
+
+ // Give hooks a chance at better match variants
+ $title = null;
+ if( !wfRunHooks( 'SearchGetNearMatch', array( $term, &$title ) ) ) {
+ return $title;
+ }
}
$title = Title::newFromText( $searchterm );
# 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() );
}
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;
}
- function legalSearchChars() {
+ public static function legalSearchChars() {
return "A-Za-z_'0-9\\x80-\\xFF\\-";
}
/**
* 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 ) {
* active database backend, and return a configured instance.
*
* @return SearchEngine
- * @private
*/
- function create() {
+ public static function create() {
global $wgDBtype, $wgSearchType;
if( $wgSearchType ) {
$class = $wgSearchType;
$class = 'SearchMySQL4';
} else if ( $wgDBtype == 'postgres' ) {
$class = 'SearchPostgres';
+ } else if ( $wgDBtype == 'oracle' ) {
+ $class = 'SearchOracle';
} else {
$class = 'SearchEngineDummy';
}
* @param string $title
* @abstract
*/
- function updateTitle( $id, $title ) {
+ function updateTitle( $id, $title ) {
// no-op
- }
+ }
}
-/** @package MediaWiki */
+
+/**
+ * @addtogroup Search
+ */
class SearchResultSet {
/**
* Fetch an array of regular expression fragments for matching
function next() {
return false;
}
+
+ /**
+ * Frees the result set, if applicable.
+ * @ access public
+ */
+ function free() {
+ // ...
+ }
}
-/** @package MediaWiki */
+
+/**
+ * @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 );
}
}
/**
- * @package MediaWiki
+ * @addtogroup Search
*/
class SearchEngineDummy {
function search( $term ) {
function searchtitle() {}
function searchtext() {}
}
-?>
+