Skip to content

Commit

Permalink
addTalkPageBanners: fix |class={{{class}}} bug (#393)
Browse files Browse the repository at this point in the history
fixes #392
  • Loading branch information
NovemLinguae authored Nov 7, 2024
1 parent 72f9c47 commit 39e14fe
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,9 @@
* @return {Object} wikicode
*/
addTalkPageBanners: function ( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName ) {
// delete |class={{{class}}} throughout the page. this is a bit too broad, but is easier than rewriting the below regexes to deal with nested templates
wikicode = wikicode.replace( /\s*\|\s*class\s*=\s*\{\{\{class\}\}\}/i, '' );

// build an array of all banners already on page
const bannerTemplates = 'wikiproject (?!banner)|football|oka';
const bannerTemplateRegEx = new RegExp( '{{(?:' + bannerTemplates + ')[^}]*}}', 'gi' );
Expand Down
84 changes: 84 additions & 0 deletions tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,90 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
{{translated page|pl|Katowice Załęże|version=|small=no|insertversion=|section=}}`
);
} );

it( 'line break between | and 1=', () => {
const wikicode =
`{{WikiProject banner shell|
1=
{{WikiProject Chicago}}
}}`;
const newAssessment = 'B';
const revId = 592681;
const isBiography = true;
const newWikiProjects = [];
const lifeStatus = 'unknown';
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell |class=B |1=
{{subst:WPAFC/article |oldid=592681}}
{{WikiProject Chicago}}
{{WikiProject Biography}}
}}`
);
} );

it( 'has task forces', () => {
const wikicode =
`{{WikiProject banner shell|1=
{{WikiProject Chicago}}
{{WikiProject United States|KY=yes|KY-importance=|category=}}
{{WikiProject Former countries|AH-taskforce=yes|AH-taskforce-importance=}}
{{WikiProject Indiana Historical Society}}
{{WikiProject Architecture}}
{{WikiProject Jewish history}}
}}`;
const newAssessment = 'B';
const revId = 592681;
const isBiography = true;
const newWikiProjects = [];
const lifeStatus = 'unknown';
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell |class=B |1=
{{subst:WPAFC/article |oldid=592681}}
{{WikiProject Chicago}}
{{WikiProject United States|KY=yes|KY-importance=|category=}}
{{WikiProject Former countries|AH-taskforce=yes|AH-taskforce-importance=}}
{{WikiProject Indiana Historical Society}}
{{WikiProject Architecture}}
{{WikiProject Jewish history}}
{{WikiProject Biography}}
}}`
);
} );

it( 'has |class={{{class}}}', () => {
const wikicode =
`{{WikiProject banner shell|1=
{{WikiProject Chicago}}
{{WikiProject United States|KY=yes|KY-importance=|category=}}
{{WikiProject Former countries|class={{{class}}}|AH-taskforce=yes|AH-taskforce-importance=}}
{{WikiProject Indiana Historical Society}}
{{WikiProject Architecture}}
{{WikiProject Jewish history}}
}}`;
const newAssessment = 'B';
const revId = 592681;
const isBiography = true;
const newWikiProjects = [];
const lifeStatus = 'unknown';
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell |class=B |1=
{{subst:WPAFC/article |oldid=592681}}
{{WikiProject Chicago}}
{{WikiProject United States|KY=yes|KY-importance=|category=}}
{{WikiProject Former countries|AH-taskforce=yes|AH-taskforce-importance=}}
{{WikiProject Indiana Historical Society}}
{{WikiProject Architecture}}
{{WikiProject Jewish history}}
{{WikiProject Biography}}
}}`
);
} );
} );

describe( 'AFCH.removeDuplicateBanners', () => {
Expand Down

0 comments on commit 39e14fe

Please sign in to comment.