2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2018-04-15 23:21:12 +00:00
|
|
|
* 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
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
|
2022-02-15 18:40:10 +00:00
|
|
|
namespace MediaWiki\Minerva;
|
|
|
|
|
|
|
|
use ExtensionRegistry;
|
|
|
|
use Hooks as MWHooks;
|
|
|
|
use Html;
|
2018-04-15 23:21:12 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-05-01 01:16:53 +00:00
|
|
|
use MediaWiki\Minerva\Skins\SkinUserPageHelper;
|
2022-02-15 18:40:10 +00:00
|
|
|
use MobileContext;
|
|
|
|
use MobileFormatter;
|
|
|
|
use MobileFrontend\Features\Feature;
|
|
|
|
use MobileFrontend\Features\FeaturesManager;
|
|
|
|
use OldChangesList;
|
|
|
|
use OutputPage;
|
|
|
|
use ResourceLoader;
|
|
|
|
use ResourceLoaderContext;
|
|
|
|
use RuntimeException;
|
|
|
|
use Skin;
|
|
|
|
use SkinMinerva;
|
|
|
|
use SpecialPage;
|
|
|
|
use User;
|
|
|
|
use Wikimedia\Services\NoSuchServiceException;
|
2018-04-15 23:21:12 +00:00
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Hook handlers for Minerva skin.
|
|
|
|
*
|
|
|
|
* Hook handler method names should be in the form of:
|
|
|
|
* on<HookName>()
|
|
|
|
*/
|
2022-02-15 18:40:10 +00:00
|
|
|
class Hooks {
|
2020-05-19 22:43:34 +00:00
|
|
|
private const FEATURE_OVERFLOW_PAGE_ACTIONS = 'MinervaOverflowInPageActions';
|
2019-04-04 21:20:39 +00:00
|
|
|
|
2019-12-18 21:15:26 +00:00
|
|
|
/**
|
|
|
|
* ResourceLoaderRegisterModules hook handler.
|
|
|
|
*
|
|
|
|
* Registers:
|
|
|
|
*
|
|
|
|
* * EventLogging schema modules, if the EventLogging extension is loaded;
|
|
|
|
* * Modules for the Visual Editor overlay, if the VisualEditor extension is loaded; and
|
|
|
|
* * Modules for the notifications overlay, if the Echo extension is loaded.
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderRegisterModules
|
|
|
|
*
|
2022-02-15 18:40:10 +00:00
|
|
|
* @param ResourceLoader $resourceLoader
|
2019-12-18 21:15:26 +00:00
|
|
|
*/
|
2022-02-15 18:40:10 +00:00
|
|
|
public static function onResourceLoaderRegisterModules( ResourceLoader $resourceLoader ) {
|
2019-12-18 21:15:26 +00:00
|
|
|
if ( !ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) {
|
|
|
|
$resourceLoader->register( [
|
|
|
|
'mobile.startup' => [
|
|
|
|
'dependencies' => [ 'mediawiki.searchSuggest' ],
|
|
|
|
'localBasePath' => dirname( __DIR__ ),
|
|
|
|
'remoteExtPath' => 'Minerva',
|
|
|
|
'scripts' => 'resources/mobile.startup.stub.js',
|
|
|
|
'targets' => [ 'desktop', 'mobile' ],
|
|
|
|
]
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 21:01:29 +00:00
|
|
|
/**
|
|
|
|
* Disable recent changes enhanced mode (table mode)
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/FetchChangesList
|
|
|
|
*
|
|
|
|
* @param User $user
|
2022-02-15 18:40:10 +00:00
|
|
|
* @param Skin $skin
|
2019-07-17 21:01:29 +00:00
|
|
|
* @param array &$list
|
|
|
|
* @param array $groups
|
2019-07-31 18:35:49 +00:00
|
|
|
* @return bool|null
|
2019-07-17 21:01:29 +00:00
|
|
|
*/
|
2022-02-15 18:40:10 +00:00
|
|
|
public static function onFetchChangesList( User $user, Skin $skin, &$list, $groups = [] ) {
|
2019-07-31 18:35:49 +00:00
|
|
|
if ( $skin->getSkinName() === 'minerva' ) {
|
|
|
|
// The new changes list (table-based) does not work with Minerva
|
|
|
|
$list = new OldChangesList( $skin->getContext(), $groups );
|
|
|
|
// returning false makes sure $list is used instead.
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-17 21:01:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 22:18:16 +00:00
|
|
|
/**
|
|
|
|
* Register mobile web beta features
|
|
|
|
* @see https://www.mediawiki.org/wiki/
|
|
|
|
* Extension:MobileFrontend/MobileFrontendFeaturesRegistration
|
|
|
|
*
|
2022-02-15 18:40:10 +00:00
|
|
|
* @param FeaturesManager $featureManager
|
2018-01-08 22:18:16 +00:00
|
|
|
*/
|
|
|
|
public static function onMobileFrontendFeaturesRegistration( $featureManager ) {
|
|
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()
|
|
|
|
->makeConfig( 'minerva' );
|
|
|
|
|
|
|
|
try {
|
|
|
|
$featureManager->registerFeature(
|
2022-02-15 18:40:10 +00:00
|
|
|
new Feature(
|
2021-04-28 21:58:51 +00:00
|
|
|
'MinervaShowCategories',
|
2018-01-08 22:18:16 +00:00
|
|
|
'skin-minerva',
|
2021-04-28 21:58:51 +00:00
|
|
|
$config->get( 'MinervaShowCategories' )
|
2018-01-08 22:18:16 +00:00
|
|
|
)
|
|
|
|
);
|
2018-11-12 20:32:28 +00:00
|
|
|
$featureManager->registerFeature(
|
2022-02-15 18:40:10 +00:00
|
|
|
new Feature(
|
2018-11-12 20:32:28 +00:00
|
|
|
'MinervaPageIssuesNewTreatment',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaPageIssuesNewTreatment' )
|
|
|
|
)
|
|
|
|
);
|
2019-01-10 22:59:56 +00:00
|
|
|
$featureManager->registerFeature(
|
2022-02-15 18:40:10 +00:00
|
|
|
new Feature(
|
2019-01-10 22:59:56 +00:00
|
|
|
'MinervaTalkAtTop',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaTalkAtTop' )
|
|
|
|
)
|
|
|
|
);
|
2020-06-25 21:06:46 +00:00
|
|
|
$featureManager->registerFeature(
|
2022-02-15 18:40:10 +00:00
|
|
|
new Feature(
|
2020-06-25 21:06:46 +00:00
|
|
|
'MinervaDonateLink',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaDonateLink' )
|
|
|
|
)
|
|
|
|
);
|
2019-03-07 20:50:57 +00:00
|
|
|
$featureManager->registerFeature(
|
2022-02-15 18:40:10 +00:00
|
|
|
new Feature(
|
2019-03-07 20:50:57 +00:00
|
|
|
'MinervaHistoryInPageActions',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaHistoryInPageActions' )
|
|
|
|
)
|
|
|
|
);
|
2019-04-04 21:20:39 +00:00
|
|
|
$featureManager->registerFeature(
|
2022-02-15 18:40:10 +00:00
|
|
|
new Feature(
|
2019-04-04 21:20:39 +00:00
|
|
|
self::FEATURE_OVERFLOW_PAGE_ACTIONS,
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( self::FEATURE_OVERFLOW_PAGE_ACTIONS )
|
|
|
|
)
|
|
|
|
);
|
2019-08-22 20:31:31 +00:00
|
|
|
$featureManager->registerFeature(
|
2022-02-15 18:40:10 +00:00
|
|
|
new Feature(
|
2019-08-22 20:31:31 +00:00
|
|
|
'MinervaAdvancedMainMenu',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaAdvancedMainMenu' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$featureManager->registerFeature(
|
2022-02-15 18:40:10 +00:00
|
|
|
new Feature(
|
2019-08-22 20:31:31 +00:00
|
|
|
'MinervaPersonalMenu',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaPersonalMenu' )
|
|
|
|
)
|
|
|
|
);
|
2018-01-08 22:18:16 +00:00
|
|
|
} catch ( RuntimeException $e ) {
|
|
|
|
// features already registered...
|
|
|
|
// due to a bug it's possible for this to run twice
|
|
|
|
// https://phabricator.wikimedia.org/T165068
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Invocation of hook SpecialPageBeforeExecute
|
|
|
|
*
|
|
|
|
* We use this hook to ensure that login/account creation pages
|
|
|
|
* are redirected to HTTPS if they are not accessed via HTTPS and
|
|
|
|
* $wgSecureLogin == true - but only when using the
|
|
|
|
* mobile site.
|
|
|
|
*
|
|
|
|
* @param SpecialPage $special
|
|
|
|
* @param string $subpage
|
|
|
|
*/
|
|
|
|
public static function onSpecialPageBeforeExecute( SpecialPage $special, $subpage ) {
|
|
|
|
$name = $special->getName();
|
|
|
|
$out = $special->getOutput();
|
|
|
|
$skin = $out->getSkin();
|
|
|
|
$request = $special->getRequest();
|
|
|
|
|
|
|
|
if ( $skin instanceof SkinMinerva ) {
|
|
|
|
switch ( $name ) {
|
2019-07-31 14:57:27 +00:00
|
|
|
case 'Recentchanges':
|
2021-06-06 12:14:30 +00:00
|
|
|
$isEnhancedDefaultForUser = MediaWikiServices::getInstance()
|
|
|
|
->getUserOptionsLookup()
|
|
|
|
->getBoolOption( $special->getUser(), 'usenewrc' );
|
2019-07-31 14:57:27 +00:00
|
|
|
$enhanced = $request->getBool( 'enhanced', $isEnhancedDefaultForUser );
|
|
|
|
if ( $enhanced ) {
|
|
|
|
$out->addHTML( Html::warningBox(
|
2020-05-23 21:49:32 +00:00
|
|
|
$special->msg( 'skin-minerva-recentchanges-warning-enhanced-not-supported' )->parse()
|
2019-07-31 14:57:27 +00:00
|
|
|
) );
|
|
|
|
}
|
|
|
|
break;
|
2017-07-12 15:12:40 +00:00
|
|
|
case 'Userlogin':
|
|
|
|
case 'CreateAccount':
|
|
|
|
// Add default warning message to Special:UserLogin and Special:UserCreate
|
|
|
|
// if no warning message set.
|
|
|
|
if (
|
2019-03-19 20:05:42 +00:00
|
|
|
!$request->getVal( 'warning' ) &&
|
2020-12-18 03:09:15 +00:00
|
|
|
!$special->getUser()->isRegistered() &&
|
2017-07-17 22:55:25 +00:00
|
|
|
!$request->wasPosted()
|
2017-07-12 15:12:40 +00:00
|
|
|
) {
|
|
|
|
$request->setVal( 'warning', 'mobile-frontend-generic-login-new' );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-01 20:15:19 +00:00
|
|
|
* Set the skin options for Minerva
|
2017-07-12 15:12:40 +00:00
|
|
|
*
|
2017-10-05 17:17:38 +00:00
|
|
|
* @param MobileContext $mobileContext
|
2017-07-12 15:12:40 +00:00
|
|
|
* @param Skin $skin
|
|
|
|
*/
|
2019-08-01 20:15:19 +00:00
|
|
|
private static function setMinervaSkinOptions(
|
2017-07-12 15:12:40 +00:00
|
|
|
MobileContext $mobileContext, Skin $skin
|
|
|
|
) {
|
|
|
|
// setSkinOptions is not available
|
2020-02-17 18:30:54 +00:00
|
|
|
if ( $skin instanceof SkinMinerva
|
|
|
|
) {
|
2019-04-10 21:43:50 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
2019-01-10 22:59:56 +00:00
|
|
|
$featureManager = $services
|
2018-01-08 22:18:16 +00:00
|
|
|
->getService( 'MobileFrontend.FeaturesManager' );
|
2019-04-10 21:43:50 +00:00
|
|
|
$skinOptions = $services->getService( 'Minerva.SkinOptions' );
|
2019-12-12 22:49:48 +00:00
|
|
|
$title = $skin->getTitle();
|
2020-02-17 18:30:54 +00:00
|
|
|
|
|
|
|
// T245162 - this should only apply if the context relates to a page view.
|
|
|
|
// Examples:
|
|
|
|
// - parsing wikitext during an REST response
|
|
|
|
// - a ResourceLoader response
|
|
|
|
if ( $title !== null ) {
|
|
|
|
// T232653: TALK_AT_TOP, HISTORY_IN_PAGE_ACTIONS, TOOLBAR_SUBMENU should
|
|
|
|
// be true on user pages and user talk pages for all users
|
|
|
|
//
|
|
|
|
// For some reason using $services->getService( 'SkinUserPageHelper' )
|
|
|
|
// here results in a circular dependency error which is why
|
|
|
|
// SkinUserPageHelper is being instantiated instead.
|
|
|
|
$relevantUserPageHelper = new SkinUserPageHelper(
|
2021-02-26 10:45:05 +00:00
|
|
|
$services->getUserNameUtils(),
|
2021-04-29 20:24:13 +00:00
|
|
|
$title->inNamespace( NS_USER_TALK ) ? $title->getSubjectPage() : $title,
|
|
|
|
$mobileContext
|
2020-02-17 18:30:54 +00:00
|
|
|
);
|
2021-04-29 20:24:13 +00:00
|
|
|
|
|
|
|
$isUserPage = $relevantUserPageHelper->isUserPage();
|
|
|
|
$isUserPageAccessible = $relevantUserPageHelper->isUserPageAccessibleToCurrentUser();
|
|
|
|
$isUserPageOrUserTalkPage = $isUserPage && $isUserPageAccessible;
|
2020-02-17 18:30:54 +00:00
|
|
|
} else {
|
|
|
|
// If no title this must be false
|
|
|
|
$isUserPageOrUserTalkPage = false;
|
|
|
|
}
|
2018-01-08 22:18:16 +00:00
|
|
|
|
|
|
|
$isBeta = $mobileContext->isBetaGroupMember();
|
2019-04-10 21:43:50 +00:00
|
|
|
$skinOptions->setMultiple( [
|
2020-06-25 21:06:46 +00:00
|
|
|
SkinOptions::SHOW_DONATE => $featureManager->isFeatureAvailableForCurrentUser( 'MinervaDonateLink' ),
|
2019-12-12 22:49:48 +00:00
|
|
|
SkinOptions::TALK_AT_TOP => $isUserPageOrUserTalkPage ?
|
|
|
|
true : $featureManager->isFeatureAvailableForCurrentUser( 'MinervaTalkAtTop' ),
|
2019-08-01 16:18:18 +00:00
|
|
|
SkinOptions::BETA_MODE
|
2018-01-08 22:18:16 +00:00
|
|
|
=> $isBeta,
|
2019-08-01 16:18:18 +00:00
|
|
|
SkinOptions::CATEGORIES
|
2021-04-28 21:58:51 +00:00
|
|
|
=> $featureManager->isFeatureAvailableForCurrentUser( 'MinervaShowCategories' ),
|
2019-08-01 16:18:18 +00:00
|
|
|
SkinOptions::PAGE_ISSUES
|
2019-07-29 23:27:55 +00:00
|
|
|
=> $featureManager->isFeatureAvailableForCurrentUser( 'MinervaPageIssuesNewTreatment' ),
|
2019-08-01 16:18:18 +00:00
|
|
|
SkinOptions::MOBILE_OPTIONS => true,
|
2019-08-22 20:31:31 +00:00
|
|
|
SkinOptions::PERSONAL_MENU => $featureManager->isFeatureAvailableForCurrentUser(
|
|
|
|
'MinervaPersonalMenu'
|
|
|
|
),
|
|
|
|
SkinOptions::MAIN_MENU_EXPANDED => $featureManager->isFeatureAvailableForCurrentUser(
|
|
|
|
'MinervaAdvancedMainMenu'
|
|
|
|
),
|
2019-12-12 22:49:48 +00:00
|
|
|
SkinOptions::HISTORY_IN_PAGE_ACTIONS => $isUserPageOrUserTalkPage ?
|
|
|
|
true : $featureManager->isFeatureAvailableForCurrentUser( 'MinervaHistoryInPageActions' ),
|
|
|
|
SkinOptions::TOOLBAR_SUBMENU => $isUserPageOrUserTalkPage ?
|
|
|
|
true : $featureManager->isFeatureAvailableForCurrentUser(
|
|
|
|
self::FEATURE_OVERFLOW_PAGE_ACTIONS
|
|
|
|
),
|
2019-08-01 16:18:18 +00:00
|
|
|
SkinOptions::TABS_ON_SPECIALS => false,
|
2017-07-12 15:12:40 +00:00
|
|
|
] );
|
2022-02-15 18:40:10 +00:00
|
|
|
MWHooks::run( 'SkinMinervaOptionsInit', [ $skin, $skinOptions ] );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 17:14:48 +00:00
|
|
|
|
2019-11-13 01:48:59 +00:00
|
|
|
/**
|
|
|
|
* MobileFrontendBeforeDOM hook handler that runs before the MobileFormatter
|
|
|
|
* executes. We use it to determine whether or not the talk page is eligible
|
|
|
|
* to be simplified (we want it only to be simplified when the MobileFormatter
|
|
|
|
* makes expandable sections).
|
|
|
|
*
|
|
|
|
* @param MobileContext $mobileContext
|
|
|
|
* @param MobileFormatter $formatter
|
|
|
|
*/
|
|
|
|
public static function onMobileFrontendBeforeDOM(
|
|
|
|
MobileContext $mobileContext,
|
|
|
|
MobileFormatter $formatter
|
|
|
|
) {
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$skinOptions = $services->getService( 'Minerva.SkinOptions' );
|
|
|
|
$skinOptions->setMultiple( [
|
|
|
|
SkinOptions::SIMPLIFIED_TALK => true
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
2019-08-01 20:15:19 +00:00
|
|
|
/**
|
|
|
|
* UserLogoutComplete hook handler.
|
|
|
|
* Resets skin options if a user logout occurs - this is necessary as the
|
|
|
|
* RequestContextCreateSkinMobile hook runs before the UserLogout hook.
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
*/
|
|
|
|
public static function onUserLogoutComplete( User $user ) {
|
|
|
|
try {
|
|
|
|
$ctx = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' );
|
|
|
|
self::setMinervaSkinOptions( $ctx, $ctx->getSkin() );
|
2022-02-15 18:40:10 +00:00
|
|
|
} catch ( NoSuchServiceException $ex ) {
|
2019-08-01 20:15:19 +00:00
|
|
|
// MobileFrontend not installed. Not important.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BeforePageDisplayMobile hook handler.
|
|
|
|
*
|
|
|
|
* @param MobileContext $mobileContext
|
|
|
|
* @param Skin $skin
|
|
|
|
*/
|
|
|
|
public static function onRequestContextCreateSkinMobile(
|
|
|
|
MobileContext $mobileContext, Skin $skin
|
|
|
|
) {
|
|
|
|
self::setMinervaSkinOptions( $mobileContext, $skin );
|
|
|
|
}
|
|
|
|
|
2018-08-13 14:29:05 +00:00
|
|
|
/**
|
|
|
|
* ResourceLoaderGetConfigVars hook handler.
|
|
|
|
* Used for setting JS variables which are pulled in dynamically with RL
|
|
|
|
* instead of embedded directly on the page with a script tag.
|
2020-04-21 22:44:18 +00:00
|
|
|
* These vars have a shorter cache-life than those in `getJsConfigVars`.
|
2018-08-13 14:29:05 +00:00
|
|
|
*
|
|
|
|
* @param array &$vars Array of variables to be added into the output of the RL startup module.
|
2018-10-31 21:32:45 +00:00
|
|
|
* @param string $skin
|
2018-08-13 14:29:05 +00:00
|
|
|
*/
|
2018-10-31 21:32:45 +00:00
|
|
|
public static function onResourceLoaderGetConfigVars( &$vars, $skin ) {
|
|
|
|
if ( $skin === 'minerva' ) {
|
|
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()
|
|
|
|
->makeConfig( 'minerva' );
|
2019-09-20 21:03:59 +00:00
|
|
|
// This is to let the UI adjust itself to a wiki that is always read-only.
|
|
|
|
// Ignore temporary read-only on live wikis, requires heavy DB check (T233458).
|
|
|
|
$roConf = MediaWikiServices::getInstance()->getConfiguredReadOnlyMode();
|
2018-10-31 21:32:45 +00:00
|
|
|
$vars += [
|
|
|
|
'wgMinervaABSamplingRate' => $config->get( 'MinervaABSamplingRate' ),
|
2019-09-20 21:03:59 +00:00
|
|
|
'wgMinervaReadOnly' => $roConf->isReadOnly(),
|
2018-10-31 21:32:45 +00:00
|
|
|
];
|
|
|
|
}
|
2018-08-13 14:29:05 +00:00
|
|
|
}
|
2020-06-18 19:11:32 +00:00
|
|
|
|
2021-03-23 22:04:58 +00:00
|
|
|
/**
|
|
|
|
* The Minerva skin loads message box styles differently from core, to
|
|
|
|
* reduce the amount of styles on the critical path.
|
|
|
|
* This adds message box styles to pages that need it, to avoid loading them
|
|
|
|
* on pages where they are not.
|
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @param Skin $skin
|
|
|
|
*/
|
|
|
|
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
|
|
|
|
if ( $skin->getSkinName() === 'minerva' ) {
|
|
|
|
self::addMessageBoxStylesToPage( $out );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Minerva skin loads message box styles differently from core, to
|
|
|
|
* reduce the amount of styles on the critical path.
|
|
|
|
* This adds message box styles to pages that need it, to avoid loading them
|
|
|
|
* on pages where they are not.
|
|
|
|
* The pages where they are needed are:
|
|
|
|
* - special pages
|
|
|
|
* - edit workflow (action=edit and action=submit)
|
|
|
|
* - when viewing old revisions
|
2021-10-26 21:19:58 +00:00
|
|
|
* - non-main namespaces for anon talk page messages
|
2021-03-23 22:04:58 +00:00
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
|
|
|
*/
|
|
|
|
private static function addMessageBoxStylesToPage( OutputPage $out ) {
|
|
|
|
$request = $out->getRequest();
|
2021-10-26 21:19:58 +00:00
|
|
|
$title = $out->getTitle();
|
2021-03-23 22:04:58 +00:00
|
|
|
// Warning box styles are needed when reviewing old revisions
|
|
|
|
// and inside the fallback editor styles to action=edit page.
|
|
|
|
$requestAction = $request->getVal( 'action' );
|
|
|
|
$viewAction = $requestAction === null || $requestAction === 'view';
|
|
|
|
|
|
|
|
if (
|
2021-10-26 21:19:58 +00:00
|
|
|
$title->getNamespace() !== NS_MAIN ||
|
2021-03-23 22:04:58 +00:00
|
|
|
$request->getText( 'oldid' ) ||
|
|
|
|
!$viewAction
|
|
|
|
) {
|
|
|
|
$out->addModuleStyles( [
|
|
|
|
'skins.minerva.messageBox.styles'
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 19:11:32 +00:00
|
|
|
/**
|
|
|
|
* Modifies the `<body>` element's attributes.
|
|
|
|
*
|
|
|
|
* By default, the `class` attribute is set to the output's "bodyClassName"
|
|
|
|
* property.
|
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @param Skin $skin
|
|
|
|
* @param string[] &$bodyAttrs
|
|
|
|
*/
|
|
|
|
public static function onOutputPageBodyAttributes( OutputPage $out, Skin $skin, &$bodyAttrs ) {
|
|
|
|
$classes = $out->getProperty( 'bodyClassName' );
|
|
|
|
$skinOptions = MediaWikiServices::getInstance()->getService( 'Minerva.SkinOptions' );
|
2020-08-01 18:12:31 +00:00
|
|
|
$isMinerva = $skin instanceof SkinMinerva;
|
2020-06-18 19:11:32 +00:00
|
|
|
|
2020-08-01 18:12:31 +00:00
|
|
|
if ( $isMinerva && $skinOptions->get( SkinOptions::HISTORY_IN_PAGE_ACTIONS ) ) {
|
2020-06-18 19:11:32 +00:00
|
|
|
// Class is used when page actions is modified to contain more elements
|
|
|
|
$classes .= ' minerva--history-page-action-enabled';
|
|
|
|
}
|
|
|
|
|
2020-08-01 18:12:31 +00:00
|
|
|
if ( $isMinerva ) {
|
|
|
|
// phan doesn't realize that $skin can only be an instance of SkinMinerva without this:
|
|
|
|
'@phan-var SkinMinerva $skin';
|
|
|
|
if ( $skin->isSimplifiedTalkPageEnabled() ) {
|
|
|
|
$classes .= ' skin-minerva--talk-simplified';
|
|
|
|
}
|
2020-06-18 19:11:32 +00:00
|
|
|
|
2020-08-01 18:12:31 +00:00
|
|
|
$bodyAttrs['class'] .= ' ' . $classes;
|
2020-06-18 19:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-14 12:59:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SkinPageReadyConfig hook handler
|
|
|
|
*
|
|
|
|
* Disable collapsible and sortable on page load
|
|
|
|
*
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
* @param mixed[] &$config Associative array of configurable options
|
|
|
|
* @return void This hook must not abort, it must return no value
|
|
|
|
*/
|
|
|
|
public static function onSkinPageReadyConfig(
|
|
|
|
ResourceLoaderContext $context,
|
|
|
|
array &$config
|
|
|
|
) {
|
|
|
|
if ( $context->getSkin() === 'minerva' ) {
|
|
|
|
$config['search'] = false;
|
|
|
|
$config['collapsible'] = false;
|
|
|
|
$config['sortable'] = false;
|
2021-02-10 23:35:17 +00:00
|
|
|
$config['selectorLogoutLink'] = 'a.menu__item--logout[data-mw="interface"]';
|
2020-07-14 12:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|