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 .= code2utf( $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 );
61 * Function coverts number of utf char into that character.
62 * Function taken from: http://www.php.net/manual/en/function.utf8-encode.php#49336
67 function code2utf( $num ) {
73 return chr( ( $num >> 6 ) +
192 ) . chr( ( $num&63 ) +
128 );
77 return chr( ( $num >> 12 ) +
224 ) . chr( ( ( $num >> 6 )&63 ) +
128 ) . chr( ( $num&63 ) +
128 );
80 if ( $num < 2097152 ) {
81 return chr( ( $num >> 18 ) +
240 ) . chr( ( ( $num >> 12 )&63 ) +
128 ) . chr( ( ( $num >> 6 )&63 ) +
128 ) . chr( ( $num&63 ) +
128 );