3 if( !defined( 'MEDIAWIKI' ) )
6 require_once('WebRequest.php');
9 * Function converts an Javascript escaped string back into a string with
10 * specified charset (default is UTF-8).
11 * Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
13 * @param $source String escaped with Javascript's escape() function
14 * @param $iconv_to String destination character set will be used as second paramether in the iconv function. Default is UTF-8.
17 function js_unescape($source, $iconv_to = 'UTF-8') {
20 $len = strlen ($source);
22 $charAt = substr ($source, $pos, 1);
25 $charAt = substr ($source, $pos, 1);
27 // we got a unicode character
29 $unicodeHexVal = substr ($source, $pos, 4);
30 $unicode = hexdec ($unicodeHexVal);
31 $decodedStr .= code2utf($unicode);
35 // we have an escaped ascii character
36 $hexVal = substr ($source, $pos, 2);
37 $decodedStr .= chr (hexdec ($hexVal));
42 $decodedStr .= $charAt;
47 if ($iconv_to != "UTF-8") {
48 $decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
55 * Function coverts number of utf char into that character.
56 * Function taken from: http://sk2.php.net/manual/en/function.utf8-encode.php#49336
61 function code2utf($num){
65 return chr(($num>>6)+
192).chr(($num&63)+
128);
67 return chr(($num>>12)+
224).chr((($num>>6)&63)+
128).chr(($num&63)+
128);
69 return chr(($num>>18)+
240).chr((($num>>12)&63)+
128).chr((($num>>6)&63)+
128) .chr(($num&63)+
128);
73 function wfSajaxSearch( $term ) {
74 global $wgContLang, $wgOut;
79 $term = str_replace( ' ', '_', $wgContLang->ucfirst(
80 $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) )
83 if ( strlen( str_replace( '_', '', $term ) )<3 )
86 $db =& wfGetDB( DB_SLAVE
);
87 $res = $db->select( 'page', 'page_title',
88 array( 'page_namespace' => 0,
89 "page_title LIKE '". $db->strencode( $term) ."%'" ),
91 array( 'LIMIT' => $limit+
1 )
97 while ( ( $row = $db->fetchObject( $res ) ) && ( ++
$i <= $limit ) ) {
98 $nt = Title
::newFromDBkey( $row->page_title
);
99 $r .= '<li>' . $l->makeKnownLinkObj( $nt ) . "</li>\n";
102 $more = '<i>' . $l->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
103 wfMsg('moredotdotdot'),
104 "namespace=0&from=" . wfUrlEncode ( $term ) ) .
110 $subtitlemsg = ( Title
::newFromText($term) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
111 $subtitle = $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ); #FIXME: parser is missing mTitle !
113 $term = htmlspecialchars( $term );
114 $html = '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">'
115 . wfMsg( 'hideresults' ) . '</a></div>'
116 . '<h1 class="firstHeading">'.wfMsg('search')
117 . '</h1><div id="contentSub">'. $subtitle . '</div><ul><li>'
118 . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
119 wfMsg( 'searchcontaining', $term ),
120 "search=$term&fulltext=Search" )
121 . '</li><li>' . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
122 wfMsg( 'searchnamed', $term ) ,
123 "search=$term&go=Go" )
124 . "</li></ul><h2>" . wfMsg( 'articletitles', $term ) . "</h2>"
125 . '<ul>' .$r .'</ul>'.$more;
127 $response = new AjaxResponse( $html );
129 $response->setCacheDuration( 30*60 );