2021-01-28 11:19:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Citizen - A responsive skin developed for the Star Citizen Wiki
|
|
|
|
*
|
|
|
|
* This file is part of Citizen.
|
|
|
|
*
|
|
|
|
* Citizen is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Citizen is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Citizen. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Skins
|
|
|
|
*/
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
declare( strict_types=1 );
|
2021-01-28 11:19:50 +00:00
|
|
|
|
2022-05-26 20:54:52 +00:00
|
|
|
namespace MediaWiki\Skins\Citizen\Partials;
|
2021-01-28 11:19:50 +00:00
|
|
|
|
|
|
|
use Exception;
|
2023-08-24 21:58:10 +00:00
|
|
|
use NumberFormatter;
|
2021-01-28 11:19:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Drawer partial of Skin Citizen
|
|
|
|
* Generates the following partials:
|
|
|
|
* - Logo
|
|
|
|
* - Drawer
|
|
|
|
* + Special Pages Link
|
|
|
|
* + Upload Link
|
|
|
|
*/
|
2021-01-28 19:34:46 +00:00
|
|
|
final class Drawer extends Partial {
|
2021-01-28 11:21:58 +00:00
|
|
|
/**
|
2022-10-03 02:31:40 +00:00
|
|
|
* Decorate sidebar template data
|
2021-01-28 11:21:58 +00:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-10-03 02:31:40 +00:00
|
|
|
public function decorateSidebarData( $sidebarData ) {
|
|
|
|
for ( $i = 0; $i < count( $sidebarData['array-portlets-rest'] ); $i++ ) {
|
2023-06-12 02:12:50 +00:00
|
|
|
if ( $sidebarData['array-portlets-rest'][$i]['id'] === 'p-tb' ) {
|
2022-10-03 02:31:40 +00:00
|
|
|
// Remove toolbox since it is handled by page tools
|
2023-06-12 02:12:50 +00:00
|
|
|
unset( $sidebarData['array-portlets-rest'][$i] );
|
|
|
|
break;
|
2021-01-28 11:21:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:42:01 +00:00
|
|
|
// Reset index after unsetting toolbox
|
|
|
|
$sidebarData['array-portlets-rest'] = array_values( $sidebarData['array-portlets-rest'] );
|
|
|
|
|
2022-10-03 02:31:40 +00:00
|
|
|
return $sidebarData;
|
2022-05-18 23:33:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 21:01:08 +00:00
|
|
|
/**
|
|
|
|
* Get messages used for site stats in the drawer
|
|
|
|
*
|
|
|
|
* @return array for use in Mustache template.
|
|
|
|
*/
|
2022-10-05 02:20:29 +00:00
|
|
|
public function getSiteStatsData(): array {
|
2023-06-02 18:31:46 +00:00
|
|
|
if ( !$this->getConfigValue( 'CitizenEnableDrawerSiteStats' ) ) {
|
2023-06-02 18:21:55 +00:00
|
|
|
return [];
|
|
|
|
}
|
2021-03-22 21:01:08 +00:00
|
|
|
|
2023-06-02 18:21:55 +00:00
|
|
|
$skin = $this->skin;
|
|
|
|
// Key => Icon
|
|
|
|
$map = [
|
|
|
|
'articles' => 'article',
|
|
|
|
'images' => 'image',
|
|
|
|
'users' => 'userAvatar',
|
|
|
|
'edits' => 'edit'
|
|
|
|
];
|
|
|
|
$items = [];
|
|
|
|
$fmt = null;
|
|
|
|
|
|
|
|
// Get NumberFormatter here so that we don't have to call it for every stats
|
2023-08-24 21:58:10 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenUseNumberFormatter' ) && class_exists( NumberFormatter::class ) ) {
|
2023-06-02 18:21:55 +00:00
|
|
|
$locale = $skin->getLanguage()->getHtmlCode() ?? 'en_US';
|
2023-08-24 21:58:10 +00:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
}
|
2023-06-02 18:21:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $map as $key => $icon ) {
|
|
|
|
$items[] = [
|
|
|
|
'id' => $key,
|
|
|
|
'icon' => $icon,
|
|
|
|
'value' => $this->getSiteStatValue( $key, $fmt ),
|
|
|
|
'label' => $skin->msg( "citizen-sitestats-$key-label" )->text(),
|
|
|
|
];
|
2021-03-22 21:01:08 +00:00
|
|
|
}
|
|
|
|
|
2023-06-02 18:21:55 +00:00
|
|
|
return [
|
|
|
|
'array-drawer-sitestats-item' => $items
|
|
|
|
];
|
2021-03-22 21:01:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-24 00:26:05 +00:00
|
|
|
/**
|
|
|
|
* Get and format sitestat value
|
2022-05-18 23:45:19 +00:00
|
|
|
*
|
2022-04-24 00:26:05 +00:00
|
|
|
* @param string $key
|
2022-05-19 18:46:35 +00:00
|
|
|
* @param NumberFormatter|null $fmt
|
2022-05-18 23:33:39 +00:00
|
|
|
* @return string
|
2022-04-24 00:26:05 +00:00
|
|
|
*/
|
2022-05-18 23:33:39 +00:00
|
|
|
private function getSiteStatValue( $key, $fmt ): string {
|
|
|
|
$value = call_user_func( 'SiteStats::' . $key ) ?? '';
|
2022-04-24 00:26:05 +00:00
|
|
|
|
2022-05-19 18:46:35 +00:00
|
|
|
if ( $fmt ) {
|
|
|
|
return $fmt->format( $value );
|
2022-04-24 00:26:05 +00:00
|
|
|
} else {
|
2022-05-19 18:50:30 +00:00
|
|
|
return number_format( $value );
|
2022-04-24 00:26:05 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 11:19:50 +00:00
|
|
|
}
|