jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/404411 )
Change subject: Don't disable local preferences if a local exception is being
saved
......................................................................
Don't disable local preferences if a local exception is being saved
Local preferences are disabled unless their already flagged as
having a local exception, or such a flag is being set in the
current request.
Bug: T184973
Change-Id: I5c063c9b4c63069b4912a6e0a980fbd94f4750de
---
M includes/GlobalPreferencesFactory.php
1 file changed, 16 insertions(+), 7 deletions(-)
Approvals:
MaxSem: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/GlobalPreferencesFactory.php
b/includes/GlobalPreferencesFactory.php
index 3d29e59..72b0288 100644
--- a/includes/GlobalPreferencesFactory.php
+++ b/includes/GlobalPreferencesFactory.php
@@ -20,6 +20,7 @@
use RequestContext;
use SpecialPage;
use User;
+use WebRequest;
/**
* Global preferences.
@@ -106,7 +107,7 @@
if ( $this->onGlobalPrefsPage() ) {
return $this->getPreferencesGlobal( $preferences,
$globalPrefNames );
}
- return $this->getPreferencesLocal( $preferences,
$globalPrefNames );
+ return $this->getPreferencesLocal( $preferences,
$globalPrefNames, $context->getRequest() );
}
/**
@@ -114,18 +115,26 @@
* and add the link to Special:GlobalPreferences to the personal
preferences tab.
* @param mixed[][] $preferences The preferences array.
* @param string[] $globalPrefNames The names of those preferences that
are already global.
+ * @param WebRequest $request The current request, to check for local
exceptions being set.
* @return mixed[][]
*/
- protected function getPreferencesLocal( $preferences, $globalPrefNames
) {
+ protected function getPreferencesLocal( $preferences, $globalPrefNames,
WebRequest $request ) {
$modifiedPrefs = [];
foreach ( $preferences as $name => $def ) {
$modifiedPrefs[$name] = $def;
// If this has been set globally.
if ( in_array( $name, $globalPrefNames ) ) {
- // Disable this preference unless it has a
local exception.
- $localException = $this->user->getOption( $name
. static::LOCAL_EXCEPTION_SUFFIX );
- $modifiedPrefs[$name]['disabled'] = is_null(
$localException );
+ // Disable this local preference unless it
either
+ // A) already has a local exception, or
+ // B) a local exception is being enabled in the
current request.
+ // This is because HTMLForm changes submitted
values to their defaults
+ // after preferences have been defined here, if
a field is disabled.
+ $localExName = $name .
static::LOCAL_EXCEPTION_SUFFIX;
+ $localExValueUser = $this->user->getOption(
$localExName );
+ $localExValueRequest = $request->getVal( 'wp' .
$localExName );
+ $modifiedPrefs[$name]['disabled'] = is_null(
$localExValueUser )
+ && is_null( $localExValueRequest );
// Add a new local exception preference after
this one.
$cssClasses = [
@@ -134,10 +143,10 @@
];
$secFragment = static::getSectionFragmentId(
$def['section'] );
$labelMsg = wfMessage(
'globalprefs-set-local-exception', [ $secFragment ] );
- $modifiedPrefs[ $name .
static::LOCAL_EXCEPTION_SUFFIX ] = [
+ $modifiedPrefs[ $localExName ] = [
'type' => 'toggle',
'label-raw' => $labelMsg->parse(),
- 'default' => $this->user->getOption(
$name . static::LOCAL_EXCEPTION_SUFFIX ),
+ 'default' => $localExValueUser,
'section' => $def['section'],
'cssclass' => join( ' ', $cssClasses ),
];
--
To view, visit https://gerrit.wikimedia.org/r/404411
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5c063c9b4c63069b4912a6e0a980fbd94f4750de
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/GlobalPreferences
Gerrit-Branch: master
Gerrit-Owner: Samwilson <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits