r44773 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44772‎ | r44773 | r44774 >
Date:18:01, 18 December 2008
Author:rainman
Status:resolved (Comments)
Tags:
Comment:
New search UI tweaks:
* Show namespace checkboxes only for advanced search. Showing these for "Project Pages" searches
does provide information for advanced users, but clutters UI for everyone else. User should be able to
refer to help pages to find out which namespace are in "Project Pages" and these are also in tooltip
* put "did you mean.." inside the fieldset for increased visibility
* missing 'advanced' req param was making advanced form behave strangely, fixed
* remove "browse pages with this prefix", clutters, sometimes shows up, sometimes not. User cannot tell why
if not familiar with namespaces and logic behind the it (e.g. it shows only when one namespace is selected)
* correct placement of external search box when search is disabled
* make search messages consistent for new and existing pages
Modified paths:
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -72,6 +72,7 @@
7373 $this->searchAdvanced = $request->getVal( 'advanced' );
7474 $this->active = 'advanced';
7575 $this->sk = $user->getSkin();
 76+ $this->didYouMeanHtml = ''; # html of did you mean... link
7677 }
7778
7879 /**
@@ -117,26 +118,6 @@
118119 $this->setupPage( $term );
119120 $this->searchEngine = SearchEngine::create();
120121
121 - $t = Title::newFromText( $term );
122 -
123 - $wgOut->addHtml(
124 - Xml::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
125 - Xml::openElement( 'tr' ) .
126 - Xml::openElement( 'td' ) . "\n" .
127 - ( $this->searchAdvanced ? $this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) .
128 - Xml::closeElement('td') .
129 - Xml::closeElement('tr') .
130 - Xml::closeElement('table')
131 - );
132 -
133 - $filePrefix = $wgContLang->getFormattedNsText(NS_FILE).':';
134 - if( '' === trim( $term ) || $filePrefix === trim( $term ) ) {
135 - $wgOut->addHTML( $this->searchAdvanced ? $this->powerSearchFocus() : $this->searchFocus() );
136 - // Empty query -- straight view of search form
137 - wfProfileOut( __METHOD__ );
138 - return;
139 - }
140 -
141122 if( $wgDisableTextSearch ) {
142123 global $wgSearchForwardUrl;
143124 if( $wgSearchForwardUrl ) {
@@ -160,7 +141,9 @@
161142 wfProfileOut( __METHOD__ );
162143 return;
163144 }
164 -
 145+
 146+ $t = Title::newFromText( $term );
 147+ // fetch search results
165148 $search =& $this->searchEngine;
166149 $search->setLimitOffset( $this->limit, $this->offset );
167150 $search->setNamespaces( $this->namespaces );
@@ -168,16 +151,9 @@
169152 $rewritten = $search->replacePrefixes($term);
170153
171154 $titleMatches = $search->searchTitle( $rewritten );
 155+ if( !($titleMatches instanceof SearchResultTooMany))
 156+ $textMatches = $search->searchText( $rewritten );
172157
173 - // Sometimes the search engine knows there are too many hits
174 - if( $titleMatches instanceof SearchResultTooMany ) {
175 - $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
176 - wfProfileOut( __METHOD__ );
177 - return;
178 - }
179 -
180 - $textMatches = $search->searchText( $rewritten );
181 -
182158 // did you mean... suggestions
183159 if( $textMatches && $textMatches->hasSuggestion() ) {
184160 $st = SpecialPage::getTitleFor( 'Search' );
@@ -188,8 +164,34 @@
189165 $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
190166 $textMatches->getSuggestionSnippet().'</a>';
191167
192 - $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
 168+ $this->didYouMeanHtml = '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
193169 }
 170+
 171+ // start rendering the page
 172+ $wgOut->addHtml(
 173+ Xml::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
 174+ Xml::openElement( 'tr' ) .
 175+ Xml::openElement( 'td' ) . "\n" .
 176+ ( $this->searchAdvanced ? $this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) .
 177+ Xml::closeElement('td') .
 178+ Xml::closeElement('tr') .
 179+ Xml::closeElement('table')
 180+ );
 181+
 182+ // Sometimes the search engine knows there are too many hits
 183+ if( $titleMatches instanceof SearchResultTooMany ) {
 184+ $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
 185+ wfProfileOut( __METHOD__ );
 186+ return;
 187+ }
 188+
 189+ $filePrefix = $wgContLang->getFormattedNsText(NS_FILE).':';
 190+ if( '' === trim( $term ) || $filePrefix === trim( $term ) ) {
 191+ $wgOut->addHTML( $this->searchAdvanced ? $this->powerSearchFocus() : $this->searchFocus() );
 192+ // Empty query -- straight view of search form
 193+ wfProfileOut( __METHOD__ );
 194+ return;
 195+ }
194196
195197 // show direct page/create link
196198 if( !is_null($t) ) {
@@ -503,7 +505,7 @@
504506 $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
505507 wfMsg('search-interwiki-caption')."</div>\n";
506508 $off = $this->offset + 1;
507 - $out .= "<ul start='{$off}' class='mw-search-iwresults'>\n";
 509+ $out .= "<ul class='mw-search-iwresults'>\n";
508510
509511 // work out custom project captions
510512 $customCaptions = array();
@@ -600,32 +602,41 @@
601603 $redirect = Xml::check( 'redirs', $this->searchRedirects, array( 'value' => '1', 'id' => 'redirs' ) );
602604 $redirectLabel = Xml::label( wfMsg( 'powersearch-redir' ), 'redirs' );
603605 $searchField = Xml::input( 'search', 50, $term, array( 'type' => 'text', 'id' => 'powerSearchText' ) );
604 - $searchButton = Xml::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' ) ) . "\n";
 606+ $searchButton = Xml::submitButton( wfMsg( 'powersearch' ), array( 'name' => 'fulltext' )) . "\n";
605607 $searchTitle = SpecialPage::getTitleFor( 'Search' );
606608
 609+ $redirectText = '';
 610+ // show redirects check only if backend supports it
 611+ if($this->searchEngine->acceptListRedirects()){
 612+ "<p>".
 613+ $redirectText = $redirect . " " . $redirectLabel
 614+ ."</p>";
 615+ }
 616+
607617 $out = Xml::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
608618 Xml::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n" .
609619 "<p>" .
610620 wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) .
611621 "</p>\n" .
 622+ '<input type="hidden" name="advanced" value="'.$this->searchAdvanced."\"/>\n".
612623 $tables .
613 - "<hr style=\"clear: both\" />\n" .
614 - "<p>" .
615 - $redirect . " " . $redirectLabel .
616 - "</p>\n" .
 624+ "<hr style=\"clear: both;\" />\n".
 625+ $redirectText ."\n".
 626+ "<div style=\"padding-top:2px;padding-bottom:2px;\">".
617627 wfMsgExt( 'powersearch-field', array( 'parseinline' ) ) .
618628 "&nbsp;" .
619629 $searchField .
620630 "&nbsp;" .
621631 $searchButton .
 632+ "</div>".
622633 "</form>";
623634 $t = Title::newFromText( $term );
624 - if( $t != null && count($this->namespaces) === 1 ) {
 635+ /* if( $t != null && count($this->namespaces) === 1 ) {
625636 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
626 - }
 637+ } */
627638 return Xml::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
628639 Xml::element( 'legend', null, wfMsg('powersearch-legend') ) .
629 - $this->formHeader($term) . $out .
 640+ $this->formHeader($term) . $out . $this->didYouMeanHtml .
630641 Xml::closeElement( 'fieldset' );
631642 }
632643
@@ -729,8 +740,8 @@
730741 $searchable = SearchEngine::searchableNamespaces();
731742 $out = Xml::openElement( 'form', array( 'id' => 'search', 'method' => 'get', 'action' => $wgScript ) );
732743 $out .= Xml::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
733 - // If searching several, but not all namespaces, show what we are searching.
734 - if( count($this->namespaces) > 1 && $this->namespaces !== array_keys($searchable) ) {
 744+ // show namespaces only for advanced search
 745+ if( $this->active == 'advanced' ) {
735746 $active = array();
736747 foreach( $this->namespaces as $ns ) {
737748 $active[$ns] = $searchable[$ns];
@@ -752,12 +763,12 @@
753764 $out .= Xml::closeElement( 'form' );
754765 // Add prefix link for single-namespace searches
755766 $t = Title::newFromText( $term );
756 - if( $t != null && count($this->namespaces) === 1 ) {
 767+ /*if( $t != null && count($this->namespaces) === 1 ) {
757768 $out .= wfMsgExt( 'searchmenu-prefix', array('parseinline'), $term );
758 - }
 769+ }*/
759770 return Xml::openElement( 'fieldset', array('id' => 'mw-searchoptions','style' => 'margin:0em;') ) .
760771 Xml::element( 'legend', null, wfMsg('searchmenu-legend') ) .
761 - $this->formHeader($term) . $out .
 772+ $this->formHeader($term) . $out . $this->didYouMeanHtml .
762773 Xml::closeElement( 'fieldset' );
763774 }
764775
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1443,7 +1443,7 @@
14441444 'viewprevnext' => 'View ($1) ($2) ($3)',
14451445 'searchmenu-legend' => 'Search options',
14461446 'searchmenu-exists' => "'''There is page named \"[[\$1]]\" on this wiki'''",
1447 -'searchmenu-new' => "'''[[:$1|Create]] the page ''$1'' on this wiki!'''",
 1447+'searchmenu-new' => "'''Create the page \"[[:$1|$1]]\" on this wiki!'''",
14481448 'searchhelp-url' => 'Help:Contents',
14491449 'searchmenu-prefix' => '[[Special:PrefixIndex/$1|Browse pages with this prefix]]',
14501450 'searchmenu-help' => '[[{{MediaWiki:Searchhelp-url}}|{{int:help}}]]?', # do not translate or duplicate this message to other languages

Comments

#Comment by Aaron Schulz (talk | contribs)   20:36, 18 December 2008

XHTML error fixed in r44777

Status & tagging log