Skip to content

Commit

Permalink
addTalkPageBanners: don't write a class if the shell auto detects it (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae authored Sep 2, 2024
1 parent b6afc53 commit 2b33a3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,11 @@
// delete |class= from banners in array
banners = banners.map( ( value ) => value.replace( /\s*\|\s*class\s*=\s*[^|}]*([\n|}])/, '$1' ) );

// The banner shell automatically detects several classes. If it's one of these auto detected classes, write |class= blank instead of writing the class.
if ( [ 'Disambig', 'Template', 'Redirect', 'Portal', 'Project', 'NA' ].indexOf( newAssessment ) !== -1 ) {
newAssessment = '';
}

// Convert array back to wikitext and append to top of talk page.
// Always add a shell even if it's just wrapping one banner, for code simplification reasons.
// Add |class= to shell.
Expand Down
18 changes: 17 additions & 1 deletion tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,29 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell |class=Disambig |1=
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592681}}
{{WikiProject Disambiguation}}
}}`
);
} );

it( 'don\'t write a |class= if the banner shell can auto detect it. Examples: Template, Portal, Disambig, etc.', () => {
const wikicode = '';
const newAssessment = 'Template';
const revId = 592681;
const isBiography = false;
const newWikiProjects = [];
const lifeStatus = 'unknown';
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592681}}
}}`
);
} );

it( 'has {{OKA}} banner and puts it in the banner shell', () => {
const wikicode =
`{{translated page|pl|Katowice Załęże|version=|small=no|insertversion=|section=}}{{OKA}}`;
Expand Down

0 comments on commit 2b33a3d

Please sign in to comment.