r28538 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28537‎ | r28538 | r28539 >
Date:13:32, 16 December 2007
Author:vasilievvv
Status:old
Tags:
Comment:
wfSajaxSearch cleanup:
* Normalize titles
* Support namespaces (including special pages)
* Hide empty results
* Other fixes
Modified paths:
  • /trunk/phase3/includes/AjaxFunctions.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/skins/monobook/main.css (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/monobook/main.css
@@ -1446,6 +1446,13 @@
14471447 content: "\00BB \0020";
14481448 }
14491449
 1450+div#searchTargetHide {
 1451+ float:right;
 1452+ border:solid 1px black;
 1453+ background:gainsboro;
 1454+ padding:2px;
 1455+}
 1456+
14501457 div.multipageimagenavbox {
14511458 border: solid 1px silver;
14521459 padding: 4px;
Index: trunk/phase3/includes/AjaxFunctions.php
@@ -74,60 +74,78 @@
7575 }
7676
7777 function wfSajaxSearch( $term ) {
78 - global $wgContLang, $wgOut;
 78+ global $wgContLang, $wgOut, $wgUser;
7979 $limit = 16;
 80+ $sk = $wgUser->getSkin();
8081
81 - $l = new Linker;
82 -
8382 $term = trim( $term );
8483 $term = str_replace( ' ', '_', $wgContLang->ucfirst(
8584 $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) )
8685 ) );
 86+ $term_title = Title::newFromText( $term );
8787
88 - if ( strlen( str_replace( '_', '', $term ) )<3 )
89 - return;
 88+ $r = $more = '';
 89+ $canSearch = true;
 90+ if( $term_title && $term_title->getNamespace() != NS_SPECIAL ) {
 91+ $db = wfGetDB( DB_SLAVE );
 92+ $res = $db->select( 'page', array( 'page_title', 'page_namespace' ),
 93+ array( 'page_namespace' => $term_title->getNamespace(),
 94+ "page_title LIKE '". $db->strencode( $term_title->getDBKey() ) ."%'" ),
 95+ "wfSajaxSearch",
 96+ array( 'LIMIT' => $limit+1 )
 97+ );
9098
91 - $db = wfGetDB( DB_SLAVE );
92 - $res = $db->select( 'page', 'page_title',
93 - array( 'page_namespace' => 0,
94 - "page_title LIKE '". $db->strencode( $term) ."%'" ),
95 - "wfSajaxSearch",
96 - array( 'LIMIT' => $limit+1 )
97 - );
 99+ $i = 0;
 100+ while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) {
 101+ $nt = Title::newFromText( $row->page_title, $row->page_namespace );
 102+ $r .= '<li>' . $sk->makeKnownLinkObj( $nt ) . "</li>\n";
 103+ }
 104+ if ( $i > $limit ) {
 105+ $more = '<i>' . $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
 106+ wfMsg('moredotdotdot'),
 107+ "namespace=0&from=" . wfUrlEncode ( $term ) ) .
 108+ '</i>';
 109+ }
 110+ } else if( $term_title && $term_title->getNamespace() == NS_SPECIAL ) {
 111+ SpecialPage::initList();
 112+ SpecialPage::initAliasList();
 113+ $specialPages = array_merge(
 114+ array_keys( SpecialPage::$mList ),
 115+ array_keys( SpecialPage::$mAliases )
 116+ );
98117
99 - $r = "";
 118+ foreach( $specialPages as $page ) {
 119+ if( $wgContLang->uc( $page ) != $page && strpos( $page, $term_title->getText() ) === 0 ) {
 120+ $r .= '<li>' . $sk->makeKnownLinkObj( Title::newFromText( $page, NS_SPECIAL ) ) . '</li>';
 121+ }
 122+ }
100123
101 - $i=0;
102 - while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) {
103 - $nt = Title::newFromDBkey( $row->page_title );
104 - $r .= '<li>' . $l->makeKnownLinkObj( $nt ) . "</li>\n";
 124+ $canSearch = false;
105125 }
106 - if ( $i > $limit ) {
107 - $more = '<i>' . $l->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
108 - wfMsg('moredotdotdot'),
109 - "namespace=0&from=" . wfUrlEncode ( $term ) ) .
110 - '</i>';
111 - } else {
112 - $more = '';
113 - }
114126
115 - $subtitlemsg = ( Title::newFromText($term) ? 'searchsubtitle' : 'searchsubtitleinvalid' );
116 - $subtitle = $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ); #FIXME: parser is missing mTitle !
117 -
 127+ $valid = (bool) $term_title;
118128 $term_url = urlencode( $term );
119 - $term_diplay = htmlspecialchars( str_replace( '_', ' ', $term ) );
120 - $html = '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">'
 129+ $term_diplay = htmlspecialchars( $valid ? $term_title->getFullText() : str_replace( '_', ' ', $term ) );
 130+ $subtitlemsg = ( $valid ? 'searchsubtitle' : 'searchsubtitleinvalid' );
 131+ $subtitle = wfMsgWikiHtml( $subtitlemsg, $term_diplay );
 132+ $html = '<div id="searchTargetHide"><a onclick="Searching_Hide_Results();">'
121133 . wfMsgHtml( 'hideresults' ) . '</a></div>'
122134 . '<h1 class="firstHeading">'.wfMsgHtml('search')
123 - . '</h1><div id="contentSub">'. $subtitle . '</div><ul><li>'
124 - . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
125 - wfMsgHtml( 'searchcontaining', $term_diplay ),
126 - "search={$term_url}&fulltext=Search" )
127 - . '</li><li>' . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
128 - wfMsgHtml( 'searchnamed', $term_diplay ) ,
129 - "search={$term_url}&go=Go" )
130 - . "</li></ul><h2>" . wfMsgHtml( 'articletitles', $term_diplay ) . "</h2>"
131 - . '<ul>' .$r .'</ul>'.$more;
 135+ . '</h1><div id="contentSub">'. $subtitle . '</div>';
 136+ if( $canSearch ) {
 137+ $html .= '<ul><li>'
 138+ . $sk->makeKnownLink( $wgContLang->specialPage( 'Search' ),
 139+ wfMsgHtml( 'searchcontaining', $term_diplay ),
 140+ "search={$term_url}&fulltext=Search" )
 141+ . '</li><li>' . $sk->makeKnownLink( $wgContLang->specialPage( 'Search' ),
 142+ wfMsgHtml( 'searchnamed', $term_diplay ) ,
 143+ "search={$term_url}&go=Go" )
 144+ . "</li></ul>";
 145+ }
 146+ if( $r ) {
 147+ $html .= "<h2>" . wfMsgHtml( 'articletitles', $term_diplay ) . "</h2>"
 148+ . '<ul>' .$r .'</ul>' . $more;
 149+ }
132150
133151 $response = new AjaxResponse( $html );
134152
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1246,7 +1246,7 @@
12471247 * to ensure that client-side caches don't keep obsolete copies of global
12481248 * styles.
12491249 */
1250 -$wgStyleVersion = '103';
 1250+$wgStyleVersion = '104';
12511251
12521252
12531253 # Server-side caching:

Status & tagging log