00001 <?php
00007 if( !defined( 'MEDIAWIKI' ) ) {
00008 die( 1 );
00009 }
00010
00021 function js_unescape($source, $iconv_to = 'UTF-8') {
00022 $decodedStr = '';
00023 $pos = 0;
00024 $len = strlen ($source);
00025
00026 while ($pos < $len) {
00027 $charAt = substr ($source, $pos, 1);
00028 if ($charAt == '%') {
00029 $pos++;
00030 $charAt = substr ($source, $pos, 1);
00031 if ($charAt == 'u') {
00032
00033 $pos++;
00034 $unicodeHexVal = substr ($source, $pos, 4);
00035 $unicode = hexdec ($unicodeHexVal);
00036 $decodedStr .= code2utf($unicode);
00037 $pos += 4;
00038 } else {
00039
00040 $hexVal = substr ($source, $pos, 2);
00041 $decodedStr .= chr (hexdec ($hexVal));
00042 $pos += 2;
00043 }
00044 } else {
00045 $decodedStr .= $charAt;
00046 $pos++;
00047 }
00048 }
00049
00050 if ($iconv_to != "UTF-8") {
00051 $decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
00052 }
00053
00054 return $decodedStr;
00055 }
00056
00064 function code2utf($num){
00065 if ( $num<128 )
00066 return chr($num);
00067 if ( $num<2048 )
00068 return chr(($num>>6)+192).chr(($num&63)+128);
00069 if ( $num<65536 )
00070 return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
00071 if ( $num<2097152 )
00072 return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
00073 return '';
00074 }
00075
00084 function wfAjaxWatch($pagename = "", $watch = "") {
00085 if(wfReadOnly()) {
00086
00087
00088 return '<err#>';
00089 }
00090
00091 if('w' !== $watch && 'u' !== $watch) {
00092 return '<err#>';
00093 }
00094 $watch = 'w' === $watch;
00095
00096 $title = Title::newFromDBkey($pagename);
00097 if(!$title) {
00098
00099 return '<err#>';
00100 }
00101 $article = new Article($title);
00102 $watching = $title->userIsWatching();
00103
00104 if($watch) {
00105 if(!$watching) {
00106 $dbw = wfGetDB(DB_MASTER);
00107 $dbw->begin();
00108 $ok = $article->doWatch();
00109 $dbw->commit();
00110 }
00111 } else {
00112 if($watching) {
00113 $dbw = wfGetDB(DB_MASTER);
00114 $dbw->begin();
00115 $ok = $article->doUnwatch();
00116 $dbw->commit();
00117 }
00118 }
00119
00120 if( isset($ok) && !$ok ) {
00121 return '<err#>';
00122 }
00123 if( $watch ) {
00124 return '<w#>'.wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
00125 } else {
00126 return '<u#>'.wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );
00127 }
00128 }
00129
00134 function wfAjaxGetThumbnailUrl( $file, $width, $height ) {
00135 $file = wfFindFile( $file );
00136
00137 if ( !$file || !$file->exists() )
00138 return null;
00139
00140 $url = $file->getThumbnail( $width, $height )->url;
00141
00142 return $url;
00143 }
00144
00149 function wfAjaxGetFileUrl( $file ) {
00150 $file = wfFindFile( $file );
00151
00152 if ( !$file || !$file->exists() )
00153 return null;
00154
00155 $url = $file->getUrl();
00156
00157 return $url;
00158 }