7 if( !defined( 'MEDIAWIKI' ) ) {
12 * Function converts an Javascript escaped string back into a string with
13 * specified charset (default is UTF-8).
14 * Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
16 * @param $source String escaped with Javascript's escape() function
17 * @param $iconv_to String destination character set will be used as second paramether in the iconv function. Default is UTF-8.
20 function js_unescape($source, $iconv_to = 'UTF-8') {
23 $len = strlen ($source);
26 $charAt = substr ($source, $pos, 1);
29 $charAt = substr ($source, $pos, 1);
31 // we got a unicode character
33 $unicodeHexVal = substr ($source, $pos, 4);
34 $unicode = hexdec ($unicodeHexVal);
35 $decodedStr .= code2utf($unicode);
38 // we have an escaped ascii character
39 $hexVal = substr ($source, $pos, 2);
40 $decodedStr .= chr (hexdec ($hexVal));
44 $decodedStr .= $charAt;
49 if ($iconv_to != "UTF-8") {
50 $decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
57 * Function coverts number of utf char into that character.
58 * Function taken from: http://www.php.net/manual/en/function.utf8-encode.php#49336
63 function code2utf($num){
67 return chr(($num>>6)+
192).chr(($num&63)+
128);
69 return chr(($num>>12)+
224).chr((($num>>6)&63)+
128).chr(($num&63)+
128);
71 return chr(($num>>18)+
240).chr((($num>>12)&63)+
128).chr((($num>>6)&63)+
128) .chr(($num&63)+
128);
76 * Called for AJAX watch/unwatch requests.
77 * @param $pagename Prefixed title string for page to watch/unwatch
78 * @param $watch String 'w' to watch, 'u' to unwatch
79 * @return String '<w#>' or '<u#>' on successful watch or unwatch,
80 * respectively, followed by an HTML message to display in the alert box; or
83 function wfAjaxWatch($pagename = "", $watch = "") {
85 // redirect to action=(un)watch, which will display the database lock
90 if('w' !== $watch && 'u' !== $watch) {
93 $watch = 'w' === $watch;
95 $title = Title
::newFromDBkey($pagename);
100 $article = new Article($title);
101 $watching = $title->userIsWatching();
105 $dbw = wfGetDB(DB_MASTER
);
107 $ok = $article->doWatch();
112 $dbw = wfGetDB(DB_MASTER
);
114 $ok = $article->doUnwatch();
118 // Something stopped the change
119 if( isset($ok) && !$ok ) {
123 return '<w#>'.wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
125 return '<u#>'.wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );