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