2019-04-10 21:43:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This program 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
namespace MediaWiki\Minerva;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A wrapper for all available Skin options.
|
|
|
|
*/
|
|
|
|
final class SkinOptions {
|
|
|
|
|
2020-05-19 22:43:34 +00:00
|
|
|
public const MOBILE_OPTIONS = 'mobileOptionsLink';
|
|
|
|
public const CATEGORIES = 'categories';
|
|
|
|
public const PAGE_ISSUES = 'pageIssues';
|
|
|
|
public const BETA_MODE = 'beta';
|
|
|
|
public const TALK_AT_TOP = 'talkAtTop';
|
2020-06-25 21:06:46 +00:00
|
|
|
public const SHOW_DONATE = 'donate';
|
2020-05-19 22:43:34 +00:00
|
|
|
public const HISTORY_IN_PAGE_ACTIONS = 'historyInPageActions';
|
|
|
|
public const TOOLBAR_SUBMENU = 'overflowSubmenu';
|
|
|
|
public const TABS_ON_SPECIALS = 'tabsOnSpecials';
|
|
|
|
public const MAIN_MENU_EXPANDED = 'mainMenuExpanded';
|
|
|
|
public const PERSONAL_MENU = 'personalMenu';
|
|
|
|
public const SIMPLIFIED_TALK = 'simplifiedTalk';
|
2019-08-01 16:18:18 +00:00
|
|
|
|
2021-01-15 20:57:04 +00:00
|
|
|
/**
|
|
|
|
* Note stable skin options default to true for desktop-Minerva and are expected to be
|
|
|
|
* overridden on mobile.
|
|
|
|
* @var array skin specific options, initialized with default values
|
|
|
|
*/
|
2019-04-10 21:43:50 +00:00
|
|
|
private $skinOptions = [
|
2019-08-01 16:18:18 +00:00
|
|
|
self::BETA_MODE => false,
|
2020-06-25 21:06:46 +00:00
|
|
|
self::SHOW_DONATE => true,
|
2019-04-10 21:43:50 +00:00
|
|
|
/**
|
|
|
|
* Whether the main menu should include a link to
|
|
|
|
* Special:Preferences of Special:MobileOptions
|
|
|
|
*/
|
2019-08-01 16:18:18 +00:00
|
|
|
self::MOBILE_OPTIONS => false,
|
2019-04-10 21:43:50 +00:00
|
|
|
/** Whether a categories button should appear at the bottom of the skin. */
|
2019-08-01 16:18:18 +00:00
|
|
|
self::CATEGORIES => false,
|
2019-07-30 00:24:23 +00:00
|
|
|
/** requires a wiki using Template:Ambox */
|
2019-08-01 16:18:18 +00:00
|
|
|
self::PAGE_ISSUES => false,
|
2019-07-30 00:24:23 +00:00
|
|
|
/** no extension requirements */
|
|
|
|
self::TALK_AT_TOP => true,
|
|
|
|
/** no extension requirements */
|
|
|
|
self::HISTORY_IN_PAGE_ACTIONS => true,
|
|
|
|
/** no extension requirements */
|
|
|
|
self::TOOLBAR_SUBMENU => true,
|
2019-06-07 11:40:13 +00:00
|
|
|
/** Whether to show tabs on special pages */
|
2022-04-08 19:21:50 +00:00
|
|
|
self::TABS_ON_SPECIALS => true,
|
2019-08-22 20:31:31 +00:00
|
|
|
/** whether to show a personal menu */
|
|
|
|
self::PERSONAL_MENU => true,
|
|
|
|
/** whether to show a main menu with additional items */
|
|
|
|
self::MAIN_MENU_EXPANDED => true,
|
2019-11-13 01:48:59 +00:00
|
|
|
/** whether the simplified talk page is eligible to be shown */
|
|
|
|
self::SIMPLIFIED_TALK => false,
|
2019-04-10 21:43:50 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* override an existing option or options with new values
|
|
|
|
* @param array $options
|
|
|
|
*/
|
|
|
|
public function setMultiple( array $options ) {
|
2019-07-31 20:47:27 +00:00
|
|
|
foreach ( $options as $option => $value ) {
|
|
|
|
if ( !array_key_exists( $option, $this->skinOptions ) ) {
|
|
|
|
throw new \OutOfBoundsException( "SkinOption $option is not defined" );
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 21:43:50 +00:00
|
|
|
$this->skinOptions = array_merge( $this->skinOptions, $options );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-01 16:18:18 +00:00
|
|
|
* Return whether a skin option is truthy. Should be one of self:* constants
|
2019-04-10 21:43:50 +00:00
|
|
|
* @param string $key
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function get( $key ) {
|
|
|
|
if ( !array_key_exists( $key, $this->skinOptions ) ) {
|
|
|
|
throw new \OutOfBoundsException( "SkinOption $key doesn't exist" );
|
|
|
|
}
|
|
|
|
return $this->skinOptions[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all skin options
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getAll() {
|
|
|
|
return $this->skinOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether any of the skin options have been set
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasSkinOptions() {
|
|
|
|
foreach ( $this->skinOptions as $key => $val ) {
|
|
|
|
if ( $val ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|