User:Qwerfjkl/scripts/massXFD.js: Difference between revisions

Content deleted Content added
m Needs signature (via CAE)
delink section names [Factotum]
Line 439:
}
return copy;
}
 
function delinkWikitext(text) {
// both piped and unpiped wikilinks
const wikilinkPattern = /\[\[([^\]]+)\|([^\]]+)\]\]|\[\[([^\]]+)\]\]/g;
 
return text.replace(wikilinkPattern, (match, p1, p2, p3) => {
if (p1 && p2) {
// If there is both link text and target (piped)
return p1; // Just return the link text
} else if (p3) {
// If there is only link text, without a target (unpiped)
return p3;
}
return match;
});
}
 
Line 486 ⟶ 502:
// Browsers that support the 'text/html' type in the Clipboard API (Chrome, Firefox 22+)
if (e && e.clipboardData && e.clipboardData.types && e.clipboardData.getData) {
// Check for 'text/html' in types list
types = e.clipboardData.types;
if (((types instanceof DOMStringList) && types.contains("text/html")) ||
Line 742 ⟶ 757:
if ('redirects' in data) {
data.redirects.forEach(redirect => {
redirectTargets[redirect.from] = redirect.to;
});
let redirects = new Set(data.redirects.map(r => r.to));
let pages = new Set(Object.values(data.pages).map(p => p.title));
nonredirects.push(...[...pages].filter(x => !redirects.has(x)));
} else {
nonredirects.push(...Object.values(data.pages).map(p => p.title));
}
 
Line 908 ⟶ 923:
Object.keys(XFDconfig).forEach(function (XfD) {
mw.util.addPortletLink('p-tb', mw.util.getUrl(`Special:Mass${XfD}`), `Mass ${XfD}`, `pt-mass${XfD.toLowerCase()}`, `Create a mass ${XfD} nomination`);
});
 
 
Line 976 ⟶ 991:
function createActionNomination(actionsContainer, first = false) {
var count = actions.length + 1;
let actionNominationTitle = XFD === 'CFD' ? 'Action batch #' + count : '';
var container = createFieldset(actionNominationTitle);
actionsContainer.append(container.$element);
Line 985 ⟶ 1,000:
elementsToDisable.push(dropdown);
dropdown.$element.css('max-width', 'fit-content');
let demoText = config.pageDemoText;
var prependTextObj = createTitleAndInputField('Text to tag the nominated pages with:', demoText, info = 'A dollar sign <code>$</code> followed by a number, such as <code>$1</code>, will be replaced with a target specified in the title field, or if not target is specified, will be removed.');
var prependTextLabel = prependTextObj.titleLabel;
Line 1,037 ⟶ 1,052:
} else if (XFD === 'RFD') {
if (str.toLowerCase().startsWith('{{subst:rfd|')) {
str = str.replace(/\{\{subst:rfd\|/i, '');
return '{{subst:rfd|' + str.replace(find, replace);
} else {
return str.replace(find, replace); // first occurence
}
}
Line 1,048 ⟶ 1,063:
var oldSectionName = sectionName;
if (XFD !== 'CFD') {
prependTextInputField.setValue(config.actions.prepend.replace('${sectionName}', delinkWikitext(sectionName)));
if (XFD === 'RFD') {
if (discussionLinkInputField.getValue().match(config.discussionLinkRegex)) {
let date = discussionLinkInputField.getValue().trim().match(/^Wikipedia:Redirects for discussion\/Log\/(\d\d\d\d \w+ \d\d)?#.+$/)[1];
let difference = getDateDifference(date);
if (difference !== 0) {
prependTextInputField.setValue(config.actions.prepend.replace('{{subst:rfd|${sectionName}|', `{{subst:rfd|${delinkWikitext(sectionName)}|days=${difference}|`));
} // else leave as default above
}
Line 1,066 ⟶ 1,081:
 
if (XFD === 'RFD') {
const date = discussionLinkInputField.getValue().trim().match(/^Wikipedia:Redirects for discussion\/Log\/(\d\d\d\d \w+ \d\d?)#.+$/)[1];
 
if (/(\| *days *= *)\d+/.test(text)) { // already has days=, update
text = text.replace(/(\| *days *= *)\d+/, '$1' + getDateDifference(date));
text = replaceOccurence(text, oldSectionName, sectionName);
} else {
Line 1,093 ⟶ 1,108:
dropdown.on('labelChange', function () {
let actionData = config.actions[dropdown.getLabel()];
prependTextInputField.setValue(actionData.prepend.replace('${sectionName}', delinkWikitext(sectionName)));
actionInputField.setValue(actionData.action);
});
Line 1,123 ⟶ 1,138:
actionContainer.$element.hide();
dropdown.$element.hide();
prependTextInfoPopup.$element.hide(); // both popups give info about targets which aren't relevant here
titleListInfoPopup.$element.hide();
}
 
Line 1,181 ⟶ 1,196:
});
if (XFD !== 'CFD') {
multiOptionButton.$element.hide();
} else {
 
Line 1,264 ⟶ 1,279:
var titleList = titleListInputField.getValue().split('\n');
function normalise(title) {
return config.normaliseFunction(title);
}
titleList.forEach(function (title) {
Line 1,323 ⟶ 1,338:
if (XFD === 'RFD') {
let fetchingRedirectsElement = createDoingElement();
fetchingRedirectsElement.setLabel('Fetching redirect targets...');
fetchingRedirectsElement.$element.css('margin-top', '16px');
bodyContent.append(fetchingRedirectsElement.$element);
 
let fetchedRedirectsElement = createCompletedElement();
fetchedRedirectsElement.setLabel('Fetched redirect targets');
fetchedRedirectsElement.$element.css('margin-top', '16px');
 
Line 1,358 ⟶ 1,373:
if (nonredirects.length) {
let nonredirectsWarningMessage = createWarningMessage();
nonredirectsWarningMessage.$element.css({ 'max-height': '20em', 'overflow-y': 'auto' }); // normally shouldn't be needed
let nonRedirectsHTML = $('<div>').append($('<span>').text('The following pages were ignored because they are not redirects:'));
let $listElement = $('<ul>');
nonredirects.forEach(item => {
const $listItem = $('<li>').html(makeLink(item));
$listElement.append($listItem);
});
nonRedirectsHTML.append($listElement);
nonredirectsWarningMessage.setLabel(nonRedirectsHTML);
bodyContent.append(nonredirectsWarningMessage.$element);
}
 
Line 1,509 ⟶ 1,524:
if (isOld) summaryDiscussionLink = discussionLinkInputField.getValue().trim();
else if (isNew) summaryDiscussionLink = `${discussionPage}#${newNomHeaderInputField.getValue().trim()}`;
summaryDiscussionLink = delinkWikitext(summaryDiscussionLink); // links can't be nested
 
const advSummary = ' ([[User:Qwerfjkl/scripts/massXFD.js|via MassXfD.js]])';
Line 1,517 ⟶ 1,533:
const nominationSummary = `Adding mass nomination at [[#${newNomHeaderInputField.getValue().trim()}]]` + advSummary;
if (XFD === 'RFD') {
var redirectTargetNotification = `{{subst:Rfd notice|\${redirectTitle}|${newNomHeaderInputField.getValue().trim()}}} ~~~~`;
var redirectTargetNotificationSummary = `Notice of [[${summaryDiscussionLink}]]${advSummary}`;
}
var batchesToProcess = [];
Line 1,589 ⟶ 1,605:
id: 'rfd-notify-target',
titles: [... new Set(Object.values(redirectTargets).map(title => {
let page = new mw.Title(title);
return page.getTalkPage().getPrefixedText();
}))], // normalise redirectTargets & remove duplicates
textToModify: redirectTargetNotification,