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;
|
2019-04-10 21:43:50 +00:00
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
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>()
|
|
|
|
*/
|
|
|
|
class MinervaHooks {
|
2019-04-04 21:20:39 +00:00
|
|
|
const FEATURE_OVERFLOW_PAGE_ACTIONS = 'MinervaOverflowInPageActions';
|
|
|
|
|
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' )
|
|
|
|
)
|
|
|
|
);
|
2018-09-17 23:37:57 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
'MinervaShareButton',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaShowShareButton' )
|
|
|
|
)
|
|
|
|
);
|
2018-11-12 20:32:28 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
'MinervaPageIssuesNewTreatment',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaPageIssuesNewTreatment' )
|
|
|
|
)
|
|
|
|
);
|
2019-01-10 22:59:56 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
'MinervaTalkAtTop',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaTalkAtTop' )
|
|
|
|
)
|
|
|
|
);
|
2019-03-07 20:50:57 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
'MinervaHistoryInPageActions',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaHistoryInPageActions' )
|
|
|
|
)
|
|
|
|
);
|
2019-04-04 21:20:39 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
self::FEATURE_OVERFLOW_PAGE_ACTIONS,
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( self::FEATURE_OVERFLOW_PAGE_ACTIONS )
|
|
|
|
)
|
|
|
|
);
|
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
|
|
|
/**
|
|
|
|
* ResourceLoaderTestModules hook handler
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
|
|
|
|
*
|
2017-10-05 17:17:38 +00:00
|
|
|
* @param array &$testModules
|
2019-03-19 20:05:42 +00:00
|
|
|
* @param ResourceLoader $resourceLoader
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
public static function onResourceLoaderTestModules( array &$testModules,
|
2019-03-19 20:05:42 +00:00
|
|
|
ResourceLoader $resourceLoader
|
2017-07-12 15:12:40 +00:00
|
|
|
) {
|
|
|
|
$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-08-16 19:00:38 +00:00
|
|
|
'mediawiki.experiments'
|
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-16 19:00:38 +00:00
|
|
|
'tests/qunit/skins.minerva.scripts/stubs.js',
|
|
|
|
|
|
|
|
'resources/skins.minerva.scripts/pageIssuesParser.js',
|
2018-11-08 00:06:54 +00:00
|
|
|
'resources/skins.minerva.scripts/downloadPageAction.js',
|
2018-05-09 15:14:44 +00:00
|
|
|
'resources/skins.minerva.scripts/AB.js',
|
2018-11-24 01:49:47 +00:00
|
|
|
'resources/skins.minerva.scripts/page-issues/overlay/IssueNotice.js',
|
|
|
|
'resources/skins.minerva.scripts/page-issues/overlay/IssueList.js',
|
|
|
|
'resources/skins.minerva.scripts/page-issues/overlay/pageIssuesOverlay.js',
|
2019-03-19 20:05:42 +00:00
|
|
|
'resources/skins.minerva.scripts/page-issues/page/PageIssueLearnMoreLink.js',
|
|
|
|
'resources/skins.minerva.scripts/page-issues/page/PageIssueLink.js',
|
|
|
|
'resources/skins.minerva.scripts/page-issues/page/pageIssueFormatter.js',
|
2018-08-16 19:00:38 +00:00
|
|
|
'resources/skins.minerva.scripts/pageIssues.js',
|
2019-03-04 22:19:33 +00:00
|
|
|
'resources/skins.minerva.scripts/UriUtil.js',
|
|
|
|
'resources/skins.minerva.scripts/TitleUtil.js',
|
2017-11-15 22:37:37 +00:00
|
|
|
// test files
|
2018-11-08 00:06:54 +00:00
|
|
|
'tests/qunit/skins.minerva.scripts/downloadPageAction.test.js',
|
2018-09-19 13:11:23 +00:00
|
|
|
'tests/qunit/skins.minerva.scripts/pageIssuesParser.test.js',
|
|
|
|
'tests/qunit/skins.minerva.scripts/AB.test.js',
|
|
|
|
'tests/qunit/skins.minerva.scripts/pageIssues.test.js',
|
2019-03-04 22:19:33 +00:00
|
|
|
'tests/qunit/skins.minerva.scripts/UriUtil.test.js',
|
|
|
|
'tests/qunit/skins.minerva.scripts/TitleUtil.test.js',
|
2018-09-19 13:11:23 +00:00
|
|
|
'tests/qunit/skins.minerva.notifications.badge/NotificationBadge.test.js'
|
2017-07-12 15:12:40 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
// Expose templates module
|
2019-03-19 20:05:42 +00:00
|
|
|
$testModules['qunit']['tests.skins.minerva'] = $testModule;
|
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 ) {
|
|
|
|
case 'MobileMenu':
|
|
|
|
$out->addModuleStyles( [
|
|
|
|
'skins.minerva.mainMenu.icons',
|
|
|
|
'skins.minerva.mainMenu.styles',
|
|
|
|
] );
|
|
|
|
break;
|
|
|
|
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' ) &&
|
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 ) {
|
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-01-10 22:59:56 +00:00
|
|
|
$userMode = $services->getService( 'MobileFrontend.AMC.UserMode' );
|
2019-04-10 21:43:50 +00:00
|
|
|
$skinOptions = $services->getService( 'Minerva.SkinOptions' );
|
2018-01-08 22:18:16 +00:00
|
|
|
|
|
|
|
$isBeta = $mobileContext->isBetaGroupMember();
|
2019-04-10 21:43:50 +00:00
|
|
|
$skinOptions->setMultiple( [
|
|
|
|
SkinOptions::OPTION_AMC => $userMode->isEnabled(),
|
|
|
|
SkinOptions::OPTIONS_TALK_AT_TOP => $featureManager->isFeatureAvailableForCurrentUser(
|
2019-01-10 22:59:56 +00:00
|
|
|
'MinervaTalkAtTop'
|
|
|
|
),
|
2019-04-10 21:43:50 +00:00
|
|
|
SkinOptions::OPTIONS_MOBILE_BETA
|
2018-01-08 22:18:16 +00:00
|
|
|
=> $isBeta,
|
2019-04-10 21:43:50 +00:00
|
|
|
SkinOptions::OPTION_CATEGORIES
|
2018-01-08 22:18:16 +00:00
|
|
|
=> $featureManager->isFeatureAvailableInContext( 'MinervaShowCategoriesButton',
|
|
|
|
$mobileContext ),
|
2019-04-10 21:43:50 +00:00
|
|
|
SkinOptions::OPTION_BACK_TO_TOP
|
2018-01-08 22:18:16 +00:00
|
|
|
=> $featureManager->isFeatureAvailableInContext( 'MinervaEnableBackToTop', $mobileContext ),
|
2019-04-10 21:43:50 +00:00
|
|
|
SkinOptions::OPTION_PAGE_ISSUES
|
2018-11-12 20:32:28 +00:00
|
|
|
=> $featureManager->isFeatureAvailableInContext(
|
|
|
|
'MinervaPageIssuesNewTreatment', $mobileContext
|
|
|
|
),
|
2019-04-10 21:43:50 +00:00
|
|
|
SkinOptions::OPTION_SHARE_BUTTON
|
2018-09-17 23:37:57 +00:00
|
|
|
=> $featureManager->isFeatureAvailableInContext( 'MinervaShareButton', $mobileContext ),
|
2019-04-10 21:43:50 +00:00
|
|
|
SkinOptions::OPTION_TOGGLING => true,
|
|
|
|
SkinOptions::OPTION_MOBILE_OPTIONS => true,
|
|
|
|
SkinOptions::OPTIONS_HISTORY_PAGE_ACTIONS => $featureManager->isFeatureAvailableForCurrentUser(
|
2019-03-07 20:50:57 +00:00
|
|
|
'MinervaHistoryInPageActions'
|
|
|
|
),
|
2019-04-04 21:20:39 +00:00
|
|
|
SkinOptions::OPTION_OVERFLOW_SUBMENU => $featureManager->isFeatureAvailableForCurrentUser(
|
|
|
|
self::FEATURE_OVERFLOW_PAGE_ACTIONS
|
|
|
|
),
|
2019-05-31 17:14:48 +00:00
|
|
|
SkinOptions::OPTION_TABS_ON_SPECIALS => false,
|
2017-07-12 15:12:40 +00:00
|
|
|
] );
|
2019-05-31 17:14:48 +00:00
|
|
|
Hooks::run( 'SkinMinervaOptionsInit', [ $skin, $skinOptions ] );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 17:14:48 +00:00
|
|
|
|
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.
|
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' );
|
|
|
|
$vars += [
|
|
|
|
'wgMinervaSchemaMainMenuClickTrackingSampleRate' =>
|
|
|
|
$config->get( 'MinervaSchemaMainMenuClickTrackingSampleRate' ),
|
|
|
|
'wgMinervaABSamplingRate' => $config->get( 'MinervaABSamplingRate' ),
|
|
|
|
'wgMinervaCountErrors' => $config->get( 'MinervaCountErrors' ),
|
|
|
|
'wgMinervaErrorLogSamplingRate' => $config->get( 'MinervaErrorLogSamplingRate' ),
|
|
|
|
'wgMinervaReadOnly' => wfReadOnly()
|
|
|
|
];
|
|
|
|
}
|
2018-08-13 14:29:05 +00:00
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|