50829cbe9124e7231551b71994f8467c1aa08fc6
[lhc/web/wiklou.git] / maintenance / language / StatOutputs.php
1 <?php
2 if (!defined('MEDIAWIKI')) die();
3 /**
4 * Statistic output classes.
5 *
6 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7 * @author Ashar Voultoiz <thoane@altern.org>
8 */
9
10 /** A general output object. Need to be overriden */
11 class statsOutput {
12 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
13 return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
14 }
15
16 # Override the following methods
17 function heading() {
18 }
19 function footer() {
20 }
21 function blockstart() {
22 }
23 function blockend() {
24 }
25 function element( $in, $heading = false ) {
26 }
27 }
28
29 /** Outputs WikiText */
30 class wikiStatsOutput extends statsOutput {
31 function heading() {
32 global $IP;
33 $version = SpecialVersion::getVersion( $IP );
34 echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
35 echo "'''Note:''' These statistics can be generated by running <code>php maintenance/language/transstat.php</code>.\n\n";
36 echo "For additional information on specific languages (the message names, the actual problems, etc.), run <code>php maintenance/language/checkLanguage.php --lang=foo</code>.\n\n";
37 echo '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;" width="100%"'."\n";
38 }
39 function footer() {
40 echo "|}\n";
41 }
42 function blockstart() {
43 echo "|-\n";
44 }
45 function blockend() {
46 echo '';
47 }
48 function element( $in, $heading = false ) {
49 echo ($heading ? '!' : '|') . " $in\n";
50 }
51 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
52 $v = @round(255 * $subset / $total);
53 if ( $revert ) {
54 $v = 255 - $v;
55 }
56 if ( $v < 128 ) {
57 # Red to Yellow
58 $red = 'FF';
59 $green = sprintf( '%02X', 2 * $v );
60 } else {
61 # Yellow to Green
62 $red = sprintf('%02X', 2 * ( 255 - $v ) );
63 $green = 'FF';
64 }
65 $blue = '00';
66 $color = $red . $green . $blue;
67
68 $percent = statsOutput::formatPercent( $subset, $total, $revert, $accuracy );
69 return 'bgcolor="#'. $color .'" | '. $percent;
70 }
71 }
72
73 /** Outputs WikiText and appends category and text only used for Meta-Wiki */
74 class metawikiStatsOutput extends wikiStatsOutput {
75 function heading() {
76 echo "See [[MediaWiki localisation]] to learn how you can help translating MediaWiki.\n\n";
77 parent::heading();
78 }
79 function footer() {
80 parent::footer();
81 echo "\n[[Category:Localisation|Statistics]]\n";
82 }
83 }
84
85 /** Output text. To be used on a terminal for example. */
86 class textStatsOutput extends statsOutput {
87 function element( $in, $heading = false ) {
88 echo $in."\t";
89 }
90 function blockend() {
91 echo "\n";
92 }
93 }
94
95 /** csv output. Some people love excel */
96 class csvStatsOutput extends statsOutput {
97 function element( $in, $heading = false ) {
98 echo $in . ";";
99 }
100 function blockend() {
101 echo "\n";
102 }
103 }