From 9bf44efcd842721e59aac8d3c247e0c033c25f7c Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Sun, 16 Dec 2007 13:32:10 +0000 Subject: [PATCH] wfSajaxSearch cleanup: * Normalize titles * Support namespaces (including special pages) * Hide empty results * Other fixes --- includes/AjaxFunctions.php | 102 ++++++++++++++++++++--------------- includes/DefaultSettings.php | 2 +- skins/monobook/main.css | 7 +++ 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/includes/AjaxFunctions.php b/includes/AjaxFunctions.php index e16f6cc49e..69212f92ae 100644 --- a/includes/AjaxFunctions.php +++ b/includes/AjaxFunctions.php @@ -74,60 +74,78 @@ function code2utf($num){ } function wfSajaxSearch( $term ) { - global $wgContLang, $wgOut; + global $wgContLang, $wgOut, $wgUser; $limit = 16; - - $l = new Linker; + $sk = $wgUser->getSkin(); $term = trim( $term ); $term = str_replace( ' ', '_', $wgContLang->ucfirst( $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) ) ) ); + $term_title = Title::newFromText( $term ); + + $r = $more = ''; + $canSearch = true; + if( $term_title && $term_title->getNamespace() != NS_SPECIAL ) { + $db = wfGetDB( DB_SLAVE ); + $res = $db->select( 'page', array( 'page_title', 'page_namespace' ), + array( 'page_namespace' => $term_title->getNamespace(), + "page_title LIKE '". $db->strencode( $term_title->getDBKey() ) ."%'" ), + "wfSajaxSearch", + array( 'LIMIT' => $limit+1 ) + ); + + $i = 0; + while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) { + $nt = Title::newFromText( $row->page_title, $row->page_namespace ); + $r .= '
  • ' . $sk->makeKnownLinkObj( $nt ) . "
  • \n"; + } + if ( $i > $limit ) { + $more = '' . $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ), + wfMsg('moredotdotdot'), + "namespace=0&from=" . wfUrlEncode ( $term ) ) . + ''; + } + } else if( $term_title && $term_title->getNamespace() == NS_SPECIAL ) { + SpecialPage::initList(); + SpecialPage::initAliasList(); + $specialPages = array_merge( + array_keys( SpecialPage::$mList ), + array_keys( SpecialPage::$mAliases ) + ); + + foreach( $specialPages as $page ) { + if( $wgContLang->uc( $page ) != $page && strpos( $page, $term_title->getText() ) === 0 ) { + $r .= '
  • ' . $sk->makeKnownLinkObj( Title::newFromText( $page, NS_SPECIAL ) ) . '
  • '; + } + } - if ( strlen( str_replace( '_', '', $term ) )<3 ) - return; - - $db = wfGetDB( DB_SLAVE ); - $res = $db->select( 'page', 'page_title', - array( 'page_namespace' => 0, - "page_title LIKE '". $db->strencode( $term) ."%'" ), - "wfSajaxSearch", - array( 'LIMIT' => $limit+1 ) - ); - - $r = ""; - - $i=0; - while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) { - $nt = Title::newFromDBkey( $row->page_title ); - $r .= '
  • ' . $l->makeKnownLinkObj( $nt ) . "
  • \n"; - } - if ( $i > $limit ) { - $more = '' . $l->makeKnownLink( $wgContLang->specialPage( "Allpages" ), - wfMsg('moredotdotdot'), - "namespace=0&from=" . wfUrlEncode ( $term ) ) . - ''; - } else { - $more = ''; + $canSearch = false; } - $subtitlemsg = ( Title::newFromText($term) ? 'searchsubtitle' : 'searchsubtitleinvalid' ); - $subtitle = $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ); #FIXME: parser is missing mTitle ! - + $valid = (bool) $term_title; $term_url = urlencode( $term ); - $term_diplay = htmlspecialchars( str_replace( '_', ' ', $term ) ); - $html = '
    ' + $term_diplay = htmlspecialchars( $valid ? $term_title->getFullText() : str_replace( '_', ' ', $term ) ); + $subtitlemsg = ( $valid ? 'searchsubtitle' : 'searchsubtitleinvalid' ); + $subtitle = wfMsgWikiHtml( $subtitlemsg, $term_diplay ); + $html = '' . '

    '.wfMsgHtml('search') - . '

    '. $subtitle . '

    " . wfMsgHtml( 'articletitles', $term_diplay ) . "

    " - . ''.$more; + . '
    '. $subtitle . '
    '; + if( $canSearch ) { + $html .= '"; + } + if( $r ) { + $html .= "

    " . wfMsgHtml( 'articletitles', $term_diplay ) . "

    " + . '' . $more; + } $response = new AjaxResponse( $html ); diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index bfde93bbf4..f066a119b4 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1246,7 +1246,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches don't keep obsolete copies of global * styles. */ -$wgStyleVersion = '103'; +$wgStyleVersion = '104'; # Server-side caching: diff --git a/skins/monobook/main.css b/skins/monobook/main.css index 7f65d4dea7..02cc9c9f9b 100644 --- a/skins/monobook/main.css +++ b/skins/monobook/main.css @@ -1446,6 +1446,13 @@ div#searchTarget ul li:before { content: "\00BB \0020"; } +div#searchTargetHide { + float:right; + border:solid 1px black; + background:gainsboro; + padding:2px; +} + div.multipageimagenavbox { border: solid 1px silver; padding: 4px; -- 2.20.1