MediaWiki:AFC-submit-wizard.js: Difference between revisions

Content deleted Content added
fix
update
Line 29:
return;
}
 
 
$('#firstHeading').text('Submitting your draft ...');
Line 51 ⟶ 50:
submitApi = new mw.Api(apiOptions);
 
var draftLayout, talkTagsLayout, shortdescLayout, isBLPLayout, isCompanyLayout, topicsLayout, submitLayout, draftInput, talkTagsInput, shortdescInput, isBLPInput, isCompanyInput, topicsInput, submitButton, mainStatusLayout, mainStatusArea, talkStatusLayout, talkStatusArea, rawClassLayout, rawClass;
 
// global
Line 71 ⟶ 70:
}),
 
isBLPLayoutrawClassLayout = new OO.ui.FieldLayout(isBLPInputrawClass = new OO.ui.CheckboxInputWidgetRadioSelectInputWidget(), {
label: 'Choose the most appropriate category',
selected: false
help: 'For biographies about scholars, choose one of the two biography categories rather than one associated to their field',
}), {
label: 'This draft is a biography of a living person',
align: 'inline'
}),
 
isCompanyLayout = new OO.ui.FieldLayout(isCompanyInput = new OO.ui.CheckboxInputWidget({
selected: false
}), {
label: 'This draft is about a company or a corporation',
align: 'inline'
}),
 
shortdescLayout = new OO.ui.FieldLayout(shortdescInput = new OO.ui.TextInputWidget({
placeholder: 'Briefly describe the subject in 2–5 words (eg. "KenyanBritish astronomer", "IndianCricket stadium in dessertIndia")',
maxLength: 100
}), {
Line 134 ⟶ 125:
 
]
});
 
// Load a JSON page from the wiki
function getJSONPage(page) {
return $.getJSON('https://en.wikipedia.org/w/index.php?title=' + encodeURIComponent(page) + '&action=raw&ctype=text/json');
}
 
var topicOptionsLoaded = $.Deferred();
getJSONPage('Wikipedia:WikiProject Articles for creation/AFC topic map.json').then(function(optionsJson) {
var options = [];
$.each(optionsJson, function(code, info) {
options.push({
label: info.label,
data: code
}), {;
});
rawClass.setOptions(options);
rawClass.setValue('o');
 
// put allowed option codes in promise resolution:
topicOptionsLoaded.resolve(options.map(function(op) {
return op.data;
}));
});
 
Line 150 ⟶ 164:
 
$('.mw-ui-button').parent().replaceWith(fieldset.$element);
 
// Load a JSON page from the wiki
function getJSONPage(page) {
return $.getJSON('https://en.wikipedia.org/w/index.php?title=' + encodeURIComponent(page) + '&action=raw&ctype=text/json');
}
 
// populate talk page tags for multi-select widget
Line 236 ⟶ 245:
]);
}
 
// set checkboxmain statescategory
isBLPInputvar topicMatch = pagetext.setSelectedmatch(/\{\{[Dd]raftBLPAFC topic\|(.*?)\}\}/.test(pagetext));
if (topicMatch) {
isCompanyInput.setSelected(/\{\{[Dd]raftCorp\}\}/.test(pagetext));
topicOptionsLoaded.then(function(allowedCodes) {
var topic = topicMatch[1];
console.log(topic);
console.log(allowedCodes);
// if the code found in the template is an invalid one, keep the default to "other",
// rather than the first item in the list
if (allowedCodes.indexOf(topic) !== -1) {
rawClass.setValue(topic);
} else {
rawClass.setValue('o');
}
}),;
}), else {
rawClass.setValue('o');
}
 
// set shortdesc in form
Line 249 ⟶ 273:
wikiprojects = [],
match;
while (match = infoboxRgx.exec(pagetext)) { // jshint ignore:line
var ibx = match[1].trim();
if (ibxmap[ibx]) {
Line 386 ⟶ 410:
var draft = draftInput.getValue();
console.log(draft);
console.log(isBLPInput.getValue());
 
submitApi.get({
Line 422 ⟶ 445:
}
 
text = text.replace(/\{\{[Dd]raft(BLPAFC topic\|Corp(.*?)\}\}\n*/g, '');
// put BLP/Company categories
header += '{{AFC topic|' + rawClass.getValue() + '}}\n';
text = text.replace(/\{\{[Dd]raft(BLP|Corp)\}\}\n*/g, '');
if (isBLPInput.isSelected()) {
header += '{{DraftBLP}}\n';
}
if (isCompanyInput.isSelected()) {
header += '{{DraftCorp}}\n';
}
 
// put AFC submission template