User:Chlod/Scripts/Deputy.js: Difference between revisions

Content deleted Content added
(bot/CD)
(bot/CD)
Line 351:
 
var version = "0.7.0";
var gitAbbrevHash = "cb532c70cff0fa";
var gitBranch = "main";
var gitDate = "MonTue, 823 Apr 2024 0801:0745:3314 +0800";
var gitVersion = "0.7.0+gcb532c7g0cff0fa";
 
/**
Line 6,588:
setDateFromRevision() {
return __awaiter(this, void 0, void 0, function* () {
const revid = this.revisionInputWidget.getValue();
if (isNaN(+revid)) {
mw.notify(mw.msg('deputy.ante.dateAuto.invalid'), { type: 'error' });
this.updateButton();
return;
}
this
.setIcon('ellipsis')
.setDisabled(true);
this.dateInputWidget.setDisabled(true);
const revid = this.revisionInputWidget.getValue();
yield MwApi.action.get({
action: 'query',
Line 6,754 ⟶ 6,759:
}
return new InternalPageLatestRevisionGetButton(config);
}
 
/**
* What it says on the tin. Attempt to parse out a `title`, `diff`,
* or `oldid` from a URL. This is useful for converting diff URLs into actual
* diff information, and especially useful for {{copied}} templates.
*
* @param url The URL to parse
* @return Parsed info: `diff` or `oldid` revision IDs, and/or the page title.
*/
function parseDiffUrl(url) {
if (typeof url === 'string') {
url = new URL(url);
}
// Attempt to get values from URL parameters (when using `/w/index.php?action=diff`)
let oldid = url.searchParams.get('oldid');
let diff = url.searchParams.get('diff');
let title = url.searchParams.get('title');
// Attempt to get information from this URL.
tryConvert: {
if (title && oldid && diff) {
// Skip if there's nothing else we need to get.
break tryConvert;
}
// Attempt to get values from Special:Diff short-link
const diffSpecialPageCheck =
// eslint-disable-next-line security/detect-unsafe-regex
/\/wiki\/Special:Diff\/(prev|next|\d+)(?:\/(prev|next|\d+))?/i.exec(url.pathname);
if (diffSpecialPageCheck != null) {
if (diffSpecialPageCheck[1] != null &&
diffSpecialPageCheck[2] == null) {
// Special:Diff/diff
diff = diffSpecialPageCheck[1];
}
else if (diffSpecialPageCheck[1] != null &&
diffSpecialPageCheck[2] != null) {
// Special:Diff/oldid/diff
oldid = diffSpecialPageCheck[1];
diff = diffSpecialPageCheck[2];
}
break tryConvert;
}
// Attempt to get values from Special:PermanentLink short-link
const permanentLinkCheck = /\/wiki\/Special:Perma(nent)?link\/(\d+)/i.exec(url.pathname);
if (permanentLinkCheck != null) {
oldid = permanentLinkCheck[2];
break tryConvert;
}
// Attempt to get values from article path with ?oldid or ?diff
// eslint-disable-next-line security/detect-non-literal-regexp
const articlePathRegex = new RegExp(mw.util.getUrl('(.*)'))
.exec(url.pathname);
if (articlePathRegex != null) {
title = articlePathRegex[1];
break tryConvert;
}
}
// Convert numbers to numbers
if (oldid != null && !isNaN(+oldid)) {
oldid = +oldid;
}
if (diff != null && !isNaN(+diff)) {
diff = +diff;
}
// Try to convert a page title
try {
title = new mw.Title(title).getPrefixedText();
}
catch (e) {
console.warn('Failed to normalize page title during diff URL conversion.');
}
return {
diff: diff,
oldid: oldid,
title: title
};
}
 
