MediaWiki  REL1_22
StatOutputs.php
Go to the documentation of this file.
00001 <?php
00002 if ( !defined( 'MEDIAWIKI' ) ) {
00003     die();
00004 }
00030 class statsOutput {
00031     function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
00032         return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
00033     }
00034 
00035     # Override the following methods
00036     function heading() {
00037     }
00038     function footer() {
00039     }
00040     function blockstart() {
00041     }
00042     function blockend() {
00043     }
00044     function element( $in, $heading = false ) {
00045     }
00046 }
00047 
00049 class wikiStatsOutput extends statsOutput {
00050     function heading() {
00051         global $wgDummyLanguageCodes;
00052         $version = SpecialVersion::getVersion( 'nodb' );
00053         echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
00054         echo "'''Note:''' These statistics can be generated by running <code>php maintenance/language/transstat.php</code>.\n\n";
00055         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";
00056         echo 'English (en) is excluded because it is the default localization';
00057         if ( is_array( $wgDummyLanguageCodes ) ) {
00058             $dummyCodes = array();
00059             foreach ( $wgDummyLanguageCodes as $dummyCode => $correctCode ) {
00060                 $dummyCodes[] = Language::fetchLanguageName( $dummyCode ) . ' (' . $dummyCode . ')';
00061             }
00062             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 );
00063         }
00064         echo ".\n\n"; # dot to end sentence
00065         echo '{| class="sortable wikitable" border="2" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both; width:100%;"' . "\n";
00066     }
00067     function footer() {
00068         echo "|}\n";
00069     }
00070     function blockstart() {
00071         echo "|-\n";
00072     }
00073     function blockend() {
00074         echo '';
00075     }
00076     function element( $in, $heading = false ) {
00077         echo ( $heading ? '!' : '|' ) . "$in\n";
00078     }
00079     function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
00080         $v = @round( 255 * $subset / $total );
00081         if ( $revert ) {
00082             # Weigh reverse with factor 20 so coloring takes effect more quickly as
00083             # this option is used solely for reporting 'bad' percentages.
00084             $v = $v * 20;
00085             if ( $v > 255 ) {
00086                 $v = 255;
00087             }
00088             $v = 255 - $v;
00089         }
00090         if ( $v < 128 ) {
00091             # Red to Yellow
00092             $red = 'FF';
00093             $green = sprintf( '%02X', 2 * $v );
00094         } else {
00095             # Yellow to Green
00096             $red = sprintf( '%02X', 2 * ( 255 - $v ) );
00097             $green = 'FF';
00098         }
00099         $blue = '00';
00100         $color = $red . $green . $blue;
00101 
00102         $percent = parent::formatPercent( $subset, $total, $revert, $accuracy );
00103         return 'style="background-color:#' . $color . ';"|' . $percent;
00104     }
00105 }
00106 
00108 class textStatsOutput extends statsOutput {
00109     function element( $in, $heading = false ) {
00110         echo $in . "\t";
00111     }
00112     function blockend() {
00113         echo "\n";
00114     }
00115 }
00116 
00118 class csvStatsOutput extends statsOutput {
00119     function element( $in, $heading = false ) {
00120         echo $in . ";";
00121     }
00122     function blockend() {
00123         echo "\n";
00124     }
00125 }