2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Minerva.hooks.php
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook handlers for Minerva skin.
|
|
|
|
*
|
|
|
|
* Hook handler method names should be in the form of:
|
|
|
|
* on<HookName>()
|
|
|
|
*/
|
2017-06-30 18:32:39 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
class MinervaHooks {
|
|
|
|
/**
|
|
|
|
* ResourceLoaderGetLessVars hook handler
|
|
|
|
*
|
|
|
|
* Add the context-based less variables.
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetLessVars
|
|
|
|
* @param array &$lessVars Variables already added
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderGetLessVars( &$lessVars ) {
|
2017-07-17 20:58:14 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()
|
2017-06-30 18:32:39 +00:00
|
|
|
->makeConfig( 'minerva' );
|
|
|
|
|
2017-07-17 20:58:14 +00:00
|
|
|
$lessVars['wgMinervaApplyKnownTemplateHacks'] = $config->get( 'MinervaApplyKnownTemplateHacks' );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Skin registration callback.
|
|
|
|
*/
|
|
|
|
public static function onRegistration() {
|
|
|
|
// Set LESS importpath
|
|
|
|
global $wgResourceLoaderLESSImportPaths;
|
|
|
|
$wgResourceLoaderLESSImportPaths[] = dirname( __DIR__ ) . "/minerva.less/";
|
|
|
|
|
|
|
|
// Setup alias for compatibility with SkinMinervaNeue.
|
|
|
|
if ( !class_exists( 'SkinMinervaNeue' ) ) {
|
|
|
|
class_alias( 'SkinMinerva', 'SkinMinervaNeue', true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ResourceLoaderTestModules hook handler
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
|
|
|
|
*
|
|
|
|
* @param array $testModules
|
|
|
|
* @param ResourceLoader $resourceLoader
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderTestModules( array &$testModules,
|
|
|
|
ResourceLoader &$resourceLoader
|
|
|
|
) {
|
|
|
|
$testModule = [
|
|
|
|
'dependencies' => [
|
|
|
|
'skins.minerva.notifications.badge'
|
|
|
|
],
|
|
|
|
'localBasePath' => dirname( __DIR__ ),
|
2017-09-14 06:45:10 +00:00
|
|
|
'remoteSkinPath' => 'MinervaNeue',
|
2017-07-12 15:12:40 +00:00
|
|
|
'targets' => [ 'mobile', 'desktop' ],
|
|
|
|
'scripts' => [
|
|
|
|
'tests/qunit/skins.minerva.notifications.badge/test_NotificationBadge.js'
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
// Expose templates module
|
|
|
|
$testModules['qunit']["tests.skins.minerva"] = $testModule;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onSpecialPageBeforeExecute( SpecialPage $special, $subpage ) {
|
|
|
|
$name = $special->getName();
|
|
|
|
$out = $special->getOutput();
|
|
|
|
$skin = $out->getSkin();
|
|
|
|
$request = $special->getRequest();
|
|
|
|
|
|
|
|
// Ensure desktop version of Special:Preferences page gets mobile targeted modules
|
|
|
|
// FIXME: Upstream to core (?)
|
|
|
|
if ( $skin instanceof SkinMinerva ) {
|
|
|
|
switch ( $name ) {
|
|
|
|
case 'MobileMenu':
|
|
|
|
$out->addModuleStyles( [
|
|
|
|
'skins.minerva.mainMenu.icons',
|
|
|
|
'skins.minerva.mainMenu.styles',
|
|
|
|
] );
|
|
|
|
$out->addModules( [
|
|
|
|
'skins.minerva.mainMenu'
|
|
|
|
] );
|
|
|
|
break;
|
|
|
|
case 'Preferences':
|
|
|
|
$out->addModules( 'skins.minerva.special.preferences.scripts' );
|
|
|
|
break;
|
|
|
|
case 'Userlogin':
|
|
|
|
case 'CreateAccount':
|
|
|
|
// FIXME: Note mobile.ajax.styles should not be necessary here.
|
|
|
|
// It's used by the Captcha extension (see T162196)
|
2017-08-18 18:45:41 +00:00
|
|
|
$out->addModuleStyles( [ 'mobile.ajax.styles' ] );
|
2017-07-12 15:12:40 +00:00
|
|
|
// Add default warning message to Special:UserLogin and Special:UserCreate
|
|
|
|
// if no warning message set.
|
|
|
|
if (
|
|
|
|
!$request->getVal( 'warning', null ) &&
|
2017-07-17 22:55:25 +00:00
|
|
|
!$special->getUser()->isLoggedIn() &&
|
|
|
|
!$request->wasPosted()
|
2017-07-12 15:12:40 +00:00
|
|
|
) {
|
|
|
|
$request->setVal( 'warning', 'mobile-frontend-generic-login-new' );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BeforePageDisplayMobile hook handler.
|
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @param Skin $skin
|
|
|
|
*/
|
|
|
|
public static function onRequestContextCreateSkinMobile(
|
|
|
|
MobileContext $mobileContext, Skin $skin
|
|
|
|
) {
|
|
|
|
// setSkinOptions is not available
|
|
|
|
if ( $skin instanceof SkinMinerva ) {
|
|
|
|
$skin->setSkinOptions( [
|
|
|
|
SkinMinerva::OPTIONS_MOBILE_BETA
|
|
|
|
=> $mobileContext->isBetaGroupMember(),
|
|
|
|
SkinMinerva::OPTION_CATEGORIES
|
|
|
|
=> $mobileContext->getConfigVariable( 'MinervaShowCategoriesButton' ),
|
|
|
|
SkinMinerva::OPTION_FONT_CHANGER
|
|
|
|
=> $mobileContext->getConfigVariable( 'MinervaEnableFontChanger' ),
|
|
|
|
SkinMinerva::OPTION_BACK_TO_TOP
|
|
|
|
=> $mobileContext->getConfigVariable( 'MinervaEnableBackToTop' ),
|
|
|
|
SkinMinerva::OPTION_TOGGLING => true,
|
|
|
|
SkinMinerva::OPTION_MOBILE_OPTIONS => true,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|