aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Musso <hashar@users.mediawiki.org>2012-01-12 09:03:38 +0000
committerAntoine Musso <hashar@users.mediawiki.org>2012-01-12 09:03:38 +0000
commitca27814f63df59050027695c4b6781ead03f790f (patch)
tree74bc3de315260d75a3fecccf0ec282afda261841
parentafe8d1cff90c967f8a5a38eea15499716a1d09d2 (diff)
downloadmediawikicore-ca27814f63df59050027695c4b6781ead03f790f.tar.gz
mediawikicore-ca27814f63df59050027695c4b6781ead03f790f.zip
bug 33583 search ns user pref ignored!
r106780 to fix bug 33270 introduced a new bug that prevented selected namespaces for search to be applied. This patch fix the issue. Credits to Brad Jorsch
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/108712
-rw-r--r--includes/specials/SpecialSearch.php21
-rw-r--r--tests/phpunit/includes/specials/SpecialSearchTest.php16
2 files changed, 20 insertions, 17 deletions
diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php
index 927464fbb132..3fa86875d691 100644
--- a/includes/specials/SpecialSearch.php
+++ b/includes/specials/SpecialSearch.php
@@ -110,6 +110,8 @@ class SpecialSearch extends SpecialPage {
/**
* Set up basic search parameters from the request and user settings.
+ *
+ * @see tests/phpunit/includes/specials/SpecialSearchTest.php
*/
public function load() {
$request = $this->getRequest();
@@ -117,27 +119,30 @@ class SpecialSearch extends SpecialPage {
$this->mPrefix = $request->getVal( 'prefix', '' );
$user = $this->getUser();
+
# Extract manually requested namespaces
$nslist = $this->powerSearch( $request );
+ if ( !count( $nslist ) ) {
+ # Fallback to user preference
+ $nslist = SearchEngine::userNamespaces( $user );
+ }
+
$profile = null;
if ( !count( $nslist ) ) {
$profile = 'default';
}
+
$profile = $request->getVal( 'profile', $profile );
$profiles = $this->getSearchProfiles();
if ( $profile === null ) {
// BC with old request format
$profile = 'advanced';
- if ( count( $nslist ) ) {
- foreach( $profiles as $key => $data ) {
- if ( $nslist === $data['namespaces'] && $key !== 'advanced') {
- $profile = $key;
- }
+ foreach( $profiles as $key => $data ) {
+ if ( $nslist === $data['namespaces'] && $key !== 'advanced') {
+ $profile = $key;
}
- $this->namespaces = $nslist;
- } else {
- $this->namespaces = SearchEngine::userNamespaces( $user );
}
+ $this->namespaces = $nslist;
} elseif ( $profile === 'advanced' ) {
$this->namespaces = $nslist;
} else {
diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php
index b1c06cdf6df7..eb60cf2048e2 100644
--- a/tests/phpunit/includes/specials/SpecialSearchTest.php
+++ b/tests/phpunit/includes/specials/SpecialSearchTest.php
@@ -14,11 +14,12 @@ class SpecialSearchTest extends MediaWikiTestCase {
function tearDown() { }
/**
+ * @covers SpecialSearch::load
* @dataProvider provideSearchOptionsTests
* @param $requested Array Request parameters. For example array( 'ns5' => true, 'ns6' => true). NULL to use default options.
* @param $userOptions Array User options to test with. For example array('searchNs5' => 1 );. NULL to use default options.
*/
- function testFoobar(
+ function testProfileAndNamespaceLoading(
$requested, $userOptions, $expectedProfile, $expectedNS,
$message = 'Profile name andnamespaces mismatches!'
) {
@@ -79,14 +80,11 @@ class SpecialSearchTest extends MediaWikiTestCase {
'advanced', array( 5),
'Web request with specific NS should override user preference'
),
- /* FIXME this test is for bug 33583
- array(
- $EMPTY_REQUEST, array( 'searchNs2' ),
- 'advanced', array( 2 ),
- 'Bug 33583: search with no option should honor User search preferences'
- ),
- */
-
+ array(
+ $EMPTY_REQUEST, array( 'searchNs2' => 1, 'searchNs14' => 1 ),
+ 'advanced', array( 2, 14 ),
+ 'Bug 33583: search with no option should honor User search preferences'
+ ),
);
}