Skip to content

Commit 1ec9205

Browse files
ante: improve diff URL conversion logic
* Gracefully handle diff URLs which are from other wikis * Show overwritten fields when converting diff URL * Show error when attempting to automatically get date from a supplied (non-)revision ID
1 parent f715e76 commit 1ec9205

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

i18n/ante/en.json

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"deputy.ante.templateOptions": "Template options",
4848

4949
"deputy.ante.dateAuto": "Pull the date from the provided revision ID (`$1` parameter)",
50+
"deputy.ante.dateAuto.invalid": "Parameter does not appear to be a valid revision ID.",
5051
"deputy.ante.dateAuto.failed": "Could not pull date from revision: $1",
5152
"deputy.ante.dateAuto.missing": "The revision $1 could not be found. Its page may have been deleted.",
5253

@@ -93,6 +94,7 @@
9394
"deputy.ante.copied.diff.placeholder": "https://en.wikipedia.org/w/index.php?diff=123456",
9495
"deputy.ante.copied.diff.label": "Diff URL",
9596
"deputy.ante.copied.diff.help": "The URL of the diff. Using <code>to_diff</code> and <code>to_oldid</code> is preferred, although supplying this parameter will override both.",
97+
9698
"deputy.ante.copied.merge.label": "Merged?",
9799
"deputy.ante.copied.merge.help": "Whether the copying was done as a result of merging two pages.",
98100
"deputy.ante.copied.afd.placeholder": "AfD page (without Wikipedia:Articles for deletion/)",
@@ -103,6 +105,7 @@
103105
"deputy.ante.copied.advanced": "Advanced",
104106
"deputy.ante.copied.dateInvalid": "The previous date value, \"$1\", was not a valid date.",
105107
"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.",
108+
"deputy.ante.copied.diffDeprecate.warnHost": "The URL in this parameter is not the same as the wiki you're currently editing on. Continue?",
106109
"deputy.ante.copied.diffDeprecate.replace": "The current value of '$1', \"$2\", will be replaced with \"$3\". Continue?",
107110
"deputy.ante.copied.diffDeprecate.failed": "Cannot convert `diff` parameter to URL. See your browser console for more details.",
108111

src/modules/ante/ui/components/RevisionDateGetButton.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,22 @@ function initRevisionDateGetButton() {
5151
* `this.revisionInputWidget`.
5252
*/
5353
async setDateFromRevision(): Promise<void> {
54+
const revid = this.revisionInputWidget.getValue();
55+
56+
if ( isNaN( +revid ) ) {
57+
mw.notify(
58+
mw.msg( 'deputy.ante.dateAuto.invalid' ),
59+
{ type: 'error' }
60+
);
61+
this.updateButton();
62+
return;
63+
}
64+
5465
this
5566
.setIcon( 'ellipsis' )
5667
.setDisabled( true );
5768
this.dateInputWidget.setDisabled( true );
58-
const revid = this.revisionInputWidget.getValue();
69+
5970
await MwApi.action.get( {
6071
action: 'query',
6172
prop: 'revisions',

src/modules/ante/ui/pages/CopiedTemplateRowPage.tsx

+17-3
Original file line numberDiff line numberDiff line change
@@ -537,15 +537,19 @@ function initCopiedTemplateRowPage() {
537537
* Converts a raw diff URL on the same wiki as the current to use `to` and `to_oldid`
538538
* (and `to_diff`, if available).
539539
*/
540-
convertDeprecatedDiff(): void {
540+
async convertDeprecatedDiff(): Promise<void> {
541541
const value = this.inputs.diff.getValue();
542542
try {
543543
const url = new URL( value, window.location.href );
544544
if ( !value ) {
545545
return;
546546
}
547-
if ( url.host === window.location.host ) {
548-
console.warn( 'Attempted to convert a diff URL from another wiki.' );
547+
if ( url.host !== window.location.host ) {
548+
if ( !( await OO.ui.confirm(
549+
mw.msg( 'deputy.ante.copied.diffDeprecate.warnHost' )
550+
) ) ) {
551+
return;
552+
}
549553
}
550554
// From the same wiki, accept deprecation
551555

@@ -556,6 +560,7 @@ function initCopiedTemplateRowPage() {
556560

557561
// Attempt to get values from Special:Diff short-link
558562
const diffSpecialPageCheck =
563+
// eslint-disable-next-line security/detect-unsafe-regex
559564
/\/wiki\/Special:Diff\/(prev|next|\d+)(?:\/(prev|next|\d+))?/.exec( url.pathname );
560565
if ( diffSpecialPageCheck != null ) {
561566
if (
@@ -574,7 +579,14 @@ function initCopiedTemplateRowPage() {
574579
}
575580
}
576581

582+
// If only an oldid was provided, and no diff
583+
if ( oldid && !diff ) {
584+
diff = oldid;
585+
oldid = undefined;
586+
}
587+
577588
const confirmProcess = new OO.ui.Process();
589+
// Looping over the row name and the value that will replace it.
578590
for ( const [ _rowName, newValue ] of [
579591
[ 'to_oldid', oldid ],
580592
[ 'to_diff', diff ],
@@ -601,12 +613,14 @@ function initCopiedTemplateRowPage() {
601613
confirmPromise.done( ( confirmed: boolean ) => {
602614
if ( confirmed ) {
603615
this.inputs[ rowName ].setValue( newValue );
616+
this.fieldLayouts[ rowName ].toggle( true );
604617
}
605618
} );
606619
return confirmPromise;
607620
} );
608621
} else {
609622
this.inputs[ rowName ].setValue( newValue );
623+
this.fieldLayouts[ rowName ].toggle( true );
610624
}
611625
}
612626
confirmProcess.next( () => {

0 commit comments

Comments
 (0)