2006-03-26 19:03:14 +00:00
|
|
|
<?php
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Ajax
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
|
|
|
|
|
2007-04-21 14:44:56 +00:00
|
|
|
if( !defined( 'MEDIAWIKI' ) ) {
|
|
|
|
|
die( 1 );
|
|
|
|
|
}
|
2006-03-26 19:03:14 +00:00
|
|
|
|
|
|
|
|
/**
|
2006-04-19 15:46:24 +00:00
|
|
|
* Function converts an Javascript escaped string back into a string with
|
|
|
|
|
* specified charset (default is UTF-8).
|
2006-03-26 19:03:14 +00:00
|
|
|
* Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $source String escaped with Javascript's escape() function
|
2008-11-04 15:57:40 +00:00
|
|
|
* @param $iconv_to String destination character set will be used as second parameter
|
|
|
|
|
* in the iconv function. Default is UTF-8.
|
2006-03-26 19:03:14 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function js_unescape($source, $iconv_to = 'UTF-8') {
|
2007-04-21 14:44:56 +00:00
|
|
|
$decodedStr = '';
|
|
|
|
|
$pos = 0;
|
|
|
|
|
$len = strlen ($source);
|
|
|
|
|
|
|
|
|
|
while ($pos < $len) {
|
|
|
|
|
$charAt = substr ($source, $pos, 1);
|
|
|
|
|
if ($charAt == '%') {
|
|
|
|
|
$pos++;
|
|
|
|
|
$charAt = substr ($source, $pos, 1);
|
|
|
|
|
if ($charAt == 'u') {
|
|
|
|
|
// we got a unicode character
|
|
|
|
|
$pos++;
|
|
|
|
|
$unicodeHexVal = substr ($source, $pos, 4);
|
|
|
|
|
$unicode = hexdec ($unicodeHexVal);
|
|
|
|
|
$decodedStr .= code2utf($unicode);
|
|
|
|
|
$pos += 4;
|
|
|
|
|
} else {
|
|
|
|
|
// we have an escaped ascii character
|
|
|
|
|
$hexVal = substr ($source, $pos, 2);
|
|
|
|
|
$decodedStr .= chr (hexdec ($hexVal));
|
|
|
|
|
$pos += 2;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$decodedStr .= $charAt;
|
|
|
|
|
$pos++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($iconv_to != "UTF-8") {
|
|
|
|
|
$decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
|
|
|
|
|
}
|
2006-03-26 19:03:14 +00:00
|
|
|
|
2007-04-21 14:44:56 +00:00
|
|
|
return $decodedStr;
|
2006-03-26 19:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function coverts number of utf char into that character.
|
2008-03-27 18:52:08 +00:00
|
|
|
* Function taken from: http://www.php.net/manual/en/function.utf8-encode.php#49336
|
2006-03-26 19:03:14 +00:00
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $num Integer
|
2006-03-26 19:03:14 +00:00
|
|
|
* @return utf8char
|
|
|
|
|
*/
|
|
|
|
|
function code2utf($num){
|
|
|
|
|
if ( $num<128 )
|
|
|
|
|
return chr($num);
|
|
|
|
|
if ( $num<2048 )
|
|
|
|
|
return chr(($num>>6)+192).chr(($num&63)+128);
|
|
|
|
|
if ( $num<65536 )
|
|
|
|
|
return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
|
|
|
|
|
if ( $num<2097152 )
|
|
|
|
|
return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-26 23:53:34 +00:00
|
|
|
/**
|
|
|
|
|
* Called for AJAX watch/unwatch requests.
|
2007-06-22 17:36:59 +00:00
|
|
|
* @param $pagename Prefixed title string for page to watch/unwatch
|
2006-12-26 23:53:34 +00:00
|
|
|
* @param $watch String 'w' to watch, 'u' to unwatch
|
2008-04-14 07:45:50 +00:00
|
|
|
* @return String '<w#>' or '<u#>' on successful watch or unwatch,
|
2007-06-22 17:36:59 +00:00
|
|
|
* respectively, followed by an HTML message to display in the alert box; or
|
|
|
|
|
* '<err#>' on error
|
2006-12-26 23:53:34 +00:00
|
|
|
*/
|
2007-06-22 17:36:59 +00:00
|
|
|
function wfAjaxWatch($pagename = "", $watch = "") {
|
|
|
|
|
if(wfReadOnly()) {
|
|
|
|
|
// redirect to action=(un)watch, which will display the database lock
|
|
|
|
|
// message
|
2008-04-14 07:45:50 +00:00
|
|
|
return '<err#>';
|
2007-06-22 17:36:59 +00:00
|
|
|
}
|
2006-12-26 23:53:34 +00:00
|
|
|
|
2007-06-22 17:36:59 +00:00
|
|
|
if('w' !== $watch && 'u' !== $watch) {
|
2006-12-26 23:53:34 +00:00
|
|
|
return '<err#>';
|
2007-06-22 17:36:59 +00:00
|
|
|
}
|
2006-12-26 23:53:34 +00:00
|
|
|
$watch = 'w' === $watch;
|
|
|
|
|
|
2007-12-31 22:42:47 +00:00
|
|
|
$title = Title::newFromDBkey($pagename);
|
2007-06-22 17:36:59 +00:00
|
|
|
if(!$title) {
|
|
|
|
|
// Invalid title
|
2006-12-26 23:53:34 +00:00
|
|
|
return '<err#>';
|
2007-06-22 17:36:59 +00:00
|
|
|
}
|
2006-12-26 23:53:34 +00:00
|
|
|
$article = new Article($title);
|
|
|
|
|
$watching = $title->userIsWatching();
|
|
|
|
|
|
|
|
|
|
if($watch) {
|
|
|
|
|
if(!$watching) {
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbw = wfGetDB(DB_MASTER);
|
2006-12-26 23:53:34 +00:00
|
|
|
$dbw->begin();
|
2008-08-04 03:37:32 +00:00
|
|
|
$ok = $article->doWatch();
|
2006-12-26 23:53:34 +00:00
|
|
|
$dbw->commit();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if($watching) {
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbw = wfGetDB(DB_MASTER);
|
2006-12-26 23:53:34 +00:00
|
|
|
$dbw->begin();
|
2008-08-04 03:37:32 +00:00
|
|
|
$ok = $article->doUnwatch();
|
2006-12-26 23:53:34 +00:00
|
|
|
$dbw->commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-08-04 03:37:32 +00:00
|
|
|
// Something stopped the change
|
|
|
|
|
if( isset($ok) && !$ok ) {
|
|
|
|
|
return '<err#>';
|
|
|
|
|
}
|
2007-06-22 17:36:59 +00:00
|
|
|
if( $watch ) {
|
|
|
|
|
return '<w#>'.wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
|
|
|
|
|
} else {
|
|
|
|
|
return '<u#>'.wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );
|
|
|
|
|
}
|
2006-12-26 23:53:34 +00:00
|
|
|
}
|
2008-11-15 01:29:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called in some places (currently just extensions)
|
2008-11-16 02:42:30 +00:00
|
|
|
* to get the thumbnail URL for a given file at a given resolution.
|
2008-11-15 01:29:52 +00:00
|
|
|
*/
|
|
|
|
|
function wfAjaxGetThumbnailUrl( $file, $width, $height ) {
|
|
|
|
|
$file = wfFindFile( $file );
|
|
|
|
|
|
|
|
|
|
if ( !$file || !$file->exists() )
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
$url = $file->getThumbnail( $width, $height )->url;
|
|
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
|
}
|