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

Content deleted Content added
(bot/CD)
(bot/CD)
Line 346:
 
var version = "0.4.2";
var gitAbbrevHash = "8a2c9f807a010c";
var gitBranch = "main";
var gitDate = "FriSun, 110 Sep 2023 1100:0855:4346 +0800";
var gitVersion = "0.4.2+g8a2c9f8g07a010c";
 
/**
Line 1,983:
getRevisionDiffURL(_revid, 'prev') :
getRevisionDiffURL(_parentid, _revid);
let cv;
if (window.deputy.config.cci.showCvLink && window.deputy.wikiConfig.cci.earwigRoot) {
cv = new URL('', window.deputy.wikiConfig.cci.earwigRoot.get());
const selfUrl = new URL(window.___location.href);
const urlSplit = selfUrl.hostname.split('.').reverse();
const proj = urlSplit[1]; // wikipedia
const lang = urlSplit[2]; // en
// Cases where the project/lang is unsupported (e.g. proj = "facebook", for example)
// should be handled by Earwig's.
cv.searchParams.set('action', 'search');
cv.searchParams.set('lang', lang);
cv.searchParams.set('project', proj);
cv.searchParams.set('oldid', `${_revid}`);
cv.searchParams.set('use_engine', '0');
cv.searchParams.set('use_links', '1');
}
return h_1("span", { class: "mw-changeslist-links" },
h_1("span", null,
Line 1,988 ⟶ 2,004:
h_1("span", null, (!_parentid && !missing) ?
mw.msg('deputy.session.revision.prev') :
h_1("a", { rel: "noopener", href: prev, title: mw.msg('deputy.session.revision.prev.tooltip'), target: "_blank" }, mw.msg('deputy.session.revision.prev'))));,
!!window.deputy.config.cci.showCvLink &&
cv &&
h_1("span", null,
h_1("a", { rel: "noopener", href: cv.toString(), title: mw.msg('deputy.session.revision.cv.tooltip'), target: "_blank" }, mw.msg('deputy.session.revision.cv'))));
}
/**
Line 6,116 ⟶ 6,136:
function equalTitle(title1, title2) {
return normalizeTitle(title1).getPrefixedDb() === normalizeTitle(title2).getPrefixedDb();
}
 
/**
* Get the API error text from an API response.
*
* @param errorData
* @param n Get the `n`th error. Defaults to 0 (first error).
*/
function getApiErrorText(errorData, n = 0) {
var _a, _b, _c, _d, _e, _f, _g;
// errorformat=html
return ((_b = (_a = errorData.errors) === null || _a === void 0 ? void 0 : _a[n]) === null || _b === void 0 ? void 0 : _b.html) ?
h_1("span", { dangerouslySetInnerHTML: (_d = (_c = errorData.errors) === null || _c === void 0 ? void 0 : _c[n]) === null || _d === void 0 ? void 0 : _d.html }) :
(
// errorformat=plaintext/wikitext
(_g = (_f = (_e = errorData.errors) === null || _e === void 0 ? void 0 : _e[n]) === null || _f === void 0 ? void 0 : _f.text) !== null && _g !== void 0 ? _g :
// errorformat=bc
errorData.info);
}
 
Line 6,135 ⟶ 6,173:
this.revisionInputWidget = config.revisionInputWidget;
this.dateInputWidget = config.dateInputWidget;
this.revisionInputWidget.on('change', this.updateDateAutoButtonupdateButton.bind(this));
this.dateInputWidget.on('change', this.updateDateAutoButtonupdateButton.bind(this));
this.on('click', this.setDateFromRevision.bind(this));
this.updateDateAutoButtonupdateButton();
}
/**
* Update the disabled state of the button.
*/
updateDateAutoButtonupdateButton() {
this.setDisabled(isNaN(+this.revisionInputWidget.getValue()) ||
!!this.dateInputWidget.getValue());
Line 6,157 ⟶ 6,195:
.setDisabled(true);
this.dateInputWidget.setDisabled(true);
const revid = this.revisionInputWidget.getValue();
yield MwApi.action.get({
action: 'query',
prop: 'revisions',
revids: this.revisionInputWidget.getValue()revid,
rvprop: 'timestamp'
}).then((data) => {
if (data.query.badrevids != null) {
mw.notify(mw.msg('deputy.ante.dateAuto.missing', revid), { type: 'error' });
this.updateButton();
return;
}
this.dateInputWidget.setValue(
// ISO-format date
Line 6,168 ⟶ 6,212:
this.dateInputWidget.setDisabled(false);
this.setIcon('download');
this.updateDateAutoButtonupdateButton();
}, (error_error, errorData) => {
mw.notify(mw.msg('deputy.ante.dateAuto.failed', getApiErrorText(errorData.info)), { type: 'error' });
type: 'error'this.dateInputWidget.setDisabled(false);
}this.setIcon('download');
this.updateDateAutoButtonupdateButton();
});
});
Line 6,190 ⟶ 6,234:
}
return new InternalRevisionDateGetButton(config);
}
 
