Merge "Follow-up I774a89d6 (2fabea7): use $this->msg() in HistoryAction"
[mediawiki.git] / maintenance / language / StatOutputs.php
blobd77029e74305f26b0b7635294f3fff2a26871a1c
1 <?php
2 if ( !defined( 'MEDIAWIKI' ) ) die();
3 /**
4 * Statistic output classes.
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.
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.
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
21 * @file
22 * @ingroup MaintenanceLanguage
23 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
24 * @author Antoine Musso <hashar at free dot fr>
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 );
33 # Override the following methods
34 function heading() {
36 function footer() {
38 function blockstart() {
40 function blockend() {
42 function element( $in, $heading = false ) {
46 /** Outputs WikiText */
47 class wikiStatsOutput extends statsOutput {
48 function heading() {
49 global $wgDummyLanguageCodes;
50 $version = SpecialVersion::getVersion( 'nodb' );
51 echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
52 echo "'''Note:''' These statistics can be generated by running <code>php maintenance/language/transstat.php</code>.\n\n";
53 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";
54 echo 'English (en) is excluded because it is the default localization';
55 if( is_array( $wgDummyLanguageCodes ) ) {
56 $dummyCodes = array();
57 foreach( $wgDummyLanguageCodes as $dummyCode => $correctCode ) {
58 $dummyCodes[] = Language::fetchLanguageName( $dummyCode ) . ' (' . $dummyCode . ')';
60 echo ', as well as the following languages that are not intended for system message translations, usually because they redirect to other language codes: ' . implode( ', ', $dummyCodes );
62 echo ".\n\n"; # dot to end sentence
63 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";
65 function footer() {
66 echo "|}\n";
68 function blockstart() {
69 echo "|-\n";
71 function blockend() {
72 echo '';
74 function element( $in, $heading = false ) {
75 echo ( $heading ? '!' : '|' ) . "$in\n";
77 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
78 $v = @round( 255 * $subset / $total );
79 if ( $revert ) {
80 # Weigh reverse with factor 20 so coloring takes effect more quickly as
81 # this option is used solely for reporting 'bad' percentages.
82 $v = $v * 20;
83 if ( $v > 255 ) $v = 255;
84 $v = 255 - $v;
86 if ( $v < 128 ) {
87 # Red to Yellow
88 $red = 'FF';
89 $green = sprintf( '%02X', 2 * $v );
90 } else {
91 # Yellow to Green
92 $red = sprintf( '%02X', 2 * ( 255 - $v ) );
93 $green = 'FF';
95 $blue = '00';
96 $color = $red . $green . $blue;
98 $percent = parent::formatPercent( $subset, $total, $revert, $accuracy );
99 return 'bgcolor="#' . $color . '"|' . $percent;
103 /** Output text. To be used on a terminal for example. */
104 class textStatsOutput extends statsOutput {
105 function element( $in, $heading = false ) {
106 echo $in . "\t";
108 function blockend() {
109 echo "\n";
113 /** csv output. Some people love excel */
114 class csvStatsOutput extends statsOutput {
115 function element( $in, $heading = false ) {
116 echo $in . ";";
118 function blockend() {
119 echo "\n";