Fix hardcoded path to the languages directory
[lhc/web/wiklou.git] / maintenance / transstat.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 *
6 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7 * @bug 2499
8 *
9 * Output is posted from time to time on:
10 * http://meta.wikimedia.org/wiki/Localization_statistics
11 */
12
13 /** */
14 require_once('commandLine.inc');
15
16 $langs = array();
17 $dir = opendir("$IP/languages");
18 while ($file = readdir($dir)) {
19 if (preg_match("/Language(.*?)\.php$/", $file, $m)) {
20 $langs[] = $m[1];
21 }
22 }
23
24 sort($langs);
25
26 // Cleanup
27 foreach($langs as $key => $lang) {
28 if ($lang == 'Utf8' || $lang == '' || $lang == 'Converter')
29 unset($langs[$key]);
30 }
31
32
33 $msgs = array();
34 foreach($langs as $lang) {
35 // Since they aren't loaded by default..
36 require_once( 'languages/Language' . $lang . '.php' );
37 $arr = 'wgAllMessages' . $lang;
38 if (@is_array($$arr)) { // Some of them don't have a message array
39 $msgs[$wgContLang->lcfirst($lang)] = array(
40 'total' => count($$arr),
41 'redundant' => redundant($$arr),
42 );
43 } else {
44 $msgs[$wgContLang->lcfirst($lang)] = array(
45 'total' => 0,
46 'redundant' => 0,
47 );
48 }
49 }
50
51 // wiki syntax header
52 $out = "{| border=2 cellpadding=4 cellspacing=0 style=\"background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;\" width=100%\n";
53 $out .= beginul();
54 $out .= li('Language', true);
55 $out .= li('Translated', true);
56 $out .= li('%', true);
57 $out .= li('Untranslated', true);
58 $out .= li('%', true);
59 $out .= li('Redundant', true);
60 $out .= li('%', true);
61 $out .= endul();
62
63 // generate table rows using wikisyntax
64 foreach($msgs as $lang => $stats) {
65 $out .= beginul();
66 $out .= li($wgContLang->getLanguageName(strtr($lang, '_', '-')) . " ($lang)"); // Language
67 $out .= li($stats['total'] . '/' . $msgs['en']['total']); // Translated
68 $out .= li(percent($stats['total'], $msgs['en']['total'])); // % Translated
69 $out .= li($msgs['en']['total'] - $stats['total']); // Untranslated
70 $out .= li(percent($msgs['en']['total'] - $stats['total'], $msgs['en']['total'])); // % Untranslated
71 $out .= li($stats['redundant'] . '/' . $stats['total']); // Redundant
72 $out .= li(percent($stats['redundant'], $stats['total'])); // % Redundant
73 $out .= endul();
74 }
75 $out = substr($out, 0, -3) . "|}\n";
76 echo $out;
77
78 function beginul() { return ''; }
79 function endul() { return "|-\n"; }
80 function li($in, $heading = false) { return ($heading ? '!' : '|') . " $in\n"; }
81 function percent($subset, $total, $accuracy = 2) { return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total ); }
82
83 // FIXME: This takes an obscene amount of time
84 function redundant(&$arr) {
85 global $wgAllMessagesEn;
86
87 $redundant = 0;
88 foreach(array_keys($arr) as $key) {
89 if ( ! array_key_exists( $key, $wgAllMessagesEn) )
90 ++$redundant;
91 }
92 return $redundant;
93 }