From ff9a20317d5085c00ca0061e0c80881a552e1775 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Tue, 3 Sep 2024 17:24:16 -0700 Subject: [PATCH] addTalkPageBanners: handle banners that redirect to biography banner Requested by MSGJ at https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Articles_for_creation&diff=prev&oldid=1243831294 https://en.wikipedia.org/w/index.php?title=Talk:Pere-Enric_de_Ferran_i_de_Rocabruna&diff=prev&oldid=1243831051 --- src/modules/core.js | 65 ++++++++++++++++++++---------- tests/test-core.js | 98 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 140 insertions(+), 23 deletions(-) diff --git a/src/modules/core.js b/src/modules/core.js index e33265c8..c03d4f8d 100644 --- a/src/modules/core.js +++ b/src/modules/core.js @@ -1673,27 +1673,6 @@ '}}' ); - // delete existing biography banner. when accepting, reviewer is forced to choose if it's a biography or not, so we'll add (or not add) our own biography banner later - banners = banners.filter( ( value ) => !value.match( /^{{WikiProject Biography/i ) ); - - // add biography banner to array. and add |living= and |listas= to banner shell - let bannerShellExtraParams = ''; - if ( isBiography ) { - banners.push( - '{{WikiProject Biography}}' - ); - - if ( lifeStatus === 'living' ) { - bannerShellExtraParams += ' |living=yes'; - } else if ( lifeStatus === 'dead' ) { - bannerShellExtraParams += ' |living=no'; - } - - if ( subjectName ) { - bannerShellExtraParams += ' |listas=' + subjectName; - } - } - // add disambiguation banner to array if ( newAssessment === 'Disambig' ) { banners.push( '{{WikiProject Disambiguation}}' ); @@ -1715,6 +1694,42 @@ newAssessment = ''; } + // Some banners such as {{WikiProject Musicians}}, when subst'd later by AnomieBOT, end up as something like {{WikiProject Biography |musician-work-group=yes}}. Do this ourselves to save a step and to prevent two {{WikiProject Biography}} banners. + const bannersThatRedirectToBiographyBanner = { + '{{WikiProject Musicians}}': ' |musician-work-group=yes', + '{{WikiProject Sportspeople}}': ' |sports-work-group=yes' + }; + let workGroupString = ''; + for ( const banner in bannersThatRedirectToBiographyBanner ) { + const workGroup = bannersThatRedirectToBiographyBanner[ banner ]; + const hasBanner = AFCH.hasArrayValueCaseInsensitive( banners, banner ); + if ( hasBanner ) { + banners = AFCH.deleteArrayValueCaseInsensitive( banners, banner ); + workGroupString += workGroup; + } + } + + // delete existing biography banner. when accepting, reviewer is forced to choose if it's a biography or not, so we'll add (or not add) our own biography banner later + banners = banners.filter( ( value ) => !value.match( /^{{WikiProject Biography/i ) ); + + // add biography banner to array. and add |living= and |listas= to banner shell + let bannerShellExtraParams = ''; + if ( isBiography ) { + banners.push( + `{{WikiProject Biography${ workGroupString }}}` + ); + + if ( lifeStatus === 'living' ) { + bannerShellExtraParams += ' |living=yes'; + } else if ( lifeStatus === 'dead' ) { + bannerShellExtraParams += ' |living=no'; + } + + if ( subjectName ) { + bannerShellExtraParams += ' |listas=' + subjectName; + } + } + // 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. @@ -1736,6 +1751,14 @@ return wikicode; }, + deleteArrayValueCaseInsensitive( array, value ) { + return array.filter( ( item ) => item.toLowerCase() !== value.toLowerCase() ); + }, + + hasArrayValueCaseInsensitive( array, value ) { + return array.some( ( item ) => item.toLowerCase() === value.toLowerCase() ); + }, + /** * In an array of templates, remove duplicate templates, case insensitive. * diff --git a/tests/test-core.js b/tests/test-core.js index e6007848..8a12dd8e 100644 --- a/tests/test-core.js +++ b/tests/test-core.js @@ -286,8 +286,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|