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

improve wikicode writing to draft talk pages #376

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
16 changes: 9 additions & 7 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@
// Put at top for historical reasons. People are used to it being there.
banners.unshift(
'{{subst:WPAFC/article' +
( revId ? '|oldid=' + revId : '' ) +
( revId ? ' |oldid=' + revId : '' ) +
'}}'
);

Expand All @@ -1679,15 +1679,15 @@
// add biography banner to array
if ( isBiography ) {
banners.push(
'{{WikiProject Biography|living=' +
'{{WikiProject Biography |living=' +
( lifeStatus !== 'unknown' ? ( lifeStatus === 'living' ? 'yes' : 'no' ) : '' ) +
'|listas=' + subjectName +
' |listas=' + subjectName +
'}}'
);
}

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

Expand All @@ -1707,8 +1707,8 @@
// Add |class= to shell.
// Add |1=. Improves readability when lots of other parameters present.
wikicode = '{{WikiProject banner shell' +
( newAssessment ? '|class=' + newAssessment : '' ) +
'|1=\n' +
( newAssessment ? ' |class=' + newAssessment : '' ) +
' |1=\n' +
banners.join( '\n' ) +
'\n}}\n' +
wikicode;
Expand All @@ -1732,7 +1732,9 @@
const uniqueBanners = [];
const bannerMap = {};
banners.forEach( ( banner ) => {
const bannerKey = banner.toLowerCase().match( /{{[^|}]+/ )[ 0 ];
let bannerKey = banner.toLowerCase().match( /{{[^|}]+/ )[ 0 ];
// get rid of whitespace at the end of the template name
bannerKey = bannerKey.trim();
if ( !bannerMap[ bannerKey ] ) {
uniqueBanners.push( banner );
bannerMap[ bannerKey ] = true;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1597,10 +1597,10 @@
// If draft is assessed as stub, show stub sorting
// interface using User:SD0001/StubSorter.js
$afch.find( '#newAssessment' ).on( 'change', function () {
const isClassStub = $( this ).val() === 'stub';
const isClassStub = $( this ).val() === 'Stub';
$afch.find( '#stubSorterWrapper' ).toggleClass( 'hidden', !isClassStub );
if ( isClassStub ) {
if ( mw.config.get( 'wgDBname' ) !== 'enwiki' ) {
if ( mw.config.get( 'wgDBname' ) !== 'enwiki' && mw.config.get( 'wgDBname' ) !== 'testwiki' ) {
console.warn( 'no stub sorting script available for this language wiki' );
return;
}
Expand All @@ -1622,7 +1622,7 @@
$( '#stub-sorter-select' ).addClass( 'afch-input' );

if ( /\{\{[^{ ]*[sS]tub(\|.*?)?\}\}\s*/.test( pageText ) ) {
$afch.find( '#newAssessment' ).val( 'stub' ).trigger( 'chosen:updated' ).trigger( 'change' );
$afch.find( '#newAssessment' ).val( 'Stub' ).trigger( 'chosen:updated' ).trigger( 'change' );
}
} );
}
Expand Down
18 changes: 9 additions & 9 deletions src/templates/tpl-submissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@
<option value="" selected></option>
<option value="B">B-class</option>
<option value="C">C-class</option>
<option value="start">Start-class</option>
<option value="stub">Stub-class</option>
<option value="list">List-class</option>
<option value="disambig">Disambig-class</option>
<option value="template">Template-class</option>
<option value="redirect">Redirect-class</option>
<option value="portal">Portal-class</option>
<option value="project">Project-class</option>
<option value="na">NA-class</option>
<option value="Start">Start-class</option>
<option value="Stub">Stub-class</option>
<option value="List">List-class</option>
<option value="Disambig">Disambig-class</option>
<option value="Template">Template-class</option>
<option value="Redirect">Redirect-class</option>
<option value="Portal">Portal-class</option>
<option value="Project">Project-class</option>
<option value="NA">NA-class</option>
</select>
</div>

Expand Down
75 changes: 43 additions & 32 deletions tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ describe( 'AFCH.addTalkPageBanners', () => {
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592485}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592485}}
}}`
);
} );
Expand All @@ -150,8 +150,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592485}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592485}}
}}

== Hello ==
Expand All @@ -172,8 +172,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592485}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592485}}
{{WikiProject Women}}
}}
{{translated page|ar|بحيرة كناو|version=|small=no|insertversion=|section=}}`
Expand All @@ -193,8 +193,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592485}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592485}}
{{WikiProject Women}}
}}
{{translated page|ar|بحيرة كناو|version=|small=no|insertversion=|section=}}`
Expand All @@ -212,8 +212,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592485}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592485}}
{{WikiProject Women}}
}}`
);
Expand All @@ -232,8 +232,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592507}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592507}}
{{WikiProject Women}}
{{WikiProject Women's sport}}
{{WikiProject Somalia}}
Expand All @@ -256,8 +256,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592507}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592507}}
{{WikiProject Women}}
{{WikiProject Women's sport}}
{{WikiProject Somalia}}
Expand All @@ -281,12 +281,12 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = 'Lazarut, Raluca';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592507}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592507}}
{{WikiProject Film}}
{{WikiProject Women}}
{{WikiProject Television}}
{{WikiProject Biography|living=yes|listas=Lazarut, Raluca}}
{{WikiProject Biography |living=yes |listas=Lazarut, Raluca}}
{{WikiProject Romania}}
}}`
);
Expand All @@ -307,8 +307,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592507}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592507}}
{{WikiProject Women}}
{{WikiProject Women's sport}}
{{WikiProject Somalia}}
Expand All @@ -326,9 +326,9 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = 'Jones, Bob';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|class=B|1=
{{subst:WPAFC/article|oldid=592496}}
{{WikiProject Biography|living=yes|listas=Jones, Bob}}
`{{WikiProject banner shell |class=B |1=
{{subst:WPAFC/article |oldid=592496}}
{{WikiProject Biography |living=yes |listas=Jones, Bob}}
{{WikiProject Africa}}
{{WikiProject Alabama}}
}}`
Expand All @@ -345,9 +345,9 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592496}}
{{WikiProject Biography|living=no|listas=}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592496}}
{{WikiProject Biography |living=no |listas=}}
}}`
);
} );
Expand All @@ -365,25 +365,25 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592496}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592496}}
{{WikiProject Somalia}}
}}`
);
} );

it( 'user selects class = disambiguation', () => {
const wikicode = '';
const newAssessment = 'disambig';
const newAssessment = 'Disambig';
const revId = 592681;
const isBiography = false;
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=disambig|1=
{{subst:WPAFC/article|oldid=592681}}
`{{WikiProject banner shell |class=Disambig |1=
{{subst:WPAFC/article |oldid=592681}}
{{WikiProject Disambiguation}}
}}`
);
Expand All @@ -400,8 +400,8 @@ I have a question. Can you help answer it? –[[User:Novem Linguae|<span style="
const subjectName = '';
const output = AFCH.addTalkPageBanners( wikicode, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName );
expect( output ).toBe(
`{{WikiProject banner shell|1=
{{subst:WPAFC/article|oldid=592681}}
`{{WikiProject banner shell |1=
{{subst:WPAFC/article |oldid=592681}}
{{OKA}}
}}
{{translated page|pl|Katowice Załęże|version=|small=no|insertversion=|section=}}`
Expand Down Expand Up @@ -454,4 +454,15 @@ describe( 'AFCH.removeDuplicateBanners', () => {
'{{WikiProject Ontario}}'
] );
} );

it( 'should handle a space at the end of the template name', () => {
const banners = [
'{{WikiProject Military history |Indian-task-force=yes}}',
'{{WikiProject Military history}}'
];
const output = AFCH.removeDuplicateBanners( banners );
expect( output ).toEqual( [
'{{WikiProject Military history |Indian-task-force=yes}}'
] );
} );
} );
Loading