Fixes Bug #28838 — remove CSS references to div.editsection which grep
[lhc/web/wiklou.git] / includes / AjaxFunctions.php
1 <?php
2 /**
3 * Handler functions for Ajax requests
4 *
5 * @file
6 * @ingroup Ajax
7 */
8
9 if ( !defined( 'MEDIAWIKI' ) ) {
10 die( 1 );
11 }
12
13 /**
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
17 *
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.
21 * @return string
22 */
23 function js_unescape( $source, $iconv_to = 'UTF-8' ) {
24 $decodedStr = '';
25 $pos = 0;
26 $len = strlen ( $source );
27
28 while ( $pos < $len ) {
29 $charAt = substr ( $source, $pos, 1 );
30 if ( $charAt == '%' ) {
31 $pos++;
32 $charAt = substr ( $source, $pos, 1 );
33
34 if ( $charAt == 'u' ) {
35 // we got a unicode character
36 $pos++;
37 $unicodeHexVal = substr ( $source, $pos, 4 );
38 $unicode = hexdec ( $unicodeHexVal );
39 $decodedStr .= codepointToUtf8( $unicode );
40 $pos += 4;
41 } else {
42 // we have an escaped ascii character
43 $hexVal = substr ( $source, $pos, 2 );
44 $decodedStr .= chr ( hexdec ( $hexVal ) );
45 $pos += 2;
46 }
47 } else {
48 $decodedStr .= $charAt;
49 $pos++;
50 }
51 }
52
53 if ( $iconv_to != "UTF-8" ) {
54 $decodedStr = iconv( "utf-8", $iconv_to, $decodedStr );
55 }
56
57 return $decodedStr;
58 }