Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7406024
CitizenComponentSiteStats.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
CitizenComponentSiteStats.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Skins\Citizen\Components
;
use
IntlException
;
use
MediaWiki\Config\Config
;
use
MediaWiki\Language\Language
;
use
MediaWiki\SiteStats\SiteStats
;
use
MediaWiki\StubObject\StubUserLang
;
use
MessageLocalizer
;
use
NumberFormatter
;
/**
* CitizenComponentSiteStats component
* FIXME: Need unit test
*/
class
CitizenComponentSiteStats
implements
CitizenComponent
{
private
const
SITESTATS_ICON_MAP
=
[
'articles'
=>
'article'
,
'images'
=>
'image'
,
'users'
=>
'userAvatar'
,
'edits'
=>
'edit'
];
public
function
__construct
(
private
readonly
Config
$config
,
private
readonly
MessageLocalizer
$localizer
,
private
readonly
Language
|
StubUserLang
$pageLang
)
{
}
/**
* Get and format sitestat value
*/
private
function
getSiteStatValue
(
string
$key
,
?
NumberFormatter
$fmt
):
string
{
$value
=
SiteStats
::
$key
();
if
(
!
$value
)
{
return
''
;
}
return
$fmt
?
$fmt
->
format
(
$value
)
:
number_format
(
$value
);
}
public
function
getTemplateData
():
array
{
$config
=
$this
->
config
;
if
(
!
$config
->
get
(
'CitizenEnableDrawerSiteStats'
)
)
{
return
[];
}
$items
=
[];
$fmt
=
null
;
// Get NumberFormatter here so that we don't have to call it for every stats
if
(
$config
->
get
(
'CitizenUseNumberFormatter'
)
&&
class_exists
(
NumberFormatter
::
class
)
)
{
$locale
=
$this
->
pageLang
->
getHtmlCode
()
??
'en_US'
;
try
{
$fmt
=
new
NumberFormatter
(
$locale
,
NumberFormatter
::
PADDING_POSITION
);
$fmt
->
setAttribute
(
NumberFormatter
::
ROUNDING_MODE
,
NumberFormatter
::
ROUND_DOWN
);
$fmt
->
setAttribute
(
NumberFormatter
::
MAX_FRACTION_DIGITS
,
1
);
}
catch
(
IntlException
$exception
)
{
/*
* FIXME: Put a proper log or error message here?
* For some unknown reason, NumberFormatter can throw an IntlException: Constructor failed
* This should allow Citizen to run as usual even if such exception is encountered.
*/
}
}
foreach
(
self
::
SITESTATS_ICON_MAP
as
$key
=>
$icon
)
{
$items
[]
=
[
'id'
=>
$key
,
'icon'
=>
$icon
,
'value'
=>
$this
->
getSiteStatValue
(
$key
,
$fmt
),
'label'
=>
$this
->
localizer
->
msg
(
"citizen-sitestats-$key-label"
)->
text
(),
];
}
return
[
'array-sitestats-items'
=>
$items
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 20:10 (1 d, 7 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
34/2c/ac44dc4decb2f078aac9204855b9
Default Alt Text
CitizenComponentSiteStats.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment