Last modified: 2008-03-18 23:23:07 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T5188, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 3188 - Search for anonymous users default to Main, but no checkbox?
Search for anonymous users default to Main, but no checkbox?
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
Search (Other open bugs)
unspecified
All All
: Low minor with 2 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
http://xnoybis.ccnmtl.columbia.edu:80...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-08-18 18:52 UTC by John Rodriguez
Modified: 2008-03-18 23:23 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Patched search function for anonymous users (610 bytes, patch)
2005-09-14 14:44 UTC, Markus W.
Details

Description John Rodriguez 2005-08-18 18:52:59 UTC
It appears confusing to naive users that on a search as an anonymous user, 
the search results page doesn't show the Main checkbox as checked (although 
anonymous searches default as such), so the user may wonder what exactly is 
the search space.  Furthermore, why DO the default namespaces to search for 
anonymous users only include Main?

The first topic:

Looking at the code, the checkboxes are outputted in 
SpecialSearch::powerSearchBox and are checked for each user namespace found 
in the user options (for anonymous users, there will be none).

Now if you look at SpecialSearch::showResults, the search is conducted 
before the call to SpecialSearch::powerSearchBox.  When that search is 
conducted, a copy of the user namespaces (up to now, empty) is passed and 
in SearchEngine::queryNamespaces, it is finally realized that if no user 
namespaces exist, then default to the Main namespace.  But since this is a 
copy of the namespaces array, the change is not reflected when control 
passes back to SpecialSearch:showResults and never displays (bug?).

The second topic:

When users are created, they inherit the $wgNamespacesToBeSearchedDefault 
as their settings, why not allow anonymous searches to include the same?

A humble suggestion to address the two topics is to rewrite 
SpecialSearch::userNamespaces as follows:

function userNamespaces( &$user ) {
  global $wgNamespacesToBeSearchedDefault;
  if( !$user->mId ) {
    return array_keys( $wgNamespacesToBeSearchedDefault );
  }
  else {
    ... //put the entire code currently in userNamespaces here
  }
}
Comment 1 John Rodriguez 2005-08-18 18:55:33 UTC
This would also allow the wiki admin to control what are the initial 
search settings for all newly-created and anonymous users if they 
choose to override $wgNamespacesToBeSearchedDefault in 
LocalSettings.php (a db script is needed to update for existing users)
Comment 2 Markus W. 2005-09-04 23:10:12 UTC
I agree that this needs fixing.
Comment 3 Markus W. 2005-09-04 23:24:41 UTC
The code above simply checks all namespaces as it just returns all namespaces
that have a key in '$wgNamespacesToBeSearchedDefault'.

This works as intended:
	function userNamespaces( &$user ) {
		global $wgNamespacesToBeSearchedDefault;
		$arr = array();
		if( !$user->mId ) {
			foreach( $wgNamespacesToBeSearchedDefault as $nsId => $value ) {
				if ($value) {
					$arr[] = $nsId;
				}
			}
		}
		else
			{
			foreach( SearchEngine::searchableNamespaces() as $ns => $name ) {
				if( $user->getOption( 'searchNs' . $ns ) ) {
					$arr[] = $ns;
				}
			}
		}
		return $arr;
	}
Comment 4 Markus W. 2005-09-14 14:44:19 UTC
Created attachment 893 [details]
Patched search function for anonymous users

Just adding the above code as a file. Apply by replacing the respective
function in 'SpecialSearch.php'.
Comment 5 Brion Vibber 2008-03-18 23:23:07 UTC
Doesn't appear to be such a problem in current MediaWiki.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links