From 4d29c754be8cae291f5066e1a8d44e4b58f56bfc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Robert=20Stojni=C4=87?= Date: Sun, 31 May 2009 13:22:35 +0000 Subject: [PATCH] More work on new search UI (follow-up to r50207): * introduce search.js (loaded only for Special:Search): ** updates target links when search term is changed and one of the header links clicked ** added Aude's code for toggling advanced search checkboxes * fix minor styling issues in IE Tried different ways to make prefix: queries look smarter, but will leave it alone for now, since there is no neat way of fixing them. --- includes/DefaultSettings.php | 2 +- includes/specials/SpecialSearch.php | 44 ++++++++++++++++++----------- languages/messages/MessagesEn.php | 3 ++ maintenance/language/messages.inc | 3 ++ skins/common/search.js | 42 +++++++++++++++++++++++++++ skins/common/shared.css | 18 ++++++++++++ 6 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 skins/common/search.js diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 26eea35bb2..4d5b9a7915 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1485,7 +1485,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches don't keep obsolete copies of global * styles. */ -$wgStyleVersion = '220'; +$wgStyleVersion = '221'; # Server-side caching: diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 6346113907..63bbbcc8f3 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -322,6 +322,8 @@ class SpecialSearch { } $wgOut->setArticleRelated( false ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); + // add javascript specific to special:search + $wgOut->addScriptFile( 'search.js' ); } /** @@ -535,7 +537,7 @@ class SpecialSearch { $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions ); $prev = $result->getInterwikiPrefix(); } - // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax).. + // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax).. $out .= "\n"; // convert the whole thing to desired language variant @@ -612,19 +614,31 @@ class SpecialSearch { $namespaces = SearchEngine::searchableNamespaces(); $tables = $this->namespaceTables( $namespaces ); - + + // include redirects in the search $redirect = Xml::check( 'redirs', $this->searchRedirects, array( 'value' => '1', 'id' => 'redirs' ) ); $redirectLabel = Xml::label( wfMsg( 'powersearch-redir' ), 'redirs' ); - $searchField = Xml::inputLabel( wfMsg('powersearch-field'), 'search', 'powerSearchText', 50, $term, - array( 'type' => 'text') ); - $searchButton = Xml::submitButton( wfMsg( 'powersearch' ) ) . "\n"; - $searchTitle = SpecialPage::getTitleFor( 'Search' ); $redirectText = ''; // show redirects check only if backend supports it if( $this->searchEngine->acceptListRedirects() ) { - $redirectText = "

". $redirect . " " . $redirectLabel ."

