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

From Test Wiki
Content deleted Content added
rm redundancy
No edit summary
Line 61: Line 61:
"submit-label": "Submit",
"submit-label": "Submit",
"utrs-label": "Go to UTRS",
"utrs-label": "Go to UTRS",
"utrs-necessary": "It is necessary to appeal your block via UTRS. This is because your talk page access is disabled. [https://utrs-beta.wmflabs.org/public/appeal/account Go to UTRS]",
"utrs-necessary-confirm": "It is necessary to appeal your block via UTRS. This is because your talk page access is disabled. Select \"Confirm\" to go to UTRS.",
"footer-text": "<small>If you are not sure about what to enter in a field, you can skip it. If you need help, you can ask on <b>[[Special:MyTalk|your talkpage]]</b> with <b>{{[[Template:Help me|Help me]]}}</b> or get live help via <b>[[WP:IRCHELP|IRC]]</b>.<br>Facing some issues in using this form? <b>[/w/index.php?title=Wikipedia_talk:Unblock_wizard&action=edit&section=new&preloadtitle=Issue%20with%20submission%20form&editintro=Wikipedia_talk:Unblock_wizard/editintro Report it]</b>.</small>",
"footer-text": "<small>If you are not sure about what to enter in a field, you can skip it. If you need help, you can ask on <b>[[Special:MyTalk|your talkpage]]</b> with <b>{{[[Template:Help me|Help me]]}}</b> or get live help via <b>[[WP:IRCHELP|IRC]]</b>.<br>Facing some issues in using this form? <b>[/w/index.php?title=Wikipedia_talk:Unblock_wizard&action=edit&section=new&preloadtitle=Issue%20with%20submission%20form&editintro=Wikipedia_talk:Unblock_wizard/editintro Report it]</b>.</small>",
"submitting-as": "Submitting as User:$1",
"submitting-as": "Submitting as User:$1",
Line 73: Line 75:
"status-redirecting-utrs": "Redirecting you to UTRS ...",
"status-redirecting-utrs": "Redirecting you to UTRS ...",
"status-not-blocked": "You are not currently blocked.",
"status-not-blocked": "You are not currently blocked.",
"status-not-blocked-confirm": "You are not currently blocked. Select \"Confirm\" to activate demo mode, which will allow you to check out the workflow without posting a block request.",
"status-error": "Due to an error, your unblock request could not be parsed. You can try to submit an unblock request manually by pasting the following on [[Special:MyTalk|your talk page]]:<br /><code>{{unblock | reason=Your reason here ~~" + "~~}}</code><br />If you are having difficulties, please [https://utrs-beta.wmflabs.org/ make a request through UTRS] and inform them of the issues you are encountering.",
"status-error": "Due to an error, your unblock request could not be parsed. You can try to submit an unblock request manually by pasting the following on [[Special:MyTalk|your talk page]]:<br /><code>$1</code><br />If you are having difficulties, please [https://utrs-beta.wmflabs.org/ make a request through UTRS] and inform them of the issues you are encountering.",
"captcha-label": "Please enter the letters appearing in the box below",
"captcha-label": "Please enter the letters appearing in the box below",
"captcha-placeholder": "Enter the letters here",
"captcha-placeholder": "Enter the letters here",
Line 132: Line 135:
}
}
console.log(blockType)
console.log(blockType)
console.log(demoMode)
blockType = blockType[blockType.length - 1];
blockType = blockType[blockType.length - 1];
switch (blockType) {
switch (blockType) {
Line 162: Line 163:
}
}
if(usernameBlock && blockType != "Username") {
if(usernameBlock && blockType != "Username" && blockType != "Clarification") {
questionLabels = ['username'].concat(questionLabels);
questionLabels = ['username'].concat(questionLabels);
}
}
Line 183: Line 184:
}
}


