mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-09-23 18:28:58 +00:00
refactor: Move footer and page links/tools
This commit is contained in:
parent
ff49d0c9be
commit
cdb05ec7fd
156
includes/Partials/Footer.php
Normal file
156
includes/Partials/Footer.php
Normal file
|
@ -0,0 +1,156 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* Footer partial of Skin Citizen
|
||||
*/
|
||||
final class Footer extends Partial {
|
||||
|
||||
/**
|
||||
* Get rows that make up the footer
|
||||
* @return array for use in Mustache template describing the footer elements.
|
||||
*/
|
||||
public function getFooterData(): array {
|
||||
$footerLinks = $this->skin->getFooterLinks();
|
||||
$lastMod = null;
|
||||
|
||||
// Get last modified message
|
||||
if ( $footerLinks['info']['lastmod'] && isset( $footerLinks['info']['lastmod'] ) ) {
|
||||
$lastMod = $footerLinks['info']['lastmod'];
|
||||
}
|
||||
|
||||
return [
|
||||
'html-lastmodified' => $lastMod,
|
||||
'array-footer-rows' => $this->getFooterRows( $footerLinks ),
|
||||
'array-footer-icons' => $this->getFooterIcons(),
|
||||
'msg-citizen-footer-desc' => $this->skin->msg( 'citizen-footer-desc' )->text(),
|
||||
'msg-citizen-footer-tagline' => $this->skin->msg( 'citizen-footer-tagline' )->text(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The footer rows
|
||||
*
|
||||
* @param array $footerLinks
|
||||
* @return array
|
||||
*/
|
||||
private function getFooterRows( array $footerLinks ) {
|
||||
$footerRows = [];
|
||||
|
||||
foreach ( $footerLinks as $category => $links ) {
|
||||
$items = [];
|
||||
$rowId = "footer-$category";
|
||||
|
||||
// Unset footer-info
|
||||
if ( $category === 'info' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $links as $key => $link ) {
|
||||
// Link may be null. If so don't include it.
|
||||
if ( $link ) {
|
||||
$items[] = [
|
||||
'id' => "$rowId-$key",
|
||||
'html' => $link,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$footerRows[] = [
|
||||
'id' => $rowId,
|
||||
'className' => null,
|
||||
'array-items' => $items
|
||||
];
|
||||
}
|
||||
|
||||
// Append footer-info after links
|
||||
if ( isset( $footerLinks['info'] ) ) {
|
||||
$items = [];
|
||||
$rowId = "footer-info";
|
||||
|
||||
foreach ( $footerLinks['info'] as $key => $link ) {
|
||||
// Don't include lastmod and null link
|
||||
if ( $key !== 'lastmod' && $link ) {
|
||||
$items[] = [
|
||||
'id' => "$rowId-$key",
|
||||
'html' => $link,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$footerRows[] = [
|
||||
'id' => $rowId,
|
||||
'className' => null,
|
||||
'array-items' => $items
|
||||
];
|
||||
}
|
||||
|
||||
return $footerRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Footer Icons
|
||||
*
|
||||
* @return array|array[]
|
||||
*/
|
||||
private function getFooterIcons() {
|
||||
// If footer icons are enabled append to the end of the rows
|
||||
$footerIcons = $this->skin->getFooterIcons();
|
||||
if ( empty( $footerIcons ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$items = [];
|
||||
foreach ( $footerIcons as $blockName => $blockIcons ) {
|
||||
$html = '';
|
||||
foreach ( $blockIcons as $icon ) {
|
||||
// Only output icons which have an image.
|
||||
// For historic reasons this mimics the `icononly` option
|
||||
// for BaseTemplate::getFooterIcons.
|
||||
if ( is_string( $icon ) || isset( $icon['src'] ) ) {
|
||||
$html .= $this->skin->makeFooterIcon( $icon );
|
||||
}
|
||||
}
|
||||
// For historic reasons this mimics the `icononly` option
|
||||
// for BaseTemplate::getFooterIcons. Empty rows should not be output.
|
||||
if ( $html ) {
|
||||
$items[] = [
|
||||
'id' => 'footer-' . htmlspecialchars( $blockName ) . 'ico',
|
||||
'html' => $html,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
[
|
||||
'id' => 'footer-icons',
|
||||
'className' => 'noprint',
|
||||
'array-items' => $items,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
54
includes/Partials/PageLinks.php
Normal file
54
includes/Partials/PageLinks.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?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;
|
||||
|
||||
final class PageLinks extends Partial {
|
||||
|
||||
/**
|
||||
* Render page-related links at the bottom
|
||||
*
|
||||
* @return array html
|
||||
*/
|
||||
public function buildPageLinks() : array {
|
||||
$contentNavigation = $this->skin->buildContentNavigationUrls();
|
||||
|
||||
$namespaceshtml = $this->skin->getMenuData( 'namespaces', $contentNavigation[ 'namespaces' ] ?? [] );
|
||||
$variantshtml = $this->skin->getMenuData( 'variants', $contentNavigation[ 'variants' ] ?? [] );
|
||||
|
||||
if ( $namespaceshtml ) {
|
||||
$namespaceshtml[ 'label-class' ] .= 'screen-reader-text';
|
||||
}
|
||||
|
||||
if ( $variantshtml ) {
|
||||
$variantshtml[ 'label-class' ] .= 'screen-reader-text';
|
||||
}
|
||||
|
||||
return [
|
||||
'data-namespaces' => $namespaceshtml,
|
||||
'data-variants' => $variantshtml,
|
||||
];
|
||||
}
|
||||
}
|
88
includes/Partials/PageTools.php
Normal file
88
includes/Partials/PageTools.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?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;
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
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
|
||||
*
|
||||
* @return array html
|
||||
*/
|
||||
public function buildPageTools(): array {
|
||||
$condition = $this->getConfigValue( 'CitizenShowPageTools' );
|
||||
$contentNavigation = $this->skin->buildContentNavigationUrls();
|
||||
$portals = $this->skin->buildSidebar();
|
||||
$props = [];
|
||||
|
||||
// Login-based condition, return true if condition is met
|
||||
if ( $condition === 'login' ) {
|
||||
$condition = $this->skin->getUser()->isLoggedIn();
|
||||
}
|
||||
|
||||
// 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() );
|
||||
} catch ( \Exception $e ) {
|
||||
$condition = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $condition === true ) {
|
||||
|
||||
$viewshtml = $this->skin->getMenuData( 'views', $contentNavigation[ 'views' ] ?? [] );
|
||||
$actionshtml = $this->skin->getMenuData( 'actions', $contentNavigation[ 'actions' ] ?? [] );
|
||||
$toolboxhtml = $this->skin->getMenuData( 'tb', $portals['TOOLBOX'] ?? [] );
|
||||
|
||||
if ( $viewshtml ) {
|
||||
$viewshtml[ 'label-class' ] .= 'screen-reader-text';
|
||||
}
|
||||
|
||||
if ( $actionshtml ) {
|
||||
$actionshtml[ 'label-class' ] .= 'screen-reader-text';
|
||||
}
|
||||
|
||||
$props = [
|
||||
'data-page-views' => $viewshtml,
|
||||
'data-page-actions' => $actionshtml,
|
||||
'data-page-toolbox' => $toolboxhtml,
|
||||
];
|
||||
}
|
||||
|
||||
return $props;
|
||||
}
|
||||
}
|
|
@ -23,10 +23,12 @@
|
|||
|
||||
use Citizen\GetConfigTrait;
|
||||
use Citizen\Partials\Drawer;
|
||||
use Citizen\Partials\Footer;
|
||||
use Citizen\Partials\Header;
|
||||
use Citizen\Partials\Metadata;
|
||||
use Citizen\Partials\PageLinks;
|
||||
use Citizen\Partials\PageTools;
|
||||
use Citizen\Partials\Theme;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Skin subclass for Citizen
|
||||
|
@ -51,8 +53,8 @@ class SkinCitizen extends SkinMustache {
|
|||
$skin = $this;
|
||||
$out = $skin->getOutput();
|
||||
|
||||
$metadata = new Metadata( $out );
|
||||
$skinTheme = new Theme( $out );
|
||||
$metadata = new Metadata( $this );
|
||||
$skinTheme = new Theme( $this );
|
||||
|
||||
$metadata->addMetadata();
|
||||
|
||||
|
@ -105,8 +107,11 @@ class SkinCitizen extends SkinMustache {
|
|||
$out = $this->getOutput();
|
||||
$title = $out->getTitle();
|
||||
|
||||
$drawer = new Drawer( $this );
|
||||
$header = new Header( $this );
|
||||
$drawer = new Drawer( $this );
|
||||
$footer = new Footer( $this );
|
||||
$links = new PageLinks( $this );
|
||||
$tools = new PageTools( $this );
|
||||
|
||||
// Naming conventions for Mustache parameters.
|
||||
//
|
||||
|
@ -143,7 +148,7 @@ class SkinCitizen extends SkinMustache {
|
|||
'data-search-box' => $header->buildSearchProps(),
|
||||
],
|
||||
|
||||
'data-pagetools' => $this->buildPageTools(),
|
||||
'data-pagetools' => $tools->buildPageTools(),
|
||||
|
||||
'html-newtalk' => $newTalksHtml ? '<div class="usermessage">' . $newTalksHtml . '</div>' : '',
|
||||
'page-langcode' => $title->getPageViewLanguage()->getHtmlCode(),
|
||||
|
@ -154,11 +159,11 @@ class SkinCitizen extends SkinMustache {
|
|||
|
||||
'msg-tagline' => $this->msg( 'tagline' )->text(),
|
||||
|
||||
'data-pagelinks' => $this->buildPageLinks(),
|
||||
'data-pagelinks' => $links->buildPageLinks(),
|
||||
|
||||
'html-categories' => $this->getCategories(),
|
||||
|
||||
'data-footer' => $this->getFooterData(),
|
||||
'data-footer' => $footer->getFooterData(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -167,10 +172,37 @@ class SkinCitizen extends SkinMustache {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildPersonalUrls() {
|
||||
final public function buildPersonalUrls() {
|
||||
return parent::buildPersonalUrls();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change access to public, as it is used in partials
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function getFooterLinks() {
|
||||
return parent::getFooterLinks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change access to public, as it is used in partials
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function getFooterIcons() {
|
||||
return parent::getFooterIcons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change access to public, as it is used in partials
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function buildContentNavigationUrls() {
|
||||
return parent::buildContentNavigationUrls();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label to be used to derive the id and human readable label of the menu
|
||||
* If the key has an entry in the constant MENU_LABEL_KEYS then that message will be used for the
|
||||
|
@ -215,7 +247,7 @@ class SkinCitizen extends SkinMustache {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* Manually disable links to upload and speacial pages
|
||||
* Manually disable links to upload and special pages
|
||||
* as they are moved from the toolbox to the drawer
|
||||
*
|
||||
* @return array
|
||||
|
@ -228,189 +260,4 @@ class SkinCitizen extends SkinMustache {
|
|||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return array html
|
||||
*/
|
||||
protected function buildPageTools(): array {
|
||||
$skin = $this;
|
||||
$condition = $this->getConfigValue( 'CitizenShowPageTools' );
|
||||
$contentNavigation = parent::buildContentNavigationUrls();
|
||||
$portals = parent::buildSidebar();
|
||||
$props = [];
|
||||
|
||||
// Login-based condition, return true if condition is met
|
||||
if ( $condition === 'login' ) {
|
||||
$condition = $skin->getUser()->isLoggedIn();
|
||||
}
|
||||
|
||||
// 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, $skin->getUser(), $skin->getTitle() );
|
||||
} catch ( Exception $e ) {
|
||||
$condition = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $condition === true ) {
|
||||
|
||||
$viewshtml = $this->getMenuData( 'views', $contentNavigation[ 'views' ] ?? [] );
|
||||
$actionshtml = $this->getMenuData( 'actions', $contentNavigation[ 'actions' ] ?? [] );
|
||||
$toolboxhtml = $this->getMenuData( 'tb', $portals['TOOLBOX'] ?? [] );
|
||||
|
||||
if ( $viewshtml ) {
|
||||
$viewshtml[ 'label-class' ] .= 'screen-reader-text';
|
||||
}
|
||||
|
||||
if ( $actionshtml ) {
|
||||
$actionshtml[ 'label-class' ] .= 'screen-reader-text';
|
||||
}
|
||||
|
||||
$props = [
|
||||
'data-page-views' => $viewshtml,
|
||||
'data-page-actions' => $actionshtml,
|
||||
'data-page-toolbox' => $toolboxhtml,
|
||||
];
|
||||
}
|
||||
|
||||
return $props;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rows that make up the footer
|
||||
* @return array for use in Mustache template describing the footer elements.
|
||||
*/
|
||||
private function getFooterData() : array {
|
||||
$skin = $this;
|
||||
$footerLinks = $this->getFooterLinks();
|
||||
$lastMod = null;
|
||||
$footerRows = [];
|
||||
$footerIconRows = [];
|
||||
|
||||
// Get last modified message
|
||||
if ( $footerLinks['info']['lastmod'] && isset( $footerLinks['info']['lastmod'] ) ) {
|
||||
$lastMod = $footerLinks['info']['lastmod'];
|
||||
}
|
||||
|
||||
foreach ( $footerLinks as $category => $links ) {
|
||||
$items = [];
|
||||
$rowId = "footer-$category";
|
||||
|
||||
// Unset footer-info
|
||||
if ( $category !== 'info' ) {
|
||||
foreach ( $links as $key => $link ) {
|
||||
// Link may be null. If so don't include it.
|
||||
if ( $link ) {
|
||||
$items[] = [
|
||||
'id' => "$rowId-$key",
|
||||
'html' => $link,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$footerRows[] = [
|
||||
'id' => $rowId,
|
||||
'className' => null,
|
||||
'array-items' => $items
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Append footer-info after links
|
||||
if ( isset( $footerLinks['info'] ) ) {
|
||||
$items = [];
|
||||
$rowId = "footer-info";
|
||||
|
||||
foreach ( $footerLinks['info'] as $key => $link ) {
|
||||
// Don't include lastmod and null link
|
||||
if ( $key !== 'lastmod' && $link ) {
|
||||
$items[] = [
|
||||
'id' => "$rowId-$key",
|
||||
'html' => $link,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$footerRows[] = [
|
||||
'id' => $rowId,
|
||||
'className' => null,
|
||||
'array-items' => $items
|
||||
];
|
||||
}
|
||||
|
||||
// If footer icons are enabled append to the end of the rows
|
||||
$footerIcons = $this->getFooterIcons();
|
||||
if ( count( $footerIcons ) > 0 ) {
|
||||
$items = [];
|
||||
foreach ( $footerIcons as $blockName => $blockIcons ) {
|
||||
$html = '';
|
||||
foreach ( $blockIcons as $icon ) {
|
||||
// Only output icons which have an image.
|
||||
// For historic reasons this mimics the `icononly` option
|
||||
// for BaseTemplate::getFooterIcons.
|
||||
if ( is_string( $icon ) || isset( $icon['src'] ) ) {
|
||||
$html .= $skin->makeFooterIcon( $icon );
|
||||
}
|
||||
}
|
||||
// For historic reasons this mimics the `icononly` option
|
||||
// for BaseTemplate::getFooterIcons. Empty rows should not be output.
|
||||
if ( $html ) {
|
||||
$items[] = [
|
||||
'id' => 'footer-' . htmlspecialchars( $blockName ) . 'ico',
|
||||
'html' => $html,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$footerIconRows[] = [
|
||||
'id' => 'footer-icons',
|
||||
'className' => 'noprint',
|
||||
'array-items' => $items,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'html-lastmodified' => $lastMod,
|
||||
'array-footer-rows' => $footerRows,
|
||||
'array-footer-icons' => $footerIconRows,
|
||||
'msg-citizen-footer-desc' => $skin->msg( 'citizen-footer-desc' )->text(),
|
||||
'msg-citizen-footer-tagline' => $skin->msg( 'citizen-footer-tagline' )->text(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render page-related links at the bottom
|
||||
*
|
||||
* @return array html
|
||||
*/
|
||||
private function buildPageLinks() : array {
|
||||
$contentNavigation = $this->buildContentNavigationUrls();
|
||||
|
||||
$namespaceshtml = $this->getMenuData( 'namespaces', $contentNavigation[ 'namespaces' ] ?? [] );
|
||||
$variantshtml = $this->getMenuData( 'variants', $contentNavigation[ 'variants' ] ?? [] );
|
||||
|
||||
if ( $namespaceshtml ) {
|
||||
$namespaceshtml[ 'label-class' ] .= 'screen-reader-text';
|
||||
}
|
||||
|
||||
if ( $variantshtml ) {
|
||||
$variantshtml[ 'label-class' ] .= 'screen-reader-text';
|
||||
}
|
||||
|
||||
return [
|
||||
'data-namespaces' => $namespaceshtml,
|
||||
'data-variants' => $variantshtml,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue