Index: maintenance/language/messages.inc =================================================================== --- maintenance/language/messages.inc (revision 48965) +++ maintenance/language/messages.inc (working copy) @@ -836,6 +836,7 @@ 'search-mwsuggest-disabled', 'search-relatedarticle', 'mwsuggest-disable', + 'mwsuggest-redirects-disable', 'searchrelated', 'searchall', 'showingresults', Index: includes/PrefixSearch.php =================================================================== --- includes/PrefixSearch.php (revision 48965) +++ includes/PrefixSearch.php (working copy) @@ -15,7 +15,7 @@ * @param array $namespaces - used if query is not explicitely prefixed * @return array of strings */ - public static function titleSearch( $search, $limit, $namespaces=array() ) { + public static function titleSearch( $search, $limit, $namespaces=array(), $showRedirects=true ) { $search = trim( $search ); if( $search == '' ) { return array(); // Return empty result @@ -28,7 +28,7 @@ if($ns[0] == NS_MAIN) $ns = $namespaces; // no explicit prefix, use default namespaces return self::searchBackend( - $ns, $title->getText(), $limit ); + $ns, $title->getText(), $limit, $showRedirects ); } // Is this a namespace prefix? @@ -37,10 +37,10 @@ && $title->getNamespace() != NS_MAIN && $title->getInterwiki() == '' ) { return self::searchBackend( - array($title->getNamespace()), '', $limit ); + array($title->getNamespace()), '', $limit, $showRedirects ); } - return self::searchBackend( $namespaces, $search, $limit ); + return self::searchBackend( $namespaces, $search, $limit, $showRedirects ); } @@ -51,7 +51,7 @@ * @param int $limit * @return array of strings */ - protected static function searchBackend( $namespaces, $search, $limit ) { + protected static function searchBackend( $namespaces, $search, $limit, $showRedirects ) { if( count($namespaces) == 1 ){ $ns = $namespaces[0]; if( $ns == NS_MEDIA ) { @@ -62,7 +62,7 @@ } $srchres = array(); if( wfRunHooks( 'PrefixSearchBackend', array( $namespaces, $search, $limit, &$srchres ) ) ) { - return self::defaultSearchBackend( $namespaces, $search, $limit ); + return self::defaultSearchBackend( $namespaces, $search, $limit, $showRedirects ); } return $srchres; } @@ -112,18 +112,19 @@ * @param int $limit max number of items to return * @return array of title strings */ - protected static function defaultSearchBackend( $namespaces, $search, $limit ) { + protected static function defaultSearchBackend( $namespaces, $search, $limit, $showRedirects ) { $ns = array_shift($namespaces); // support only one namespace if( in_array(NS_MAIN,$namespaces)) $ns = NS_MAIN; // if searching on many always default to main - + // Prepare nested request $req = new FauxRequest(array ( 'action' => 'query', 'list' => 'allpages', 'apnamespace' => $ns, 'aplimit' => $limit, - 'apprefix' => $search + 'apprefix' => $search, + 'apfilterredir' => ( $showRedirects ? '' : 'nonredirects' ), )); // Execute Index: includes/SearchEngine.php =================================================================== --- includes/SearchEngine.php (revision 48965) +++ includes/SearchEngine.php (working copy) @@ -404,11 +404,12 @@ * @static */ public static function getMWSuggestTemplate() { - global $wgMWSuggestTemplate, $wgServer, $wgScriptPath; + global $wgMWSuggestTemplate, $wgServer, $wgScriptPath, $wgUser; + $showRedirects = !$wgUser->getOption( 'disablesuggestredirects', false ); if($wgMWSuggestTemplate) return $wgMWSuggestTemplate; else - return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace={namespaces}&suggest'; + return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace={namespaces}&suggest' . ( $showRedirects ? '' : '&noredirects' ); } } Index: includes/api/ApiOpenSearch.php =================================================================== --- includes/api/ApiOpenSearch.php (revision 48965) +++ includes/api/ApiOpenSearch.php (working copy) @@ -48,13 +48,17 @@ $limit = $params['limit']; $namespaces = $params['namespace']; $suggest = $params['suggest']; + $noredirects = $params['noredirects']; + # $wgEnableMWSuggest hit incoming when $wgEnableMWSuggest is disabled if( $suggest && !$wgEnableMWSuggest ) return; - + + $showRedirects = $noredirects ? false : true; + // Open search results may be stored for a very long time $this->getMain()->setCacheMaxAge(1200); - $srchres = PrefixSearch::titleSearch( $search, $limit, $namespaces ); + $srchres = PrefixSearch::titleSearch( $search, $limit, $namespaces, $showRedirects ); // Set top level elements $result = $this->getResult(); @@ -78,6 +82,7 @@ ApiBase :: PARAM_ISMULTI => true ), 'suggest' => false, + 'noredirects' => false, ); } @@ -87,6 +92,7 @@ 'limit' => 'Maximum amount of results to return', 'namespace' => 'Namespaces to search', 'suggest' => 'Do nothing if $wgEnableMWSuggest is false', + 'noredirects' => 'Don\'t includes redirects', ); } Index: includes/specials/SpecialPreferences.php =================================================================== --- includes/specials/SpecialPreferences.php (revision 48965) +++ includes/specials/SpecialPreferences.php (working copy) @@ -66,6 +66,7 @@ $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' ); $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' ); $this->mDisableMWSuggest = $request->getCheck( 'wpDisableMWSuggest' ); + $this->mDisableMWSuggestRedirects = $request->getCheck( 'wpDisableMWSuggestRedirects' ); $this->mGender = $request->getVal( 'wpGender' ); $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) && @@ -282,6 +283,7 @@ $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) ); $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) ); $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest ); + $wgUser->setOption( 'disablesuggestredirects', $this->mDisableMWSuggestRedirects ); $wgUser->setOption( 'gender', $this->validateGender( $this->mGender ) ); # Set search namespace options @@ -434,6 +436,7 @@ $this->mUnderline = $wgUser->getOption( 'underline' ); $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' ); $this->mDisableMWSuggest = $wgUser->getBoolOption( 'disablesuggest' ); + $this->mDisableMWSuggestRedirects = $wgUser->getBoolOption( 'disablesuggestredirects' ); $this->mGender = $wgUser->getOption( 'gender' ); $togs = User::getToggles(); @@ -1210,7 +1213,10 @@ $this->addRow( Xml::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ), Xml::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest, array( 'id' => 'wpDisableMWSuggest' ) ) - ) : ''; + ) . $this->addRow( + Xml::label( wfMsg( 'mwsuggest-redirects-disable' ), 'wpDisableMWSuggestRedirects' ), + Xml::check( 'wpDisableMWSuggestRedirects', $this->mDisableMWSuggestRedirects, array( 'id' => 'wpDisableMWSuggestRedirects' ) ) + ) : ''; $wgOut->addHTML( // Elements for the search tab itself Xml::openElement( 'fieldset' ) . Index: languages/messages/MessagesEn.php =================================================================== --- languages/messages/MessagesEn.php (revision 48965) +++ languages/messages/MessagesEn.php (working copy) @@ -1506,6 +1506,7 @@ 'search-mwsuggest-disabled' => 'no suggestions', 'search-relatedarticle' => 'Related', 'mwsuggest-disable' => 'Disable AJAX suggestions', +'mwsuggest-redirects-disable' => 'Don\'t show redirects in AJAX suggestions', 'searchrelated' => 'related', 'searchall' => 'all', 'showingresults' => "Showing below up to {{PLURAL:$1|'''1''' result|'''$1''' results}} starting with #'''$2'''.",