function setBlockData(json) {
async function setBlockData(json) {
var userinfo = json.query.userinfo;
var userinfo = json.query.userinfo;
var errors = errorsFromPageData(userinfo);
var errors = errorsFromPageData(userinfo);
block.target = userinfo.name;
if (errors.length) {
if (errors.length) {
return block;
return block;
Line 193: Line 195:
block.by = userinfo.blockedby;
block.by = userinfo.blockedby;
block.reason = userinfo.blockreason;
block.reason = userinfo.blockreason;
block.notalk = userinfo.blockowntalk;
}
}
return block;
return block;
Line 238: Line 241:
ui.itemsLayout.push(ui.submitLayout = new OO.ui.FieldLayout(ui.submitButton = new OO.ui.ButtonWidget({
ui.itemsLayout.push(ui.submitLayout = new OO.ui.FieldLayout(ui.submitButton = new OO.ui.ButtonWidget({
label: blockType == "IP_hardblock" ? msg('utrs-label') : msg('submit-label'),
label: blockType == "IP_hardblock" ? msg('utrs-label') : msg('submit-label'),
flags: [ 'progressive', 'primary' ],
flags: [ 'progressive', 'primary' ],
})));
})));
if(copyrightEligible){
if(copyrightEligible){
Line 264: Line 267:


var asUser = mw.util.getParamValue('username');
var asUser = mw.util.getParamValue('username');
if (asUser && asUser !== mw.config.get('wgUserName')) {
if (asUser && asUser !== block.target) {
ui.fieldset.addItems([
ui.fieldset.addItems([
new OO.ui.FieldLayout(new OO.ui.MessageWidget({
new OO.ui.FieldLayout(new OO.ui.MessageWidget({
Line 277: Line 280:
$('#unblock-wizard-container').empty().append(ui.fieldset.$element, ui.footerLayout.$element);
$('#unblock-wizard-container').empty().append(ui.fieldset.$element, ui.footerLayout.$element);


ui.submitButton.on('click', handleSubmit);


initLookup();
initLookup();

if (blockType != "IP" && !("id" in block) && !demoMode) {
setMainStatus('warning', msg('status-not-blocked'));
demoMode = confirm(msg('status-not-blocked-confirm'));
console.log(demoMode)
}

if (block.notalk) {
ui.submitButton.setDisabled(true);
setMainStatus('error', msg('utrs-necessary'));
if (confirm(msg("utrs-necessary-confirm"))) {
location.href = "https://utrs-beta.wmflabs.org/public/appeal/account";
}
} else {
ui.submitButton.on('click', handleSubmit);
}


// The default font size in monobook and modern are too small at 10px
// The default font size in monobook and modern are too small at 10px
Line 306: Line 324:
wizard.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:" + block.target;
if (!mw.config.get('wgUserName')) { // empty
return; // here we should get the ip or something
}


// re-initialize
// re-initialize
Line 361: Line 376:
mainPosition = ui.fieldset.items.length;
mainPosition = ui.fieldset.items.length;
ui.fieldset.addItems([
ui.fieldset.addItems([
ui.mainStatusLayout = new OO.ui.FieldLayout(ui.mainStatusArea = new OO.ui.LabelWidget({
ui.mainLabel = new OO.ui.MessageWidget( {
align: 'top',
label: $('<tr>').append('<td style="vertical-align:top; padding-right: 5px;">' + imglink(infoLevels[type]) + '</td><td style="vertical-align:middle;">' + linkify(message)+ '</td>')
}), {
type: type,
label: $("<span/>").append(linkify(message))
align: 'top'
})
})
]);
]);
} else {
} else {
ui.mainLabel.setType(type);
ui.mainStatusArea.setLabel($('<tr>').append('<td style="vertical-align:top; padding-right: 5px;">' + imglink(infoLevels[type]) + '</td><td style="vertical-align:middle;">' + linkify(message)+ '</td>'));
ui.mainLabel.setLabel($('<span/>').append(linkify(message)));
}
}
}
}


function handleSubmit() {
function handleSubmit() {
if (ui.submitButton.isDisabled()) {

return;
setMainStatus('process', msg('status-processing'));
}
setMainStatus('', msg('status-processing'));
ui.submitButton.setDisabled(true);
ui.submitButton.setDisabled(true);
ui.mainStatusLayout.scrollElementIntoView();
ui.mainLabel.scrollElementIntoView();
var text = prepareUserTalkText();
if (blockType == "IP_hardblock") {
if (blockType == "IP_hardblock") {
setMainStatus('redirect', msg('status-redirecting-utrs'));
setMainStatus('redirect', msg('status-redirecting-utrs'));
Line 384: Line 403:
location.href = "https://utrs-beta.wmflabs.org/public/appeal/account";
location.href = "https://utrs-beta.wmflabs.org/public/appeal/account";
}, config.redirectionDelay);
}, config.redirectionDelay);
} else if (blockType != "IP" && !("id" in block) && !demoMode) {
setMainStatus('warning', msg('status-not-blocked'));
} else {
} else {
for(var [i, label] of questionLabels.entries()){
for(var [i, label] of questionLabels.entries()){
Line 397: Line 414:
ui.submitButton.setDisabled(false);
ui.submitButton.setDisabled(false);
} else {
} else {
var userTalk = "User talk:" + mw.config.get('wgUserName');
var userTalk = "User talk:" + block.target;
if (!mw.config.get('wgUserName')) { // empty
if (!block.target) { // empty
ui.fieldset.removeItems([ui.mainStatusLayout]);
ui.fieldset.removeItems([ui.mainLabel]);
ui.submitButton.setDisabled(false);
ui.submitButton.setDisabled(false);
return; // really get the ip please
return; // really get the ip please
Line 415: Line 432:
var errors = errorsFromPageData(apiPage);
var errors = errorsFromPageData(apiPage);
if (errors.length) {
if (errors.length) {
// ui.fieldset.removeItems([ui.mainStatusLayout]);
// ui.fieldset.removeItems([ui.mainLabel]);
ui.submitButton.setDisabled(false);
ui.submitButton.setDisabled(false);
setMainStatus('error', msg('status-error'));
setMainStatus('error', msg('status-error').replace("$1", text));
return;
return;
}
}
setMainStatus('', msg('status-saving'));
var text = prepareUserTalkText();
setMainStatus('process', msg('status-saving'));
if (demoMode) {
if (demoMode) {
setMainStatus('success', '<code style="display: block">' + text + '</code>');
setMainStatus('success', '<code style="display: block">' + text + '</code>');
Line 436: Line 451:
}, function (code, err) {
}, function (code, err) {
if (code === 'captcha') {
if (code === 'captcha') {
ui.fieldset.removeItems([ui.mainStatusLayout, ui.talkStatusLayout]);
ui.fieldset.removeItems([ui.mainLabel, ui.talkStatusLayout]);
ui.captchaLayout.scrollElementIntoView();
ui.captchaLayout.scrollElementIntoView();
} else {
} else {
setMainStatus('error', msg('status-error'));
setMainStatus('error', msg('status-error').replace('$1', text));
}
}
ui.submitButton.setDisabled(false);
ui.submitButton.setDisabled(false);
Line 445: Line 460:
}
}
}).catch(function (code, err) {
}).catch(function (code, err) {
setMainStatus('error', msg('status-error'));
setMainStatus('error', msg('status-error').replace("$1", text));
ui.submitButton.setDisabled(false);
ui.submitButton.setDisabled(false);
});
});