let InternalSmartTitleInputWidget;
/**
* Initializes the process element.
*/
function initSmartTitleInputWidget() {
InternalSmartTitleInputWidget = class SmartTitleInputWidget extends mw.widgets.TitleInputWidget {
/**
* @param config Configuration to be passed to the element.
*/
constructor(config) {
super(Object.assign(config, {
// Force this to be true
allowSuggestionsWhenEmpty: true
}));
}
/**
* @inheritDoc
*/
getRequestQuery() {
const v = super.getRequestQuery();
return v || normalizeTitle().getSubjectPage().getPrefixedText();
}
/**
* @inheritDoc
*/
getQueryValue() {
const v = super.getQueryValue();
return v || normalizeTitle().getSubjectPage().getPrefixedText();
}
};
}
/**
* Creates a new SmartTitleInputWidget.
*
* @param config Configuration to be passed to the element.
* @return A SmartTitleInputWidget object
*/
function SmartTitleInputWidget (config) {
if (!InternalSmartTitleInputWidget) {
initSmartTitleInputWidget();
}
return new InternalSmartTitleInputWidget(config);
}
 
let InternalPageLatestRevisionGetButton;
/**
* Initializes the process element.
*/
function initPageLatestRevisionGetButton() {
InternalPageLatestRevisionGetButton = class PageLatestRevisionGetButton extends OO.ui.ButtonWidget {
/**
* @param config Configuration to be passed to the element.
*/
constructor(config) {
super(Object.assign({
icon: 'download',
invisibleLabel: true,
disabled: true
}, config));
this.titleInputWidget = config.titleInputWidget;
this.revisionInputWidget = config.revisionInputWidget;
this.titleInputWidget.on('change', this.updateButton.bind(this));
this.revisionInputWidget.on('change', this.updateButton.bind(this));
this.on('click', this.setRevisionFromPageLatestRevision.bind(this));
this.updateButton();
}
/**
* Update the disabled state of the button.
*/
updateButton() {
this.setDisabled(this.titleInputWidget.getValue().trim().length === 0 ||
this.revisionInputWidget.getValue().trim().length !== 0 ||
!this.titleInputWidget.isQueryValid());
}
/**
* Set the revision ID from the page provided in the value of
* `this.titleInputWidget`.
*/
setRevisionFromPageLatestRevision() {
return __awaiter(this, void 0, void 0, function* () {
this
.setIcon('ellipsis')
.setDisabled(true);
this.revisionInputWidget.setDisabled(true);
const title = this.titleInputWidget.getValue();
yield MwApi.action.get({
action: 'query',
prop: 'revisions',
titles: title,
rvprop: 'ids'
}).then((data) => {
if (data.query.pages[0].missing) {
mw.notify(mw.msg('deputy.ante.revisionAuto.missing', title), { type: 'error' });
this.updateButton();
return;
}
this.revisionInputWidget.setValue(data.query.pages[0].revisions[0].revid);
this.revisionInputWidget.setDisabled(false);
this.setIcon('download');
this.updateButton();
}, (_error, errorData) => {
mw.notify(mw.msg('deputy.ante.revisionAuto.failed', getApiErrorText(errorData)), { type: 'error' });
this.revisionInputWidget.setDisabled(false);
this.setIcon('download');
this.updateButton();
});
});
}
};
}
/**
* Creates a new PageLatestRevisionGetButton.
*
* @param config Configuration to be passed to the element.
* @return A PageLatestRevisionGetButton object
*/
function PageLatestRevisionGetButton (config) {
if (!InternalPageLatestRevisionGetButton) {
initPageLatestRevisionGetButton();
}
return new InternalPageLatestRevisionGetButton(config);
}
 
