r51228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51227‎ | r51228 | r51229 >
Date:13:22, 31 May 2009
Author:rainman
Status:ok
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)
  • /trunk/phase3/skins/common/search.js (added) (history)
  • /trunk/phase3/skins/common/shared.css (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -820,6 +820,9 @@
821821 'powersearch-ns',
822822 'powersearch-redir',
823823 'powersearch-field',
 824+ 'powersearch-togglelabel',
 825+ 'powersearch-toggleall',
 826+ 'powersearch-togglenone',
824827 'search-external',
825828 'searchdisabled',
826829 'googlesearch',
Index: trunk/phase3/skins/common/search.js
@@ -0,0 +1,42 @@
 2+// JS specific to Special:Search
 3+
 4+// change the search link to what user entered
 5+function mwSearchHeaderClick(obj){
 6+ var searchbox = document.getElementById("searchText");
 7+ if( searchbox == null )
 8+ searchbox = document.getElementById("powerSearchText");
 9+ if( searchbox == null)
 10+ return; // should always have either normal or advanced search
 11+
 12+ var searchterm = searchbox.value;
 13+ var parts = obj.href.split("search=");
 14+ var lastpart = '';
 15+ if( parts[1].indexOf('&') >= 0 )
 16+ lastpart = parts[1].substring( parts[1].indexOf('&') )
 17+ obj.href = parts[0] + "search=" + encodeURIComponent(searchterm) + lastpart;
 18+}
 19+
 20+function mwToggleSearchCheckboxes( btn ) {
 21+ if( !document.getElementById ) return;
 22+
 23+ var nsInputs = document.getElementById( 'powersearch' ).getElementsByTagName( 'input' );
 24+ var isChecked = false;
 25+
 26+ for ( var i = 0; i < nsInputs.length; i++ ) {
 27+ var pattern = /^ns/;
 28+ if ( ( nsInputs[i].type == 'checkbox' ) && ( pattern.test( nsInputs[i].name ) ) ) {
 29+ switch ( btn.value ) {
 30+ case "None":
 31+ if ( nsInputs[i].checked ) {
 32+ nsInputs[i].checked = false;
 33+ }
 34+ break;
 35+ case "All":
 36+ if ( !nsInputs[i].checked ) {
 37+ nsInputs[i].checked = true;
 38+ }
 39+ break;
 40+ }
 41+ }
 42+ }
 43+}
Index: trunk/phase3/skins/common/shared.css
@@ -123,6 +123,7 @@
124124 .mw-search-results li {
125125 padding-bottom: 1em;
126126 list-style:none;
 127+ list-style-image:none;
127128 }
128129 .mw-search-results li a {
129130 font-size: 108%;
@@ -214,6 +215,23 @@
215216
216217
217218 /*
 219+ * Advanced PowerSearch box
 220+ */
 221+
 222+td#mw-search-togglebox {
 223+ text-align: right;
 224+}
 225+
 226+div#mw-search-redirbox {
 227+ width:100%;
 228+}
 229+
 230+table#mw-search-redirtable {
 231+ width:95%;
 232+}
 233+
 234+
 235+/*
218236 * UserRights stuff
219237 */
220238 .mw-userrights-disabled {
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1485,7 +1485,7 @@
14861486 * to ensure that client-side caches don't keep obsolete copies of global
14871487 * styles.
14881488 */
1489 -$wgStyleVersion = '220';
 1489+$wgStyleVersion = '221';
14901490
14911491
14921492 # Server-side caching:
Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -322,6 +322,8 @@
323323 }
324324 $wgOut->setArticleRelated( false );
325325 $wgOut->setRobotPolicy( 'noindex,nofollow' );
 326+ // add javascript specific to special:search
 327+ $wgOut->addScriptFile( 'search.js' );
