MediaWiki:DYK-nomination-wizard.js: Difference between revisions

Content deleted Content added
sync from User:SD0001/DYK-helper/withJsMode2.js - requested on talk
per tper
 
(3 intermediate revisions by 3 users not shown)
Line 1:
/**
* DYK-nomination-wizard
*
* Wizard to easily create DYK nominations
*
* Loaded on [[Wikipedia:Did you know/Create new nomination]]
* using [[mw:Snippets/Load JS and CSS by URL]]
*
* Author: [[User:SD0001]]
*
Line 102:
dyk.callback = function dykMainCallback() {
 
var form = new Morebits.quickForm( dyk.evaluate );
 
form.append({
Line 136:
name: 'date',
tooltip: 'The date on which creation/expansion began. Must be within the past week. ',
value: new Date().toISOString().slice(0, 10), // YYYY-MM-DD format
event: dyk.dateCheck // for the benefit of browsers that don't support a datepicker for date fields
});
Line 318 ⟶ 317:
label: 'Number of QPQs required: <span id=dyk-qpq-count>calculating ...</span>'
});
 
form.append({
type: 'button',
Line 391 ⟶ 390:
'form.quickform div textarea.dyk-source { font-size: 110%; height: 35px; }' +
'form.quickform div textarea.dyk-comments { font-size: 125%; height: 35px; }'
//'form.quickform div.dyk-source { display: table-row; }' +
//'form.quickform div.dyk-source label { display: table-cell; vertical-align: middle; }' +
//'div.dyk-source > textarea { font-size: 110%; height: 19px; }' +
//'html form.quickform div textarea.dyk-source { font-size: 110%; height: 35px; }'
);
 
Line 448 ⟶ 443:
 
// Show number of QPQs required
mw.loader.using('ext.gadget.libLua').then(function() {
new mw.Api().get({
return mw.libs.lua.call({
"action": "query",
module: 'NewDYKnomination',
"prop": "revisions",
func: 'getRequiredQpqCount',
"titles": "User:SDZeroBot/DYK nomination counts.json|Template:Did you know/Backlog mode?",
var args: numPriorNoms = nomCounts[mw.config.get('wgUserName')] || 0;
"formatversion": "2",
});
"rvprop": "content",
}).then(function(jsonoutput) {
"rvslots": "main"
var [numQpqsNeeded, numPriorNoms] = output.split('\t').map(num => parseInt(num));
}).then(function(json) {
dyk.numQpqsRequiredPerArticle = numQpqsNeeded;
var nomCountsText = json.query.pages[0].revisions[0].slots.main.content;
if (numQpqsNeeded === 2) {
var nomCounts = JSON.parse(nomCountsText);
$('#dyk-qpq-count').text('2, as DYK is currently in backlog mode and you have ' + numPriorNoms + ' past nominations');
var backlogModeText = json.query.pages[1].revisions[0].slots.main.content;
} else if (numPriorNomsnumQpqsNeeded >=== 51) {
var isInBacklogMode = /^true/.test(backlogModeText);
var numPriorNoms = nomCounts[mw.config.get('wgUserName')] || 0;
if (isInBacklogMode && numPriorNoms >= 20) {
$('#dyk-qpq-count').text('2, as DYK is currently in backlog mode and you have ' + numPriorNoms + ' past nominations')
} else if (numPriorNoms >= 5) {
$('#dyk-qpq-count').text('1, as you have ' + numPriorNoms + ' past nominations');
} else if (numQpqsNeeded === 0) {
$('#dyk-qpq-count').text('0, as you have fewer than 5 past nominations');
} else {
$('#dyk-qpq-count').text('0,failed asto you have less than 5 past nominationscalculate');
}
}).catch(function(err) {
$('#dyk-qpq-count').text('failed to calculate');
console.log(err);
});
 
};
 
Line 502 ⟶ 494:
 
if (type === 'source') {
// var width = txtarea.parentElement.previousElementSibling.offsetWidth - txtarea.previousElementSibling.offsetWidth;
// txtarea.style.width = width + 'px';
txtarea.previousElementSibling.style.borderTop = 'none';
txtarea.previousElementSibling.style.marginTop = '0';
Line 571 ⟶ 561:
 
addTemplateParam('status', params.status);
addTemplateParam('hook', params.hook + (params.source ? ('\n{{smalldiv|1= \n* <small>Source: ' + params.source + '</small>}}') : ''));
 
Object.keys(params).filter(function (field) {
Line 656 ⟶ 646:
 
var prosesizewarn = $('#dyk-prosesize').css('color') === "rgb(255, 0, 0)";
if (prosesizewarn && !confirm('This article has afewer readablethan prose1500 sizecharacters of lessreadable than 1500 charactersprose. \n\nWhile you may still nominate it for DYK, it may be rejected unless you expand it to more than 1500 characters after the nomination. \n\nClick OK to continue with the nomination.' )) {
return;
}
 
if (sourcewarning && !confirm('You have not specified the source for each hook. Are you sure you want to continue?')) {
return;
}
 
if (dyk.numQpqsRequiredPerArticle > 0 &&
!/Template:Did you know nominations\/\w+/.test(form.qpq.value) &&
!confirm('You have not specified a QPQ. The nomination may be rejected unless you provide a QPQ soon after the nomination. Are you sure you want to continue?')) {
return;
}