Skip to content

Commit

Permalink
cci: fix pre-2014 style processing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Mar 22, 2023
1 parent ddd3101 commit 595ce69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
26 changes: 22 additions & 4 deletions src/models/ContributionSurveyRowParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ export interface RawContributionSurveyRow {
*
* $1 - Revision ID
* $2 - Diff size
* $3 - Bold syntax (if any; "'''").
*/
diffTemplate: string;
/**
* Template to use for rebuilding the entirety of the diffs section.
*
* $1 - Diff links
*
* @default "$1"
*/
diffsTemplate?: string;
}

/**
Expand Down Expand Up @@ -118,6 +125,7 @@ export default class ContributionSurveyRowParser {
this.eatUntil( /^(?:'''?)?\[\[Special:Diff\/\d+/, true ) ??
// {{dif|12345|6789}}
this.eatUntil( /^(?:'''?)?{{dif\|\d+/, true );
let diffsBolded = false;

// At this point, `extras` is either a string or `null`. If it's a string,
// extras exist, and we should add them. If not, there's likely no more
Expand All @@ -143,9 +151,18 @@ export default class ContributionSurveyRowParser {
// All diff links removed. Get diff of starting and current to get entire diff part.
diffs = starting.slice( 0, starting.length - this.current.length );

// Dawkeye support.
// Pre-2014 style support.
if ( ( diffs ?? '' ).includes( '{{dif' ) ) {
diffTemplate = '$3{{dif|$1|$2}}$3';
diffTemplate = '{{dif|$1|($2)}}';
}

// Bolded diffs support.
if (
diffs.slice( 0, 3 ) === "'''" &&
diffs.slice( -3 ) === "'''" &&
!diffs.slice( 3, -3 ).includes( "'''" )
) {
diffsBolded = true;
}

// Comments should be empty, but just in case we do come across comments.
Expand Down Expand Up @@ -180,7 +197,8 @@ export default class ContributionSurveyRowParser {
diffs,
comments,
revids,
diffTemplate
diffTemplate,
diffsTemplate: diffsBolded ? "'''$1'''" : '$1'
};
}

Expand Down
8 changes: 5 additions & 3 deletions src/ui/root/DeputyContributionSurveyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,18 @@ export default class DeputyContributionSurveyRow extends EventTarget implements
)
) ?? [];

let diffsText = '';
if ( unfinishedDiffs.length > 0 ) {
result += unfinishedDiffs.map( ( v ) => {
diffsText += unfinishedDiffs.map( ( v ) => {
return mw.format(
this.row.data.diffTemplate,
v.revision.revid,
v.revision.diffsize > 0 ? '+' + v.revision.diffsize : v.revision.diffsize,
Math.abs( v.revision.diffsize ) > 500 ? "'''" : ''
v.revision.diffsize > 0 ? '+' + v.revision.diffsize : v.revision.diffsize
);
} ).join( '' );

result += mw.format( this.row.data.diffsTemplate, diffsText );

if ( this.row.data.comments ) {
// Comments existed despite not being finished yet. Allow anyway.
result += this.row.data.comments;
Expand Down

0 comments on commit 595ce69

Please sign in to comment.