From 93c1a046b089bc018e63a7bfaae812c60a59f422 Mon Sep 17 00:00:00 2001 From: briick03 Date: Fri, 24 Feb 2023 22:20:47 +0100 Subject: [PATCH 1/5] Change placement order at RMTR --- modules/twinklexfd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index 275dcde39..b40d72786 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -2016,8 +2016,8 @@ Twinkle.xfd.callbacks = { var params = pageobj.getCallbackParameters(); var statelem = pageobj.getStatusElement(); - var hiddenCommentRE = /==== ?Uncontroversial technical requests ?====(?:.|\n)*? -->/i; - var newtext = text.replace(hiddenCommentRE, '$&\n' + Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params)); + var placementRE = /===== ?Requests to revert undiscussed moves ?=====/i; + var newtext = text.replace(placementRE, Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params) + '\n$&'); if (text === newtext) { statelem.error('failed to find target spot for the entry'); return; From 342adb22cd80be6229d2b3bfa93e88b2d89670af Mon Sep 17 00:00:00 2001 From: briick03 Date: Fri, 24 Feb 2023 22:30:38 +0100 Subject: [PATCH 2/5] Fix newline issues --- modules/twinklexfd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index b40d72786..9e145b3dd 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -2016,8 +2016,8 @@ Twinkle.xfd.callbacks = { var params = pageobj.getCallbackParameters(); var statelem = pageobj.getStatusElement(); - var placementRE = /===== ?Requests to revert undiscussed moves ?=====/i; - var newtext = text.replace(placementRE, Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params) + '\n$&'); + var placementRE = /\n\n?(===== ?Requests to revert undiscussed moves ?=====)/i; + var newtext = text.replace(placementRE, Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params) + '\n$1'); if (text === newtext) { statelem.error('failed to find target spot for the entry'); return; From feab8d0774ba8c123175d1ddb68e7f9835661361 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Sun, 23 Jul 2023 01:13:59 -0700 Subject: [PATCH 3/5] level 4 heading --- modules/twinklexfd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index 9e145b3dd..210e61dbf 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -2016,7 +2016,7 @@ Twinkle.xfd.callbacks = { var params = pageobj.getCallbackParameters(); var statelem = pageobj.getStatusElement(); - var placementRE = /\n\n?(===== ?Requests to revert undiscussed moves ?=====)/i; + var placementRE = /\n\n?(==== ?Requests to revert undiscussed moves ?====)/i; var newtext = text.replace(placementRE, Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params) + '\n$1'); if (text === newtext) { statelem.error('failed to find target spot for the entry'); From 09a3ef61719813687bb85a1c2a5b4fb323b720b0 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Sun, 23 Jul 2023 01:52:28 -0700 Subject: [PATCH 4/5] add tests, always add exactly 1 empty line --- modules/twinklexfd.js | 15 ++++-- tests/jest.setup.js | 1 + tests/twinklexfd.test.js | 110 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 tests/twinklexfd.test.js diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index 210e61dbf..72aa00500 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -2016,8 +2016,8 @@ Twinkle.xfd.callbacks = { var params = pageobj.getCallbackParameters(); var statelem = pageobj.getStatusElement(); - var placementRE = /\n\n?(==== ?Requests to revert undiscussed moves ?====)/i; - var newtext = text.replace(placementRE, Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params) + '\n$1'); + var discussionWikitext = Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params); + var newtext = Twinkle.xfd.insertRMTR(text, discussionWikitext); if (text === newtext) { statelem.error('failed to find target spot for the entry'); return; @@ -2034,7 +2034,16 @@ Twinkle.xfd.callbacks = { } }; - +/** + * Given the wikitext of the WP:RM/TR page and the wikitext to insert, insert it at the bottom of the ==== Uncontroversial technical requests ==== section. + * @param {String} pageWikitext + * @param {String} wikitextToInsert Will typically be `{{subst:RMassist|1=From|2=To|reason=Reason}}`, which expands out to `* {{RMassist/core | 1 = From | 2 = To | discuss = yes | reason = Reason | sig = Signature | requester = YourUserName}}` + * @return {String} + */ +Twinkle.xfd.insertRMTR = function(pageWikitext, wikitextToInsert) { + var placementRE = /\n{1,}(==== ?Requests to revert undiscussed moves ?====)/i; + return pageWikitext.replace(placementRE, '\n' + wikitextToInsert + '\n\n$1'); +}; Twinkle.xfd.callback.evaluate = function(e) { var form = e.target; diff --git a/tests/jest.setup.js b/tests/jest.setup.js index 805abb9e9..b3d3c7790 100644 --- a/tests/jest.setup.js +++ b/tests/jest.setup.js @@ -7,6 +7,7 @@ mw.config.set({ require('../morebits.js'); require('../twinkle.js'); require('../modules/twinklewarn.js'); +require('../modules/twinklexfd.js'); global.Morebits = window.Morebits; global.assert = require('assert'); diff --git a/tests/twinklexfd.test.js b/tests/twinklexfd.test.js new file mode 100644 index 000000000..b96b87a8f --- /dev/null +++ b/tests/twinklexfd.test.js @@ -0,0 +1,110 @@ +describe('modules/twinklexfd', () => { + describe('insertRMTR', () => { + test('0 rows, 1 line breaks', () => { + const pageWikitext = +` +==== Requests to revert undiscussed moves ====`; + const wikitextToInsert = `* {{RMassist/core}}`; + const expected = +` +* {{RMassist/core}} + +==== Requests to revert undiscussed moves ====`; + expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected); + }); + + test('0 rows, 1 line breaks', () => { + const pageWikitext = +` + +==== Requests to revert undiscussed moves ====`; + const wikitextToInsert = `* {{RMassist/core}}`; + const expected = +` +* {{RMassist/core}} + +==== Requests to revert undiscussed moves ====`; + expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected); + }); + + test('0 rows, 2 line breaks', () => { + const pageWikitext = +` + + +==== Requests to revert undiscussed moves ====`; + const wikitextToInsert = `* {{RMassist/core}}`; + const expected = +` +* {{RMassist/core}} + +==== Requests to revert undiscussed moves ====`; + expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected); + }); + + test('1 rows, 0 line breaks', () => { + const pageWikitext = +` +* {{RMassist/core2}} +==== Requests to revert undiscussed moves ====`; + const wikitextToInsert = `* {{RMassist/core}}`; + const expected = +` +* {{RMassist/core2}} +* {{RMassist/core}} + +==== Requests to revert undiscussed moves ====`; + expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected); + }); + + test('2 rows, 0 line breaks', () => { + const pageWikitext = +` +* {{RMassist/core2}} +* {{RMassist/core3}} +==== Requests to revert undiscussed moves ====`; + const wikitextToInsert = `* {{RMassist/core}}`; + const expected = +` +* {{RMassist/core2}} +* {{RMassist/core3}} +* {{RMassist/core}} + +==== Requests to revert undiscussed moves ====`; + expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected); + }); + + test('1 rows, 1 line breaks', () => { + const pageWikitext = +` +* {{RMassist/core2}} + +==== Requests to revert undiscussed moves ====`; + const wikitextToInsert = `* {{RMassist/core}}`; + const expected = +` +* {{RMassist/core2}} +* {{RMassist/core}} + +==== Requests to revert undiscussed moves ====`; + expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected); + }); + + test('1 rows, 2 line breaks', () => { + const pageWikitext = +` +* {{RMassist/core2}} + + +==== Requests to revert undiscussed moves ====`; + const wikitextToInsert = `* {{RMassist/core}}`; + const expected = +` +* {{RMassist/core2}} +* {{RMassist/core}} + +==== Requests to revert undiscussed moves ====`; + expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected); + }); + }); +}); From a6d13e5c8a50afd3e814741a44f9ebac3886123e Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Sun, 23 Jul 2023 01:57:53 -0700 Subject: [PATCH 5/5] comment --- modules/twinklexfd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index 72aa00500..69b2ea52e 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -2038,7 +2038,7 @@ Twinkle.xfd.callbacks = { * Given the wikitext of the WP:RM/TR page and the wikitext to insert, insert it at the bottom of the ==== Uncontroversial technical requests ==== section. * @param {String} pageWikitext * @param {String} wikitextToInsert Will typically be `{{subst:RMassist|1=From|2=To|reason=Reason}}`, which expands out to `* {{RMassist/core | 1 = From | 2 = To | discuss = yes | reason = Reason | sig = Signature | requester = YourUserName}}` - * @return {String} + * @return {String} pageWikitext */ Twinkle.xfd.insertRMTR = function(pageWikitext, wikitextToInsert) { var placementRE = /\n{1,}(==== ?Requests to revert undiscussed moves ?====)/i;