@@ -2,6 +2,9 @@ import cloneRegex from '../util/cloneRegex';
22import { ContributionSurveyRevision } from './ContributionSurveyRevision' ;
33import DeputyCasePage from '../wiki/DeputyCasePage' ;
44import MwApi from '../MwApi' ;
5+ import ContributionSurveyRowParser , {
6+ RawContributionSurveyRow
7+ } from './ContributionSurveyRowParser' ;
58
69export enum ContributionSurveyRowStatus {
710 // The row has not been processed yet.
@@ -25,16 +28,6 @@ export enum ContributionSurveyRowStatus {
2528 */
2629export default class ContributionSurveyRow {
2730
28- /**
29- * Wikitext for checking if a given row is a contribution survey row.
30- * $1 - Page name
31- * $2 - Post-page name text (`(3 edits)`)
32- * $3 - ID of first revision
33- * $4 - Comments
34- */
35- static readonly rowWikitextRegex =
36- / \* ? (?: ' ' ' .' ' ' ) ? \[ \[ : ? ( .+ ?) ] ] (?: ? ( [ ^ { : ] * ) ? (?: : ? ) ? ) ? (?: (?: \[ \[ S p e c i a l : D i f f \/ ( \d + ) \| .+ ?] ] ) + | ( .+ $ ) ) / gm;
37-
3831 /**
3932 * A set of regular expressions that will match a specific contribution survey row
4033 * comment. Used to determine the status of the comment.
@@ -53,16 +46,6 @@ export default class ContributionSurveyRow {
5346 [ ContributionSurveyRowStatus . PresumptiveRemoval ] : / \{ \{ x } } / gi
5447 } ;
5548
56- /**
57- * Determines if a given wikitext line is a valid contribution survey row.
58- *
59- * @param text The wikitext to check
60- * @return Whether the provided wikitext is a contribution survey row or not
61- */
62- static isContributionSurveyRowText ( text : string ) : boolean {
63- return cloneRegex ( ContributionSurveyRow . rowWikitextRegex ) . test ( text ) ;
64- }
65-
6649 /**
6750 * Identifies a row's current status based on the comment's contents.
6851 *
@@ -140,23 +123,31 @@ export default class ContributionSurveyRow {
140123 */
141124 private diffs ?: Map < number , ContributionSurveyRevision > ;
142125
126+ /**
127+ * Data returned by the ContributionSurveyRowParser. Run on the wikitext
128+ * during instantiation.
129+ *
130+ * @private
131+ */
132+ private readonly data : RawContributionSurveyRow ;
133+
143134 /**
144135 * Creates a new contribution survey row from MediaWiki parser output.
145136 *
146137 * @param casePage The case page of this row
147138 * @param wikitext The wikitext of the row
148139 */
149140 constructor ( casePage : DeputyCasePage , wikitext : string ) {
150- const rowExec = cloneRegex ( ContributionSurveyRow . rowWikitextRegex ) . exec ( wikitext ) ;
141+ this . data = new ContributionSurveyRowParser ( wikitext ) . parse ( ) ;
151142
152143 this . casePage = casePage ;
153144 this . wikitext = wikitext ;
154- this . title = new mw . Title ( rowExec [ 1 ] ) ;
155- this . extras = rowExec [ 2 ] ;
156- this . comment = rowExec [ 4 ] ;
157- this . status = this . originalStatus = rowExec [ 4 ] == null ?
145+ this . title = new mw . Title ( this . data . page ) ;
146+ this . extras = this . data . extras ;
147+ this . comment = this . data . comments ;
148+ this . status = this . originalStatus = this . data . comments == null ?
158149 ContributionSurveyRowStatus . Unfinished :
159- ContributionSurveyRow . identifyCommentStatus ( rowExec [ 4 ] ) ;
150+ ContributionSurveyRow . identifyCommentStatus ( this . data . comments ) ;
160151
161152 if ( ( ContributionSurveyRow . commentMatchRegex as any ) [ this . status ] != null ) {
162153 if (
@@ -187,49 +178,34 @@ export default class ContributionSurveyRow {
187178 return this . diffs ;
188179 }
189180
190- const rowExec = cloneRegex ( ContributionSurveyRow . rowWikitextRegex ) . exec ( this . wikitext ) ;
191181 const revisionData : Map < number , ContributionSurveyRevision > = new Map ( ) ;
192- const diffs = [ ] ;
182+ const revids = this . data . revids ;
193183
194184 // Load revision information
195- if ( rowExec [ 3 ] !== null && rowExec . length !== 0 ) {
196- const diffRegex = cloneRegex ( / S p e c i a l : D i f f \/ ( \d + ) / g ) ;
197- let diffMatch = diffRegex . exec ( rowExec [ 0 ] ) ;
198- while ( diffMatch != null ) {
199- if ( diffMatch [ 1 ] == null ) {
200- console . warn ( 'Could not parse revision ID: ' + diffMatch [ 0 ] ) ;
201- } else {
202- diffs . push ( + diffMatch [ 1 ] ) ;
203- }
204-
205- diffMatch = diffRegex . exec ( rowExec [ 0 ] ) ;
185+ const toCache = [ ] ;
186+ for ( const revisionID of revids ) {
187+ const cachedDiff = await window . deputy . storage . db . get ( 'diffCache' , revisionID ) ;
188+ if ( cachedDiff ) {
189+ revisionData . set (
190+ revisionID , new ContributionSurveyRevision ( this , cachedDiff )
191+ ) ;
192+ } else {
193+ toCache . push ( revisionID ) ;
206194 }
207-
208- const toCache = [ ] ;
209- for ( const revisionID of diffs ) {
210- const cachedDiff = await window . deputy . storage . db . get ( 'diffCache' , revisionID ) ;
211- if ( cachedDiff ) {
212- revisionData . set (
213- revisionID , new ContributionSurveyRevision ( this , cachedDiff )
214- ) ;
215- } else {
216- toCache . push ( revisionID ) ;
217- }
195+ }
196+ if ( toCache . length > 0 ) {
197+ const expandedData = await window . deputy . api . getExpandedRevisionData ( toCache ) ;
198+ for ( const revisionID in expandedData ) {
199+ revisionData . set (
200+ + revisionID ,
201+ new ContributionSurveyRevision ( this , expandedData [ revisionID ] )
202+ ) ;
218203 }
219- if ( toCache . length > 0 ) {
220- const expandedData = await window . deputy . api . getExpandedRevisionData ( toCache ) ;
221- for ( const revisionID in expandedData ) {
222- revisionData . set (
223- + revisionID ,
224- new ContributionSurveyRevision ( this , expandedData [ revisionID ] )
225- ) ;
226- }
227204
228- for ( const revisionID in expandedData ) {
229- await window . deputy . storage . db . put (
230- 'diffCache' , expandedData [ revisionID ]
231- ) ;
232- }
205+ for ( const revisionID in expandedData ) {
206+ await window . deputy . storage . db . put (
207+ 'diffCache' , expandedData [ revisionID ]
208+ ) ;
233209 }
234210 }
235211
0 commit comments