User:Chaotic Enby/Unblock wizard.js: Difference between revisions
From Test Wiki
Content deleted Content added
Chaotic Enby (talk | contribs) check for emptiness |
Chaotic Enby (talk | contribs) testing updates |
||
| Line 47: | Line 47: | ||
"page-title": "Wikipedia Unblock Wizard", |
"page-title": "Wikipedia Unblock Wizard", |
||
"explain-label": "Can you explain, in your own words, what you were blocked for?", |
"explain-label": "Can you explain, in your own words, what you were blocked for?", |
||
"future-label": "If unblocked, what edits would you make |
"future-label": "If unblocked, what edits would you make and what (if applicable) would you do differently?", |
||
"other-label": "Is there anything else that may be helpful to your unblock request?", |
"other-label": "Is there anything else that may be helpful to your unblock request?", |
||
"accounts-label": "Please list all accounts you have used besides this one.", |
"accounts-label": "Please list all accounts you have used besides this one.", |
||
| Line 64: | Line 64: | ||
"status-processing": "Processing ...", |
"status-processing": "Processing ...", |
||
"status-saving": "Saving talk page ...", |
"status-saving": "Saving talk page ...", |
||
"status-blank": "One or several required forms are missing.", |
|||
"editsummary-main": "Submitting using [[User:Chaotic Enby/Unblock wizard]]", |
"editsummary-main": "Submitting using [[User:Chaotic Enby/Unblock wizard]]", |
||
"status-redirecting": "Submission succeeded. Redirecting you to your talk page ...", |
"status-redirecting": "Submission succeeded. Redirecting you to your talk page ...", |
||
"status-redirecting-utrs": "Submission succeeded. Redirecting you to UTRS ...", |
"status-redirecting-utrs": "Submission succeeded. Redirecting you to UTRS ...", |
||
"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 your talk page:\n{{unblock | reason=Your reason here ~~" + "~~}}\nIf you are having difficulties, please make a request through UTRS and inform them of the issues you are having.", |
|||
"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 77: | Line 79: | ||
var questionLabels = []; |
var questionLabels = []; |
||
var questionFields = {'explain': 0, 'future': 0, 'other': 0, 'accounts': 0, 'so': 2, 'explain-promo': 0, 'coi': 0, 'future-promo': 0, 'username': 1, 'clarification': 0}; |
var questionFields = {'explain': 0, 'future': 0, 'other': 0, 'accounts': 0, 'so': 2, 'explain-promo': 0, 'coi': 0, 'future-promo': 0, 'username': 1, 'clarification': 0}; |
||
var required = {'explain': true, 'future': true, 'other': false, 'accounts': true, 'so': true, 'explain-promo': true, 'coi': true, 'future-promo': true, 'username': false, 'clarification': false}; |
|||
var blockType = ''; |
var blockType = ''; |
||
var emptyFields = false; |
|||
var emptyFieldsWarned = false; |
|||
function init() { |
function init() { |
||
| Line 329: | Line 334: | ||
} |
} |
||
return []; |
return []; |
||
} |
|||
/** |
|||
* @param {Object} page - from query API response |
|||
* @returns {string[]} |
|||
*/ |
|||
function warningsFromPageData(page) { |
|||
var pagetext = page.revisions[0].slots.main.content; |
|||
var warnings = []; |
|||
// Show no refs warning |
|||
if (!/<ref/i.test(pagetext) && !/\{\{([Ss]fn|[Hh]arv)/.test(pagetext)) { |
|||
warnings.push('warning-norefs'); |
|||
} |
|||
// TODO: Show warning for use of deprecated/unreliable sources |
|||
// TODO: Show tip for avoiding peacock words or promotional language? |
|||
return warnings.map(function (warning) { |
|||
return new OO.ui.HtmlSnippet(linkify(msg(warning))); |
|||
}); |
|||
} |
} |
||
| Line 397: | Line 380: | ||
}, config.redirectionDelay); |
}, config.redirectionDelay); |
||
} else { |
} else { |
||
for(var [i, label] of questionLabels.entries()){ |
|||
var userTalk = "User talk:" + mw.config.get('wgUserName'); |
|||
if(required[label] && !ui.itemsInput[i].getValue()){ |
|||
if (!mw.config.get('wgUserName')) { // empty |
|||
emptyFields = true; |
|||
ui.fieldset.removeItems([ui.mainStatusLayout]); |
|||
} |
|||
ui.submitButton.setDisabled(false); |
|||
return; // really get the ip please |
|||
} |
} |
||
debug( |
debug("Empty fields:" + emptyFields); |
||
if (emptyFields && !emptyFieldsWarned) { |
|||
setMainStatus('warning', msg('status-blank')); |
|||
afc.api.get({ |
|||
emptyFieldsWarned = true; |
|||
"action": "query", |
|||
ui.submitButton.setDisabled(false); |
|||
"prop": "revisions|description", |
|||
} else { |
|||
"titles": userTalk, |
|||
var userTalk = "User talk:" + mw.config.get('wgUserName'); |
|||
"rvprop": "content", |
|||
if (!mw.config.get('wgUserName')) { // empty |
|||
"rvslots": "main", |
|||
}).then(function (json) { |
|||
var apiPage = json.query.pages[0]; |
|||
var errors = errorsFromPageData(apiPage); |
|||
if (errors.length) { |
|||
ui.fieldset.removeItems([ui.mainStatusLayout]); |
ui.fieldset.removeItems([ui.mainStatusLayout]); |
||
ui.submitButton.setDisabled(false); |
ui.submitButton.setDisabled(false); |
||
return; // really get the ip please |
|||
debug(errors); |
|||
return; |
|||
} |
} |
||
debug(" |
debug('debug user talk page: "' + userTalk + '"'); |
||
afc.api.get({ |
|||
var text = prepareUserTalkText(apiPage); |
|||
"action": "query", |
|||
debug("text[0] = " + text[0]); |
|||
"prop": "revisions|description", |
|||
"titles": userTalk, |
|||
setMainStatus('notice', msg('status-saving')); |
|||
"rvprop": "content", |
|||
saveUserTalkPage(userTalk, text).then(function () { |
|||
"rvslots": "main", |
|||
setMainStatus('success', msg('status-redirecting')); |
|||
}).then(function (json) { |
|||
mw.track('counter.gadget_afcsw.submit_succeeded'); |
|||
var apiPage = json.query.pages[0]; |
|||
$(window).off('beforeunload', afc.beforeUnload); |
|||
var errors = errorsFromPageData(apiPage); |
|||
setTimeout(function () { |
|||
if (errors.length) { |
|||
location.href = mw.util.getUrl(userTalk); |
|||
// ui.fieldset.removeItems([ui.mainStatusLayout]); |
|||
}, config.redirectionDelay); |
|||
ui.submitButton.setDisabled(false); |
|||
}, function (code, err) { |
|||
setMainStatus('error', msg('status-error')); |
|||
if (code === 'captcha') { |
|||
debug(errors); |
|||
ui.fieldset.removeItems([ui.mainStatusLayout, ui.talkStatusLayout]); |
|||
return; |
|||
ui.captchaLayout.scrollElementIntoView(); |
|||
mw.track('counter.gadget_afcsw.submit_captcha'); |
|||
} else { |
|||
setMainStatus('error', msg('error-saving-main', makeErrorMessage(code, err))); |
|||
mw.track('counter.gadget_afcsw.submit_failed'); |
|||
mw.track('counter.gadget_afcsw.submit_failed_' + code); |
|||
} |
} |
||
debug("no errors"); |
|||
var text = prepareUserTalkText(apiPage); |
|||
debug("text[0] = " + text[0]); |
|||
setMainStatus('notice', msg('status-saving')); |
|||
saveUserTalkPage(userTalk, text).then(function () { |
|||
setMainStatus('success', msg('status-redirecting')); |
|||
mw.track('counter.gadget_afcsw.submit_succeeded'); |
|||
$(window).off('beforeunload', afc.beforeUnload); |
|||
setTimeout(function () { |
|||
location.href = mw.util.getUrl(userTalk); |
|||
}, config.redirectionDelay); |
|||
}, function (code, err) { |
|||
if (code === 'captcha') { |
|||
ui.fieldset.removeItems([ui.mainStatusLayout, ui.talkStatusLayout]); |
|||
ui.captchaLayout.scrollElementIntoView(); |
|||
mw.track('counter.gadget_afcsw.submit_captcha'); |
|||
} else { |
|||
setMainStatus('error', msg('error-saving-main', makeErrorMessage(code, err))); |
|||
mw.track('counter.gadget_afcsw.submit_failed'); |
|||
mw.track('counter.gadget_afcsw.submit_failed_' + code); |
|||
} |
|||
ui.submitButton.setDisabled(false); |
|||
}); |
|||
}).catch(function (code, err) { |
|||
setMainStatus('error', msg('error-main', makeErrorMessage(code, err))); |
|||
ui.submitButton.setDisabled(false); |
ui.submitButton.setDisabled(false); |
||
mw.track('counter.gadget_afcsw.submit_failed'); |
|||
mw.track('counter.gadget_afcsw.submit_failed_' + code); |
|||
}); |
}); |
||
} |
|||
}).catch(function (code, err) { |
|||
setMainStatus('error', msg('error-main', makeErrorMessage(code, err))); |
|||
ui.submitButton.setDisabled(false); |
|||
mw.track('counter.gadget_afcsw.submit_failed'); |
|||
mw.track('counter.gadget_afcsw.submit_failed_' + code); |
|||
}); |
|||
} |
} |
||
} |
} |
||