| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
om> |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
use MediaWiki\Specials\SpecialVersion; |
| 27 |
use Wikimedia\AtEase\AtEase; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class StatsOutput { |
| 33 |
public function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) { |
| 34 |
AtEase::suppressWarnings(); |
| 35 |
$return = sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total ); |
| 36 |
AtEase::restoreWarnings(); |
| 37 |
|
| 38 |
return $return; |
| 39 |
} |
| 40 |
|
| 41 |
public function heading() { |
| 42 |
} |
| 43 |
|
| 44 |
public function footer() { |
| 45 |
} |
| 46 |
|
| 47 |
public function blockstart() { |
| 48 |
} |
| 49 |
|
| 50 |
public function blockend() { |
| 51 |
} |
| 52 |
|
| 53 |
public function element( $in, $heading = false ) { |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
class WikiStatsOutput extends StatsOutput { |
| 59 |
public function heading() { |
| 60 |
global $wgDummyLanguageCodes; |
| 61 |
$version = SpecialVersion::getVersion( 'nodb' ); |
| 62 |
echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n"; |
| 63 |
echo 'English (en) is excluded because it is the default localization'; |
| 64 |
if ( is_array( $wgDummyLanguageCodes ) ) { |
| 65 |
$dummyCodes = []; |
| 66 |
foreach ( $wgDummyLanguageCodes as $dummyCode => $correctCode ) { |
| 67 |
$dummyCodes[] = $this->getServiceContainer() |
| 68 |
->getLanguageNameUtils() |
| 69 |
->getLanguageName( $dummyCode ) . ' (' . $dummyCode . ')'; |
| 70 |
} |
| 71 |
echo ', as well as the following languages that are not intended for ' . |
| 72 |
'system message translations, usually because they redirect to other ' . |
| 73 |
'language codes: ' . implode( ', ', $dummyCodes ); |
| 74 |
} |
| 75 |
|
| 76 |
echo ".\n\n"; |
| 77 |
echo '{| class="sortable wikitable" border="2" style="background-color: #F9F9F9; ' . |
| 78 |
'border: 1px #AAAAAA solid; border-collapse: collapse; clear:both; width:100%;"' . "\n"; |
| 79 |
} |
| 80 |
|
| 81 |
public function footer() { |
| 82 |
echo "|}\n"; |
| 83 |
} |
| 84 |
|
| 85 |
public function blockstart() { |
| 86 |
echo "|-\n"; |
| 87 |
} |
| 88 |
|
| 89 |
public function blockend() { |
| 90 |
echo ''; |
| 91 |
} |
| 92 |
|
| 93 |
public function element( $in, $heading = false ) { |
| 94 |
echo ( $heading ? '!' : '|' ) . "$in\n"; |
| 95 |
} |
| 96 |
|
| 97 |
public function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) { |
| 98 |
AtEase::suppressWarnings(); |
| 99 |
$v = round( 255 * $subset / $total ); |
| 100 |
AtEase::restoreWarnings(); |
| 101 |
|
| 102 |
if ( $revert ) { |
| 103 |
|
| 104 |
|
| 105 |
$v = $v * 20; |
| 106 |
if ( $v > 255 ) { |
| 107 |
$v = 255; |
| 108 |
} |
| 109 |
$v = 255 - $v; |
| 110 |
} |
| 111 |
if ( $v < 128 ) { |
| 112 |
|
| 113 |
$red = 'FF'; |
| 114 |
$green = sprintf( '%02X', 2 * $v ); |
| 115 |
} else { |
| 116 |
|
| 117 |
$red = sprintf( '%02X', 2 * ( 255 - $v ) ); |
| 118 |
$green = 'FF'; |
| 119 |
} |
| 120 |
$blue = '00'; |
| 121 |
$color = $red . $green . $blue; |
| 122 |
|
| 123 |
$percent = parent::formatPercent( $subset, $total, $revert, $accuracy ); |
| 124 |
|
| 125 |
return 'style="background-color:#' . $color . ';"|' . $percent; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
class TextStatsOutput extends StatsOutput { |
| 131 |
public function element( $in, $heading = false ) { |
| 132 |
echo $in . "\t"; |
| 133 |
} |
| 134 |
|
| 135 |
public function blockend() { |
| 136 |
echo "\n"; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
class CsvStatsOutput extends StatsOutput { |
| 142 |
public function element( $in, $heading = false ) { |
| 143 |
echo $in . ";"; |
| 144 |
} |
| 145 |
|
| 146 |
public function blockend() { |
| 147 |
echo "\n"; |
| 148 |
} |
| 149 |
} |