From fbe4a5ab5f35ade8850e8a8afc2440b80aac2517 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Robert=20Stojni=C4=87?= Date: Sun, 31 May 2009 16:46:52 +0000 Subject: [PATCH] New search option: * new option to search all namespaces: searcheverything * add a switch ($wgSearchEverythingOnlyLoggedIn) to limit this option only to logged-in users, this way one can set different default values of this option for logged-in and logged-out (disabled by default) --- includes/DefaultSettings.php | 7 +++++++ includes/Preferences.php | 12 +++++++++++- includes/SearchEngine.php | 12 ++++++++++++ languages/messages/MessagesEn.php | 3 ++- maintenance/language/messages.inc | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 4d5b9a7915..5a49bfc128 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1997,6 +1997,13 @@ $wgNamespacesToBeSearchedHelp = array( $wgUseOldSearchUI = true; // temp testing variable +/** + * If set to true the 'searcheverything' preference will be effective only for logged-in users. + * Useful for big wikis to maintain different search profiles for anonymous and logged-in users. + * + */ +$wgSearchEverythingOnlyLoggedIn = false; + /** * Site notice shown at the top of each page * diff --git a/includes/Preferences.php b/includes/Preferences.php index 116a52c582..c659144842 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -833,7 +833,14 @@ class Preferences { 'label-message' => 'mwsuggest-disable', 'section' => 'searchoptions/display', ); - } + } + + $defaultPreferences['searcheverything'] = + array( + 'type' => 'toggle', + 'label-message' => 'searcheverything-enable', + 'section' => 'searchoptions/advancedsearchoptions', + ); // Searchable namespaces back-compat with old format $searchableNamespaces = SearchEngine::searchableNamespaces(); @@ -857,6 +864,9 @@ class Preferences { 'section' => 'searchoptions/advancedsearchoptions', 'prefix' => 'searchNs', ); + + + } static function miscPreferences( $user, &$defaultPreferences ) { diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 3a4dacaf8b..daec7cad39 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -241,6 +241,18 @@ class SearchEngine { * @return Array */ public static function userNamespaces( $user ) { + global $wgSearchEverythingOnlyLoggedIn; + + // get search everything preference, that can be set to be read for logged-in users + $searcheverything = false; + if( ( $wgSearchEverythingOnlyLoggedIn && $user->isLoggedIn() ) + || !$wgSearchEverythingOnlyLoggedIn ) + $searcheverything = $user->getOption('searcheverything'); + + // searcheverything overrides other options + if( $searcheverything ) + return array_keys(SearchEngine::searchableNamespaces()); + $arr = Preferences::loadOldSearchNs( $user ); $searchableNamespaces = SearchEngine::searchableNamespaces(); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 2657b80754..416eb2a6fa 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1476,6 +1476,7 @@ You can [[:\$1|create this page]].", 'search-mwsuggest-disabled' => 'no suggestions', 'search-relatedarticle' => 'Related', 'mwsuggest-disable' => 'Disable AJAX suggestions', +'searcheverything-enable' => 'Search in all namespaces', 'searchrelated' => 'related', 'searchall' => 'all', 'showingresults' => "Showing below up to {{PLURAL:$1|'''1''' result|'''$1''' results}} starting with #'''$2'''.", @@ -1583,7 +1584,7 @@ Note that their indexes of {{SITENAME}} content may be out of date.', 'allowemail' => 'Enable e-mail from other users', 'prefs-searchoptions' => 'Search options', 'prefs-namespaces' => 'Namespaces', -'defaultns' => 'Search in these namespaces by default:', +'defaultns' => 'Otherwise search in these namespaces:', 'default' => 'default', 'prefs-files' => 'Files', 'prefs-custom-css' => 'Custom CSS', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 0b6b38cc41..3cd96a1b85 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -826,6 +826,7 @@ $wgMessageStructure = array( 'search-external', 'searchdisabled', 'googlesearch', + 'searcheverything-enable', ), 'opensearch' => array( 'opensearch-desc', -- 2.20.1