Use capital as first letter for class names
[lhc/web/wiklou.git] / maintenance / language / StatOutputs.php
1 <?php
2 /**
3 * Statistic output classes.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup MaintenanceLanguage
22 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
23 * @author Antoine Musso <hashar at free dot fr>
24 */
25
26 /** A general output object. Need to be overriden */
27 class StatsOutput {
28 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
29 return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
30 }
31
32 # Override the following methods
33 function heading() {
34 }
35
36 function footer() {
37 }
38
39 function blockstart() {
40 }
41
42 function blockend() {
43 }
44
45 function element( $in, $heading = false ) {
46 }
47 }
48
49 /** Outputs WikiText */
50 class WikiStatsOutput extends statsOutput {
51 function heading() {
52 global $wgDummyLanguageCodes;
53 $version = SpecialVersion::getVersion( 'nodb' );
54 echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
55 echo "'''Note:''' These statistics can be generated by running " .
56 "<code>php maintenance/language/transstat.php</code>.\n\n";
57 echo "For additional information on specific languages (the message names, the actual " .
58 "problems, etc.), run <code>php maintenance/language/checkLanguage.php --lang=foo</code>.\n\n";
59 echo 'English (en) is excluded because it is the default localization';
60 if ( is_array( $wgDummyLanguageCodes ) ) {
61 $dummyCodes = array();
62 foreach ( $wgDummyLanguageCodes as $dummyCode => $correctCode ) {
63 $dummyCodes[] = Language::fetchLanguageName( $dummyCode ) . ' (' . $dummyCode . ')';
64 }
65 echo ', as well as the following languages that are not intended for ' .
66 'system message translations, usually because they redirect to other ' .
67 'language codes: ' . implode( ', ', $dummyCodes );
68 }
69 echo ".\n\n"; # dot to end sentence
70 echo '{| class="sortable wikitable" border="2" style="background-color: #F9F9F9; ' .
71 'border: 1px #AAAAAA solid; border-collapse: collapse; clear:both; width:100%;"' . "\n";
72 }
73
74 function footer() {
75 echo "|}\n";
76 }
77
78 function blockstart() {
79 echo "|-\n";
80 }
81
82 function blockend() {
83 echo '';
84 }
85
86 function element( $in, $heading = false ) {
87 echo ( $heading ? '!' : '|' ) . "$in\n";
88 }
89
90 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
91 $v = @round( 255 * $subset / $total );
92 if ( $revert ) {
93 # Weigh reverse with factor 20 so coloring takes effect more quickly as
94 # this option is used solely for reporting 'bad' percentages.
95 $v = $v * 20;
96 if ( $v > 255 ) {
97 $v = 255;
98 }
99 $v = 255 - $v;
100 }
101 if ( $v < 128 ) {
102 # Red to Yellow
103 $red = 'FF';
104 $green = sprintf( '%02X', 2 * $v );
105 } else {
106 # Yellow to Green
107 $red = sprintf( '%02X', 2 * ( 255 - $v ) );
108 $green = 'FF';
109 }
110 $blue = '00';
111 $color = $red . $green . $blue;
112
113 $percent = parent::formatPercent( $subset, $total, $revert, $accuracy );
114
115 return 'style="background-color:#' . $color . ';"|' . $percent;
116 }
117 }
118
119 /** Output text. To be used on a terminal for example. */
120 class TextStatsOutput extends statsOutput {
121 function element( $in, $heading = false ) {
122 echo $in . "\t";
123 }
124
125 function blockend() {
126 echo "\n";
127 }
128 }
129
130 /** csv output. Some people love excel */
131 class CsvStatsOutput extends statsOutput {
132 function element( $in, $heading = false ) {
133 echo $in . ";";
134 }
135
136 function blockend() {
137 echo "\n";
138 }
139 }