"; + $redirectText = "". $redirect . " " . $redirectLabel .""; } + + + $searchField = Xml::inputLabel( wfMsg( 'powersearch-field' ), 'search', 'powerSearchText', 50, $term, + array( 'type' => 'text') ); + + // toggle for turning on and off all checkboxes + $selectOptionsLabel = Xml::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' ); + $selectAllButton = Xml::submitButton( wfMsg( 'powersearch-toggleall' ), array( 'id' => 'mw-search-toggleall', 'onclick' => 'mwToggleSearchCheckboxes(this);return false;' ) ); + $selectNoneButton = Xml::submitButton( wfMsg( 'powersearch-togglenone' ), array( 'id' => 'mw-search-togglenone', 'onclick' => 'mwToggleSearchCheckboxes(this);return false;' ) ); + $selectOptionsText = "" . $selectOptionsLabel . $selectAllButton . $selectNoneButton . ""; + + $searchButton = Xml::submitButton( wfMsg( 'powersearch' ) ) . "\n"; + $searchTitle = SpecialPage::getTitleFor( 'Search' ); + + $optionsText = "
" . $redirectText . $selectOptionsText . "
"; $out = Xml::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) . Xml::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" . @@ -634,8 +648,8 @@ class SpecialSearch { '\n". $tables . "
\n". - $redirectText ."\n". - "
". + $optionsText . "\n". + "
". $searchField . " " . Xml::hidden( 'fulltext', 'Advanced search' ) . "\n" . @@ -691,7 +705,7 @@ class SpecialSearch { if( $this->active == 'default' ) { $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m ); } else { - $out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultNamespaces(), $m, $tt ); + $out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultNamespaces(), $m, $tt); } $out .= $sep; @@ -777,13 +791,7 @@ class SpecialSearch { $out .= Xml::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n"; $out .= Xml::hidden( 'fulltext', 'Search' ); $out .= Xml::submitButton( wfMsg( 'searchbutton' ) ); - //$out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')'; $out .= Xml::closeElement( 'form' ); - // Add prefix link for single-namespace searches - $t = Title::newFromText( $term ); - /*if( $t != null && count($this->namespaces) === 1 ) { - $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term ); - }*/ return $out . $this->didYouMeanHtml; } @@ -799,7 +807,9 @@ class SpecialSearch { $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt ); return Xml::element( 'a', - array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ), + array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip, + 'onmousedown' => 'mwSearchHeaderClick(this);', + 'onkeydown' => 'mwSearchHeaderClick(this);'), $label ); } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 08dabe915e..2edea0e86c 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1490,6 +1490,9 @@ Try prefixing your query with ''all:'' to search all content (including talk pag 'powersearch-ns' => 'Search in namespaces:', 'powersearch-redir' => 'List redirects', 'powersearch-field' => 'Search for', +'powersearch-togglelabel' => 'Check: ', +'powersearch-toggleall' => 'All', +'powersearch-togglenone' => 'None', 'search-external' => 'External search', 'searchdisabled' => '{{SITENAME}} search is disabled. You can search via Google in the meantime. diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 31aa3cbf44..0b6b38cc41 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -820,6 +820,9 @@ $wgMessageStructure = array( 'powersearch-ns', 'powersearch-redir', 'powersearch-field', + 'powersearch-togglelabel', + 'powersearch-toggleall', + 'powersearch-togglenone', 'search-external', 'searchdisabled', 'googlesearch', diff --git a/skins/common/search.js b/skins/common/search.js new file mode 100644 index 0000000000..773aba6c30 --- /dev/null +++ b/skins/common/search.js @@ -0,0 +1,42 @@ +// JS specific to Special:Search + +// change the search link to what user entered +function mwSearchHeaderClick(obj){ + var searchbox = document.getElementById("searchText"); + if( searchbox == null ) + searchbox = document.getElementById("powerSearchText"); + if( searchbox == null) + return; // should always have either normal or advanced search + + var searchterm = searchbox.value; + var parts = obj.href.split("search="); + var lastpart = ''; + if( parts[1].indexOf('&') >= 0 ) + lastpart = parts[1].substring( parts[1].indexOf('&') ) + obj.href = parts[0] + "search=" + encodeURIComponent(searchterm) + lastpart; +} + +function mwToggleSearchCheckboxes( btn ) { + if( !document.getElementById ) return; + + var nsInputs = document.getElementById( 'powersearch' ).getElementsByTagName( 'input' ); + var isChecked = false; + + for ( var i = 0; i < nsInputs.length; i++ ) { + var pattern = /^ns/; + if ( ( nsInputs[i].type == 'checkbox' ) && ( pattern.test( nsInputs[i].name ) ) ) { + switch ( btn.value ) { + case "None": + if ( nsInputs[i].checked ) { + nsInputs[i].checked = false; + } + break; + case "All": + if ( !nsInputs[i].checked ) { + nsInputs[i].checked = true; + } + break; + } + } + } +} diff --git a/skins/common/shared.css b/skins/common/shared.css index 7d123bd0e4..d4cbbd1994 100644 --- a/skins/common/shared.css +++ b/skins/common/shared.css @@ -123,6 +123,7 @@ div.searchresult { .mw-search-results li { padding-bottom: 1em; list-style:none; + list-style-image:none; } .mw-search-results li a { font-size: 108%; @@ -213,6 +214,23 @@ div.searchdidyoumean em { } +/* + * Advanced PowerSearch box + */ + +td#mw-search-togglebox { + text-align: right; +} + +div#mw-search-redirbox { + width:100%; +} + +table#mw-search-redirtable { + width:95%; +} + + /* * UserRights stuff */ -- 2.20.1