Line 7,151 ⟶ 7,232:
*/
convertDeprecatedDiff() {
constreturn value__awaiter(this, =void 0, void 0, function* this.inputs.diff.getValue(); {
try { const value = this.inputs.diff.getValue();
try {
const url = new URL(value, window.___location.href);
if (!value) {
return;
}
if (url.host === window.___location.host) {
console.warn('Attempted to convert a diff URL from another wiki.');
}
// From the same wiki, accept deprecation
// Attempt to get values from URL parameters (when using `/w/index.php?action=diff`)
let oldid = url.searchParams.get('oldid');
let diff = url.searchParams.get('diff');
const title = url.searchParams.get('title');
// Attempt to get values from Special:Diff short-link
const diffSpecialPageCheck = /\/wiki\/Special:Diff\/(prev|next|\d+)(?:\/(prev|next|\d+))?/.exec(url.pathname);
if (diffSpecialPageCheck != null) {
if (diffSpecialPageCheck[1] != null &&
diffSpecialPageCheck[2] == null) {
// Special:Diff/diff
diff = diffSpecialPageCheck[1];
}
else if (diffSpecialPageCheck[1]url.host !== nullwindow.___location.host) &&{
diffSpecialPageCheck[2]if (!=(yield nullOO.ui.confirm(mw.msg('deputy.ante.copied.diffDeprecate.warnHost')))) {
// Special:Diff/oldid/diff return;
oldid = diffSpecialPageCheck[1];}
diff = diffSpecialPageCheck[2];
}
} // From the same wiki, accept deprecation immediately.
const confirmProcess = new OO.ui.Process();// Parse out info from this diff URL
for (const [_rowName, newValue] ofconst [parseInfo = parseDiffUrl(url);
['to_oldid'let { diff, oldid], } = parseInfo;
['to_diff',const diff],{ title } = parseInfo;
['to'// If only an oldid was provided, title]and no diff
] if (oldid && !diff) {
const rowName diff = _rowNameoldid;
if (newValue == null) {oldid = undefined;
continue;
}
ifconst confirmProcess = new OO.ui.Process();
// FieldLooping hasover anthe existingrow name and the value that will replace it.
this.copiedTemplateRowfor (const [rowName_rowName, newValue] !=of null &&[
this.copiedTemplateRow[rowName'to_oldid', oldid].length > 0 &&,
this.copiedTemplateRow[rowName'to_diff', diff] !== newValue) {,
confirmProcess.next(() => __awaiter(this['to', void 0, void 0, function* () {title]
]) {
const confirmPromise = dangerModeConfirm(window.CopiedTemplateEditor.config, mw.message('deputy.ante.copied.diffDeprecate.replace', rowName, this.copiedTemplateRow[rowName], newValue).text());
const confirmPromise.done((confirmed)rowName => {_rowName;
if (newValue == if (confirmednull) {
this.inputs[rowName].setValue(newValue)continue;
}
if });(
// Field has an returnexisting confirmPromise;value
}));this.copiedTemplateRow[rowName] != null &&
} this.copiedTemplateRow[rowName].length > 0 &&
else this.copiedTemplateRow[rowName] !== newValue) {
this confirmProcess.inputs[rowName].setValuenext(() => __awaiter(this, void 0, void 0, function* (newValue); {
const confirmPromise = dangerModeConfirm(window.CopiedTemplateEditor.config, mw.message('deputy.ante.copied.diffDeprecate.replace', rowName, this.copiedTemplateRow[rowName], newValue).text());
confirmPromise.done((confirmed) => {
if (confirmed) {
this.inputs[rowName].setValue(newValue);
this.fieldLayouts[rowName].toggle(true);
}
});
return confirmPromise;
}));
}
else {
this.inputs[rowName].setValue(newValue);
this.fieldLayouts[rowName].toggle(true);
}
}
confirmProcess.next(() => {
this.copiedTemplateRow.parent.save();
this.inputs.diff.setValue('');
if (!this.inputs.toggle.getValue()) {
this.fieldLayouts.diff.toggle(false);
}
});
confirmProcess.execute();
}
confirmProcess.next(catch (e) => {
thisconsole.copiedTemplateRowerror('Cannot convert `diff` parameter to URL.parent.save(', e);
thisOO.inputsui.diffalert(mw.setValuemsg('deputy.ante.copied.diffDeprecate.failed'));
if (!this.inputs.toggle.getValue()) {}
this.fieldLayouts.diff.toggle(false});
}
});
confirmProcess.execute();
}
catch (e) {
console.error('Cannot convert `diff` parameter to URL.', e);
OO.ui.alert(mw.msg('deputy.ante.copied.diffDeprecate.failed'));
}
}
/**
Line 12,057 ⟶ 12,135:
"deputy.ante.templateOptions": "Template options",
"deputy.ante.dateAuto": "Pull the date from the provided revision ID (`$1` parameter)",
"deputy.ante.dateAuto.invalid": "Parameter does not appear to be a valid revision ID.",
"deputy.ante.dateAuto.failed": "Could not pull date from revision: $1",
"deputy.ante.dateAuto.missing": "The revision $1 could not be found. Its page may have been deleted.",
Line 12,105 ⟶ 12,184:
"deputy.ante.copied.dateInvalid": "The previous date value, \"$1\", was not a valid date.",
"deputy.ante.copied.diffDeprecate": "The <code>to_diff</code> and <code>to_oldid</code> parameters are preferred in favor of the <code>diff</code> parameter.",
"deputy.ante.copied.diffDeprecate.warnHost": "The URL in this parameter is not the same as the wiki you're currently editing on. Continue?",
"deputy.ante.copied.diffDeprecate.replace": "The current value of '$1', \"$2\", will be replaced with \"$3\". Continue?",
"deputy.ante.copied.diffDeprecate.failed": "Cannot convert `diff` parameter to URL. See your browser console for more details.",
Line 16,848 ⟶ 16,928:
cloneRegex: cloneRegex$1,
copyToClipboard: copyToClipboard,
dangerModeConfirm: dangerModeConfirm,
equalTitle: equalTitle,
findNextSiblingElement: findNextSiblingElement,
fromObjectEntries: fromObjectEntries,
generateId: generateId,
Line 16,855 ⟶ 16,937:
matchAll: matchAll,
moveToStart: moveToStart,
organize: organize,
pickSequence: pickSequence,
removeElement: removeElement,
Line 16,860 ⟶ 16,943:
sleep: sleep,
swapElements: swapElements,
unwrapElement: unwrapElement,
unwrapWidget: unwrapWidget,
yesNo: yesNo
Line 16,897 ⟶ 16,981:
 
var wikiUtil = {
anchorToTitle: pagelinkToTitle,
decorateEditSummary: decorateEditSummary,
delink: delink,
errorToOO: errorToOO,
getApiErrorText: getApiErrorText,
getNativeRange: getNativeRange,
getPageContent: getPageContent,
Line 16,914 ⟶ 16,998:
nsId: nsId,
openWindow: openWindow,
pagelinkToTitle: pagelinkToTitle,
parseDiffUrl: parseDiffUrl,
performHacks: performHacks,
purge: purge,