<?php
/**
- * @defgroup Search Search
+ * Basic search engine
*
* @file
* @ingroup Search
*/
+/**
+ * @defgroup Search Search
+ */
+
/**
* Contain a class for special pages
* @ingroup Search
var $namespaces = array( NS_MAIN );
var $showRedirects = false;
+ /// Feature values
+ protected $features = array();
+
+ /**
+ * @var DatabaseBase
+ */
+ protected $db;
+
+ function __construct($db = null) {
+ if ( $db ) {
+ $this->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.
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;
}
/**
$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;
}
*/
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 );
* @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;
}
}
* @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';
}
}
* @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.
*
class SearchHighlighter {
var $mCleanWikitext = true;
- function SearchHighlighter( $cleanupWikitext = true ) {
+ function __construct( $cleanupWikitext = true ) {
$this->mCleanWikitext = $cleanupWikitext;
}
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];