More work on new search UI (follow-up to r50207):
authorRobert Stojnić <rainman@users.mediawiki.org>
Sun, 31 May 2009 13:22:35 +0000 (13:22 +0000)
committerRobert Stojnić <rainman@users.mediawiki.org>
Sun, 31 May 2009 13:22:35 +0000 (13:22 +0000)
* 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
includes/specials/SpecialSearch.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc
skins/common/search.js [new file with mode: 0644]
skins/common/shared.css

index 26eea35..4d5b9a7 100644 (file)
@@ -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:
index 6346113..63bbbcc 100644 (file)
@@ -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 .= "</ul></div>\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 = "<p>". $redirect . " " . $redirectLabel ."</p>";
+                       $redirectText = "<td id='powersearch-rediropt'>". $redirect . " " . $redirectLabel ."</td>";
                }
+               
+               $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 = "<td id='mw-search-togglebox'>" . $selectOptionsLabel . $selectAllButton . $selectNoneButton . "</td>";
+
+               $searchButton = Xml::submitButton( wfMsg( 'powersearch' ) ) . "\n";
+               $searchTitle = SpecialPage::getTitleFor( 'Search' );
+
+               $optionsText = "<div id='mw-search-redirbox'><table id='mw-search-redirtable'><tr>" . $redirectText . $selectOptionsText . "</tr></table></div>";
 
                $out = Xml::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
                        Xml::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
@@ -634,8 +648,8 @@ class SpecialSearch {
                        '<input type="hidden" name="advanced" value="'.$this->searchAdvanced."\"/>\n".
                        $tables .
                        "<hr style=\"clear: both;\" />\n".
-                       $redirectText ."\n".
-                       "<div style=\"padding-top:2px;padding-bottom:2px;\">".
+                       $optionsText . "\n".
+                       "<div style=\"padding-top:4px;padding-bottom:2px;text-align:center;\">".
                        $searchField .
                        "&nbsp;" .
                        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 );
        }
 
index 08dabe9..2edea0e 100644 (file)
@@ -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.
index 31aa3cb..0b6b38c 100644 (file)
@@ -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 (file)
index 0000000..773aba6
--- /dev/null
@@ -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;
+                       }
+               }
+       }
+}
index 7d123bd..d4cbbd1 100644 (file)
@@ -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
  */