-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestMOSOrderPositionFinder.js
766 lines (705 loc) · 20.7 KB
/
TestMOSOrderPositionFinder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
// <nowiki>
/*
- Testing a powerful class called MOSOrderPositionFinder. Feed it an article's wikitext, and it finds the location of every section listed at [[MOS:ORDER]].
- This is useful because then you can use that position to insert something in that section, or check for the existence of that section.
- Test articles
- https://en.wikipedia.org/w/index.php?title=California
- https://en.wikipedia.org/w/index.php?title=Rohingya_genocide
*/
$( async () => {
async function getWikicodeOfDiff( diffID ) {
if ( !mw.config.get( 'wgCurRevisionId' ) ) {
return '';
} // if page is deleted, return blank
let wikicode = '';
diffID = encodeURIComponent( diffID );
await $.ajax( {
url: 'https://en.wikipedia.org/w/api.php?action=parse&oldid=' + diffID + '&prop=wikitext&formatversion=2&format=json',
success: function ( result ) {
wikicode = result.parse.wikitext;
},
dataType: 'json'
} );
return wikicode;
}
function shouldRunOnThisPage( title ) {
// don't run when not viewing articles
const action = mw.config.get( 'wgAction' );
if ( action != 'view' ) {
return false;
}
// don't run when viewing diffs
// let isDiff = mw.config.get('wgDiffNewId');
// if ( isDiff ) return false;
const isDeletedPage = ( !mw.config.get( 'wgCurRevisionId' ) );
if ( isDeletedPage ) {
return false;
}
// Only run in mainspace or draftspace
const namespace = mw.config.get( 'wgNamespaceNumber' );
const isMainspaceOrDraftspace = ( [ 0, 118 ].includes( namespace ) );
if ( !isMainspaceOrDraftspace && title != 'User:Novem_Linguae/sandbox' ) {
return false;
}
return true;
}
// Making this more complex than needed for this program. There are some other things I can use this for and I want to start developing it.
class MOSOrderPositionFinder {
constructor( wikitext, debug = false ) {
this.debug = debug;
this.wikitext = wikitext;
this._recalculate();
}
_recalculate() {
this.sectionOrder = [
'top',
'shortDescription',
'displayTitle',
'hatnotes',
'featured',
'deletionAndProtection',
'maintenanceTags',
'engvar',
'infoboxes',
'languageScriptNeeded',
'sidebars',
'lead',
'tableOfContents',
'body',
'worksOrPublications',
'seeAlso',
'notesAndReferences',
'furtherReading',
'externalLinks',
'successionAndGeographyBoxes',
'navboxes',
'portalBar',
'taxonBar',
'authorityControl',
'geographicalCoordinates',
'defaultSort',
'categories',
'stubTemplates',
'bottom'
];
this.sectionStartPositions = {
top: 0,
shortDescription: -1,
displayTitle: -1,
hatnotes: -1,
featured: -1,
deletionAndProtection: -1,
maintenanceTags: -1,
engvar: -1,
infoboxes: -1,
languageScriptNeeded: -1,
sidebars: -1,
lead: -1,
tableOfContents: -1,
body: -1,
worksOrPublications: -1,
seeAlso: -1,
notesAndReferences: -1,
furtherReading: -1,
externalLinks: -1,
successionAndGeographyBoxes: -1,
navboxes: -1,
portalBar: -1,
taxonBar: -1,
authorityControl: -1,
geographicalCoordinates: -1,
defaultSort: -1,
categories: -1,
stubTemplates: -1,
bottom: this.wikitext.length
};
// https://en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/Template:Short_description&hidelinks=1&hidetrans=1
this.sectionStartPositions.shortDescription = this._lookForTemplates( this.wikitext, [
'Short description',
'Shortdesc',
'Shortdescription',
'Short desc'
] );
this.sectionStartPositions.displayTitle = this._lookForTemplates( this.wikitext, [
'DISPLAYTITLE',
'Lowercase title',
'Italic title'
] );
// https://en.wikipedia.org/wiki/Wikipedia:Hatnote
this.sectionStartPositions.hatnotes = this._lookForTemplates( this.wikitext, [
'About-distinguish',
'About',
'About other people',
'Distinguish',
'For',
'For2',
'Hatnote',
'Other hurricanes',
'Other people',
'Other places',
'Other ships',
'Other uses of',
'Other uses',
'Other uses',
'Redirect-distinguish',
'Redirect-distinguish-text',
'Redirect-distinguish2',
'Redirect-multi',
'Redirect',
'Redirect2',
'Self reference',
'Similar names',
'Technical reasons',
'Malay name' // TODO: add more {{X name}} type templates.
] );
this.sectionStartPositions.featured = this._lookForTemplates( this.wikitext, [
'Featured list',
'Featured article',
'Good article'
] );
// https://en.wikipedia.org/wiki/Wikipedia:Criteria_for_speedy_deletion
// https://en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/Template:Proposed_deletion&hidelinks=1&hidetrans=1
this.sectionStartPositions.deletionAndProtection = this._lookForTemplates( this.wikitext, [
'Db-a1', // CSD
'Db-a10',
'Db-a11',
'Db-a2',
'Db-a3',
'Db-a5',
'Db-a7',
'Db-a9',
'Db-afc',
'Db-album',
'Db-animal',
'Db-attack',
'Db-attackorg',
'Db-author',
'Db-badfairuse',
'Db-badfiletype',
'Db-band',
'Db-banned',
'db-blankdraft',
'Db-blanked',
'Db-c1',
'db-catempty',
'Db-club',
'Db-contact',
'Db-copypaste',
'Db-copyvio',
'Db-disambig',
'Db-discog',
'Db-empty',
'Db-emptyportal',
'Db-error',
'Db-event',
'Db-f1',
'Db-f10',
'Db-f2',
'Db-f3',
'Db-f5',
'Db-f7',
'Db-f8',
'Db-f9',
'Db-filecopyvio',
'Db-foreign',
'Db-fpcfail',
'Db-g1',
'Db-g10',
'Db-g11',
'Db-g12',
'Db-g13',
'Db-g14',
'Db-g2',
'Db-g3',
'Db-g4',
'Db-g5',
'Db-g6',
'Db-g7',
'Db-g8',
'Db-hoax',
'Db-imagepage',
'Db-inc',
'Db-invented',
'Db-madeup',
'Db-move',
'Db-moved',
'Db-multiple',
'Db-negublp',
'Db-nocontent',
'Db-nocontext',
'Db-nofile',
'Db-noncom',
'Db-nonsense',
'Db-notwebhost',
'Db-nouser',
'Db-p1',
'Db-p2',
'Db-person',
'Db-personal attack',
'Db-promo',
'Db-r2',
'Db-r3',
'Db-r4',
'Db-redircom',
'Db-redirnone',
'Db-redirtypo',
'Db-rediruser',
'Db-redundantfile',
'Db-repost',
'Db-same',
'Db-self',
'Db-song',
'Db-spam',
'Db-spamuser',
'Db-subpage',
'Db-talk',
'Db-templatecat',
'Db-test',
'Db-transwiki',
'Db-u1',
'Db-u2',
'Db-u5',
'Db-userreq',
'Db-vandalism',
'Db-web',
'Db-xfd',
'Proposed deletion', // PROD
'Prod',
'Proposed delete',
'Proposal to delete',
'Propose deletion',
'Draft-prod',
'Article for deletion', // AFD
'Pp' // page protection padlocks, includes {{Pp}} and {{Pp-*}}
] );
// Source: Twinkle
this.sectionStartPositions.maintenanceTags = this._lookForTemplates( this.wikitext, [
'Cleanup',
'Cleanup rewrite',
'Copy edit',
'Close paraphrasing',
'Copypaste',
'External links',
'Non-free',
'Cleanup reorganize',
'Lead missing',
'Lead rewrite',
'Lead too long',
'Lead too short',
'Sections',
'Too many sections',
'Very long',
'All plot',
'Fiction',
'In-universe',
'Long plot',
'No plot',
'Notability',
'Advert',
'Cleanup tense',
'Essay-like',
'Fanpov',
'Like resume',
'Manual',
'Cleanup-PR',
'Over-quotation',
'Prose',
'Technical',
'Tone',
'Confusing',
'Incomprehensible',
'Unfocused',
'Context',
'Expert needed',
'Overly detailed',
'Undue weight',
'Current',
'Update',
'Autobiography',
'COI',
'Disputed',
'Hoax',
'Globalize',
'Over-coverage',
'Paid contributions',
'Peacock',
'POV',
'Recentism',
'Too few opinions',
'Undisclosed paid',
'Weasel',
'BLP sources',
'BLP unsourced',
'More citations needed',
'One source',
'Original research',
'Primary sources',
'Self-published',
'Sources exist',
'Third-party',
'Unreferenced',
'Unreliable sources',
'Not English',
'Rough translation',
'Expand language',
'Dead end',
'Orphan',
'Overlinked',
'Underlinked',
'Citation style',
'Cleanup bare URLs',
'More footnotes',
'No footnotes',
'Improve categories',
'Uncategorized',
'History merge',
'Merge',
'Merge from',
'Merge to',
'GOCEinuse',
'In use',
'Under construction'
] );
// https://en.wikipedia.org/wiki/Template:Use_X_English
this.sectionStartPositions.engvar = this._lookForTemplates( this.wikitext, [
'Engvar', // engvar
'EngvarA',
'EngvarB',
'Use American English',
'Use Australian English',
'Use Bangladeshi English',
'Use British English',
'Use Oxford spelling',
'Use Canadian English',
'Use Ghanaian English',
'Use Hiberno-English',
'Use Hong Kong English',
'Use Indian English',
'Use Jamaican English',
'Use Kenyan English',
'Use Liberian English',
'Use New Zealand English',
'Use Nigerian English',
'Use Pakistani English',
'Use Philippine English',
'Use Singapore English',
'Use South African English',
'Use Trinidad and Tobago English',
'Use dmy dates', // dates
'Use mdy dates'
] );
this.sectionStartPositions.infoboxes = this._lookForTemplates( this.wikitext, [
'Infobox',
'Speciesbox',
'Automatic taxobox',
'Taxobox',
'Subspeciesbox',
'Infraspeciesbox',
'Hybridbox',
'Virusbox'
] );
// https://en.wikipedia.org/wiki/Category:Language_maintenance_templates
this.sectionStartPositions.languageScriptNeeded = this._lookForTemplates( this.wikitext, [
'Arabic script needed',
'Armenian script needed',
'Berber script needed',
'Burmese script needed',
'Cherokee script needed',
'Chinese script needed',
'Chinese script needed inline',
'Contains special characters',
'Devanagari script needed',
'Egyptian hieroglyphic script needed',
'EngvarB',
'Ge\'ez script needed',
'Georgian script needed',
'Greek script needed',
'Hebrew script needed',
'IPA-ga notice',
'Japanese script needed',
'Khmer script needed',
'Korean script needed',
'Lao script needed',
'Needchunom',
'Needhanja',
'Needhiragana',
'Needkanji',
'Needs IPA',
'Nepali script needed',
'Persian script needed',
'Pronunciation needed',
'Romanization needed',
'Samoan script needed',
'Syriac script needed',
'Tamil script needed',
'Thai script needed',
'Tibetan script needed',
'Tok Pisin script needed',
'User language subcategory',
'User programming subcategory',
'Verify spelling',
'Vietnamese script needed',
'Yiddish script needed'
] );
// No reliable way to search for these. Some end in sidebar, many don't. Example of ones that don't: [[Rohingya genocide]] -> {{Rohingya conflict}}, {{Genocide}}.
// TODO: Will need to return the position of any template between top and first sentence that isn't in one of the lists above.
this.sectionStartPositions.sidebars = -1;
// Return first text that isn't whitespace, a template, or inside a template. This is the article's first sentence.
this.sectionStartPositions.lead = this._getFirstNonTemplateNonWhitespace( this.wikitext );
// https://en.wikipedia.org/wiki/Help:Magic_words#Behavior_switches
this.sectionStartPositions.tableOfContents = this._lookForStrings( this.wikitext, [
'__TOC__'
] );
this.sectionStartPositions.body = this._lookForRegEx( this.wikitext, /(?<=\n)==/i );
this.sectionStartPositions.worksOrPublications = this._lookForHeadings( this.wikitext, [
'Works\\s*==',
'Publications',
'Discography',
'Filmography'
] );
this.sectionStartPositions.seeAlso = this._lookForHeadings( this.wikitext, [
'See also'
] );
this.sectionStartPositions.notesAndReferences = this._lookForHeadings( this.wikitext, [
'Bibliography',
'Citations',
'Endnotes',
'Footnotes',
'Notes',
'References',
'Sources',
'Works cited'
] );
this.sectionStartPositions.furtherReading = this._lookForHeadings( this.wikitext, [
'Further reading'
] );
this.sectionStartPositions.externalLinks = this._lookForHeadings( this.wikitext, [
'External links'
] );
// https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Succession_Box_Standardization/Templates
// TODO: figure out what "geography boxes" are, add them
this.sectionStartPositions.successionAndGeographyBoxes = this._lookForTemplates( this.wikitext, [
'S-' // they all are of the format {{S-*}}
] );
// Hard to figure these out, unless they are contained in the {{Navbox}} wrapper
// TODO: assume any templates in this area that aren't on other lists are navboxes
// https://en.wikipedia.org/w/index.php?title=Special%3AWhatLinksHere&hidetrans=1&hidelinks=1&target=Template%3ANavbox&namespace=
this.sectionStartPositions.navboxes = this._lookForTemplates( this.wikitext, [
'Navbox',
'Dynamic navigation box',
'Navigation',
'Hider hiding',
'Horror navbox',
'VG navigation',
'CVG navigation',
'TransNB',
'Navtable'
] );
// https://en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/Template:Portal_bar&hidetrans=1&hidelinks=1
this.sectionStartPositions.portalBar = this._lookForTemplates( this.wikitext, [
'Portal bar',
'Prb'
] );
// https://en.wikipedia.org/w/index.php?title=Special%3AWhatLinksHere&hidetrans=1&hidelinks=1&target=Template%3ATaxonbar&namespace=
this.sectionStartPositions.taxonBar = this._lookForTemplates( this.wikitext, [
'Taxonbar',
'Taxon-bar',
'Taxobar',
'TaxonIDs',
'Taxon identifiers'
] );
// https://en.wikipedia.org/w/index.php?title=Special%3AWhatLinksHere&hidetrans=1&hidelinks=1&target=Template%3AAuthority+control&namespace=
this.sectionStartPositions.authorityControl = this._lookForTemplates( this.wikitext, [
'Authority control',
'Normdaten',
'Authoritycontrol',
'External identifiers',
'Autorité',
'Control de autoridades',
'전거 통제',
'Normativna kontrola'
] );
// https://en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/Template:Coord&hidetrans=1&hidelinks=1
// https://en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/Template:Coord_missing&hidetrans=1&hidelinks=1
// using _findStringNotInsideTemplate because {{Coord}} inside infobox doesn't count
this.sectionStartPositions.geographicalCoordinates = this._findTemplateNotInsideTemplate( this.wikitext, [
'Coord', // coord
'Coor',
'Location',
'Geocoord',
'Geobox coor',
'Co-ord',
'Coord missing', // coord missing
'No geolocation',
'Missing coord',
'Coords missing',
'Locate me',
'Needs coordinates'
] );
// https://en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/Template:DEFAULTSORT&hidetrans=1&hidelinks=1
this.sectionStartPositions.defaultSort = this._lookForTemplates( this.wikitext, [
'DEFAULTSORT',
'Default sort',
'SORTIERUNG'
] );
this.sectionStartPositions.categories = this._lookForRegEx( this.wikitext, /\[\[:?Category:/i );
this.sectionStartPositions.stubTemplates = this._lookForRegEx( this.wikitext, /\{\{[^}]*-stub\}\}/i );
// If the body is the same position as any of the appendices, set body to -1, since there isn't really a body, just appendices.
const appendices = [
this.sectionStartPositions.worksOrPublications,
this.sectionStartPositions.seeAlso,
this.sectionStartPositions.notesAndReferences,
this.sectionStartPositions.furtherReading,
this.sectionStartPositions.externalLinks
];
if ( this.sectionStartPositions.body !== -1 && appendices.includes( this.sectionStartPositions.body ) ) {
this.sectionStartPositions.body = -1;
}
if ( this.debug ) {
for ( const section of this.sectionOrder ) {
const position = this.sectionStartPositions[ section ];
const chunkPreview = this.wikitext.slice( position, position + 50 );
console.log( `${ section }: ${ position }: ${ chunkPreview }` );
}
}
}
_getFirstNonTemplateNonWhitespace( wikicode ) {
const length = wikicode.length;
let nesting = 0;
for ( let i = 0; i < length; i++ ) {
const chunk = wikicode.slice( i );
if ( chunk.startsWith( '{{' ) ) {
nesting++;
} else if ( chunk.startsWith( '}}' ) ) {
nesting--;
i++; // skip 2nd }
} else if ( nesting === 0 && !chunk.match( /^\s/ ) ) {
return i;
}
}
return -1;
}
_findTemplateNotInsideTemplate( wikicode, arrayOfStrings ) {
const length = wikicode.length;
for ( const string of arrayOfStrings ) {
let nesting = 0;
for ( let i = 0; i < length; i++ ) {
const chunk = wikicode.slice( i, i + 20 );
const match = chunk.match( new RegExp( '^\\{\\{' + string, 'i' ) );
if ( nesting === 0 && match ) {
return i;
} else if ( chunk.startsWith( '{{' ) ) {
nesting++;
} else if ( chunk.startsWith( '}}' ) ) {
nesting--;
i++; // skip 2nd }
}
}
}
return -1;
}
/** Template names are not RegEx escaped. */
_lookForTemplates( haystack, arrayOfTemplateNames ) {
let regExString = '\\{\\{(?:';
for ( let name of arrayOfTemplateNames ) {
// space or underscore, same thing
name = name.replace( '_', ' ' );
name = name.replace( ' ', '[ _]' );
regExString += name + '|';
}
regExString = regExString.slice( 0, -1 ); // delete last character |
regExString += ')(?![ -\\|]section)'; // don't match section maintenance tags, e.g. {{More citations needed section}} and {{More citations needed|section}}
const matches = haystack.match( new RegExp( regExString, 'i' ) );
return matches ? matches.index : -1;
}
/** Heading names are not RegEx escaped. */
_lookForHeadings( haystack, arrayOfHeadingNames ) {
let regExString = '={2,}\\s*(?:';
for ( const name of arrayOfHeadingNames ) {
regExString += name + '|';
}
regExString = regExString.slice( 0, -1 ); // delete last character |
regExString += ')';
const matches = haystack.match( new RegExp( regExString, 'i' ) );
return matches ? matches.index : -1;
}
_lookForStrings( haystack, arrayOfRegExStrings ) {
let regExString = '(?:';
for ( const name of arrayOfRegExStrings ) {
regExString += name + '|';
}
regExString = regExString.slice( 0, -1 ); // delete last character |
regExString += ')';
const matches = haystack.match( new RegExp( regExString, 'i' ) );
return matches ? matches.index : -1;
}
_lookForRegEx( haystack, regEx ) {
const matches = haystack.match( regEx );
return matches ? matches.index : -1;
}
hasSection( section ) {
return this.sectionStartPositions[ section ] !== -1;
}
/** @return {number} sectionPosition: -1 if no section, integer if section */
getSectionPosition( section ) {
let position = this.sectionStartPositions[ section ];
if ( position === -1 ) {
position = this._getPositionOfClosestSection( section );
}
return position;
}
getWikicode() {
return this.wikitext;
}
/** If section is absent, we will guess where the section should go. Do not add whitespace, we will figure it out for you. */
insertAtSection( needle, section ) {
let position = this.sectionStartPositions[ section ];
if ( position === -1 ) {
position = this._getPositionOfClosestSection( section );
}
let topHalf = this.wikitext.slice( 0, position );
let bottomHalf = this.wikitext.slice( position );
if ( topHalf.endsWith( '\n' ) && !topHalf.endsWith( '\n\n' ) ) {
topHalf += '\n';
} else {
topHalf += '\n\n';
}
if ( !bottomHalf.startsWith( '\n' ) ) {
bottomHalf = '\n' + bottomHalf;
}
this.wikitext = topHalf + needle + bottomHalf;
this.wikitext = this.wikitext.trim();
this._recalculate();
return this.wikitext;
}
// https://stackoverflow.com/a/13109786/3480193
_arraySearch( arr, val ) {
for ( let i = 0; i < arr.length; i++ ) {
if ( arr[ i ] === val ) {
return i;
}
}
return false;
}
_getPositionOfClosestSection( section ) {
const sectionKey = this._arraySearch( this.sectionOrder, section );
// scan until you find a section that is not -1
// can scan in either direction. I chose to scan down.
for ( let i = sectionKey; i < this.sectionOrder.length; i++ ) {
const sectionKey2 = this.sectionOrder[ i ];
const sectionPosition = this.sectionStartPositions[ sectionKey2 ];
if ( sectionPosition !== -1 ) {
return sectionPosition;
}
}
}
}
const title = mw.config.get( 'wgPageName' ); // includes namespace, underscores instead of spaces
if ( !shouldRunOnThisPage( title ) ) {
return;
}
const diffID = mw.config.get( 'wgRevisionId' );
const wikicode = await getWikicodeOfDiff( diffID );
const pf = new MOSOrderPositionFinder( wikicode, true );
} );
// </nowiki>