-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathrevcheck.php
More file actions
453 lines (400 loc) · 16.1 KB
/
revcheck.php
File metadata and controls
453 lines (400 loc) · 16.1 KB
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
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once __DIR__ . '/../include/init.inc.php';
require_once __DIR__ . '/../include/lib_revcheck.inc.php';
if (isset($_GET['lang']) && in_array($_GET['lang'], array_keys($LANGUAGES))) {
$lang = $_GET['lang'];
}
else {
$lang = 'en';
}
if ($lang != 'en' ) $lang_name = $LANGUAGES[$lang];
$tool = '';
if (isset($_GET['p'])) {
$tool = $_GET['p'];
}
// Prevent viewing other tools in EN (except alllangs)
if ($lang == 'en' && $tool !== 'alllangs') {
$tool = 'default';
}
if (!defined('SQLITE_DIR')) {
site_header();
echo "<p>Unable to find SQLite database with revisions.</p>";
site_footer();
die;
}
$DBLANG = SQLITE_DIR . 'status.sqlite';
$dbhandle = new SQLite3($DBLANG);
if (!$dbhandle) {
site_header();
echo "<p>Database connection couldn't be established</p>";
site_footer();
die;
}
// Check if db connection can be established and if revcheck for requested lang exists
$lang_intro = get_language_intro($dbhandle, $lang);
if ($lang !== 'en' && is_null($lang_intro)) {
site_header();
echo "<p>This revision check doesn't exist yet.</p>";
site_footer();
die;
}
site_header();
switch($tool) {
case 'translators':
$translators = get_translators($dbhandle, $lang);
if (empty($translators)) {
echo '<p>Error: no translators info found in database.</p>';
}
else {
foreach($translators as $nick =>$data) {
$files_w[$nick] = array('uptodate' => '', 'outdated' => '', 'norev' => '', 'wip' => '');
$files_w[$nick]['uptodate'] = $data['countOk'];
$files_w[$nick]['wip'] = $data['countOther'];
$files_w[$nick]['outdated'] = $data['countOld'];
}
echo <<<TRANSLATORS_HEAD
<table class="c">
<tr>
<th rowspan="2">Name</th>
<th rowspan="2">Nick</th>
<th rowspan="2">Karma</th>
<th colspan="7">Files maintained</th>
</tr>
<tr>
<th>upto-<br>date</th>
<th>out-<br>dated</th>
<th>wip</th>
<th>sum</th>
</tr>
TRANSLATORS_HEAD;
foreach ($translators as $nick => $data) {
echo '<tr>',
'<td><a href="mailto:'.$data['mail'].'">'.$data['name'].'</a></td>',
'<td><a href="/revcheck.php?p=files&user='.$nick.'&lang='.$lang.'">'.$nick.'</a></td>',
'<td>'.(($data['karma'] == 'yes') ? '✓' : ' ').'</td>',
'<td>' , @$files_w[$nick]['uptodate'], '</td>',
'<td>' , $files_w[$nick]['outdated'], '</td>',
'<td>', $files_w[$nick]['wip'], '</td>',
'<th>' , @array_sum($files_w[$nick]), '</th>',
'</tr>';
}
echo '</table>';
}
echo gen_date($DBLANG);
break;
case 'missfiles':
$missfiles = get_missfiles($dbhandle, $lang);
if (!$missfiles) {
echo '<p>All files translated? Would be nice... but it\'s probably an error :(</p>';
} else {
$num = count($missfiles);
$last_dir = false;
$first_dir = false;
echo '<p>Choose a directory:</p>';
echo '<form method="get" action="revcheck.php"><p><select name="dir">';
foreach ($missfiles as $miss) {
if (isset($_GET['dir']) && $_GET['dir'] == $miss['dir']) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
if (!$last_dir || $last_dir != $miss['dir']) {
echo '<option value="'.$miss['dir'].'"'.$selected.'>'.$miss['dir'].'</option>';
$last_dir = $miss['dir'];
if (!$first_dir) $first_dir = $last_dir;
}
}
echo '</select>';
echo '<input type="hidden" name="p" value="missfiles">';
echo '<input type="hidden" name="lang" value="'.$lang.'">';
echo '<input type="submit" value="See untranslated files"></p></form>';
echo '<table class="c">';
echo '<tr><th rowspan="1">Available for translation</th><th>Commit Hash</th><th colspan="1">kB</th></tr>';
$last_dir = false;
$total_size = 0;
$dir = isset($_GET['dir']) ? $_GET['dir'] : $first_dir;
foreach ($missfiles as $miss) {
if ($dir == $miss['dir']) {
if (!$last_dir || $last_dir != $miss['dir']) {
echo '<tr><th colspan="3">'.$miss['dir'].'</th></tr>';
$last_dir = $miss['dir'];
}
$key = $miss['dir'] == '' ? "/" : $miss['dir']."/". $miss['file'];
echo "<tr><td><a href='https://github.com/php/doc-en/blob/{$miss['revision']}/$key'>{$miss['file']}</a></td><td>{$miss['revision']}</td><td>{$miss['size']}</td></tr>";
$total_size += $miss['size'];
// flush every 200 kbytes
if (($total_size % 200) == 0)
flush();
}
}
echo "<tr><th colspan='3'>Total Size: $total_size kB</th></tr>";
echo '</table>';
}
echo gen_date($DBLANG);
break;
case 'oldfiles':
$oldfiles = get_oldfiles($dbhandle, $lang);
if (!$oldfiles) {
echo '<p>Good, it seems that this translation doesn\'t contain any file which is not present in English tree.</p>';
} else {
$num = count($oldfiles);
echo '<table class="c">';
echo '<tr><th rowspan="1">Not in EN tree ('.$num.' files):</th><th colspan="1">kB</th></tr>';
$last_dir = false;
$total_size = 0;
foreach ($oldfiles as $old) {
if (!$last_dir || $last_dir != $old['dir']) {
echo '<tr><th colspan="2">'.$old['dir'].'</th></tr>';
$last_dir = $old['dir'];
}
echo '<tr><td>', $old['file'], '</td><td>'.$old['size'].'</td></tr>';
$total_size += $old['size'];
// flush every 200 kbytes
if (($total_size % 200) == 0)
flush();
}
echo '<tr><th colspan="2">Total Size ('.$num.' files): '.$total_size.' kB</th></tr>';
echo '</table>';
}
echo gen_date($DBLANG);
break;
case 'misstags':
$misstags = get_misstags($dbhandle, $lang);
if ($misstags == NULL) {
echo '<p>Good, all files contain revision numbers.</p>';
} else {
$num = count($misstags);
echo '<table class="c">';
echo '<tr><th>Files without EN-Revision number ('.$num.' files):</th></tr>';
$last_dir = false;
foreach ($misstags as $row) {
if (!$last_dir || $last_dir != $row['dir']) {
echo '<tr><th>'.$row['dir'].'</th></tr>';
$last_dir = $row['dir'];
}
echo '<tr><td>'.$row['name'].'</td></tr>';
}
echo '</table>';
}
echo gen_date($DBLANG);
break;
case 'filesummary':
$stats = get_lang_stats($dbhandle, $lang);
echo '<table class="c">';
echo '<tr><th>File status type</th><th>Number of files</th><th>Percent of files</th><th>Size of files (kB)</th><th>Percent of size</th></tr>';
foreach ($TRANSLATION_STATUSES as $status => $description) {
echo
'<tr>',
'<td>', $description, '</td>',
'<td>', $stats[$status]['total'] ?? 0, '</td>',
'<td>',
sprintf('%.2f%%', 100 * (($stats[$status]['total'] ?? 0) / $stats['total']['total'])),
'</td>',
'<td>', $stats[$status]['size'] ?? 0, '</td>',
'<td>',
sprintf('%.2f%%', 100 * (($stats[$status]['size'] ?? 0) / $stats['total']['size'])),
'</td>',
'</tr>';
}
echo
'<tr>',
'<th>Total</th>',
'<th>', $stats['total']['total'] ?? 0, '</th>',
'<th>100.00%</th>',
'<th>', $stats['total']['size'] ?? 0, '</th>',
'<th>100.00%</th>',
'</tr>';
echo '</table>';
echo gen_date($DBLANG);
break;
case 'files' :
// we need a dir to browse
$dirs = get_dirs($dbhandle, $lang);
$users = get_translators($dbhandle, $lang);
echo '<p>This tool allows you to check which files in your translation need updates. To show the list ';
echo 'choose a directory (it doesn\'t work recursively) or translator.</p>';
echo '<p>When you click on the filename you will see the plaintext diff showing changes between revisions, so ';
echo 'you will know what has changed in the English version and which information you need to update.';
echo 'You can also click on [diff] to show the colored diff.</p>';
echo '<p>Choose a directory:</p>';
echo '<form method="get" action="revcheck.php"><p><select name="dir">';
foreach ($dirs as $id => $name) {
if (isset($_GET['dir']) && $_GET['dir'] == $id) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
echo '<option value="'.$id.'"'.$selected.'>'.$name.'</option>';
}
echo '</select>';
echo '<input type="hidden" name="p" value="files">';
echo '<input type="hidden" name="lang" value="'.$lang.'">';
echo '<input type="submit" value="See outdated files"></p></form>';
echo '<p>Or choose a translator:</p>';
echo '<form method="get" action="revcheck.php"><p><select name="user">';
foreach ($users as $id => $user) {
if (isset($_GET['user']) && $_GET['user'] == $id) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
echo '<option value="'.$id.'"'.$selected.'>'.$id.'</option>';
}
echo '</select>';
echo '<input type="hidden" name="p" value="files">';
echo '<input type="hidden" name="lang" value="'.$lang.'">';
echo '<input type="submit" value="See outdated files"></p></form>';
// Get outdated files filtered as requested
if (isset($_GET['user'])) {
$outdated = get_outdated_files($dbhandle, $lang, 'translator', $_GET['user']);
} elseif (isset($_GET['dir'])) {
$outdated = get_outdated_files($dbhandle, $lang, 'dir', $_GET['dir']);
} else {
$outdated = get_outdated_files($dbhandle, $lang, 'all');
}
if (empty($outdated)) {
echo '<p>Good, it seems that all files are up to date for these conditions.</p>';
} else {
echo <<<END_OF_MULTILINE
<table>
<tr>
<th rowspan="2">Translated file</th>
<th rowspan="2">Changes</th>
<th colspan="2">Revision</th>
<th rowspan="2">Maintainer</th>
<th rowspan="2">Status</th>
</tr>
<tr>
<th>en</th>
<th>$lang</th>
</tr>
<tr><th colspan="6">{$outdated[0]['name']}</th></tr>
END_OF_MULTILINE;
$last_dir = false;
$prev_name = $outdated[0]['name'];
foreach ($outdated as $r) {
if ($r['name'] != $prev_name) {
echo '<tr><th colspan="6">'.$r['name'].'</th></tr>';
$prev_name = $r['name'];
}
// Make the maintainer a link, if we have that maintainer in the list
if ($r['maintainer'] && $r["maintainer"] != 'nobody') {
$r["maintainer"] = '<a href="?p=translators&lang=' . $lang . '">' . $r["maintainer"] . '</a>';
}
// Make a link to the GIT repository's diff script
$key = $r['name'] . '/' . $r['file'];
if ($r['name'] == '/')
$key = $r['file'];
//plaintext -color
$d1 = "?p=plain&lang={$lang}&hbp={$r['trans_rev']}&f=$key&c=on";
//plaintext
$d2 = "?p=plain&lang={$lang}&hbp={$r['trans_rev']}&f=$key&c=off";
$h1 = '<button class="btn copy" data-clipboard-text="';
$h1 .= $r['en_rev'] . '">Copy</button> ';
$h1 .= "<a href='https://github.com/php/doc-en/blob/{$r['en_rev']}/$key'>{$r['en_rev']}</a>";
$h2 = "<a href='https://github.com/php/doc-en/blob/{$r['trans_rev']}/$key'>{$r['trans_rev']}</a>";
$nm = "<a href='$d2'>{$r['file']}</a> <a href='$d1'>[diff]</a>";
if ($r['additions'] < 0)
$ch = "<span style='color: firebrick;'>no data</span>";
else
$ch = "<span style='color: darkgreen;'>+{$r['additions']}</span> <span style='color: firebrick;'>-{$r['deletions']}</span>";
// Write out the line for the current file (get file name shorter)
echo <<<END_OF_MULTILINE
<tr>
<td class='n'>{$nm}</td>
<td class='c'>{$ch}</td>
<td class='n o6'>{$h1}</td>
<td class='n o3'>{$h2}</td>
<td class='c'>{$r['maintainer']}</td>
<td class='c'>{$r['status']}</td>
</tr>
END_OF_MULTILINE;
}
echo '</table>';
}
echo gen_date($DBLANG);
break;
case 'plain':
showdiff();
echo gen_date($DBLANG);
break;
case 'alllangs':
$dirs_en = get_dirs_en($dbhandle);
$selected_dir = isset($_GET['dir']) ? $_GET['dir'] : ($dirs_en[0] ?? '');
echo '<h2>Translation status across all languages</h2>';
echo '<p>Choose a directory to see the translation status of each file across all languages.</p>';
echo '<form method="get" action="revcheck.php"><p><select name="dir">';
foreach ($dirs_en as $d) {
$sel = ($d === $selected_dir) ? ' selected="selected"' : '';
$display = $d === '' ? '/' : $d;
echo '<option value="' . htmlspecialchars($d) . '"' . $sel . '>' . htmlspecialchars($display) . '</option>';
}
echo '</select>';
echo '<input type="hidden" name="p" value="alllangs">';
echo '<input type="hidden" name="lang" value="en">';
echo '<input type="submit" value="Show status"></p></form>';
$files_matrix = get_files_all_langs($dbhandle, $selected_dir);
if (empty($files_matrix)) {
echo '<p>No files found in this directory.</p>';
} else {
$langs = array_keys($LANGUAGES);
echo '<table class="c">';
echo '<tr><th>File</th>';
foreach ($langs as $l) {
echo '<th>' . htmlspecialchars($l) . '</th>';
}
echo '</tr>';
foreach ($files_matrix as $filename => $statuses) {
echo '<tr>';
echo '<td class="n" style="text-align:left;">' . htmlspecialchars($filename) . '</td>';
foreach ($langs as $l) {
$status = $statuses[$l] ?? 'Untranslated';
[$label, $color] = match ($status) {
'TranslatedOk' => ['✓', '#ccebc5'],
'TranslatedOld' => ['old', '#fbb4ae'],
'TranslatedWip' => ['wip', '#fed9a6'],
'RevTagProblem' => ['tag', '#ffffcc'],
'Untranslated' => ['—', '#e0e0e0'],
'NotInEnTree' => ['?', '#decbe4'],
default => ['?', '#ffffff'],
};
echo '<td style="background-color:' . $color . ';" title="' . htmlspecialchars($TRANSLATION_STATUSES[$status] ?? $status) . '">' . $label . '</td>';
}
echo '</tr>';
}
echo '</table>';
echo '<p>';
echo '<span style="background-color:#ccebc5;padding:2px 6px;">✓</span> Up to date ';
echo '<span style="background-color:#fbb4ae;padding:2px 6px;">old</span> Outdated ';
echo '<span style="background-color:#fed9a6;padding:2px 6px;">wip</span> Work in progress ';
echo '<span style="background-color:#ffffcc;padding:2px 6px;">tag</span> Missing revision tag ';
echo '<span style="background-color:#e0e0e0;padding:2px 6px;">—</span> Untranslated';
echo '</p>';
}
echo gen_date($DBLANG);
$sidebar = nav_languages();
site_footer($sidebar);
break;
case 'graph':
default:
if ($lang == 'en') {
echo '<img src="img-status-all.php" width="662" height="262" alt="Info" class="chart">';
echo '<p>This is all what we can show for original manual. To get more tools, please select translation language.</p>';
echo '<p><a href="?p=alllangs&lang=en">View translation status across all languages</a></p>';
echo gen_date($DBLANG);
$sidebar = nav_languages();
site_footer($sidebar);
} else {
echo '<h2>Intro for language</h2>';
echo '<p>'.$lang_intro.'</p>';
echo '<img src="img-status-lang.php?lang=', $lang, '" width="680" height="300" alt="info">';
echo gen_date($DBLANG);
echo '<p>Links to available tools are placed on the right sidebar.</p>';
}
break;
}
if ($lang != 'en') {
$sidebar = nav_languages($lang);
site_footer($sidebar);
}