@@ -2,6 +2,9 @@ import cloneRegex from '../util/cloneRegex';
2
2
import { ContributionSurveyRevision } from './ContributionSurveyRevision' ;
3
3
import DeputyCasePage from '../wiki/DeputyCasePage' ;
4
4
import MwApi from '../MwApi' ;
5
+ import ContributionSurveyRowParser , {
6
+ RawContributionSurveyRow
7
+ } from './ContributionSurveyRowParser' ;
5
8
6
9
export enum ContributionSurveyRowStatus {
7
10
// The row has not been processed yet.
@@ -25,16 +28,6 @@ export enum ContributionSurveyRowStatus {
25
28
*/
26
29
export default class ContributionSurveyRow {
27
30
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
-
38
31
/**
39
32
* A set of regular expressions that will match a specific contribution survey row
40
33
* comment. Used to determine the status of the comment.
@@ -53,16 +46,6 @@ export default class ContributionSurveyRow {
53
46
[ ContributionSurveyRowStatus . PresumptiveRemoval ] : / \{ \{ x } } / gi
54
47
} ;
55
48
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
-
66
49
/**
67
50
* Identifies a row's current status based on the comment's contents.
68
51
*
@@ -140,23 +123,31 @@ export default class ContributionSurveyRow {
140
123
*/
141
124
private diffs ?: Map < number , ContributionSurveyRevision > ;
142
125
126
+ /**
127
+ * Data returned by the ContributionSurveyRowParser. Run on the wikitext
128
+ * during instantiation.
129
+ *
130
+ * @private
131
+ */
132
+ private readonly data : RawContributionSurveyRow ;
133
+
143
134
/**
144
135
* Creates a new contribution survey row from MediaWiki parser output.
145
136
*
146
137
* @param casePage The case page of this row
147
138
* @param wikitext The wikitext of the row
148
139
*/
149
140
constructor ( casePage : DeputyCasePage , wikitext : string ) {
150
- const rowExec = cloneRegex ( ContributionSurveyRow . rowWikitextRegex ) . exec ( wikitext ) ;
141
+ this . data = new ContributionSurveyRowParser ( wikitext ) . parse ( ) ;
151
142
152
143
this . casePage = casePage ;
153
144
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 ?
158
149
ContributionSurveyRowStatus . Unfinished :
159
- ContributionSurveyRow . identifyCommentStatus ( rowExec [ 4 ] ) ;
150
+ ContributionSurveyRow . identifyCommentStatus ( this . data . comments ) ;
160
151
161
152
if ( ( ContributionSurveyRow . commentMatchRegex as any ) [ this . status ] != null ) {
162
153
if (
@@ -187,49 +178,34 @@ export default class ContributionSurveyRow {
187
178
return this . diffs ;
188
179
}
189
180
190
- const rowExec = cloneRegex ( ContributionSurveyRow . rowWikitextRegex ) . exec ( this . wikitext ) ;
191
181
const revisionData : Map < number , ContributionSurveyRevision > = new Map ( ) ;
192
- const diffs = [ ] ;
182
+ const revids = this . data . revids ;
193
183
194
184
// 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 ) ;
206
194
}
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
+ ) ;
218
203
}
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
- }
227
204
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
+ ) ;
233
209
}
234
210
}
235
211
0 commit comments