Extension:Multi-select Namespace Search

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Multi-select Namespace Search
Release status: stable
Implementation Search, Page action
Description Converts namespace search checkboxes into multi-select list boxes
Author(s) Eep, Tim Laqua
Latest version .2 (July 29, 2007)
MediaWiki 1.9.3
License No license specified
Download see below
Example [1]
Translate the Multi-select Namespace Search extension if it is available at translatewiki.net
Check usage and version matrix.

Have you ever been frustrated at namespace search checkboxes (see bug 10718)? I know I have. A multi-select menu (list box) makes more sense here, I believe.

This "extension" (more like a hack) is 2 1 rewrites of a files in the includes directory: SpecialSearch.php and SpecialPreferences.php (coming) which contain namespace checkboxes.[1] This hack was tested on MediaWiki 1.9.3 so it may not work for older/newer versions. Please mention here if it does.

Unfortunately, not being that much of a PHP coder, I haven't been able to figure out how to get the select form to output the option name so it equals ns0=1&ns1=1, etc. The select form will output its name but the option fields won't, for some reason. If you can figure it out, please edit this code accordingly. Thanks.

Thanks to Tim Laqua for figuring it out! Now to figure out how to add multiple authors to the extension template...

Because a MediaWiki site can have a lot of namespaces, the multi-select listbox can get very long (especially if expanded to its full length). To reduce this "screenhogging" aspect, positioning the form#powersearch CSS element can be done by adding this to the appropriate stylesheet:

form#powersearch {
  float: right !important;
  position: fixed !important;
  right: 1em !important;
  bottom: 5em !important;
}

Notes[edit]

  1. SpecialAllpages.php could use this too since it only has a single-select listbox but I'm not sure it supports multiple namespaces.

Changes[edit]

SpecialSearch.php[edit]

In this file, functions changed are:

	function powerSearch( &$request ) {
                preg_match_all("/ns=(\d+)&/i",$_SERVER['QUERY_STRING'],$nsArray, PREG_PATTERN_ORDER);
                return $nsArray[1];
        }

	function powerSearchBox( $term ) {
                $namespaces = '';
                foreach( SearchEngine::searchableNamespaces() as $ns => $name ) {
                        $checked = in_array( $ns, $this->namespaces )
                                ? ' SELECTED' # from ' checked="checked"'
                                : '';
                        $name = str_replace( '_', ' ', $name );
                        if( '' == $name ) {
                                $name = wfMsg( 'blanknamespace' );
                        }
                        $namespaces .= " <option value=\"$ns\" {$checked} >{$name}</option>\n";
                }
 
                $checked = $this->searchRedirects
                        ? ' CHECKED' # from ' checked="checked"'
                        : '';
                $redirect = "</select><input type='checkbox' value='1' name=\"redirs\"{$checked} />\n";
 
                $searchField = '<input type="text" name="search" value="' .
                        htmlspecialchars( $term ) ."\" size=\"16\" />\n";
 
                $searchButton = '<input type="submit" name="searchx" value="' .
                  htmlspecialchars( wfMsg('powersearch') ) . "\" />\n";
 
                $ret = wfMsg( 'powersearchtext',
                        $namespaces, $redirect, $searchField,
                        '', '', '', '', '', # Dummy placeholders
                        $searchButton );
 
                $title = SpecialPage::getTitleFor( 'Search' );
                $action = $title->escapeLocalURL();
                return "<br /><br />\n<form id=\"powersearch\" method=\"get\" " .
                  "action=\"$action\">\n<select name=\"ns\" multiple>{$ret}\n</form>\n"; # from "action=\"$action\">\n{$ret}\n</form>\n"
        }

SpecialPreferences.php[edit]

to-do

Installation[edit]

Copy over the above functions into ../includes/SpecialSearch.php . I'd advise making a backup of the existing file.