-
Notifications
You must be signed in to change notification settings - Fork 12
/
checkdb.py
executable file
·744 lines (587 loc) · 25.6 KB
/
checkdb.py
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
#! /usr/bin/env python3
from pprint import pprint, pformat
import datetime
import traceback
import copy
from collections import OrderedDict
from itertools import chain
import html
import sqlalchemy as sa
import requests.packages.urllib3 as urllib3
from ws.client import API
from ws.interactive import require_login
from ws.db.database import Database, parser_cache
from ws.utils.containers import dmerge
import ws.diff
from ws.parser_helpers.encodings import urldecode
def _pprint_diff(i, db_entry, api_entry, *, key=None):
if key is not None:
print(f"\n\nDiff for entry no. {i}: {key}={db_entry[key]}")
if key == "pageid" and "title" in db_entry:
print(f"Page title: [[{db_entry['title']}]]")
# diff shows just the difference
db_f = pformat(db_entry)
api_f = pformat(api_entry)
print(ws.diff.diff_highlighted(db_f, api_f, "db_entry", "api_entry"))
if key is None:
# full entries are needed for context
print("db_entry no. {}:".format(i))
pprint(db_entry)
print("api_entry no. {}:".format(i))
pprint(api_entry)
print()
def _check_entries(i, db_entry, api_entry, *, key=None):
try:
assert db_entry == api_entry
except AssertionError:
_pprint_diff(i, db_entry, api_entry, key=key)
raise
def _check_lists(db_list, api_list, *, key=None, db=None):
if key is not None and len(db_list) != len(api_list):
print("Lists have different lengths: {} vs {}".format(len(db_list), len(api_list)))
db_keys = set(item[key] for item in db_list)
api_keys = set(item[key] for item in api_list)
# compare common items
common_db_items = [item for item in db_list if item[key] in api_keys]
common_api_items = [item for item in api_list if item[key] in db_keys]
print("Comparing common items...")
_check_lists(common_db_items, common_api_items)
# extra DB items
extra_db_items = [item for item in db_list if item[key] not in api_keys]
if extra_db_items:
print("Extra items from the SQL database:")
pprint(extra_db_items)
# extra API items
extra_api_items = [item for item in api_list if item[key] not in db_keys]
if extra_api_items:
print("Extra items from the API:")
pprint(extra_api_items)
else:
try:
assert len(db_list) == len(api_list), "{} vs. {}".format(len(db_list), len(api_list))
last_assert_exc = None
invalid_keys = set()
for i, entries in enumerate(zip(db_list, api_list)):
db_entry, api_entry = entries
try:
_check_entries(i, db_entry, api_entry, key=key)
except AssertionError as e:
if key:
invalid_keys.add(db_entry[key])
last_assert_exc = e
pass
if db and key == "pageid" and invalid_keys:
cache = parser_cache.ParserCache(db)
cache.invalidate_pageids(invalid_keys)
print("Invalidated pageids in the parser cache:", invalid_keys)
if last_assert_exc is not None:
raise AssertionError from last_assert_exc
except AssertionError:
traceback.print_exc()
def _check_lists_of_unordered_pages(db_list, api_list, *, db=None):
# FIXME: apparently the ArchWiki's MySQL backend does not use the C locale...
# difference between C and MySQL's binary collation: "2bwm (简体中文)" should come before "2bwm(简体中文)"
# TODO: if we connect to MediaWiki running on PostgreSQL, its locale might be anything...
api_list = sorted(api_list, key=lambda item: item["pageid"])
db_list = sorted(db_list, key=lambda item: item["pageid"])
_check_lists(db_list, api_list, key="pageid", db=db)
# pages may be yielded multiple times, so we need to merge them manually
def _squash_list_of_dicts(api_list, *, key="pageid"):
api_dict = OrderedDict()
for item in api_list:
key_value = item[key]
if key_value not in api_dict:
api_dict[key_value] = item
else:
dmerge(item, api_dict[key_value])
return list(api_dict.values())
def _deduplicate_list_of_dicts(iterable):
return [dict(t) for t in {tuple(d.items()) for d in iterable}]
def check_titles(api, db):
print("Checking individual titles...")
titles = {"Main page", "Nonexistent"}
pageids = {1, 2, 3, 4, 5}
db_list = list(db.query(titles=titles))
api_list = api.call_api(action="query", titles="|".join(titles))["pages"]
_check_lists(db_list, api_list)
api_dict = api.call_api(action="query", pageids="|".join(str(p) for p in pageids))["pages"]
api_list = list(api_dict.values())
api_list.sort(key=lambda p: ("missing" not in p, p["pageid"]))
db_list = list(db.query(pageids=pageids))
_check_lists(db_list, api_list)
def check_specific_titles(api, db):
titles = [
"Main page",
"en:Main page",
"wikipedia:Main page",
"wikipedia:en:Main page",
"Main page#section",
"en:Main page#section",
"wikipedia:Main page#section",
"wikipedia:en:Main page#section",
]
for title in titles:
api_title = api.Title(title)
db_title = db.Title(title)
assert api_title.context == db_title.context
assert api_title == db_title
def check_recentchanges(api, db):
print("Checking the recentchanges table...")
params = {
"list": "recentchanges",
"rclimit": "max",
}
rcprop = {"title", "ids", "user", "userid", "flags", "timestamp", "comment", "sizes", "loginfo", "patrolled", "sha1", "redirect", "tags"}
db_list = list(db.query(**params, rcprop=rcprop))
api_list = list(api.list(**params, rcprop="|".join(rcprop)))
# FIXME: some deleted pages stay in recentchanges, although according to the tests they should be deleted
s = sa.select(db.page.c.page_id)
with db.engine.connect() as conn:
current_pageids = {page.page_id for page in conn.execute(s)}
new_api_list = []
for rc in api_list:
if "logid" in rc or rc["pageid"] in current_pageids:
new_api_list.append(rc)
api_list = new_api_list
for api_entry in api_list:
# TODO: how the hell should we know...
if "autopatrolled" in api_entry:
del api_entry["autopatrolled"]
# TODO: I don't know what this means
if "unpatrolled" in api_entry:
del api_entry["unpatrolled"]
for entry in chain(db_list, api_list):
# FIXME: rolled-back edits are automatically patrolled, but there does not seem to be any way to detect this
# skipping all patrol checks for now...
if "patrolled" in entry:
del entry["patrolled"]
# MediaWiki does not sort tags alphabetically
entry["tags"].sort()
# since MW 1.36.1, the "mw-reverted" tag is applied to past revisions
# that were reverted/undone and wiki-scripts cannot sync that on past
# revisions
if "mw-reverted" in entry["tags"]:
entry["tags"].remove("mw-reverted")
_check_lists(db_list, api_list, key="rcid")
def check_logging(api, db):
print("Checking the logging table...")
since = datetime.datetime.utcnow() - datetime.timedelta(days=30)
params = {
"list": "logevents",
"lelimit": "max",
"ledir": "newer",
"lestart": since,
}
leprop = {"user", "userid", "comment", "timestamp", "title", "ids", "type", "details", "tags"}
db_list = list(db.query(**params, leprop=leprop))
api_list = list(api.list(**params, leprop="|".join(leprop)))
for entry in db_list:
# hack for the comparison of infinite protection expirations
if entry["type"] == "protect" and "details" in entry["params"]:
details = entry["params"]["details"]
for item in details:
if item["expiry"] == "infinite":
item["expiry"] = datetime.datetime.max
# hack for the comparison of moved DeveloperWiki pages
elif entry["type"] == "move":
if entry["params"]["target_title"].startswith("DeveloperWiki:"):
entry["params"]["target_ns"] = 3000
elif entry["params"]["target_title"].startswith("Talk:DeveloperWiki:"):
entry["params"]["target_ns"] = -1
entry["params"]["target_title"] = "Special:Badtitle/" + entry["params"]["target_title"]
elif entry["type"] == "protect" and entry["action"] == "move_prot":
if entry["params"]["oldtitle_title"].startswith("DeveloperWiki:"):
entry["params"]["oldtitle_ns"] = 3000
_check_lists(db_list, api_list, key="logid")
def check_users(api, db):
print("Checking the user table...")
params = {
"list": "allusers",
"aulimit": "max",
}
auprop = {"groups", "blockinfo", "registration", "editcount"}
db_list = list(db.query(**params, auprop=auprop))
api_list = list(api.list(**params, auprop="|".join(auprop)))
# skip the "Anonymous" dummy user residing in MediaWiki running on PostgreSQL
api_list = [user for user in api_list if user["userid"] > 0]
# fix sorting due to potentially different locale
db_list.sort(key=lambda u: u["name"])
api_list.sort(key=lambda u: u["name"])
# sort user groups - neither we or MediaWiki do that
for user in chain(db_list, api_list):
user["groups"].sort()
for user in chain(db_list, api_list):
# drop autoconfirmed - not reliably refreshed in the SQL database
# TODO: try to fix that...
if "autoconfirmed" in user["groups"]:
user["groups"].remove("autoconfirmed")
# drop blockedtimestampformatted - unimportant, only in API entries since some MW version
if "blockedtimestampformatted" in user:
del user["blockedtimestampformatted"]
_check_lists(db_list, api_list, key="userid")
def check_allpages(api, db):
print("Checking the page table...")
params = {
"list": "allpages",
"aplimit": "max",
}
db_list = list(db.query(**params))
api_list = list(api.list(**params))
_check_lists_of_unordered_pages(db_list, api_list)
def check_info(api, db):
print("Checking prop=info...")
params = {
"generator": "allpages",
"gaplimit": "max",
"prop": "info",
}
inprop = {"protection", "displaytitle"}
db_list = list(db.query(**params, inprop=inprop))
api_list = list(api.generator(**params, inprop="|".join(inprop)))
# fix ordering of the protection lists
for entry in chain(db_list, api_list):
if "protection" in entry:
entry["protection"].sort(key=lambda p: p["type"])
# FIXME: we can't assert page_touched because we track only page edits, not cache invalidations...
for entry in chain(db_list, api_list):
del entry["touched"]
# MW 1.39 does not decode HTML entities
if "displaytitle" in entry:
entry["displaytitle"] = html.unescape(entry["displaytitle"])
_check_lists_of_unordered_pages(db_list, api_list)
def check_pageprops(api, db):
print("Checking prop=pageprops...")
params = {
"generator": "allpages",
"gaplimit": "max",
"prop": "pageprops",
}
db_list = list(db.query(params))
api_list = list(api.generator(params))
_check_lists_of_unordered_pages(db_list, api_list)
def check_protected_titles(api, db):
print("Checking the protected_titles table...")
params = {
"list": "protectedtitles",
"ptlimit": "max",
}
ptprop = {"timestamp", "user", "userid", "comment", "expiry", "level"}
db_list = list(db.query(**params, ptprop=ptprop))
api_list = list(api.list(**params, ptprop="|".join(ptprop)))
for db_entry, api_entry in zip(db_list, api_list):
# the timestamps may be off by couple of seconds, because we're looking in the logging table
if "timestamp" in db_entry and "timestamp" in api_entry:
if abs(db_entry["timestamp"] - api_entry["timestamp"]) <= datetime.timedelta(seconds=1):
db_entry["timestamp"] = api_entry["timestamp"]
_check_lists(db_list, api_list, key="pageid")
def check_archive(api, db):
print("Checking the archive table...")
params = {
"list": "alldeletedrevisions",
"adrlimit": "max",
"adrdir": "newer",
"adrslots": "main",
}
adrprop = {"ids", "flags", "timestamp", "user", "userid", "size", "sha1", "contentmodel", "comment", "tags"}
db_list = list(db.query(**params, adrprop=adrprop))
api_list = list(api.list(**params, adrprop="|".join(adrprop)))
# compare without the lost revisions - see issue #47
db_list = [r for r in db_list if r["title"] != "Deleted archived revision (original title lost)"]
# FIXME: hack until we have per-page grouping like MediaWiki
api_revisions = []
for page in api_list:
for rev in page["revisions"]:
rev["pageid"] = page["pageid"]
rev["ns"] = page["ns"]
rev["title"] = page["title"]
api_revisions.append(rev)
api_revisions.sort(key=lambda item: (item["timestamp"], item["revid"]))
api_list = api_revisions
# MediaWiki does not sort tags alphabetically
for rev in api_list:
rev["tags"].sort()
_check_lists(db_list, api_list, key="revid")
def check_revisions(api, db):
print("Checking the revision table...")
since = datetime.datetime.utcnow() - datetime.timedelta(days=30)
params = {
"list": "allrevisions",
"arvlimit": "max",
"arvdir": "newer",
"arvstart": since,
"arvslots": "main",
}
arvprop = {"ids", "flags", "timestamp", "user", "userid", "size", "sha1", "contentmodel", "comment", "tags"}
db_list = list(db.query(**params, arvprop=arvprop))
api_list = list(api.list(**params, arvprop="|".join(arvprop)))
# FIXME: hack until we have per-page grouping like MediaWiki
api_revisions = []
for page in api_list:
for rev in page["revisions"]:
rev["pageid"] = page["pageid"]
rev["ns"] = page["ns"]
rev["title"] = page["title"]
api_revisions.append(rev)
api_revisions.sort(key=lambda item: (item["timestamp"], item["revid"]))
api_list = api_revisions
for rev in chain(db_list, api_list):
# FIXME: WTF, MediaWiki does not restore rev_parent_id when undeleting...
# https://phabricator.wikimedia.org/T183375
del rev["parentid"]
# MediaWiki does not sort tags alphabetically
rev["tags"].sort()
# since MW 1.36.1, the "mw-reverted" tag is applied to past revisions
# that were reverted/undone and wiki-scripts cannot sync that on past
# revisions
if "mw-reverted" in rev["tags"]:
rev["tags"].remove("mw-reverted")
_check_lists(db_list, api_list, key="revid")
def check_latest_revisions(api, db):
print("Checking latest revisions...")
db_params = {
"generator": "allpages",
"prop": "latestrevisions",
}
api_params = {
"generator": "allpages",
"gaplimit": "max",
"prop": "revisions",
}
db_list = list(db.query(db_params))
api_list = list(api.generator(api_params))
_check_lists_of_unordered_pages(db_list, api_list)
def check_revisions_of_main_page(api, db):
print("Checking revisions of the Main page...")
titles = {"Main page"}
rvprop = {"ids", "flags", "timestamp", "user", "userid", "size", "sha1", "contentmodel", "comment", "tags"}
api_params = {
"prop": "revisions",
"rvlimit": "max",
"rvslots": "main",
}
db_list = list(db.query(**api_params, titles=titles, rvprop=rvprop))
api_dict = api.call_api(**api_params, action="query", titles="|".join(titles), rvprop="|".join(rvprop))["pages"]
api_list = list(api_dict.values())
# first check the lists without revisions
db_list_copy = copy.deepcopy(db_list)
api_list_copy = copy.deepcopy(api_list)
_check_lists(db_list_copy, api_list_copy, key="pageid")
# then check only the revisions
for db_page, api_page in zip(db_list, api_list):
_check_lists(db_page["revisions"], api_page["revisions"], key="revid")
def check_templatelinks(api, db):
print("Checking the templatelinks table...")
params = {
"generator": "allpages",
"gaplimit": "max",
"tllimit": "max",
"tilimit": "max",
}
prop = {"templates", "transcludedin"}
db_list = list(db.query(**params, prop=prop))
api_list = list(api.generator(**params, prop="|".join(prop)))
api_list = _squash_list_of_dicts(api_list)
# sort the templates due to different locale (e.g. "Template:Related2" should come after "Template:Related")
for entry in api_list:
entry.get("templates", []).sort(key=lambda t: (t["ns"], t["title"]))
_check_lists_of_unordered_pages(db_list, api_list, db=db)
def check_pagelinks(api, db):
print("Checking the pagelinks table...")
params = {
"generator": "allpages",
"gaplimit": "max",
"pllimit": "max",
"lhlimit": "max",
}
prop = {"links", "linkshere"}
db_list = list(db.query(**params, prop=prop))
api_list = list(api.generator(**params, prop="|".join(prop)))
api_list = _squash_list_of_dicts(api_list)
# fix sorting due to different locale
for page in api_list:
page.get("links", []).sort(key=lambda d: (d["ns"], d["title"]))
page.get("linkshere", []).sort(key=lambda d: (d["pageid"]))
_check_lists_of_unordered_pages(db_list, api_list, db=db)
def check_imagelinks(api, db):
print("Checking the imagelinks table...")
params = {
"generator": "allpages",
"gaplimit": "max",
"imlimit": "max",
}
prop = {"images"}
db_list = list(db.query(**params, prop=prop))
api_list = list(api.generator(**params, prop="|".join(prop)))
api_list = _squash_list_of_dicts(api_list)
_check_lists_of_unordered_pages(db_list, api_list, db=db)
def check_categorylinks(api, db):
print("Checking the categorylinks table...")
params = {
"generator": "allpages",
"gaplimit": "max",
"cllimit": "max",
}
prop = {"categories"}
db_list = list(db.query(**params, prop=prop))
api_list = list(api.generator(**params, prop="|".join(prop)))
api_list = _squash_list_of_dicts(api_list)
# drop unsupported automatic categories: http://w.localhost/index.php/Special:TrackingCategories
automatic_categories = {
"Category:Indexed pages",
"Category:Noindexed pages",
"Category:Pages using duplicate arguments in template calls",
"Category:Pages with too many expensive parser function calls",
"Category:Pages containing omitted template arguments",
"Category:Pages where template include size is exceeded",
"Category:Hidden categories",
"Category:Pages with broken file links",
"Category:Pages where node count is exceeded",
"Category:Pages where expansion depth is exceeded",
"Category:Pages with ignored display titles",
"Category:Pages using invalid self-closed HTML tags",
"Category:Pages with template loops",
}
for page in api_list:
if "categories" in page:
page["categories"] = [cat for cat in page["categories"] if cat["title"] not in automatic_categories]
# remove empty list
if not page["categories"]:
del page["categories"]
# fix sorting due to different locale
page["categories"].sort(key=lambda d: d["title"])
_check_lists_of_unordered_pages(db_list, api_list, db=db)
def check_interwiki_links(api, db):
print("Checking the langlinks and iwlinks tables...")
params = {
"generator": "allpages",
"gaplimit": "max",
"iwlimit": "max",
"lllimit": "max",
}
prop = {"langlinks", "iwlinks"}
db_list = list(db.query(**params, prop=prop))
api_list = list(api.generator(**params, prop="|".join(prop)))
api_list = _squash_list_of_dicts(api_list)
# In our database, we store spaces instead of underscores and capitalize first letter.
def ucfirst(s):
if s:
return s[0].upper() + s[1:]
return s
for page in api_list:
for link in chain(page.get("langlinks", []), page.get("iwlinks", [])):
link["*"] = ucfirst(link["*"].replace("_", " "))
# deduplicate, [[w:foo]] and [[w:Foo]] should be equivalent
if "langlinks" in page:
page["langlinks"] = _deduplicate_list_of_dicts(page["langlinks"])
if "iwlinks" in page:
page["iwlinks"] = _deduplicate_list_of_dicts(page["iwlinks"])
# fix sorting due to different locale
page.get("langlinks", []).sort(key=lambda d: (d["lang"], d["*"]))
page.get("iwlinks", []).sort(key=lambda d: (d["prefix"], d["*"]))
_check_lists_of_unordered_pages(db_list, api_list, db=db)
def check_external_links(api, db):
print("Checking the externallinks table...")
params = {
"generator": "allpages",
"gaplimit": "max",
"ellimit": "max",
}
prop = {"extlinks"}
db_list = list(db.query(**params, prop=prop))
api_list = list(api.generator(**params, prop="|".join(prop)))
api_list = _squash_list_of_dicts(api_list)
hostname = urllib3.util.url.parse_url(api.index_url).host
def get_hostname(url):
try:
return urllib3.util.url.parse_url(url).host
except urllib3.exceptions.LocationParseError:
return None
for page in db_list:
if "extlinks" in page:
# MediaWiki does not track external links to its self hostname
page["extlinks"] = [el for el in page["extlinks"] if get_hostname(el["*"]) != hostname]
# delete empty list
if len(page["extlinks"]) == 0:
del page["extlinks"]
for page in chain(db_list, api_list):
if "extlinks" in page:
# decode percent-encoding
# ws.db stores the exact URL used in wikicode, but MediaWiki has
# some characters decoded (e.g. "@") and some encoded (e.g. spaces,
# some unicode characters with accents and other special characters
# like "|")
for el in page["extlinks"]:
try:
el["*"] = urldecode(el["*"])
except UnicodeDecodeError:
pass
# make sure that extlinks are sorted the same way
# (MediaWiki does not order the URLs, PostgreSQL ordering does not match Python due to locale)
page["extlinks"].sort(key=lambda d: d["*"])
_check_lists_of_unordered_pages(db_list, api_list, db=db)
def check_redirects(api, db):
print("Checking the redirects table...")
params = {
"generator": "allpages",
"gaplimit": "max",
"rdlimit": "max",
}
prop = {"redirects"}
rdprop = {"pageid", "title", "fragment"}
db_list = list(db.query(**params, prop=prop, rdprop=rdprop))
api_list = list(api.generator(**params, prop="|".join(prop), rdprop="|".join(rdprop)))
api_list = _squash_list_of_dicts(api_list)
for page in db_list:
for redirect in page.get("redirects", []):
if "fragment" in redirect:
# MediaWiki stores URL-decoded fragments
redirect["fragment"] = urldecode(redirect["fragment"])
_check_lists_of_unordered_pages(db_list, api_list, db=db)
if __name__ == "__main__":
import ws.config
argparser = ws.config.getArgParser(description="Test database synchronization")
API.set_argparser(argparser)
Database.set_argparser(argparser)
argparser.add_argument("--sync", dest="sync", action="store_true", default=True,
help="synchronize the SQL database with the remote wiki API (default: %(default)s)")
argparser.add_argument("--no-sync", dest="sync", action="store_false",
help="opposite of --sync")
argparser.add_argument("--content-sync-mode", choices=["latest", "all"], default="latest",
help="mode of revisions content synchronization")
argparser.add_argument("--parser-cache", dest="parser_cache", action="store_true", default=False,
help="update parser cache (default: %(default)s)")
argparser.add_argument("--no-parser-cache", dest="parser_cache", action="store_false",
help="opposite of --parser-cache")
args = ws.config.parse_args(argparser)
api = API.from_argparser(args)
db = Database.from_argparser(args)
if args.sync:
require_login(api)
db.sync_with_api(api)
db.sync_revisions_content(api, mode=args.content_sync_mode)
check_titles(api, db)
check_specific_titles(api, db)
check_recentchanges(api, db)
check_logging(api, db)
# TODO: select active users
check_users(api, db)
check_allpages(api, db)
check_info(api, db)
check_pageprops(api, db)
check_protected_titles(api, db)
check_archive(api, db)
check_revisions(api, db)
check_latest_revisions(api, db)
check_revisions_of_main_page(api, db)
if args.parser_cache:
db.update_parser_cache()
check_templatelinks(api, db)
# FIXME:
# - mwph can't parse "[[VirtualBox#Installation in EFI mode on VirtualBox < 6.1]]" as a wikilink
# (most likely due to the single '<', see https://github.com/earwig/mwparserfromhell/issues/211#issuecomment-570898958 )
check_pagelinks(api, db)
check_imagelinks(api, db)
check_categorylinks(api, db)
check_interwiki_links(api, db)
check_external_links(api, db)
check_redirects(api, db)