From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/search/SearchEngine.php | 124 ++++++++++++++++++++++++++++----------- 1 file changed, 91 insertions(+), 33 deletions(-) (limited to 'includes/search/SearchEngine.php') diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 17482da2..40b992de 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -22,6 +22,14 @@ class SearchEngine { 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; @@ -54,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.18 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; } /** @@ -95,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 */ @@ -124,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; } @@ -259,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 ) { @@ -321,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 ); @@ -434,13 +472,15 @@ class SearchEngine { * @return String */ public static function getOpenSearchTemplate() { - global $wgOpenSearchTemplate, $wgServer; - if ( $wgOpenSearchTemplate ) { + global $wgOpenSearchTemplate, $wgCanonicalServer; + if ( $wgOpenSearchTemplate ) { return $wgOpenSearchTemplate; } else { $ns = implode( '|', SearchEngine::defaultNamespaces() ); - if ( !$ns ) $ns = "0"; - return $wgServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns; + if ( !$ns ) { + $ns = "0"; + } + return $wgCanonicalServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns; } } @@ -575,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; @@ -598,7 +641,7 @@ class SqlSearchResultSet extends SearchResultSet { $row = $this->mResultSet->fetchObject(); if ( $row === false ) return false; - + return SearchResult::newFromRow( $row ); } @@ -619,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 ) { @@ -641,7 +698,7 @@ class SearchResult { } /** * Return a new SearchResult and initializes it with a row. - * + * * @param $row object * @return SearchResult */ @@ -650,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 ) { @@ -788,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 ''; } @@ -886,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>)/'; @@ -972,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 :( @@ -1318,12 +1375,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]; @@ -1344,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 */ -- cgit v1.2.3-54-g00ecf