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