2021-01-28 19:35:31 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare( strict_types=1 );
|
|
|
|
|
|
|
|
namespace Citizen\Partials;
|
|
|
|
|
2021-01-28 20:09:52 +00:00
|
|
|
use Exception;
|
2021-01-28 19:35:31 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2022-04-14 04:30:33 +00:00
|
|
|
use SkinTemplate;
|
2021-01-28 19:35:31 +00:00
|
|
|
|
|
|
|
final class PageTools extends Partial {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render page-related tools
|
|
|
|
* Possible visibility conditions:
|
|
|
|
* * true: always visible (bool)
|
|
|
|
* * false: never visible (bool)
|
|
|
|
* * 'login': only visible if logged in (string)
|
|
|
|
* * 'permission-*': only visible if user has permission
|
|
|
|
* e.g. permission-edit = only visible if user can edit pages
|
|
|
|
*
|
2022-04-14 04:30:33 +00:00
|
|
|
* @param array $parentData
|
2021-01-28 19:35:31 +00:00
|
|
|
* @return array html
|
|
|
|
*/
|
2022-04-14 04:30:33 +00:00
|
|
|
public function buildPageTools( $parentData ): array {
|
2021-01-28 19:35:31 +00:00
|
|
|
$condition = $this->getConfigValue( 'CitizenShowPageTools' );
|
2021-01-28 20:09:52 +00:00
|
|
|
$contentNavigation = $this->skin->buildContentNavigationUrlsPublic();
|
2021-01-28 19:35:31 +00:00
|
|
|
$portals = $this->skin->buildSidebar();
|
|
|
|
$props = [];
|
|
|
|
|
|
|
|
// Login-based condition, return true if condition is met
|
|
|
|
if ( $condition === 'login' ) {
|
2021-03-25 19:06:54 +00:00
|
|
|
$condition = $this->skin->getUser()->isRegistered();
|
2021-01-28 19:35:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Permission-based condition, return true if condition is met
|
|
|
|
if ( is_string( $condition ) && strpos( $condition, 'permission' ) === 0 ) {
|
|
|
|
$permission = substr( $condition, 11 );
|
|
|
|
try {
|
|
|
|
$condition = MediaWikiServices::getInstance()->getPermissionManager()->userCan(
|
|
|
|
$permission, $this->skin->getUser(), $this->skin->getTitle() );
|
2021-01-28 20:09:52 +00:00
|
|
|
} catch ( Exception $e ) {
|
2021-01-28 19:35:31 +00:00
|
|
|
$condition = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $condition === true ) {
|
|
|
|
|
2022-04-14 04:30:33 +00:00
|
|
|
if ( !method_exists( SkinTemplate::class, 'runOnSkinTemplateNavigationHooks' ) ) {
|
|
|
|
$viewshtml = $this->skin->getMenuData( 'views', $contentNavigation[ 'views' ] ?? [] );
|
|
|
|
$actionshtml = $this->skin->getMenuData( 'actions', $contentNavigation[ 'actions' ] ?? [] );
|
|
|
|
$namespaceshtml = $this->skin->getMenuData( 'namespaces', $contentNavigation[ 'namespaces' ] ?? [] );
|
|
|
|
$variantshtml = $this->skin->getMenuData( 'variants', $contentNavigation[ 'variants' ] ?? [] );
|
|
|
|
$toolboxhtml = $this->skin->getMenuData( 'tb', $portals['TOOLBOX'] ?? [] );
|
|
|
|
} else {
|
|
|
|
$viewshtml = $parentData['data-portlets']['data-views'];
|
|
|
|
$actionshtml = $parentData['data-portlets']['data-actions'];
|
|
|
|
$namespaceshtml = $parentData['data-portlets']['data-namespaces'];
|
|
|
|
$variantshtml = $parentData['data-portlets']['data-variants'];
|
2022-04-30 06:54:13 +00:00
|
|
|
// Finds the toolbox in the sidebar.
|
2022-04-14 04:30:33 +00:00
|
|
|
$sidebar = [ $parentData['data-portlets-sidebar']['data-portlets-first'],
|
|
|
|
...$parentData['data-portlets-sidebar']['array-portlets-rest'] ];
|
2022-04-30 06:54:13 +00:00
|
|
|
$toolboxhtml = null;
|
|
|
|
foreach ( $sidebar as $portlet ) {
|
|
|
|
if ( $portlet['id'] === 'p-tb' ) {
|
|
|
|
$toolboxhtml = $portlet;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-04-14 04:30:33 +00:00
|
|
|
}
|
2021-01-28 19:35:31 +00:00
|
|
|
|
|
|
|
if ( $viewshtml ) {
|
2022-04-14 04:30:33 +00:00
|
|
|
$viewshtml[ 'label-class' ] ??= '';
|
2021-01-28 19:35:31 +00:00
|
|
|
$viewshtml[ 'label-class' ] .= 'screen-reader-text';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $actionshtml ) {
|
2022-04-14 04:30:33 +00:00
|
|
|
$actionshtml[ 'label-class' ] ??= '';
|
2021-01-28 19:35:31 +00:00
|
|
|
$actionshtml[ 'label-class' ] .= 'screen-reader-text';
|
|
|
|
}
|
|
|
|
|
2022-04-24 05:52:41 +00:00
|
|
|
if ( $namespaceshtml ) {
|
|
|
|
$namespaceshtml[ 'label-class' ] ??= '';
|
|
|
|
$namespaceshtml[ 'label-class' ] .= 'screen-reader-text';
|
|
|
|
}
|
|
|
|
|
2021-01-28 19:35:31 +00:00
|
|
|
$props = [
|
|
|
|
'data-page-views' => $viewshtml,
|
|
|
|
'data-page-actions' => $actionshtml,
|
2021-02-26 21:21:11 +00:00
|
|
|
'data-namespaces' => $namespaceshtml,
|
|
|
|
'data-variants' => $variantshtml,
|
2021-01-28 19:35:31 +00:00
|
|
|
'data-page-toolbox' => $toolboxhtml,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $props;
|
|
|
|
}
|
|
|
|
}
|