Implement extension registration from an extension.json file
[mediawiki.git] / maintenance / language / StatOutputs.php
blob257fe14660ed98f6adda945af5fb0d817abca952
1 <?php
2 /**
3 * Statistic output classes.
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.
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.
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
20 * @file
21 * @ingroup MaintenanceLanguage
22 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
23 * @author Antoine Musso <hashar at free dot fr>
26 /** A general output object. Need to be overridden */
27 class StatsOutput {
28 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
29 wfSuppressWarnings();
30 $return = sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
31 wfRestoreWarnings();
33 return $return;
36 # Override the following methods
37 function heading() {
40 function footer() {
43 function blockstart() {
46 function blockend() {
49 function element( $in, $heading = false ) {
53 /** Outputs WikiText */
54 class WikiStatsOutput extends StatsOutput {
55 function heading() {
56 global $wgDummyLanguageCodes;
57 $version = SpecialVersion::getVersion( 'nodb' );
58 echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
59 echo "'''Note:''' These statistics can be generated by running " .
60 "<code>php maintenance/language/transstat.php</code>.\n\n";
61 echo "For additional information on specific languages (the message names, the actual " .
62 "problems, etc.), run <code>php maintenance/language/checkLanguage.php --lang=foo</code>.\n\n";
63 echo 'English (en) is excluded because it is the default localization';
64 if ( is_array( $wgDummyLanguageCodes ) ) {
65 $dummyCodes = array();
66 foreach ( $wgDummyLanguageCodes as $dummyCode => $correctCode ) {
67 $dummyCodes[] = Language::fetchLanguageName( $dummyCode ) . ' (' . $dummyCode . ')';
69 echo ', as well as the following languages that are not intended for ' .
70 'system message translations, usually because they redirect to other ' .
71 'language codes: ' . implode( ', ', $dummyCodes );
73 echo ".\n\n"; # dot to end sentence
74 echo '{| class="sortable wikitable" border="2" style="background-color: #F9F9F9; ' .
75 'border: 1px #AAAAAA solid; border-collapse: collapse; clear:both; width:100%;"' . "\n";
78 function footer() {
79 echo "|}\n";
82 function blockstart() {
83 echo "|-\n";
86 function blockend() {
87 echo '';
90 function element( $in, $heading = false ) {
91 echo ( $heading ? '!' : '|' ) . "$in\n";
94 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
95 wfSuppressWarnings();
96 $v = round( 255 * $subset / $total );
97 wfRestoreWarnings();
99 if ( $revert ) {
100 # Weigh reverse with factor 20 so coloring takes effect more quickly as
101 # this option is used solely for reporting 'bad' percentages.
102 $v = $v * 20;
103 if ( $v > 255 ) {
104 $v = 255;
106 $v = 255 - $v;
108 if ( $v < 128 ) {
109 # Red to Yellow
110 $red = 'FF';
111 $green = sprintf( '%02X', 2 * $v );
112 } else {
113 # Yellow to Green
114 $red = sprintf( '%02X', 2 * ( 255 - $v ) );
115 $green = 'FF';
117 $blue = '00';
118 $color = $red . $green . $blue;
120 $percent = parent::formatPercent( $subset, $total, $revert, $accuracy );
122 return 'style="background-color:#' . $color . ';"|' . $percent;
126 /** Output text. To be used on a terminal for example. */
127 class TextStatsOutput extends StatsOutput {
128 function element( $in, $heading = false ) {
129 echo $in . "\t";
132 function blockend() {
133 echo "\n";
137 /** csv output. Some people love excel */
138 class CsvStatsOutput extends StatsOutput {
139 function element( $in, $heading = false ) {
140 echo $in . ";";
143 function blockend() {
144 echo "\n";