MediaWiki  master
StatOutputs.php
Go to the documentation of this file.
1 <?php
27 
31 class StatsOutput {
32  public function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
33  Wikimedia\suppressWarnings();
34  $return = sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
35  Wikimedia\restoreWarnings();
36 
37  return $return;
38  }
39 
40  public function heading() {
41  }
42 
43  public function footer() {
44  }
45 
46  public function blockstart() {
47  }
48 
49  public function blockend() {
50  }
51 
52  public function element( $in, $heading = false ) {
53  }
54 }
55 
58  public function heading() {
59  global $wgDummyLanguageCodes;
60  $version = SpecialVersion::getVersion( 'nodb' );
61  echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
62  echo 'English (en) is excluded because it is the default localization';
63  if ( is_array( $wgDummyLanguageCodes ) ) {
64  $dummyCodes = [];
65  foreach ( $wgDummyLanguageCodes as $dummyCode => $correctCode ) {
66  $dummyCodes[] = MediaWikiServices::getInstance()
67  ->getLanguageNameUtils()
68  ->getLanguageName( $dummyCode ) . ' (' . $dummyCode . ')';
69  }
70  echo ', as well as the following languages that are not intended for ' .
71  'system message translations, usually because they redirect to other ' .
72  'language codes: ' . implode( ', ', $dummyCodes );
73  }
74  # dot to end sentence
75  echo ".\n\n";
76  echo '{| class="sortable wikitable" border="2" style="background-color: #F9F9F9; ' .
77  'border: 1px #AAAAAA solid; border-collapse: collapse; clear:both; width:100%;"' . "\n";
78  }
79 
80  public function footer() {
81  echo "|}\n";
82  }
83 
84  public function blockstart() {
85  echo "|-\n";
86  }
87 
88  public function blockend() {
89  echo '';
90  }
91 
92  public function element( $in, $heading = false ) {
93  echo ( $heading ? '!' : '|' ) . "$in\n";
94  }
95 
96  public function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
97  Wikimedia\suppressWarnings();
98  $v = round( 255 * $subset / $total );
99  Wikimedia\restoreWarnings();
100 
101  if ( $revert ) {
102  # Weigh reverse with factor 20 so coloring takes effect more quickly as
103  # this option is used solely for reporting 'bad' percentages.
104  $v = $v * 20;
105  if ( $v > 255 ) {
106  $v = 255;
107  }
108  $v = 255 - $v;
109  }
110  if ( $v < 128 ) {
111  # Red to Yellow
112  $red = 'FF';
113  $green = sprintf( '%02X', 2 * $v );
114  } else {
115  # Yellow to Green
116  $red = sprintf( '%02X', 2 * ( 255 - $v ) );
117  $green = 'FF';
118  }
119  $blue = '00';
120  $color = $red . $green . $blue;
121 
122  $percent = parent::formatPercent( $subset, $total, $revert, $accuracy );
123 
124  return 'style="background-color:#' . $color . ';"|' . $percent;
125  }
126 }
127 
130  public function element( $in, $heading = false ) {
131  echo $in . "\t";
132  }
133 
134  public function blockend() {
135  echo "\n";
136  }
137 }
138 
141  public function element( $in, $heading = false ) {
142  echo $in . ";";
143  }
144 
145  public function blockend() {
146  echo "\n";
147  }
148 }
CsvStatsOutput
csv output.
Definition: StatOutputs.php:140
StatsOutput\blockstart
blockstart()
Definition: StatOutputs.php:46
WikiStatsOutput\blockend
blockend()
Definition: StatOutputs.php:88
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:152
WikiStatsOutput\footer
footer()
Definition: StatOutputs.php:80
TextStatsOutput\blockend
blockend()
Definition: StatOutputs.php:134
StatsOutput\footer
footer()
Definition: StatOutputs.php:43
StatsOutput\blockend
blockend()
Definition: StatOutputs.php:49
TextStatsOutput
Output text.
Definition: StatOutputs.php:129
StatsOutput\formatPercent
formatPercent( $subset, $total, $revert=false, $accuracy=2)
Definition: StatOutputs.php:32
StatsOutput
A general output object.
Definition: StatOutputs.php:31
CsvStatsOutput\blockend
blockend()
Definition: StatOutputs.php:145
StatsOutput\element
element( $in, $heading=false)
Definition: StatOutputs.php:52
TextStatsOutput\element
element( $in, $heading=false)
Definition: StatOutputs.php:130
SpecialVersion\getVersion
static getVersion( $flags='', $lang=null)
Return a string of the MediaWiki version with Git revision if available.
Definition: SpecialVersion.php:316
WikiStatsOutput\element
element( $in, $heading=false)
Definition: StatOutputs.php:92
WikiStatsOutput\blockstart
blockstart()
Definition: StatOutputs.php:84
WikiStatsOutput\formatPercent
formatPercent( $subset, $total, $revert=false, $accuracy=2)
Definition: StatOutputs.php:96
WikiStatsOutput\heading
heading()
Definition: StatOutputs.php:58
CsvStatsOutput\element
element( $in, $heading=false)
Definition: StatOutputs.php:141
WikiStatsOutput
Outputs WikiText.
Definition: StatOutputs.php:57
StatsOutput\heading
heading()
Definition: StatOutputs.php:40
$wgDummyLanguageCodes
$wgDummyLanguageCodes
Functionally the same as $wgExtraLanguageCodes, but deprecated.
Definition: DefaultSettings.php:3184