MediaWiki:Gadget-watchlist.js: различия между версиями

Содержимое удалено Содержимое добавлено
м исправление
используем mw.Api() для API-запроса вместо $.ajax()
Строка 241:
function changeWatchState(e) {
var $star = $(this), errorMsg = '';
var req = {
token: mw.user.tokens.get('watchToken'),
title: getLinkTitle($star)
};
var action;
var req = {unwatch;
if ($star.attr('href').includes('&action=unwatch')) {
req.unwatch = '';
action = 'unwatch';
} else {
action = 'watch';
}
title:var titles = getLinkTitle($star);
$star
.removeClass('gadgetWatchlist-failure')
.addClass('gadgetWatchlist-waiting');
new mw.Api().postWithToken('watch', {
$.ajax({
typeaction: 'POSTwatch',
dataTypetitles: 'json'titles,
unwatch: unwatch,
url: mw.util.wikiScript('api') + '?action=watch&format=json',
dataformatversion: req2,
timeout: 5000,}).then(
success: function (resp) {
if (!resp.errorwatch || !resp.watch[0]) {
errorMsg = resp.error.info;
} else if (!resp.watch) {
errorMsg = 'empty response';
} else if (typeof resp.watch[0].unwatched === 'stringboolean') {
changeWatchStateSuccess(req.titletitles, true);
} else if (typeof resp.watch[0].watched === 'stringboolean') {
changeWatchStateSuccess(req.titletitles, false);
} else {
errorMsg = strings.unrecognizedReponse;
}
},
error: function (xhr, statuscode, errordata) {
errorMsgvar errorText = status + ':' + error;(
}, // HTTP error
data.textStatus ||
complete: function () { // update unwatch link
 
$star.removeClass('gadgetWatchlist-waiting');
if // (errorMsg)API {error
(data.error && data.error.info)
$star
);
.attr('title', strings.error + ': ' + errorMsg)
errorMsg = resp.error.infocode;
.addClass('gadgetWatchlist-failure gadgetWatchlist-' + action + 'Link');
} else if (!resp.watcherrorText) {
errorMsg += ': ' + errorText;
}
};
complete: ).always(function () { // update unwatch link
$star.removeClass('gadgetWatchlist-waiting');
if (errorMsg) {
$star
.attr('title', strings.error + ': ' + errorMsg)
.addClass('gadgetWatchlist-failure gadgetWatchlist-' + action + 'Link');
}
});
e.preventDefault();
return false;
}