User:Chaotic Enby/Unblock wizard.js: Difference between revisions

From Test Wiki
Content deleted Content added
by aasim
doing some renaming
Line 32: Line 32:
});
});


var afc = {}, ui = {}, block = {};
var wizard = {}, ui = {}, block = {};
window.afc = afc;
window.wizard = wizard;
afc.ui = ui;
wizard.ui = ui;


var config = {
var config = {
debounceDelay: 500,
debounceDelay: 500,
redirectionDelay: 1000,
redirectionDelay: 1000
defaultAfcTopic: 'other'
};
};


Line 117: Line 116:
// Two different API objects so that aborts on the lookupApi don't stop the final
// Two different API objects so that aborts on the lookupApi don't stop the final
// evaluate process
// evaluate process
afc.api = new mw.Api(apiOptions);
wizard.api = new mw.Api(apiOptions);
afc.lookupApi = new mw.Api(apiOptions);
wizard.lookupApi = new mw.Api(apiOptions);
afc.lookupApi.get({
wizard.lookupApi.get({
"action": "query",
"action": "query",
"meta": "userinfo",
"meta": "userinfo",
Line 284: Line 283:
mw.util.addCSS('.skin-modern .projectTagOverlay, .skin-monobook .projectTagOverlay { font-size: 130%; }');
mw.util.addCSS('.skin-modern .projectTagOverlay, .skin-monobook .projectTagOverlay { font-size: 130%; }');


afc.beforeUnload = function (e) {
wizard.beforeUnload = function (e) {
var changedContent = false;
var changedContent = false;
for (var [i, label] of questionLabels.entries()) {
for (var [i, label] of questionLabels.entries()) {
Line 300: Line 299:
return '';
return '';
};
};
$(window).on('beforeunload', afc.beforeUnload);
$(window).on('beforeunload', wizard.beforeUnload);
}
}


function initLookup() {
function initLookup() {
afc.lookupApi.abort(); // abort older API requests
wizard.lookupApi.abort(); // abort older API requests


var userTalk = "User talk:" + mw.config.get('wgUserName');
var userTalk = "User talk:" + mw.config.get('wgUserName');
Line 312: Line 311:


// re-initialize
// re-initialize
afc.oresTopics = null;
wizard.oresTopics = null;
afc.talktext = null;
wizard.talktext = null;
afc.pagetext = null;
wizard.pagetext = null;


afc.lookupApi.get({
wizard.lookupApi.get({
"action": "query",
"action": "query",
"prop": "revisions|description|info",
"prop": "revisions|description|info",
Line 334: Line 333:
}
}


afc.pagetext = page.revisions[0].slots.main.content;
wizard.pagetext = page.revisions[0].slots.main.content;
}
}


Line 385: Line 384:
setMainStatus('redirect', msg('status-redirecting-utrs'));
setMainStatus('redirect', msg('status-redirecting-utrs'));
mw.track('counter.gadget_afcsw.submit_succeeded');
mw.track('counter.gadget_afcsw.submit_succeeded');
$(window).off('beforeunload', afc.beforeUnload);
$(window).off('beforeunload', wizard.beforeUnload);
setTimeout(function () {
setTimeout(function () {
location.href = "https://utrs-beta.wmflabs.org/public/appeal/account";
location.href = "https://utrs-beta.wmflabs.org/public/appeal/account";
Line 407: Line 406:
}
}
afc.api.get({
wizard.api.get({
"action": "query",
"action": "query",
"prop": "revisions|description",
"prop": "revisions|description",
Line 434: Line 433:
mw.track('counter.gadget_afcsw.submit_succeeded');
mw.track('counter.gadget_afcsw.submit_succeeded');
$(window).off('beforeunload', afc.beforeUnload);
$(window).off('beforeunload', wizard.beforeUnload);
setTimeout(function () {
setTimeout(function () {
location.href = mw.util.getUrl(userTalk);
location.href = mw.util.getUrl(userTalk);
Line 471: Line 470:
};
};
if (ui.captchaLayout && ui.captchaLayout.isElementAttached()) {
if (ui.captchaLayout && ui.captchaLayout.isElementAttached()) {
editParams.captchaid = afc.captchaid;
editParams.captchaid = wizard.captchaid;
editParams.captchaword = ui.captchaInput.getValue();
editParams.captchaword = ui.captchaInput.getValue();
ui.fieldset.removeItems([ui.captchaLayout]);
ui.fieldset.removeItems([ui.captchaLayout]);
}
}
return afc.api.postWithEditToken(editParams).then(function (data) {
return wizard.api.postWithEditToken(editParams).then(function (data) {
if (!data.edit || data.edit.result !== 'Success') {
if (!data.edit || data.edit.result !== 'Success') {
if (data.edit && data.edit.captcha) {
if (data.edit && data.edit.captcha) {
Line 481: Line 480:


var url = data.edit.captcha.url;
var url = data.edit.captcha.url;
afc.captchaid = data.edit.captcha.id; // abuse of global?
wizard.captchaid = data.edit.captcha.id; // abuse of global?
ui.fieldset.addItems([
ui.fieldset.addItems([
ui.captchaLayout = new OO.ui.FieldLayout(ui.captchaInput = new OO.ui.TextInputWidget({
ui.captchaLayout = new OO.ui.FieldLayout(ui.captchaInput = new OO.ui.TextInputWidget({
Line 548: Line 547:
**/
**/
function getJSONPage (page) {
function getJSONPage (page) {
return afc.api.get({
return wizard.api.get({
action: 'query',
action: 'query',
titles: page,
titles: page,