326328 }
327329
328330 /**
@@ -535,7 +537,7 @@
536538 $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions );
537539 $prev = $result->getInterwikiPrefix();
538540 }
539 - // FIXME: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
 541+ // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax)..
540542 $out .= "</ul></div>\n";
541543
542544 // convert the whole thing to desired language variant
@@ -612,20 +614,32 @@
613615 $namespaces = SearchEngine::searchableNamespaces();
614616
615617 $tables = $this->namespaceTables( $namespaces );
616 -
 618+
 619+ // include redirects in the search
617620 $redirect = Xml::check( 'redirs', $this->searchRedirects, array( 'value' => '1', 'id' => 'redirs' ) );
618621 $redirectLabel = Xml::label( wfMsg( 'powersearch-redir' ), 'redirs' );
619 - $searchField = Xml::inputLabel( wfMsg('powersearch-field'), 'search', 'powerSearchText', 50, $term,
620 - array( 'type' => 'text') );
621 - $searchButton = Xml::submitButton( wfMsg( 'powersearch' ) ) . "\n";
622 - $searchTitle = SpecialPage::getTitleFor( 'Search' );
623622
624623 $redirectText = '';
625624 // show redirects check only if backend supports it
626625 if( $this->searchEngine->acceptListRedirects() ) {
627 - $redirectText = "<p>". $redirect . " " . $redirectLabel ."</p>";
 626+ $redirectText = "<td id='powersearch-rediropt'>". $redirect . " " . $redirectLabel ."</td>";
628627 }
 628+
 629+
 630+ $searchField = Xml::inputLabel( wfMsg( 'powersearch-field' ), 'search', 'powerSearchText', 50, $term,
 631+ array( 'type' => 'text') );
629632
 633+ // toggle for turning on and off all checkboxes
 634+ $selectOptionsLabel = Xml::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' );
 635+ $selectAllButton = Xml::submitButton( wfMsg( 'powersearch-toggleall' ), array( 'id' => 'mw-search-toggleall', 'onclick' => 'mwToggleSearchCheckboxes(this);return false;' ) );
 636+ $selectNoneButton = Xml::submitButton( wfMsg( 'powersearch-togglenone' ), array( 'id' => 'mw-search-togglenone', 'onclick' => 'mwToggleSearchCheckboxes(this);return false;' ) );
 637+ $selectOptionsText = "<td id='mw-search-togglebox'>" . $selectOptionsLabel . $selectAllButton . $selectNoneButton . "</td>";
 638+
 639+ $searchButton = Xml::submitButton( wfMsg( 'powersearch' ) ) . "\n";
 640+ $searchTitle = SpecialPage::getTitleFor( 'Search' );
 641+
 642+ $optionsText = "<div id='mw-search-redirbox'><table id='mw-search-redirtable'><tr>" . $redirectText . $selectOptionsText . "</tr></table></div>";
 643+
630644 $out = Xml::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
631645 Xml::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
632646 "<p>" .
@@ -634,8 +648,8 @@
635649 '<input type="hidden" name="advanced" value="'.$this->searchAdvanced."\"/>\n".
636650 $tables .
637651 "<hr style=\"clear: both;\" />\n".
638 - $redirectText ."\n".
639 - "<div style=\"padding-top:2px;padding-bottom:2px;\">".
 652+ $optionsText . "\n".
 653+ "<div style=\"padding-top:4px;padding-bottom:2px;text-align:center;\">".
640654 $searchField .
641655 "&nbsp;" .
642656 Xml::hidden( 'fulltext', 'Advanced search' ) . "\n" .
@@ -691,7 +705,7 @@
692706 if( $this->active == 'default' ) {
693707 $out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );
694708 } else {
695 - $out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultNamespaces(), $m, $tt );
 709+ $out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultNamespaces(), $m, $tt);
696710 }
697711 $out .= $sep;
698712
@@ -777,13 +791,7 @@
778792 $out .= Xml::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'searchText' ) ) . "\n";
779793 $out .= Xml::hidden( 'fulltext', 'Search' );
780794 $out .= Xml::submitButton( wfMsg( 'searchbutton' ) );
781 - //$out .= ' (' . wfMsgExt('searchmenu-help',array('parseinline') ) . ')';
782795 $out .= Xml::closeElement( 'form' );
783 - // Add prefix link for single-namespace searches
784 - $t = Title::newFromText( $term );
785 - /*if( $t != null && count($this->namespaces) === 1 ) {
786 - $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
787 - }*/
788796 return $out . $this->didYouMeanHtml;
789797 }
790798
@@ -799,7 +807,9 @@
800808 $stParams = wfArrayToCGI( array( 'search' => $term, 'fulltext' => wfMsg( 'search' ) ), $opt );
801809
802810 return Xml::element( 'a',
803 - array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip ),
 811+ array( 'href'=> $st->getLocalURL( $stParams ), 'title' => $tooltip,
 812+ 'onmousedown' => 'mwSearchHeaderClick(this);',
 813+ 'onkeydown' => 'mwSearchHeaderClick(this);'),
804814 $label );
805815 }
806816
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1490,6 +1490,9 @@
14911491 'powersearch-ns' => 'Search in namespaces:',
14921492 'powersearch-redir' => 'List redirects',
14931493 'powersearch-field' => 'Search for',
 1494+'powersearch-togglelabel' => 'Check: ',
 1495+'powersearch-toggleall' => 'All',
 1496+'powersearch-togglenone' => 'None',
14941497 'search-external' => 'External search',
14951498 'searchdisabled' => '{{SITENAME}} search is disabled.
14961499 You can search via Google in the meantime.

Follow-up revisions

RevisionCommit summaryAuthorDate
r51251Don't use submit buttons in r51228 for select all/none since that confuses th...rainman17:35, 31 May 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r50207Redesign of the "new search UI" per Trevor's design plans from usability wiki:...rainman23:07, 4 May 2009

Status & tagging log