From 7134e2c65466282ecdfc6e8568b64b528063498a Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 20 Jan 2012 16:12:34 +0000 Subject: [PATCH] * Inlinise Preferences::loadOldSearchNs() in SearchEngine::userNamespaces(); the latter is the only caller of the former * Made code clearer and removed duplication * Marked Preferences::loadOldSearchNs() as deprecated --- includes/Preferences.php | 3 +++ includes/search/SearchEngine.php | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/includes/Preferences.php b/includes/Preferences.php index 942b04f76b..a42c3844eb 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -1456,10 +1456,13 @@ class Preferences { } /** + * @deprecated in 1.19; will be removed in 1.20. * @param $user User * @return array */ public static function loadOldSearchNs( $user ) { + wfDeprecated( __METHOD__, '1.19' ); + $searchableNamespaces = SearchEngine::searchableNamespaces(); // Back compat with old format $arr = array(); diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index b3f5da9099..2f7dfd7ee5 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -344,20 +344,22 @@ class SearchEngine { 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(); - $arr = array_intersect( $arr, array_keys( $searchableNamespaces ) ); // Filter + // get search everything preference, that can be set to be read for logged-in users + // it overrides other options + if ( !$wgSearchEverythingOnlyLoggedIn || $user->isLoggedIn() ) { + if ( $user->getOption( 'searcheverything' ) ) { + return array_keys( $searchableNamespaces ); + } + } + + $arr = array(); + foreach ( $searchableNamespaces as $ns => $name ) { + if ( $user->getOption( 'searchNs' . $ns ) ) { + $arr[] = $ns; + } + } return $arr; } -- 2.20.1