Skip to content

Commit 25adf3f

Browse files
committed
DraftCleaner: don't use colon trick if {{Draft categories}} is present
1 parent 02f5296 commit 25adf3f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

DraftCleaner/modules/DraftCleaner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ export class DraftCleaner {
314314
// if in draftspace, and draft has categories, disable the categories
315315
disableCategoriesInDraftspace( wikicode, namespace ) {
316316
const draft = ( namespace == 118 );
317-
if ( draft ) {
317+
const hasDraftCategoriesTemplate = wikicode.match( /\{\{Draft categories/i );
318+
if ( draft && !hasDraftCategoriesTemplate ) {
318319
wikicode = wikicode.replace( /:?(\[\[)(Category:[^\]]*\]\])/gm, '$1:$2' );
319320
}
320321
wikicode = wikicode.replace( /\[\[:Category:Created via preloaddraft\]\]/gi, '[[Category:Created via preloaddraft]]' );

DraftCleaner/tests/DraftCleaner.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,20 @@ describe( 'disableCategoriesInDraftspace(wikicode, namespace)', () => {
11041104
[[:Category:Test2]]`;
11051105
expect( dc.disableCategoriesInDraftspace( wikicode, namespace ) ).toBe( output );
11061106
} );
1107+
1108+
test( 'Skip disabling categories if {{Draft categories}} template is present', () => {
1109+
// Adding a colon to categories wrapped in {{Draft categories}} doesn't break anything, but generated a user request to turn this off. See https://en.wikipedia.org/wiki/User_talk:Novem_Linguae/Scripts/DraftCleaner.js#Category_escaping
1110+
const namespace = 118;
1111+
const wikicode =
1112+
`{{draft categories|
1113+
[[Category:20th-century British rappers]]
1114+
}}`;
1115+
const output =
1116+
`{{draft categories|
1117+
[[Category:20th-century British rappers]]
1118+
}}`;
1119+
expect( dc.disableCategoriesInDraftspace( wikicode, namespace ) ).toBe( output );
1120+
} );
11071121
} );
11081122

11091123
describe( 'deleteSomeHTMLTags(wikicode)', () => {

0 commit comments

Comments
 (0)