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
// global
Line 71 ⟶ 70:
}),
label: 'Choose the most appropriate category',
help: 'For biographies about scholars, choose one of the two biography categories rather than one associated to their field',
}), {▼
}),▼
}), {▼
align: 'inline'
}),
shortdescLayout = new OO.ui.FieldLayout(shortdescInput = new OO.ui.TextInputWidget({
placeholder: 'Briefly describe the subject in 2–5 words (eg. "
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
if (topicMatch) {
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');
}▼
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);
submitApi.get({
Line 422 ⟶ 445:
}
header += '{{AFC topic|' + rawClass.getValue() + '}}\n';
▲ text = text.replace(/\{\{[Dd]raft(BLP|Corp)\}\}\n*/g, '');
▲ }
▲ }
// put AFC submission template
|