User:Chaotic Enby/Unblock wizard.js: Difference between revisions
From Test Wiki
Content deleted Content added
Chaotic Enby (talk | contribs) by aasim |
Chaotic Enby (talk | contribs) doing some renaming |
||
| Line 32: | Line 32: | ||
}); |
}); |
||
var |
var wizard = {}, ui = {}, block = {}; |
||
window. |
window.wizard = wizard; |
||
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 |
||
wizard.api = new mw.Api(apiOptions); |
|||
wizard.lookupApi = new mw.Api(apiOptions); |
|||
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%; }'); |
||
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', |
$(window).on('beforeunload', wizard.beforeUnload); |
||
} |
} |
||
function initLookup() { |
function initLookup() { |
||
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 |
||
wizard.oresTopics = null; |
|||
wizard.talktext = null; |
|||
wizard.pagetext = null; |
|||
wizard.lookupApi.get({ |
|||
"action": "query", |
"action": "query", |
||
"prop": "revisions|description|info", |
"prop": "revisions|description|info", |
||
| Line 334: | Line 333: | ||
} |
} |
||
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', |
$(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: | ||
} |
} |
||
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', |
$(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 = |
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 |
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; |
||
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 |
return wizard.api.get({ |
||
action: 'query', |
action: 'query', |
||
titles: page, |
titles: page, |
||