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';
|
|
|
|
|
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
|
|
|
|
* @param Skin &$skin
|
|
|
|
* @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
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @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' )
|
|
|
|
)
|
|
|
|
);
|
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 )
|
|
|
|
)
|
|
|
|
);
|
2019-08-22 20:31:31 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
'MinervaAdvancedMainMenu',
|
|
|
|
'skin-minerva',
|
|
|
|
$config->get( 'MinervaAdvancedMainMenu' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
new MobileFrontend\Features\Feature(
|
|
|
|
'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 ) {
|
|
|
|
case 'MobileMenu':
|
|
|
|
$out->addModuleStyles( [
|
|
|
|
'skins.minerva.mainMenu.icons',
|
|
|
|
'skins.minerva.mainMenu.styles',
|
|
|
|
] );
|
|
|
|
break;
|
2019-07-31 14:57:27 +00:00
|
|
|
case 'Recentchanges':
|
|
|
|
$isEnhancedDefaultForUser = $special->getUser()->getOption( 'usenewrc' );
|
|
|
|
$enhanced = $request->getBool( 'enhanced', $isEnhancedDefaultForUser );
|
|
|
|
if ( $enhanced ) {
|
|
|
|
$out->addHTML( Html::warningBox(
|
|
|
|
$special->msg( 'skin-minerva-recentchanges-warning-enhanced-not-supported' )
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
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' ) &&
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
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' );
|
2018-01-08 22:18:16 +00:00
|
|
|
|
|
|
|
$isBeta = $mobileContext->isBetaGroupMember();
|
2019-04-10 21:43:50 +00:00
|
|
|
$skinOptions->setMultiple( [
|
2019-08-01 16:18:18 +00:00
|
|
|
SkinOptions::TALK_AT_TOP => $featureManager->isFeatureAvailableForCurrentUser(
|
2019-01-10 22:59:56 +00:00
|
|
|
'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
|
2019-07-29 23:27:55 +00:00
|
|
|
=> $featureManager->isFeatureAvailableForCurrentUser( 'MinervaShowCategoriesButton' ),
|
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-08-01 16:18:18 +00:00
|
|
|
SkinOptions::HISTORY_IN_PAGE_ACTIONS => $featureManager->isFeatureAvailableForCurrentUser(
|
2019-03-07 20:50:57 +00:00
|
|
|
'MinervaHistoryInPageActions'
|
|
|
|
),
|
2019-08-01 16:18:18 +00:00
|
|
|
SkinOptions::TOOLBAR_SUBMENU => $featureManager->isFeatureAvailableForCurrentUser(
|
2019-04-04 21:20:39 +00:00
|
|
|
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
|
|
|
] );
|
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
|
|
|
|
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() );
|
|
|
|
} catch ( Wikimedia\Services\NoSuchServiceException $ex ) {
|
|
|
|
// 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.
|
|
|
|
* 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' );
|
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' ),
|
|
|
|
'wgMinervaCountErrors' => $config->get( 'MinervaCountErrors' ),
|
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
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|