Skip to content

Commit 76863e5

Browse files
committed
UnblockReview: don't put decline reason when accepting
- if someone accepts while leaving the default decline reason, blank it - if a reason is completely blank, add a signature fixes #238
1 parent b839c12 commit 76863e5

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

DraftCleaner/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const { DraftCleaner } = require( './modules/DraftCleaner.js' );
7070
const wgServer = mw.config.get( 'wgServer' );
7171
const wgScriptPath = mw.config.get( 'wgScriptPath' );
7272
const baseURL = wgServer + wgScriptPath + '/';
73-
// https://stackoverflow.com/a/12464290/3480193
73+
// @copyright devside, CC BY-SA 4.0, https://stackoverflow.com/a/12464290/3480193
7474
$( `<form action="${ baseURL }index.php?title=${ titleEncoded }&action=submit" method="POST"/>` )
7575
.append( $( '<input type="hidden" name="wpTextbox1">' ).val( wikicode ) )
7676
.append( $( '<input type="hidden" name="wpSummary">' ).val( editSummary ) )

UnblockReview/main.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ Many additional bugs fixed.
7979
return;
8080
}
8181

82-
const title = mw.config.get( 'wgPageName' );
83-
const wikitext = await getWikitext( title );
84-
8582
// change wikitext
8683
// eslint-disable-next-line no-undef
8784
const unblockReview = new UnblockReview();
85+
const title = mw.config.get( 'wgPageName' );
86+
const wikitext = await getWikitext( title );
8887
const acceptDeclineReason = reasonArea.value;
8988
let wikitext2;
9089
try {

UnblockReview/modules/UnblockReview.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,22 @@ export class UnblockReview {
2828
initialText = this.getLeftHalfOfUnblockTemplate( wikitext, paramsAndReason );
2929
}
3030

31-
if ( !acceptDeclineReason.trim() ) {
32-
acceptDeclineReason = DEFAULT_DECLINE_REASON + ' ' + this.SIGNATURE;
33-
} else if ( !this.hasSignature( acceptDeclineReason ) ) {
34-
acceptDeclineReason = acceptDeclineReason + ' ' + this.SIGNATURE;
31+
// if reason is blank, use the default decline reason
32+
if ( !acceptDeclineReason.trim() && acceptOrDecline === 'decline' ) {
33+
acceptDeclineReason = DEFAULT_DECLINE_REASON;
34+
}
35+
36+
// if someone accepts using the default decline reason, blank it.
37+
// we can't combine this line with the above because the default decline reason can also be entered by the user, and this is common because it's the default reason in the HTML form.
38+
if ( acceptOrDecline === 'accept' && acceptDeclineReason === DEFAULT_DECLINE_REASON ) {
39+
acceptDeclineReason = '';
40+
}
41+
42+
// add signature if not present, including if the reason is blank
43+
if ( acceptDeclineReason && !this.hasSignature( acceptDeclineReason ) ) {
44+
acceptDeclineReason += ' ' + this.SIGNATURE;
45+
} else if ( !acceptDeclineReason ) {
46+
acceptDeclineReason = this.SIGNATURE;
3547
}
3648

3749
// eslint-disable-next-line no-useless-concat

UnblockReview/tests/UnblockReview.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,26 @@ Seem’st thou thrive if he did banish thee, arm against thy quarrel.`;
255255
`{{unblock reviewed|decline=Please use your other account. ~~~~|1=I was blocked a few days ago for... <span style="font-family:'Courier New', monospace;">[[User:Test]]</span>}}`;
256256
expect( unblockReview.processAcceptOrDecline( wikitext, paramsAndReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline ) ).toBe( expected );
257257
} );
258+
259+
test( 'Add {{subst:Decline reason here}} when declining with a blank reason', () => {
260+
const wikitext =
261+
`{{unblock|1=I was blocked a few days ago for... <span style="font-family:'Courier New', monospace;">[[User:Test]]</span>}}`;
262+
const paramsAndReason = `I was blocked a few days ago for...`;
263+
const acceptDeclineReason = ``;
264+
const acceptOrDecline = `decline`;
265+
const expected =
266+
`{{unblock reviewed|decline={{subst:Decline reason here}} ~~~~|1=I was blocked a few days ago for... <span style="font-family:'Courier New', monospace;">[[User:Test]]</span>}}`;
267+
expect( unblockReview.processAcceptOrDecline( wikitext, paramsAndReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline ) ).toBe( expected );
268+
} );
269+
270+
test( `Don't add {{subst:Decline reason here}} when accepting with a blank reason`, () => {
271+
const wikitext =
272+
`{{unblock|1=I was blocked a few days ago for... <span style="font-family:'Courier New', monospace;">[[User:Test]]</span>}}`;
273+
const paramsAndReason = `I was blocked a few days ago for...`;
274+
const acceptDeclineReason = ``;
275+
const acceptOrDecline = `accept`;
276+
const expected =
277+
`{{unblock reviewed|accept=~~~~|1=I was blocked a few days ago for... <span style="font-family:'Courier New', monospace;">[[User:Test]]</span>}}`;
278+
expect( unblockReview.processAcceptOrDecline( wikitext, paramsAndReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline ) ).toBe( expected );
279+
} );
258280
} );

0 commit comments

Comments
 (0)