]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/language/StatOutputs.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.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 <hashar at free dot fr>
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                 $version = SpecialVersion::getVersion( 'nodb' );
35                 echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
36                 echo "'''Note:''' These statistics can be generated by running <code>php maintenance/language/transstat.php</code>.\n\n";
37                 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";
38                 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";
39         }
40         function footer() {
41                 echo "|}\n";
42         }
43         function blockstart() {
44                 echo "|-\n";
45         }
46         function blockend() {
47                 echo '';
48         }
49         function element( $in, $heading = false ) {
50                 echo ( $heading ? '!' : '|' ) . "$in\n";
51         }
52         function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
53                 $v = @round( 255 * $subset / $total );
54                 if ( $revert ) {
55                         # Weigh reverse with factor 20 so coloring takes effect more quickly as
56                         # this option is used solely for reporting 'bad' percentages.
57                         $v = $v * 20;
58                         if ( $v > 255 ) $v = 255;
59                         $v = 255 - $v;
60                 }
61                 if ( $v < 128 ) {
62                         # Red to Yellow
63                         $red = 'FF';
64                         $green = sprintf( '%02X', 2 * $v );
65                 } else {
66                         # Yellow to Green
67                         $red = sprintf( '%02X', 2 * ( 255 - $v ) );
68                         $green = 'FF';
69                 }
70                 $blue = '00';
71                 $color = $red . $green . $blue;
72
73                 $percent = parent::formatPercent( $subset, $total, $revert, $accuracy );
74                 return 'bgcolor="#' . $color . '"|' . $percent;
75         }
76 }
77
78 /** Output text. To be used on a terminal for example. */
79 class textStatsOutput extends statsOutput {
80         function element( $in, $heading = false ) {
81                 echo $in . "\t";
82         }
83         function blockend() {
84                 echo "\n";
85         }
86 }
87
88 /** csv output. Some people love excel */
89 class csvStatsOutput extends statsOutput {
90         function element( $in, $heading = false ) {
91                 echo $in . ";";
92         }
93         function blockend() {
94                 echo "\n";
95         }
96 }