3 * Handler functions for Ajax requests
9 if ( !defined( 'MEDIAWIKI' ) ) {
14 * Function converts an Javascript escaped string back into a string with
15 * specified charset (default is UTF-8).
16 * Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
18 * @param $source String escaped with Javascript's escape() function
19 * @param $iconv_to String destination character set will be used as second parameter
20 * in the iconv function. Default is UTF-8.
23 function js_unescape( $source, $iconv_to = 'UTF-8' ) {
26 $len = strlen ( $source );
28 while ( $pos < $len ) {
29 $charAt = substr ( $source, $pos, 1 );
30 if ( $charAt == '%' ) {
32 $charAt = substr ( $source, $pos, 1 );
34 if ( $charAt == 'u' ) {
35 // we got a unicode character
37 $unicodeHexVal = substr ( $source, $pos, 4 );
38 $unicode = hexdec ( $unicodeHexVal );
39 $decodedStr .= codepointToUtf8( $unicode );
42 // we have an escaped ascii character
43 $hexVal = substr ( $source, $pos, 2 );
44 $decodedStr .= chr ( hexdec ( $hexVal ) );
48 $decodedStr .= $charAt;
53 if ( $iconv_to != "UTF-8" ) {
54 $decodedStr = iconv( "utf-8", $iconv_to, $decodedStr );