Part of bug 26280: added license headers to PHP files in maintenance
[lhc/web/wiklou.git] / maintenance / language / StatOutputs.php
1 <?php
2 if ( !defined( 'MEDIAWIKI' ) ) die();
3 /**
4 * Statistic output classes.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 * @ingroup MaintenanceLanguage
23 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
24 * @author Ashar Voultoiz <hashar at free dot fr>
25 */
26
27 /** A general output object. Need to be overriden */
28 class statsOutput {
29 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
30 return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
31 }
32
33 # Override the following methods
34 function heading() {
35 }
36 function footer() {
37 }
38 function blockstart() {
39 }
40 function blockend() {
41 }
42 function element( $in, $heading = false ) {
43 }
44 }
45
46 /** Outputs WikiText */
47 class wikiStatsOutput extends statsOutput {
48 function heading() {
49 $version = SpecialVersion::getVersion( 'nodb' );
50 echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
51 echo "'''Note:''' These statistics can be generated by running <code>php maintenance/language/transstat.php</code>.\n\n";
52 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";
53 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";
54 }
55 function footer() {
56 echo "|}\n";
57 }
58 function blockstart() {
59 echo "|-\n";
60 }
61 function blockend() {
62 echo '';
63 }
64 function element( $in, $heading = false ) {
65 echo ( $heading ? '!' : '|' ) . "$in\n";
66 }
67 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
68 $v = @round( 255 * $subset / $total );
69 if ( $revert ) {
70 # Weigh reverse with factor 20 so coloring takes effect more quickly as
71 # this option is used solely for reporting 'bad' percentages.
72 $v = $v * 20;
73 if ( $v > 255 ) $v = 255;
74 $v = 255 - $v;
75 }
76 if ( $v < 128 ) {
77 # Red to Yellow
78 $red = 'FF';
79 $green = sprintf( '%02X', 2 * $v );
80 } else {
81 # Yellow to Green
82 $red = sprintf( '%02X', 2 * ( 255 - $v ) );
83 $green = 'FF';
84 }
85 $blue = '00';
86 $color = $red . $green . $blue;
87
88 $percent = parent::formatPercent( $subset, $total, $revert, $accuracy );
89 return 'bgcolor="#' . $color . '"|' . $percent;
90 }
91 }
92
93 /** Output text. To be used on a terminal for example. */
94 class textStatsOutput extends statsOutput {
95 function element( $in, $heading = false ) {
96 echo $in . "\t";
97 }
98 function blockend() {
99 echo "\n";
100 }
101 }
102
103 /** csv output. Some people love excel */
104 class csvStatsOutput extends statsOutput {
105 function element( $in, $heading = false ) {
106 echo $in . ";";
107 }
108 function blockend() {
109 echo "\n";
110 }
111 }