Skip to content

Commit

Permalink
Use WikiProject banner shell on draft talk pages
Browse files Browse the repository at this point in the history
- Fix #319 Implement WP:PIQA (put the article's class rating in the banner shell instead of in the wikiproject templates)
- Fix #73 Multiple WikiProject banners should be collapsed in {{WikiProject banner shell}}
- In unit tests, switch from single quotes to backticks, for increased multi-line readability.
  • Loading branch information
NovemLinguae committed Aug 21, 2024
1 parent 5f1f3e8 commit cb43f58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
15 changes: 13 additions & 2 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@
talkText = talkTextPrefix + '\n\n' + talkText;

// Add banner shell if needed
var banners = talkText.match( /{{(?:wikiproject[^}]+}}|subst:wpafc)/gi );
var banners = talkText.match( /{{(?:wikiproject[^}]+}}|subst:wpafc|football)/gi );
// https://en.wikipedia.org/wiki/Special:WhatLinksHere?target=Template%3AWikiProject+banner+shell&namespace=&hidetrans=1&hidelinks=1
var bannerShellDetectionRegex = /{{(?:WikiProject banner shell|WikiProjectBanners|WikiProject Banners|WPB|WPBS|WikiProject cooperation shell|Wikiprojectbannershell|WikiProject Banner Shell|Wpb|WPBannerShell|Wpbs|Wikiprojectbanners|WP Banner Shell|WP banner shell|Bannershell|Wikiproject banner shell|WIkiProjectBanner Shell|WikiProjectBannerShell|WikiProject BannerShell|Coopshell|WikiprojectBannerShell|WikiProject Shell|Scope shell|Project shell|WikiProject shell|WikiProject banner|Wpbannershell|Multiple wikiprojects|Wikiproject banner holder|Project banner holder|WikiProject banner shell\/test1|Article assessment|WikiProject bannershell)/i;
var hasBannerShell = talkText.match( bannerShellDetectionRegex );
Expand All @@ -1722,11 +1722,22 @@
talkText = talkText.replace( lastBanner, lastBanner + '\n' + bannerShellEnd );
}

// If banner shell is present, comply with [[WP:PIQA]]. Add the class only to the banner shell. Delete any other class parameters.
hasBannerShell = talkText.match( bannerShellDetectionRegex );
if ( hasBannerShell ) {
// delete all |class= from the entire talk page
talkText = talkText.replace( /[\n|}]class\s*=\s*[^\n|}]*([\n|}])/g, '$1' );
// add |class= to the banner shell only
if ( newAssessment ) {
talkText = talkText.replace( bannerShellDetectionRegex, '$&|class=' + newAssessment );
}
}

return {
talkText: talkText,
countOfWikiProjectsAdded: wikiProjectsToAdd.length,
countOfWikiProjectsRemoved: wikiProjectsToRemove.length,
// adding this param mainly for unit tests, so we can test how well the banner detection algorithm works
// adding this param for unit tests, so we can test that the banner detection algorithm works
bannerCount: banners.length
};
},
Expand Down
28 changes: 14 additions & 14 deletions tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
var output = AFCH.addTalkPageBanners( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName );
expect( output.talkText ).toBe(
`{{WikiProject banner shell|
{{subst:WPAFC/article|class=|oldid=592507}}
{{subst:WPAFC/article|oldid=592507}}
{{WikiProject Women}}
{{WikiProject Women's sport}}
Expand Down Expand Up @@ -249,7 +249,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
var output = AFCH.addTalkPageBanners( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName );
expect( output.talkText ).toBe(
`{{WikiProject banner shell|
{{subst:WPAFC/article|class=|oldid=592507}}
{{subst:WPAFC/article|oldid=592507}}
{{WikiProject Women}}
{{WikiProject Women's sport}}
Expand All @@ -274,11 +274,11 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
var existingWPBioTemplateName = null;
var output = AFCH.addTalkPageBanners( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName );
expect( output.talkText ).toBe(
`{{WikiProject banner shell|
{{subst:WPAFC/article|class=B|oldid=592496}}
{{WikiProject Biography|living=yes|class=B|listas=Jones, Bob}}
{{WikiProject Africa|class=B}}
{{WikiProject Alabama|class=B}}
`{{WikiProject banner shell|class=B|
{{subst:WPAFC/article|oldid=592496}}
{{WikiProject Biography|living=yes|listas=Jones, Bob}}
{{WikiProject Africa}}
{{WikiProject Alabama}}
}}
`
Expand All @@ -302,8 +302,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
var output = AFCH.addTalkPageBanners( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName );
expect( output.talkText ).toBe(
`{{WikiProject banner shell|
{{subst:WPAFC/article|class=|oldid=592496}}
{{WikiProject Biography|living=no|class=|listas=}}
{{subst:WPAFC/article|oldid=592496}}
{{WikiProject Biography|living=no|listas=}}
}}
`
Expand Down Expand Up @@ -342,9 +342,9 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
var output = AFCH.addTalkPageBanners( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName );
expect( output.talkText ).toBe(
`{{WikiProject banner shell|
{{subst:WPAFC/article|class=|oldid=592496}}
{{subst:WPAFC/article|oldid=592496}}
{{wikiproject biography|living=yes|class=B|listas=Jones, Bob}}
{{wikiproject biography|living=yes|listas=Jones, Bob}}
{{WikiProject Somalia}}
}}`
);
Expand All @@ -366,9 +366,9 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
var existingWPBioTemplateName = null;
var output = AFCH.addTalkPageBanners( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName );
expect( output.talkText ).toBe(
`{{WikiProject banner shell|
{{subst:WPAFC/article|class=disambig|oldid=592681}}
{{WikiProject Disambiguation|class=disambig}}
`{{WikiProject banner shell|class=disambig|
{{subst:WPAFC/article|oldid=592681}}
{{WikiProject Disambiguation}}
}}
`
Expand Down

0 comments on commit cb43f58

Please sign in to comment.