Skip to content

Commit

Permalink
get rid of "X banners added" edit summary code. simplifies things
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Aug 23, 2024
1 parent 5adb7a7 commit 0f274a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 60 deletions.
16 changes: 4 additions & 12 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1654,17 +1654,16 @@
* 3) {boolean} alreadyOnPage
* @param {boolean} alreadyHasWPBio
* @param {null} existingWPBioTemplateName
* @return {Object} { {string} talkText, {number} countOfWikiProjectsAdded, {number} countOfWikiProjectsRemoved }
* @return {Object}
* 1) {string} talkText
* 2) {number} wikiProjectBannerCount
*/
addTalkPageBanners: function ( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName ) {
// build an array of all banners already on page
var bannerTemplates = 'wikiproject (?!banner)|football|oka';
var bannerTemplateRegEx = new RegExp( '{{(?:' + bannerTemplates + ')[^}]+}}', 'gi' );
var banners = talkText.match( bannerTemplateRegEx ) || [];

// log the count of existing banners. used to calculate how many banners added and removed in the edit summary
var originalBannerCount = banners.length;

// delete all banners already on page
banners.forEach( function ( v ) {
talkText = talkText.replace( v, '' );
Expand All @@ -1684,8 +1683,6 @@
( revId ? '|oldid=' + revId : '' ) +
'}}'
);
// AFCH doesn't count the AFC banner, biography banner, and disambiguation banner towards the "added banners" count in the edit summary
originalBannerCount++;

// 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( function ( value ) {
Expand All @@ -1700,13 +1697,11 @@
'|listas=' + subjectName +
'}}'
);
originalBannerCount++;
}

// add disambiguation banner to array
if ( newAssessment === 'disambig' ) {
banners.push( '{{WikiProject Disambiguation}}' );
originalBannerCount++;
}

// add banners selected in UI to array
Expand Down Expand Up @@ -1741,11 +1736,8 @@
return {
// what to write to the talk page
talkText: talkText,
// used in edit summary. the -1 is because the AFC banner should be ignored
countOfWikiProjectsAdded: banners.length - originalBannerCount,
countOfWikiProjectsRemoved: 0,
// used by unit tests
countOfWikiProjects: banners.length
wikiProjectBannerCount: banners.length
};
},

Expand Down
10 changes: 1 addition & 9 deletions src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2402,15 +2402,7 @@
);
talkText = results.talkText;

var summary = 'Placing [[Wikipedia:Articles for creation|Articles for creation]] banner';
if ( results.countOfWikiProjectsAdded > 0 ) {
summary += ', adding ' + results.countOfWikiProjectsAdded +
' WikiProject banner' + ( ( results.countOfWikiProjectsAdded === 1 ) ? '' : 's' );
}
if ( results.countOfWikiProjectsRemoved > 0 ) {
summary += ', removing ' + results.countOfWikiProjectsRemoved +
' WikiProject banner' + ( ( results.countOfWikiProjectsRemoved === 1 ) ? '' : 's' );
}
var summary = 'Placing [[Wikipedia:Articles for creation|Articles for creation]] banner, and possibly other banners';

if ( comments && comments.length > 0 ) {
talkText = talkText.trim() + '\n\n== Comments left by AfC reviewers ==\n' + comments.join( '\n\n' );
Expand Down
52 changes: 13 additions & 39 deletions tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ describe( 'AFCH.addTalkPageBanners', function () {
{{subst:WPAFC/article|oldid=592485}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 1 );
expect( output.wikiProjectBannerCount ).toBe( 1 );
} );

it( 'talk page has existing sections', function () {
Expand All @@ -166,9 +164,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
== Hello ==
I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="color:blue">'''Novem Linguae'''</span>]] <small>([[User talk:Novem Linguae|talk]])</small> 20:22, 10 April 2024 (UTC)`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 1 );
expect( output.wikiProjectBannerCount ).toBe( 1 );
} );

it( 'talk page has existing templates, WikiProject banners on top', function () {
Expand All @@ -193,9 +189,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
}}
{{translated page|ar|بحيرة كناو|version=|small=no|insertversion=|section=}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 2 );
expect( output.wikiProjectBannerCount ).toBe( 2 );
} );

// FIXME: we probably need to write code that cuts every existing WikiProject banner template and pastes it at the top of the page
Expand All @@ -221,9 +215,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
}}
{{translated page|ar|بحيرة كناو|version=|small=no|insertversion=|section=}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 2 );
expect( output.wikiProjectBannerCount ).toBe( 2 );
} );

it( '|class= is removed from existing banners', function () {
Expand All @@ -245,9 +237,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{subst:WPAFC/article|oldid=592485}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 2 );
expect( output.wikiProjectBannerCount ).toBe( 2 );
} );

it( 'talk page has existing WikiProject banners', function () {
Expand Down Expand Up @@ -289,9 +279,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{subst:WPAFC/article|oldid=592507}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 4 );
expect( output.wikiProjectBannerCount ).toBe( 4 );
} );

it( 'talk page has existing WikiProject banner shell and banners', function () {
Expand Down Expand Up @@ -335,9 +323,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{subst:WPAFC/article|oldid=592507}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 4 );
expect( output.wikiProjectBannerCount ).toBe( 4 );
} );

it( 'talk page has existing WikiProject banner shell and banners, and reviewer adds more banners', function () {
Expand Down Expand Up @@ -371,9 +357,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{WikiProject Romania}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 1 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 6 );
expect( output.wikiProjectBannerCount ).toBe( 6 );
} );

// FIXME
Expand Down Expand Up @@ -417,9 +401,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{subst:WPAFC/article|oldid=592507}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 1 );
expect( output.countOfWikiProjects ).toBe( 4 );
expect( output.wikiProjectBannerCount ).toBe( 4 );
} );

it( 'accept form is a biography with all fields filled in', function () {
Expand All @@ -442,9 +424,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{WikiProject Alabama}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 2 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 4 );
expect( output.wikiProjectBannerCount ).toBe( 4 );
} );

it( 'lifeStatus = dead', function () {
Expand All @@ -465,9 +445,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{WikiProject Biography|living=no|listas=}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 2 );
expect( output.wikiProjectBannerCount ).toBe( 2 );
} );

it.skip( 'talk page has {{wikiproject biography}}, and user selects that it\'s not a biography, so should remove {{wikiproject biography}}', function () {
Expand Down Expand Up @@ -502,9 +480,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{subst:WPAFC/article|oldid=592496}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 0 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 3 );
expect( output.wikiProjectBannerCount ).toBe( 3 );
} );

it( 'user selects class = disambiguation', function () {
Expand All @@ -525,9 +501,7 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{WikiProject Disambiguation}}
}}`
);
expect( output.countOfWikiProjectsAdded ).toBe( 1 );
expect( output.countOfWikiProjectsRemoved ).toBe( 0 );
expect( output.countOfWikiProjects ).toBe( 2 );
expect( output.wikiProjectBannerCount ).toBe( 2 );
} );
} );

Expand Down

0 comments on commit 0f274a0

Please sign in to comment.