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
|
|
|
*/
|
|
|
|
|
2018-04-15 23:21:12 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
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>()
|
|
|
|
*/
|
|
|
|
class MinervaHooks {
|
2018-01-08 22:18:16 +00:00
|
|
|
/**
|
|
|
|
* Register mobile web beta features
|
|
|
|
* @see https://www.mediawiki.org/wiki/
|
|
|
|
* Extension:MobileFrontend/MobileFrontendFeaturesRegistration
|
|
|
|
*
|
|
|
|
* @param MobileFrontend\Features\FeaturesManager $featureManager
|
|
|
|
*/
|
|
|
|
public static function onMobileFrontendFeaturesRegistration( $featureManager ) {
|
|
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()
|
|
|
|
->makeConfig( 'minerva' );
|
|
|
|
|
|
|
|
try {
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
'MinervaShowCategoriesButton',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaShowCategoriesButton' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
'MinervaEnableBackToTop',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaEnableBackToTop' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} 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
|
|
|
/**
|
|
|
|
* ResourceLoaderTestModules hook handler
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
|
|
|
|
*
|
2017-10-05 17:17:38 +00:00
|
|
|
* @param array &$testModules
|
|
|
|
* @param ResourceLoader &$resourceLoader
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
public static function onResourceLoaderTestModules( array &$testModules,
|
|
|
|
ResourceLoader &$resourceLoader
|
|
|
|
) {
|
|
|
|
$testModule = [
|
|
|
|
'dependencies' => [
|
2017-11-15 22:37:37 +00:00
|
|
|
'mobile.startup',
|
2018-05-09 15:14:44 +00:00
|
|
|
'skins.minerva.notifications.badge',
|
|
|
|
'mediawiki.user',
|
2018-07-30 14:35:54 +00:00
|
|
|
'mediawiki.experiments',
|
|
|
|
'mobile.issues'
|
2017-07-12 15:12:40 +00:00
|
|
|
],
|
|
|
|
'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' => [
|
2017-11-15 22:37:37 +00:00
|
|
|
// additional scaffolding (minus initialisation scripts)
|
2018-08-13 21:54:24 +00:00
|
|
|
'resources/skins.minerva.scripts/pageIssueLogger.js',
|
2018-07-10 20:06:51 +00:00
|
|
|
'resources/skins.minerva.scripts/pageIssueParser.js',
|
2017-11-15 22:37:37 +00:00
|
|
|
'resources/skins.minerva.scripts/DownloadIcon.js',
|
2018-05-09 15:14:44 +00:00
|
|
|
'resources/skins.minerva.scripts/AB.js',
|
2018-07-30 14:35:54 +00:00
|
|
|
'resources/skins.minerva.scripts/cleanuptemplates.js',
|
2017-11-15 22:37:37 +00:00
|
|
|
// test files
|
|
|
|
'tests/qunit/skins.minerva.scripts/test_DownloadIcon.js',
|
2018-07-10 20:06:51 +00:00
|
|
|
'tests/qunit/skins.minerva.scripts/test_pageIssueParser.js',
|
2018-05-09 15:14:44 +00:00
|
|
|
'tests/qunit/skins.minerva.scripts/test_AB.js',
|
2018-07-30 14:35:54 +00:00
|
|
|
'tests/qunit/skins.minerva.scripts/test_cleanuptemplates.js',
|
2017-07-12 15:12:40 +00:00
|
|
|
'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
|
|
|
|
*/
|
|
|
|
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 ) {
|
|
|
|
case 'MobileMenu':
|
|
|
|
$out->addModuleStyles( [
|
2018-06-25 19:07:29 +00:00
|
|
|
'skins.minerva.icons.images.variants',
|
2017-07-12 15:12:40 +00:00
|
|
|
'skins.minerva.mainMenu.icons',
|
|
|
|
'skins.minerva.mainMenu.styles',
|
|
|
|
] );
|
|
|
|
$out->addModules( [
|
|
|
|
'skins.minerva.mainMenu'
|
|
|
|
] );
|
|
|
|
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.
|
|
|
|
*
|
2017-10-05 17:17:38 +00:00
|
|
|
* @param MobileContext $mobileContext
|
2017-07-12 15:12:40 +00:00
|
|
|
* @param Skin $skin
|
|
|
|
*/
|
|
|
|
public static function onRequestContextCreateSkinMobile(
|
|
|
|
MobileContext $mobileContext, Skin $skin
|
|
|
|
) {
|
|
|
|
// setSkinOptions is not available
|
|
|
|
if ( $skin instanceof SkinMinerva ) {
|
2018-01-08 22:18:16 +00:00
|
|
|
$featureManager = \MediaWiki\MediaWikiServices::getInstance()
|
|
|
|
->getService( 'MobileFrontend.FeaturesManager' );
|
|
|
|
|
|
|
|
$isBeta = $mobileContext->isBetaGroupMember();
|
2017-07-12 15:12:40 +00:00
|
|
|
$skin->setSkinOptions( [
|
|
|
|
SkinMinerva::OPTIONS_MOBILE_BETA
|
2018-01-08 22:18:16 +00:00
|
|
|
=> $isBeta,
|
2017-07-12 15:12:40 +00:00
|
|
|
SkinMinerva::OPTION_CATEGORIES
|
2018-01-08 22:18:16 +00:00
|
|
|
=> $featureManager->isFeatureAvailableInContext( 'MinervaShowCategoriesButton',
|
|
|
|
$mobileContext ),
|
2017-07-12 15:12:40 +00:00
|
|
|
SkinMinerva::OPTION_BACK_TO_TOP
|
2018-01-08 22:18:16 +00:00
|
|
|
=> $featureManager->isFeatureAvailableInContext( 'MinervaEnableBackToTop', $mobileContext ),
|
2017-07-12 15:12:40 +00:00
|
|
|
SkinMinerva::OPTION_TOGGLING => true,
|
|
|
|
SkinMinerva::OPTION_MOBILE_OPTIONS => true,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
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.
|
|
|
|
* These vars have a shorter cache-life than those in `getSkinConfigVariables`.
|
|
|
|
*
|
|
|
|
* @param array &$vars Array of variables to be added into the output of the RL startup module.
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderGetConfigVars( &$vars ) {
|
|
|
|
$vars += [
|
|
|
|
'wgMinervaReadOnly' => wfReadOnly()
|
|
|
|
];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|