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

Content deleted Content added
(bot/CD)
(bot/CD)
Line 3,663:
 
var version = "0.4.2";
var gitAbbrevHash = "0349076e65d73d";
var gitBranch = "main";
var gitDate = "ThuTue, 1722 Aug 2023 1122:5209:0530 +0800";
var gitVersion = "0.4.2+g0349076ge65d73d";
 
/**
Line 6,104:
function equalTitle(title1, title2) {
return normalizeTitle(title1).getPrefixedDb() === normalizeTitle(title2).getPrefixedDb();
}
 
let InternalRevisionDateGetButton;
/**
* Initializes the process element.
*/
function initRevisionDateGetButton() {
InternalRevisionDateGetButton = class RevisionDateGetButton 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.revisionInputWidget = config.revisionInputWidget;
this.dateInputWidget = config.dateInputWidget;
this.revisionInputWidget.on('change', this.updateDateAutoButton.bind(this));
this.dateInputWidget.on('change', this.updateDateAutoButton.bind(this));
this.on('click', this.setDateFromRevision.bind(this));
this.updateDateAutoButton();
}
/**
* Update the disabled state of the button.
*/
updateDateAutoButton() {
this.setDisabled(isNaN(+this.revisionInputWidget.getValue()) ||
!!this.dateInputWidget.getValue());
}
/**
* Set the date from the revision ID provided in the value of
* `this.revisionInputWidget`.
*/
setDateFromRevision() {
return __awaiter(this, void 0, void 0, function* () {
this
.setIcon('ellipsis')
.setDisabled(true);
this.dateInputWidget.setDisabled(true);
yield MwApi.action.get({
action: 'query',
prop: 'revisions',
revids: this.revisionInputWidget.getValue(),
rvprop: 'timestamp'
}).then((data) => {
this.dateInputWidget.setValue(data.query.pages[0].revisions[0].timestamp.split('T')[0]);
this.dateInputWidget.setDisabled(false);
this.setIcon('download');
this.updateDateAutoButton();
}, (error, errorData) => {
mw.notify(mw.msg('deputy.ante.dateAuto.failed', errorData.info), {
type: 'error'
});
this.updateDateAutoButton();
});
});
}
};
}
/**
* Creates a new RevisionDateGetButton.
*
* @param config Configuration to be passed to the element.
* @return A RevisionDateGetButton object
*/
function RevisionDateGetButton (config) {
if (!InternalRevisionDateGetButton) {
initRevisionDateGetButton();
}
return new InternalRevisionDateGetButton(config);
}
 
Line 6,307 ⟶ 6,379:
};
const diffConvert = new OO.ui.ButtonWidget({
label: mw.msg('Convertdeputy.ante.copied.convert')
});
const dateAuto = RevisionDateGetButton({
label: mw.msg('deputy.ante.dateAuto', 'to_diff'),
revisionInputWidget: this.inputs.to_diff,
dateInputWidget: this.inputs.date
});
// const dateButton = new OO.ui.PopupButtonWidget({
// icon: "calendar",
// title: "Select a date"
// });
this.fieldLayouts = {
from: new OO.ui.FieldLayout(this.inputs.from, {
Line 6,363 ⟶ 6,436:
help: mw.msg('deputy.ante.copied.afd.help')
}),
date: new OO.ui.FieldLayoutActionFieldLayout(this.inputs.date, dateAuto, {
align: 'inline',
classes: ['cte-fieldset-date']
Line 7,520 ⟶ 7,593:
value: this.splitArticleTemplateRow.from_oldid || '',
placeholder: mw.msg('deputy.ante.splitArticle.from_oldid.placeholder')
}),
date: new mw.widgets.DateInputWidget({
$overlay: this.parent.$overlay,
required: true,
icon: 'calendar',
value: parsedDate ? `${parsedDate.getUTCFullYear()}-${parsedDate.getUTCMonth() + 1}-${parsedDate.getUTCDate()}` : undefined,
placeholder: mw.msg('deputy.ante.copied.date.placeholder')
}),
diff: new OO.ui.TextInputWidget({
Line 7,546 ⟶ 7,612:
}
}
}),
date: new mw.widgets.DateInputWidget({
$overlay: this.parent.$overlay,
required: true,
icon: 'calendar',
value: parsedDate ? `${parsedDate.getUTCFullYear()}-${parsedDate.getUTCMonth() + 1}-${parsedDate.getUTCDate()}` : undefined,
placeholder: mw.msg('deputy.ante.copied.date.placeholder')
})
};
const dateAuto = RevisionDateGetButton({
label: mw.msg('deputy.ante.dateAuto', 'diff'),
revisionInputWidget: inputs.diff,
dateInputWidget: inputs.date
});
const fieldLayouts = {
to: new OO.ui.FieldLayout(inputs.to, {
Line 7,561 ⟶ 7,639:
label: mw.msg('deputy.ante.splitArticle.from_oldid.label'),
help: mw.msg('deputy.ante.splitArticle.from_oldid.help')
}),
date: new OO.ui.FieldLayout(inputs.date, {
$overlay: this.parent.$overlay,
align: 'left',
label: mw.msg('deputy.ante.splitArticle.date.label'),
help: mw.msg('deputy.ante.splitArticle.date.help')
}),
diff: new OO.ui.FieldLayout(inputs.diff, {
Line 7,573 ⟶ 7,645:
label: mw.msg('deputy.ante.splitArticle.diff.label'),
help: mw.msg('deputy.ante.splitArticle.diff.help')
}),
date: new OO.ui.ActionFieldLayout(inputs.date, dateAuto, {
$overlay: this.parent.$overlay,
align: 'left',
label: mw.msg('deputy.ante.splitArticle.date.label'),
help: mw.msg('deputy.ante.splitArticle.date.help')
})
};
Line 11,418 ⟶ 11,496:
"deputy.ante.merge.button": "Merge",
"deputy.ante.templateOptions": "Template options",
"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.copied.label": "Copied $1",
"deputy.ante.copied.remove": "Remove notice",
Line 11,432 ⟶ 11,512:
"deputy.ante.copied.collapse": "Collapse",
"deputy.ante.copied.small": "Small",
"deputy.ante.copied.convert": "Convert",
"deputy.ante.copied.from.placeholder": "Page A",
"deputy.ante.copied.from.label": "Page copied from",
Line 13,622 ⟶ 13,703:
'mediawiki.Title',
'mediawiki.widgets',
'mediawiki.widgets.datetimeDateInputWidget',
'jquery.makeCollapsible'
];