forked from wikimedia/operations-mediawiki-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefresh-dblist
executable file
·136 lines (111 loc) · 3.04 KB
/
refresh-dblist
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
#!/usr/bin/env php
<?php
/*
Master file of all wikis:
all.dblist
Exceptions list:
special.dblist
Generated by this script:
wikibooks.dblist
wikinews.dblist
wikipedia.dblist
wikiquote.dblist
wikisource.dblist
wiktionary.dblist
wikimedia.dblist
wikivoyage.dblist
The split-out files are used by the backup script.
Split by cluster:
s1.dblist
s2.dblist
s3.dblist
s4.dblist
s5.dblist
s6.dblist
s7.dblist
*/
require_once( __DIR__ . '/multiversion/MWRealm.php' );
require_once( __DIR__ . '/multiversion/defines.php' );
$base = MEDIAWIKI_STAGING_DIR;
$defaultCluster = 's3';
$clusterOverrides = loadClusterList(getRealmSpecificFilename("$base/wmf-config/db.php"));
$clusterAssignments = array();
$all = array_filter(array_map('trim', file(getRealmSpecificFilename("$base/all.dblist"))));
listOut('all', $all, false);
printf("%d wikis listed in " . basename(getRealmSpecificFilename("$base/all.dblist")) . "...\n", count($all));
$special = array_filter(array_map('trim', file(getRealmSpecificFilename("$base/special.dblist"))));
listOut('special', $special, false);
printf("%d special wikis to be exempted from wikipedia group...\n", count($special));
$suffixes = array(
"wiki" => "wikipedia",
"wikinews" => "wikinews",
"wikibooks" => "wikibooks",
"wikiquote" => "wikiquote",
"wikisource" => "wikisource",
"wiktionary" => "wiktionary",
"wikimedia" => "wikimedia",
"wikiversity" => "wikiversity",
"wikivoyage" => "wikivoyage" );
$groups = array();
$specialMatch = array();
foreach ($all as $wiki) {
if (isset($clusterOverrides[$wiki])) {
$cluster = $clusterOverrides[$wiki];
} else {
$cluster = $defaultCluster;
}
$clusterAssignments[$cluster][] = $wiki;
if (in_array($wiki, $special)) {
$specialMatch[] = $wiki;
continue;
}
foreach ($suffixes as $suffix => $group) {
if (substr($wiki, -strlen($suffix)) == $suffix) {
$groups[$group][] = $wiki;
continue 2;
}
}
printf("Warning: wiki '%s' matches no known group.\n", $wiki);
}
if (count($special) != count($specialMatch)) {
printf("Warning: expected %d special wikis, matched %d.\n",
count($special), count($specialMatch));
}
foreach ($groups as $group => $list) {
listOut($group, $list);
}
echo "Writing out db cluster assignments...\n";
foreach ($clusterAssignments as $cluster => $list) {
listOut($cluster, $list);
}
echo "Done.\n";
function loadClusterList($file) {
$wgDBname = $wgDBuser = $wgDBpassword = '';
include( $file );
return $wgLBFactoryConf['sectionsByDB'];
}
function listOut($group, $list, $print = true) {
global $base;
$filename = getRealmSpecificFilename("$base/$group.dblist");
if ( $print ) {
printf("Listing %d wikis in %s...\n", count($list), $filename);
}
$out = fopen("$filename.new", "xt");
if ($out) {
sort($list);
foreach ($list as $wiki) {
fwrite($out, "$wiki\n");
}
fclose($out);
if (file_exists("$filename.bak")) {
unlink("$filename.bak");
}
if (file_exists($filename)) {
rename($filename, "$filename.bak");
}
rename("$filename.new", $filename);
if (file_exists("$filename.bak")) {
unlink("$filename.bak");
}
}
}