Hide gadgets on Special:Preferences when forcesafemode=true

See https://gerrit.wikimedia.org/r/c/mediawiki/core/+/940156/comments/bdd88839_f9bdd28a

Bug: T342347
Depends-On: I6f2d024c01cdb1d7305ff024996175eb2656d0a8
Change-Id: Ia72bb33a3fd559cd5a30a44f736b0d3040843323
This commit is contained in:
Dringsim 2023-09-07 21:42:23 +08:00 committed by Jdlrobson
parent 929bfc6404
commit e292854740
3 changed files with 15 additions and 1 deletions

View file

@ -8,6 +8,7 @@
"prefs-gadgets": "Gadgets",
"prefs-description-gadgets": "Enable additional features for your account.",
"gadgets-prefstext": "Below is a list of special gadgets you can enable for your account.\nThese gadgets are mostly based on JavaScript, so JavaScript has to be enabled in your browser for them to work.\nNote that these gadgets will have no effect on this preferences page.\n\nAlso note that these special gadgets are not part of the MediaWiki software, and are usually developed and maintained by users on your local wiki.\nLocal interface administrators can edit the [[MediaWiki:Gadgets-definition|definitions]] of available gadgets, and local administrators can edit their [[Special:Gadgets|descriptions]], where you can see the source code of each gadget. The numbers of users for each gadget on this wiki is listed at [[Special:GadgetUsage|Gadget usage statistics]].",
"gadgets-prefstext-safemode": "Gadgets are currently unavailable as safe mode has been enabled. Please [[#mw-input-wpforcesafemode|disable safe mode]] to use gadgets.",
"gadgets": "Gadgets",
"gadgetusage": "Gadget usage statistics",
"gadgetusage-gadget": "Gadget",

View file

@ -22,6 +22,7 @@
"prefs-gadgets": "In Gadgets extension. The name of a tab in [[Special:Preferences#mw-prefsection-gadgets|Special:Preferences]] where user set their preferences for the extension.\n\n{{Identical|Gadgets}}",
"prefs-description-gadgets": "Used in [[Special:Preferences]] for mobile to describe the Gadgets features section.",
"gadgets-prefstext": "In Gadgets extension. This is the explanation text displayed under the Gadgets tab in [[Special:Preferences#mw-prefsection-gadgets|Special:Preferences]].",
"gadgets-prefstext-safemode": "In Gadgets extension. Shown under the Gadgets tab in [[Special:Preferences#mw-prefsection-gadgets|Special:Preferences]] when safe mode is enabled (thus gadgets are disabled).",
"gadgets": "{{doc-special|Gadgets}}\n{{Identical|Gadgets}}",
"gadgetusage": "{{doc-special|Gadget usage statistics}}",
"gadgetusage-gadget": "Table column header on [[Special:GadgetUsage]]\n{{Identical|Gadget}}",

View file

@ -36,6 +36,7 @@ use MediaWiki\Hook\DeleteUnknownPreferencesHook;
use MediaWiki\Hook\EditFilterMergedContentHook;
use MediaWiki\Hook\PreferencesGetIconHook;
use MediaWiki\Hook\PreferencesGetLegendHook;
use MediaWiki\Html\Html;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\Hook\PageDeleteCompleteHook;
use MediaWiki\Page\ProperPageIdentity;
@ -179,6 +180,16 @@ class Hooks implements
'raw' => true,
];
$safeMode = MediaWikiServices::getInstance()->getUserOptionsLookup()->getOption( $user, 'forcesafemode' );
if ( $safeMode ) {
$preferences['gadgets-safemode'] = [
'type' => 'info',
'default' => Html::warningBox( wfMessage( 'gadgets-prefstext-safemode' )->parse() ),
'section' => 'gadgets',
'raw' => true,
];
}
$skin = RequestContext::getMain()->getSkin();
$isMobileView = self::isMobileView();
foreach ( $gadgets as $section => $thisSection ) {
@ -191,7 +202,8 @@ class Hooks implements
// Only show option to enable gadget if it can be enabled
$type = 'api';
if (
!$gadget->isHidden()
!$safeMode
&& !$gadget->isHidden()
&& $gadget->isAllowed( $user )
&& $gadget->isTargetSupported( $isMobileView )
&& $gadget->isSkinSupported( $skin )