94388b0c5588f269ffee84a22269c93169c768c7
3 if( !defined( 'MEDIAWIKI' ) )
7 * Function converts an Javascript escaped string back into a string with
8 * specified charset (default is UTF-8).
9 * Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
11 * @param $source String escaped with Javascript's escape() function
12 * @param $iconv_to String destination character set will be used as second paramether in the iconv function. Default is UTF-8.
15 function js_unescape($source, $iconv_to = 'UTF-8') {
18 $len = strlen ($source);
20 $charAt = substr ($source, $pos, 1);
23 $charAt = substr ($source, $pos, 1);
25 // we got a unicode character
27 $unicodeHexVal = substr ($source, $pos, 4);
28 $unicode = hexdec ($unicodeHexVal);
29 $decodedStr .= code2utf($unicode);
33 // we have an escaped ascii character
34 $hexVal = substr ($source, $pos, 2);
35 $decodedStr .= chr (hexdec ($hexVal));
40 $decodedStr .= $charAt;
45 if ($iconv_to != "UTF-8") {
46 $decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
53 * Function coverts number of utf char into that character.
54 * Function taken from: http://sk2.php.net/manual/en/function.utf8-encode.php#49336
59 function code2utf($num){
63 return chr(($num>>6)+
192).chr(($num&63)+
128);
65 return chr(($num>>12)+
224).chr((($num>>6)&63)+
128).chr(($num&63)+
128);
67 return chr(($num>>18)+
240).chr((($num>>12)&63)+
128).chr((($num>>6)&63)+
128) .chr(($num&63)+
128);
71 class AjaxCachePolicy
{
74 function AjaxCachePolicy( $policy = null ) {
75 $this->policy
= $policy;
78 function setPolicy( $policy ) {
79 $this->policy
= $policy;
82 function writeHeader() {
83 header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
84 if ( is_null( $this->policy
) ) {
85 // Bust cache in the head
86 header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
88 header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
89 header ("Pragma: no-cache"); // HTTP/1.0
91 header ("Expires: " . gmdate( "D, d M Y H:i:s", time() +
$this->policy
) . " GMT");
92 header ("Cache-Control: s-max-age={$this->policy},public,max-age={$this->policy}");
98 function wfSajaxSearch( $term ) {
99 global $wgContLang, $wgAjaxCachePolicy;
104 $term = str_replace( ' ', '_', $wgContLang->ucfirst(
105 $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) )
108 if ( strlen( str_replace( '_', '', $term ) )<3 )
111 $wgAjaxCachePolicy->setPolicy( 30*60 );
113 $db =& wfGetDB( DB_SLAVE
);
114 $res = $db->select( 'page', 'page_title',
115 array( 'page_namespace' => 0,
116 "page_title LIKE '". $db->strencode( $term) ."%'" ),
118 array( 'LIMIT' => $limit+
1 )
124 while ( ( $row = $db->fetchObject( $res ) ) && ( ++
$i <= $limit ) ) {
125 $nt = Title
::newFromDBkey( $row->page_title
);
126 $r .= '<li>' . $l->makeKnownLinkObj( $nt ) . "</li>\n";
129 $more = '<i>' . $l->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
130 wfMsg('moredotdotdot'),
131 "namespace=0&from=" . wfUrlEncode ( $term ) ) .
137 $term = htmlspecialchars( $term );
138 return '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">'
139 . wfMsg( 'hideresults' ) . '</a></div>'
140 . '<h1 class="firstHeading">'.wfMsg('search')
141 . '</h1><div id="contentSub">'.wfMsg('searchquery', $term) . '</div><ul><li>'
142 . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
143 wfMsg( 'searchcontaining', $term ),
144 "search=$term&fulltext=Search" )
145 . '</li><li>' . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
146 wfMsg( 'searchnamed', $term ) ,
147 "search=$term&go=Go" )
148 . "</li></ul><h2>" . wfMsg( 'articletitles', $term ) . "</h2>"
149 . '<ul>' .$r .'</ul>'.$more;