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
|
|
|
|
|
|
|
namespace Citizen\Partials;
|
|
|
|
|
|
|
|
use Exception;
|
2021-01-28 20:45:37 +00:00
|
|
|
use ExtensionRegistry;
|
|
|
|
use MWException;
|
2021-01-28 11:19:50 +00:00
|
|
|
use Skin;
|
2021-01-28 20:45:37 +00:00
|
|
|
use SpecialPage;
|
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
|
|
|
/**
|
|
|
|
* Render the navigation drawer
|
2022-05-16 01:37:39 +00:00
|
|
|
* Based on getPortletsTemplateData in SkinTemplate
|
2021-01-28 11:21:58 +00:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-05-16 01:37:39 +00:00
|
|
|
public function getDrawerTemplateData() {
|
|
|
|
$drawer = [];
|
|
|
|
$drawerData = $this->skin->buildSidebar();
|
2021-01-28 11:21:58 +00:00
|
|
|
|
|
|
|
// Render portals
|
2022-05-16 01:37:39 +00:00
|
|
|
foreach ( $drawerData as $name => $items ) {
|
|
|
|
if ( is_array( $items ) ) {
|
|
|
|
// Numeric strings gets an integer when set as key, cast back - T73639
|
|
|
|
$name = (string)$name;
|
|
|
|
switch ( $name ) {
|
|
|
|
// ignore search
|
|
|
|
case 'SEARCH':
|
|
|
|
// we build in PageTools instead
|
|
|
|
case 'TOOLBOX':
|
|
|
|
break;
|
|
|
|
case 'LANGUAGES':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$drawer[] = $this->skin->getPortletData( $name, $items );
|
|
|
|
break;
|
|
|
|
}
|
2021-01-28 11:21:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 20:49:01 +00:00
|
|
|
$portalLabel = $this->getConfigValue( 'CitizenPortalAttach' ) ?? 'first';
|
2021-01-28 11:21:58 +00:00
|
|
|
|
2022-05-16 01:37:39 +00:00
|
|
|
$firstPortal = array_shift( $drawer );
|
2021-01-29 20:49:01 +00:00
|
|
|
|
|
|
|
if ( $portalLabel === 'first' && $firstPortal !== null && isset( $firstPortal['html-items'] ) ) {
|
|
|
|
$this->addToolboxLinksToDrawer( $firstPortal['html-items'] );
|
|
|
|
} else {
|
2022-05-16 01:37:39 +00:00
|
|
|
for ( $i = 0, $portalCount = count( $drawer ); $i < $portalCount; $i++ ) {
|
|
|
|
if ( isset( $drawer[$i]['label'] ) && $drawer[$i]['label'] === $portalLabel ) {
|
|
|
|
$this->addToolboxLinksToDrawer( $drawer[$i]['html-items'] );
|
2021-01-29 20:49:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-01-28 11:21:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-16 01:37:39 +00:00
|
|
|
$drawerData = [
|
2021-01-28 11:21:58 +00:00
|
|
|
'msg-citizen-drawer-toggle' => $this->skin->msg( 'citizen-drawer-toggle' )->text(),
|
|
|
|
'data-portals-first' => $firstPortal,
|
2022-05-16 01:37:39 +00:00
|
|
|
'array-portals-rest' => $drawer,
|
2021-03-22 21:01:08 +00:00
|
|
|
'data-drawer-sitestats' => $this->getSiteStats(),
|
2021-01-28 11:21:58 +00:00
|
|
|
];
|
2021-02-03 20:00:43 +00:00
|
|
|
|
2022-05-16 01:37:39 +00:00
|
|
|
return $drawerData;
|
2021-01-28 11:21:58 +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.
|
|
|
|
*/
|
|
|
|
private function getSiteStats() {
|
|
|
|
$props = [];
|
|
|
|
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnableDrawerSiteStats' ) ) {
|
|
|
|
$stats = [ 'articles', 'images', 'users', 'edits' ];
|
|
|
|
$items = [];
|
2022-04-23 05:32:12 +00:00
|
|
|
$fmt = new \NumberFormatter( 'en_US', \NumberFormatter::PADDING_POSITION );
|
|
|
|
$fmt->setAttribute( \NumberFormatter::ROUNDING_MODE, \NumberFormatter::ROUND_DOWN );
|
|
|
|
$fmt->setAttribute( \NumberFormatter::MAX_FRACTION_DIGITS, 1 );
|
2021-03-22 21:01:08 +00:00
|
|
|
|
|
|
|
foreach ( $stats as &$stat ) {
|
|
|
|
$items[] = [
|
|
|
|
'id' => $stat,
|
2022-04-24 00:26:05 +00:00
|
|
|
'value' => $this->getSiteStat( $stat ),
|
2021-03-22 21:01:08 +00:00
|
|
|
'label' => $this->skin->msg( "citizen-sitestats-$stat-label" )->text(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$props['array-drawer-sitestats-item'] = $items;
|
|
|
|
return $props;
|
|
|
|
}
|
|
|
|
|
2022-04-24 00:26:05 +00:00
|
|
|
/**
|
|
|
|
* Get and format sitestat value
|
|
|
|
* TODO: Formatting should be based on user locale
|
2022-04-24 00:27:06 +00:00
|
|
|
*
|
2022-04-24 00:26:05 +00:00
|
|
|
* @param string $key
|
2022-04-24 00:27:06 +00:00
|
|
|
*
|
2022-04-24 00:26:05 +00:00
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private function getSiteStat( $key ) {
|
|
|
|
$value = call_user_func( 'SiteStats::' . $key );
|
|
|
|
|
|
|
|
if ( $value >= 10000 ) {
|
|
|
|
$fmt = new \NumberFormatter( 'en_US', \NumberFormatter::PADDING_POSITION );
|
|
|
|
$fmt->setAttribute( \NumberFormatter::ROUNDING_MODE, \NumberFormatter::ROUND_DOWN );
|
|
|
|
$fmt->setAttribute( \NumberFormatter::MAX_FRACTION_DIGITS, 1 );
|
|
|
|
|
|
|
|
$value = $fmt->format( $value );
|
|
|
|
} else {
|
|
|
|
$value = number_format( $value );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
/**
|
|
|
|
* Add a link to special pages and the upload form to the first portal in the drawer
|
|
|
|
*
|
|
|
|
* @param string &$htmlItems
|
|
|
|
*
|
|
|
|
* @return void
|
2021-01-28 20:45:37 +00:00
|
|
|
* @throws MWException
|
2021-01-28 11:21:58 +00:00
|
|
|
*/
|
|
|
|
private function addToolboxLinksToDrawer( &$htmlItems ) {
|
|
|
|
// First add a link to special pages
|
|
|
|
$htmlItems .= $this->skin->makeListItem( 'specialpages', [
|
2021-01-28 19:53:07 +00:00
|
|
|
'href' => Skin::makeSpecialUrl( 'Specialpages' ),
|
2021-01-28 11:21:58 +00:00
|
|
|
'id' => 't-specialpages'
|
|
|
|
] );
|
|
|
|
|
2021-01-28 20:45:37 +00:00
|
|
|
$uploadHref = Skin::makeSpecialUrl( 'Upload' );
|
|
|
|
|
|
|
|
if ( ExtensionRegistry::getInstance()->isLoaded( 'Upload Wizard' ) ) {
|
|
|
|
$uploadHref = SpecialPage::getTitleFor( 'UploadWizard' )->getLocalURL();
|
|
|
|
}
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
// Then add a link to the upload form
|
|
|
|
$htmlItems .= $this->skin->makeListItem( 'upload', [
|
2021-01-28 20:45:37 +00:00
|
|
|
'href' => $uploadHref,
|
2021-01-28 11:21:58 +00:00
|
|
|
'id' => 't-upload'
|
|
|
|
] );
|
|
|
|
}
|
2021-01-28 11:19:50 +00:00
|
|
|
}
|