MediaWiki
REL1_41
StatOutputs.php
Go to the documentation of this file.
1
<?php
26
use Wikimedia\AtEase\AtEase;
27
31
class
StatsOutput
{
32
public
function
formatPercent
( $subset, $total, $revert =
false
, $accuracy = 2 ) {
33
AtEase::suppressWarnings();
34
$return = sprintf(
'%.'
. $accuracy .
'f%%'
, 100 * $subset / $total );
35
AtEase::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
57
class
WikiStatsOutput
extends
StatsOutput
{
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[] = $this->getServiceContainer()
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
AtEase::suppressWarnings();
98
$v = round( 255 * $subset / $total );
99
AtEase::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
129
class
TextStatsOutput
extends
StatsOutput
{
130
public
function
element
( $in, $heading =
false
) {
131
echo $in .
"\t"
;
132
}
133
134
public
function
blockend
() {
135
echo
"\n"
;
136
}
137
}
138
140
class
CsvStatsOutput
extends
StatsOutput
{
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
CsvStatsOutput\element
element( $in, $heading=false)
Definition
StatOutputs.php:141
CsvStatsOutput\blockend
blockend()
Definition
StatOutputs.php:145
StatsOutput
A general output object.
Definition
StatOutputs.php:31
StatsOutput\blockstart
blockstart()
Definition
StatOutputs.php:46
StatsOutput\formatPercent
formatPercent( $subset, $total, $revert=false, $accuracy=2)
Definition
StatOutputs.php:32
StatsOutput\element
element( $in, $heading=false)
Definition
StatOutputs.php:52
StatsOutput\heading
heading()
Definition
StatOutputs.php:40
StatsOutput\footer
footer()
Definition
StatOutputs.php:43
StatsOutput\blockend
blockend()
Definition
StatOutputs.php:49
TextStatsOutput
Output text.
Definition
StatOutputs.php:129
TextStatsOutput\element
element( $in, $heading=false)
Definition
StatOutputs.php:130
TextStatsOutput\blockend
blockend()
Definition
StatOutputs.php:134
WikiStatsOutput
Outputs WikiText.
Definition
StatOutputs.php:57
WikiStatsOutput\footer
footer()
Definition
StatOutputs.php:80
WikiStatsOutput\element
element( $in, $heading=false)
Definition
StatOutputs.php:92
WikiStatsOutput\blockstart
blockstart()
Definition
StatOutputs.php:84
WikiStatsOutput\blockend
blockend()
Definition
StatOutputs.php:88
WikiStatsOutput\heading
heading()
Definition
StatOutputs.php:58
WikiStatsOutput\formatPercent
formatPercent( $subset, $total, $revert=false, $accuracy=2)
Definition
StatOutputs.php:96
$wgDummyLanguageCodes
$wgDummyLanguageCodes
Config variable stub for the DummyLanguageCodes setting, for use by phpdoc and IDEs.
Definition
config-vars.php:1814
maintenance
language
StatOutputs.php
Generated on Sat Nov 23 2024 08:26:24 for MediaWiki by
1.10.0