r108712 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108711‎ | r108712 | r108713 >
Date:09:03, 12 January 2012
Author:hashar
Status:ok (Comments)
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/specials/SpecialSearchTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/specials/SpecialSearchTest.php
@@ -14,11 +14,12 @@
1515 function tearDown() { }
1616
1717 /**
 18+ * @covers SpecialSearch::load
1819 * @dataProvider provideSearchOptionsTests
1920 * @param $requested Array Request parameters. For example array( 'ns5' => true, 'ns6' => true). NULL to use default options.
2021 * @param $userOptions Array User options to test with. For example array('searchNs5' => 1 );. NULL to use default options.
2122 */
22 - function testFoobar(
 23+ function testProfileAndNamespaceLoading(
2324 $requested, $userOptions, $expectedProfile, $expectedNS,
2425 $message = 'Profile name andnamespaces mismatches!'
2526 ) {
@@ -79,14 +80,11 @@
8081 'advanced', array( 5),
8182 'Web request with specific NS should override user preference'
8283 ),
83 - /* FIXME this test is for bug 33583
84 - array(
85 - $EMPTY_REQUEST, array( 'searchNs2' ),
86 - 'advanced', array( 2 ),
87 - 'Bug 33583: search with no option should honor User search preferences'
88 - ),
89 - */
90 -
 84+ array(
 85+ $EMPTY_REQUEST, array( 'searchNs2' => 1, 'searchNs14' => 1 ),
 86+ 'advanced', array( 2, 14 ),
 87+ 'Bug 33583: search with no option should honor User search preferences'
 88+ ),
9189 );
9290 }
9391
Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -110,6 +110,8 @@
111111
112112 /**
113113 * Set up basic search parameters from the request and user settings.
 114+ *
 115+ * @see tests/phpunit/includes/specials/SpecialSearchTest.php
114116 */
115117 public function load() {
116118 $request = $this->getRequest();
@@ -117,27 +119,30 @@
118120 $this->mPrefix = $request->getVal( 'prefix', '' );
119121
120122 $user = $this->getUser();
 123+
121124 # Extract manually requested namespaces
122125 $nslist = $this->powerSearch( $request );
 126+ if ( !count( $nslist ) ) {
 127+ # Fallback to user preference
 128+ $nslist = SearchEngine::userNamespaces( $user );
 129+ }
 130+
123131 $profile = null;
124132 if ( !count( $nslist ) ) {
125133 $profile = 'default';
126134 }
 135+
127136 $profile = $request->getVal( 'profile', $profile );
128137 $profiles = $this->getSearchProfiles();
129138 if ( $profile === null ) {
130139 // BC with old request format
131140 $profile = 'advanced';
132 - if ( count( $nslist ) ) {
133 - foreach( $profiles as $key => $data ) {
134 - if ( $nslist === $data['namespaces'] && $key !== 'advanced') {
135 - $profile = $key;
136 - }
 141+ foreach( $profiles as $key => $data ) {
 142+ if ( $nslist === $data['namespaces'] && $key !== 'advanced') {
 143+ $profile = $key;
137144 }
138 - $this->namespaces = $nslist;
139 - } else {
140 - $this->namespaces = SearchEngine::userNamespaces( $user );
141145 }
 146+ $this->namespaces = $nslist;
142147 } elseif ( $profile === 'advanced' ) {
143148 $this->namespaces = $nslist;
144149 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r108751MFT r108712 to fix fixme on r107975...reedy20:05, 12 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106780Fix for bug 33270: default to 'default' search profile...nikerabbit11:17, 20 December 2011
r108400test skeleton for Special:Search...hashar11:41, 9 January 2012

Comments

#Comment by Hashar (talk | contribs)   09:06, 12 January 2012

Tagging 1.18wmf1 since it fix a regression that was applied to live site with r107975.

Status & tagging log