Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addTalkPageBanners: fix |class={{{class}}} bug #393

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading