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
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 overriden */
28 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
30 $return = sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
35 # Override the following methods
42 function blockstart() {
48 function element( $in, $heading = false ) {
52 /** Outputs WikiText */
53 class WikiStatsOutput
extends StatsOutput
{
55 global $wgDummyLanguageCodes;
56 $version = SpecialVersion
::getVersion( 'nodb' );
57 echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
58 echo "'''Note:''' These statistics can be generated by running " .
59 "<code>php maintenance/language/transstat.php</code>.\n\n";
60 echo "For additional information on specific languages (the message names, the actual " .
61 "problems, etc.), run <code>php maintenance/language/checkLanguage.php --lang=foo</code>.\n\n";
62 echo 'English (en) is excluded because it is the default localization';
63 if ( is_array( $wgDummyLanguageCodes ) ) {
64 $dummyCodes = array();
65 foreach ( $wgDummyLanguageCodes as $dummyCode => $correctCode ) {
66 $dummyCodes[] = Language
::fetchLanguageName( $dummyCode ) . ' (' . $dummyCode . ')';
68 echo ', as well as the following languages that are not intended for ' .
69 'system message translations, usually because they redirect to other ' .
70 'language codes: ' . implode( ', ', $dummyCodes );
72 echo ".\n\n"; # dot to end sentence
73 echo '{| class="sortable wikitable" border="2" style="background-color: #F9F9F9; ' .
74 'border: 1px #AAAAAA solid; border-collapse: collapse; clear:both; width:100%;"' . "\n";
81 function blockstart() {
89 function element( $in, $heading = false ) {
90 echo ( $heading ?
'!' : '|' ) . "$in\n";
93 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
95 $v = round( 255 * $subset / $total );
99 # Weigh reverse with factor 20 so coloring takes effect more quickly as
100 # this option is used solely for reporting 'bad' percentages.
110 $green = sprintf( '%02X', 2 * $v );
113 $red = sprintf( '%02X', 2 * ( 255 - $v ) );
117 $color = $red . $green . $blue;
119 $percent = parent
::formatPercent( $subset, $total, $revert, $accuracy );
121 return 'style="background-color:#' . $color . ';"|' . $percent;
125 /** Output text. To be used on a terminal for example. */
126 class TextStatsOutput
extends StatsOutput
{
127 function element( $in, $heading = false ) {
131 function blockend() {
136 /** csv output. Some people love excel */
137 class CsvStatsOutput
extends StatsOutput
{
138 function element( $in, $heading = false ) {
142 function blockend() {