MediaWiki  REL1_24
StatOutputs.php
Go to the documentation of this file.
00001 <?php
00027 class StatsOutput {
00028     function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
00029         wfSuppressWarnings();
00030         $return = sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
00031         wfRestoreWarnings();
00032 
00033         return $return;
00034     }
00035 
00036     # Override the following methods
00037     function heading() {
00038     }
00039 
00040     function footer() {
00041     }
00042 
00043     function blockstart() {
00044     }
00045 
00046     function blockend() {
00047     }
00048 
00049     function element( $in, $heading = false ) {
00050     }
00051 }
00052 
00054 class WikiStatsOutput extends StatsOutput {
00055     function heading() {
00056         global $wgDummyLanguageCodes;
00057         $version = SpecialVersion::getVersion( 'nodb' );
00058         echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
00059         echo "'''Note:''' These statistics can be generated by running " .
00060             "<code>php maintenance/language/transstat.php</code>.\n\n";
00061         echo "For additional information on specific languages (the message names, the actual " .
00062             "problems, etc.), run <code>php maintenance/language/checkLanguage.php --lang=foo</code>.\n\n";
00063         echo 'English (en) is excluded because it is the default localization';
00064         if ( is_array( $wgDummyLanguageCodes ) ) {
00065             $dummyCodes = array();
00066             foreach ( $wgDummyLanguageCodes as $dummyCode => $correctCode ) {
00067                 $dummyCodes[] = Language::fetchLanguageName( $dummyCode ) . ' (' . $dummyCode . ')';
00068             }
00069             echo ', as well as the following languages that are not intended for ' .
00070                 'system message translations, usually because they redirect to other ' .
00071                 'language codes: ' . implode( ', ', $dummyCodes );
00072         }
00073         echo ".\n\n"; # dot to end sentence
00074         echo '{| class="sortable wikitable" border="2" style="background-color: #F9F9F9; ' .
00075             'border: 1px #AAAAAA solid; border-collapse: collapse; clear:both; width:100%;"' . "\n";
00076     }
00077 
00078     function footer() {
00079         echo "|}\n";
00080     }
00081 
00082     function blockstart() {
00083         echo "|-\n";
00084     }
00085 
00086     function blockend() {
00087         echo '';
00088     }
00089 
00090     function element( $in, $heading = false ) {
00091         echo ( $heading ? '!' : '|' ) . "$in\n";
00092     }
00093 
00094     function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
00095         wfSuppressWarnings();
00096         $v = round( 255 * $subset / $total );
00097         wfRestoreWarnings();
00098 
00099         if ( $revert ) {
00100             # Weigh reverse with factor 20 so coloring takes effect more quickly as
00101             # this option is used solely for reporting 'bad' percentages.
00102             $v = $v * 20;
00103             if ( $v > 255 ) {
00104                 $v = 255;
00105             }
00106             $v = 255 - $v;
00107         }
00108         if ( $v < 128 ) {
00109             # Red to Yellow
00110             $red = 'FF';
00111             $green = sprintf( '%02X', 2 * $v );
00112         } else {
00113             # Yellow to Green
00114             $red = sprintf( '%02X', 2 * ( 255 - $v ) );
00115             $green = 'FF';
00116         }
00117         $blue = '00';
00118         $color = $red . $green . $blue;
00119 
00120         $percent = parent::formatPercent( $subset, $total, $revert, $accuracy );
00121 
00122         return 'style="background-color:#' . $color . ';"|' . $percent;
00123     }
00124 }
00125 
00127 class TextStatsOutput extends StatsOutput {
00128     function element( $in, $heading = false ) {
00129         echo $in . "\t";
00130     }
00131 
00132     function blockend() {
00133         echo "\n";
00134     }
00135 }
00136 
00138 class CsvStatsOutput extends StatsOutput {
00139     function element( $in, $heading = false ) {
00140         echo $in . ";";
00141     }
00142 
00143     function blockend() {
00144         echo "\n";
00145     }
00146 }