Line 6,343 ⟶ 6,510:
new Date(copiedTemplateRow.date.trim()) : null));
this.inputs = {
from: new mw.widgets.TitleInputWidgetSmartTitleInputWidget({
$overlay: this.parent.$overlay,
placeholder: mw.msg('deputy.ante.copied.from.placeholder'),
Line 6,354 ⟶ 6,521:
validate: /^\d*$/
}),
to: new mw.widgets.TitleInputWidgetSmartTitleInputWidget({
$overlay: this.parent.$overlay,
placeholder: mw.msg('deputy.ante.copied.to.placeholder'),
Line 6,402 ⟶ 6,569:
revisionInputWidget: this.inputs.to_diff,
dateInputWidget: this.inputs.date
});
const revisionAutoFrom = PageLatestRevisionGetButton({
invisibleLabel: false,
label: mw.msg('deputy.ante.revisionAuto'),
title: mw.msg('deputy.ante.revisionAuto.title', 'from'),
titleInputWidget: this.inputs.from,
revisionInputWidget: this.inputs.from_oldid
});
const revisionAutoTo = PageLatestRevisionGetButton({
invisibleLabel: false,
label: mw.msg('deputy.ante.revisionAuto'),
title: mw.msg('deputy.ante.revisionAuto.title', 'to'),
titleInputWidget: this.inputs.to,
revisionInputWidget: this.inputs.to_diff
});
this.fieldLayouts = {
Line 6,410 ⟶ 6,591:
help: mw.msg('deputy.ante.copied.from.help')
}),
from_oldid: new OO.ui.FieldLayoutActionFieldLayout(this.inputs.from_oldid, revisionAutoFrom, {
$overlay: this.parent.$overlay,
label: mw.msg('deputy.ante.copied.from_oldid.label'),
Line 6,422 ⟶ 6,603:
help: mw.msg('deputy.ante.copied.to.help')
}),
to_diff: new OO.ui.FieldLayoutActionFieldLayout(this.inputs.to_diff, revisionAutoTo, {
$overlay: this.parent.$overlay,
label: mw.msg('deputy.ante.copied.to_diff.label'),
Line 7,600 ⟶ 7,781:
new Date(rowDate.trim()) : null));
const inputs = {
to: new mw.widgets.TitleInputWidgetSmartTitleInputWidget({
$overlay: this.parent.$overlay,
required: true,
Line 7,900 ⟶ 8,081:
yesNo(this.splitArticleTemplate.collapse) : false
});
const from = new mw.widgets.TitleInputWidgetSmartTitleInputWidget({
$overlay: this.parent.$overlay,
value: this.splitArticleTemplate.from || '',
Line 8,118 ⟶ 8,299:
new Date(rowDate.trim()) : null));
const inputs = {
article: new mw.widgets.TitleInputWidgetSmartTitleInputWidget({
$overlay: this.parent.$overlay,
required: true,
Line 8,131 ⟶ 8,312:
placeholder: mw.msg('deputy.ante.copied.date.placeholder')
}),
target: new mw.widgets.TitleInputWidgetSmartTitleInputWidget({
$overlay: this.parent.$overlay,
value: this.mergedFromTemplate.target || '',
Line 8,380 ⟶ 8,561:
new Date(rowDate.trim()) : null));
const inputs = {
to: new mw.widgets.TitleInputWidgetSmartTitleInputWidget({
$overlay: this.parent.$overlay,
required: true,
Line 11,505 ⟶ 11,686:
"deputy.ante.dateAuto": "Pull the date from the provided revision ID (`$1` parameter)",
"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.",
"deputy.ante.revisionAuto": "Latest",
"deputy.ante.revisionAuto.title": "Pull the revision ID from the latest (current) revision of the page in `$1`.",
"deputy.ante.revisionAuto.failed": "Could not pull revision ID from page: $1",
"deputy.ante.revisionAuto.missing": "The page $1 could not be found. It may have been deleted.",
"deputy.ante.copied.label": "Copied $1",
"deputy.ante.copied.remove": "Remove notice",
Line 12,114 ⟶ 12,300:
this.cci = {
enablePageToolbar: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
showCvLink: new Setting({
defaultValue: true,
displayOptions: {
Line 12,578 ⟶ 12,770:
"deputy.setting.user.cci.enablePageToolbar.name": "Enable page toolbar",
"deputy.setting.user.cci.enablePageToolbar.description": "Enables the page toolbar, which is used to quickly show tools, analysis options, and related case information on a page that is the subject of a CCI investigation.",
"deputy.setting.user.cci.enablePageToolbarshowCvLink.unimplementedname": "ThisShow feature\"cv\" has(\"copyvios\") notlink yetfor been implemented.revisions",
"deputy.setting.user.cci.showCvLink.description": "Show a \"cv\" link next to \"cur\" and \"prev\" on revision rows. This link will only appear if this wiki is configured to use Earwig's Copyvio Detector.",
"deputy.setting.user.cci.forceUtc.name": "Force UTC time",
"deputy.setting.user.cci.forceUtc.description": "Forces Deputy to use UTC time whenever displaying dates and times, irregardless of your system's timezone or your MediaWiki time settings.",
Line 12,627 ⟶ 12,820:
"deputy.setting.wiki.core.dispatchRoot.name": "Deputy Dispatch root URL",
"deputy.setting.wiki.core.dispatchRoot.description": "The URL to a Deputy Dispatch instance that can handle this wiki. Deputy Dispatch is a webserver responsible for centralizing and optimizing data used by Deputy, and can be used to reduce load on wikis. More information can be found at https://github.com/ChlodAlejandro/deputy-dispatch.",
"deputy.setting.wiki.core.changeTag.name": "Change tag",
"deputy.setting.wiki.core.changeTag.description": "Tag to use for all Deputy edits.",
"deputy.setting.wiki.cci": "CCI",
"deputy.setting.wiki.cci.enabled.name": "Enable contributor copyright investigations assistant",
Line 13,803 ⟶ 13,998:
"deputy.session.revision.cur": "cur",
"deputy.session.revision.prev": "prev",
"deputy.session.revision.cv": "cv",
"deputy.session.revision.cur.tooltip": "Difference with latest revision",
"deputy.session.revision.prev.tooltip": "Difference with preceding revision",
"deputy.session.revision.cv.tooltip": "Run through Earwig's Copyvio Detector",
"deputy.session.revision.talk": "talk",
"deputy.session.revision.contribs": "contribs",