X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=includes%2Fsearch%2FSearchEngine.php;h=1293353ebecbc33c12254aca912ca858eb6fd0e9;hb=4fc982ebd977dd32b3cd5236904faadc94e3c8a5;hp=141f67278d3be67ebc2075db6f820ee198a89cad;hpb=2d64c69910873334f9e1370894cc7b15431ab709;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 141f67278d..1293353ebe 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -22,6 +22,9 @@ class SearchEngine { var $namespaces = array( NS_MAIN ); var $showRedirects = false; + /// Feature values + protected $features = array(); + /** * @var DatabaseBase */ @@ -59,9 +62,38 @@ class SearchEngine { return null; } - /** If this search backend can list/unlist redirects */ + /** + * If this search backend can list/unlist redirects + * @deprecated since 1.19 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; } /** @@ -100,11 +132,11 @@ class SearchEngine { wfRunHooks( 'SearchGetNearMatchComplete', array( $searchterm, &$title ) ); return $title; } - + /** - * Do a near match (see SearchEngine::getNearMatch) and wrap it into a + * Do a near match (see SearchEngine::getNearMatch) and wrap it into a * SearchResultSet. - * + * * @param $searchterm string * @return SearchResultSet */ @@ -129,19 +161,23 @@ class SearchEngine { 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 = Article::newFromTitle( $title, $context ); if ( $article->hasViewableContent() ) { return $title; } @@ -264,7 +300,7 @@ class SearchEngine { if ( strncmp( $query, $allkeyword, strlen( $allkeyword ) ) == 0 ) { $this->namespaces = null; $parsed = substr( $query, strlen( $allkeyword ) ); - } else if ( strpos( $query, ':' ) !== false ) { + } elseif ( strpos( $query, ':' ) !== false ) { $prefix = substr( $query, 0, strpos( $query, ':' ) ); $index = $wgContLang->getNsIndex( $prefix ); if ( $index !== false ) { @@ -326,14 +362,11 @@ class SearchEngine { } /** - * Find snippet highlight settings for a given user + * Find snippet highlight settings for all users * - * @param $user User * @return Array contextlines, contextchars */ - public static function userHighlightPrefs( &$user ) { - // $contextlines = $user->getOption( 'contextlines', 5 ); - // $contextchars = $user->getOption( 'contextchars', 50 ); + public static function userHighlightPrefs() { $contextlines = 2; // Hardcode this. Old defaults sucked. :) $contextchars = 75; // same as above.... :P return array( $contextlines, $contextchars ); @@ -439,13 +472,15 @@ class SearchEngine { * @return String */ public static function getOpenSearchTemplate() { - global $wgOpenSearchTemplate, $wgServer, $wgScriptPath; - if ( $wgOpenSearchTemplate ) { + 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; + if ( !$ns ) { + $ns = "0"; + } + return $wgServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns; } } @@ -455,11 +490,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'; } } @@ -580,6 +615,9 @@ class SearchResultSet { * This class is used for different SQL-based search engines shipped with MediaWiki */ class SqlSearchResultSet extends SearchResultSet { + + protected $mResultSet; + function __construct( $resultSet, $terms ) { $this->mResultSet = $resultSet; $this->mTerms = $terms; @@ -603,7 +641,7 @@ class SqlSearchResultSet extends SearchResultSet { $row = $this->mResultSet->fetchObject(); if ( $row === false ) return false; - + return SearchResult::newFromRow( $row ); } @@ -624,19 +662,33 @@ class SearchResultTooMany { /** - * @todo Fixme: This class is horribly factored. It would probably be better to + * @todo FIXME: This class is horribly factored. It would probably be better to * have a useful base class to which you pass some standard information, then * let the fancy self-highlighters extend that. * @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. - * - * @param $title Title + * + * @param $title Title * @return SearchResult */ public static function newFromTitle( $title ) { @@ -646,7 +698,7 @@ class SearchResult { } /** * Return a new SearchResult and initializes it with a row. - * + * * @param $row object * @return SearchResult */ @@ -655,28 +707,28 @@ class SearchResult { $result->initFromRow( $row ); return $result; } - + public function __construct( $row = null ) { if ( !is_null( $row ) ) { // Backwards compatibility with pre-1.17 callers $this->initFromRow( $row ); } } - + /** * Initialize from a database row. Makes a Title and passes that to * initFromTitle. - * + * * @param $row object */ protected function initFromRow( $row ) { $this->initFromTitle( Title::makeTitle( $row->page_namespace, $row->page_title ) ); } - + /** * Initialize from a Title and if possible initializes a corresponding * Revision and File. - * + * * @param $title Title */ protected function initFromTitle( $title ) { @@ -793,7 +845,7 @@ class SearchResult { function getTimestamp() { if ( $this->mRevision ) return $this->mRevision->getTimestamp(); - else if ( $this->mImage ) + elseif ( $this->mImage ) return $this->mImage->getTimestamp(); return ''; } @@ -891,7 +943,7 @@ class SearchHighlighter { 2 => '/(\[\[)|(\]\])/', // image 3 => "/(\n\\{\\|)|(\n\\|\\})/" ); // table - // FIXME: this should prolly be a hook or something + // @todo FIXME: This should prolly be a hook or something if ( function_exists( 'wfCite' ) ) { $spat .= '|()'; // references via cite extension $endPatterns[4] = '/()|(<\/ref>)/'; @@ -977,7 +1029,7 @@ class SearchHighlighter { $anyterm = implode( '|', $terms ); $phrase = implode( "$wgSearchHighlightBoundaries+", $terms ); - // FIXME: a hack to scale contextchars, a correct solution + // @todo FIXME: A hack to scale contextchars, a correct solution // would be to have contextchars actually be char and not byte // length, and do proper utf-8 substrings and lengths everywhere, // but PHP is making that very hard and unclean to implement :( @@ -1350,7 +1402,7 @@ class SearchHighlighter { /** * Dummy class to be used when non-supported Database engine is present. - * @todo Fixme: dummy class should probably try something at least mildly useful, + * @todo FIXME: Dummy class should probably try something at least mildly useful, * such as a LIKE search through titles. * @ingroup Search */