Samwilson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/370152 )
Change subject: [WiP] Move the enable-globally checkboxes to the side of the form ...................................................................... [WiP] Move the enable-globally checkboxes to the side of the form This moves each preference's 'enable this globally?' toggle to the side of the preferences form to make it easier to see what's enabled and what's not. Bug: T68869 Change-Id: I3c10dfeacf02367e90f84a3e572ecf3f4048e02a --- M extension.json M i18n/en.json A includes/GlobalPreferencesForm.php M includes/Hooks.php M includes/SpecialGlobalPreferences.php M resources/ext.GlobalPreferences.special.css M resources/ext.GlobalPreferences.special.js M resources/ext.GlobalPreferences.special.nojs.css 8 files changed, 126 insertions(+), 42 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GlobalPreferences refs/changes/52/370152/1 diff --git a/extension.json b/extension.json index 8245339..f39dd87 100644 --- a/extension.json +++ b/extension.json @@ -25,7 +25,8 @@ "AutoloadClasses": { "GlobalPreferences\\GlobalPreferences": "includes/GlobalPreferences.php", "GlobalPreferences\\Hooks": "includes/Hooks.php", - "GlobalPreferences\\SpecialGlobalPreferences": "includes/SpecialGlobalPreferences.php" + "GlobalPreferences\\SpecialGlobalPreferences": "includes/SpecialGlobalPreferences.php", + "GlobalPreferences\\GlobalPreferencesForm": "includes/GlobalPreferencesForm.php" }, "Hooks": { "UserLoadOptions": [ diff --git a/i18n/en.json b/i18n/en.json index 0043b24..4613fe7 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -11,5 +11,6 @@ "globalprefs-notglobal": "Your account is not a global account and cannot set global preferences.", "globalpreferences": "Global preferences", "globalprefs-info-label": "Global preferences:", - "globalprefs-info-link": "Set your global preferences" + "globalprefs-info-link": "Set your global preferences", + "globalprefs-section-header": "Select which preferences should be global." } \ No newline at end of file diff --git a/includes/GlobalPreferencesForm.php b/includes/GlobalPreferencesForm.php new file mode 100644 index 0000000..cd010b1 --- /dev/null +++ b/includes/GlobalPreferencesForm.php @@ -0,0 +1,41 @@ +<?php + +namespace GlobalPreferences; + +use Html; +use IContextSource; +use PreferencesForm; + +class GlobalPreferencesForm extends PreferencesForm { + + /** + * Build a new GlobalPreferencesForm from an array of field attributes, and force it to be + * have a 'div' display format. + * + * @param array $descriptor Array of Field constructs, as described above. + * @param IContextSource $context The context of the form. + * @param string $messagePrefix A prefix to go in front of default messages. + */ + public function __construct( $descriptor, IContextSource $context = null, $messagePrefix = '' ) { + parent::__construct( $descriptor, $context, $messagePrefix ); + $this->displayFormat = 'div'; + } + + /** + * Get the whole body of the form, + * adding the global preferences help text to the top of each section. + * @return string + */ + function getBody() { + foreach ( array_keys( $this->mFieldTree ) as $section ) { + $secHeader = Html::element( + 'p', + [ 'class' => 'globalprefs-section-header' ], + wfMessage( 'globalprefs-section-header' ) + ); + $this->addHeaderText( $secHeader, $section ); + } + return parent::getBody(); + } + +} diff --git a/includes/Hooks.php b/includes/Hooks.php index 1f57698..282c67c 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -25,6 +25,8 @@ // @todo Should global edit count instead? 'editcount', 'registrationdate', + 'nickname', + 'fancysig', ]; /** @@ -202,27 +204,37 @@ // Just in case the user hasn't been loaded yet. Triggers User::loadOptions. $user->getOption( '' ); } + + $globalPrefs = []; foreach ( $prefs as $name => $info ) { - // FIXME: This whole code section sucks - if ( isset( $info['type'] ) - && substr( $name, -strlen( 'global' ) ) !== 'global' - && !isset( $prefs["$name-global"] ) - && !in_array( $info['type'], self::$badTypes ) - && !in_array( $name, self::$badPrefs ) - ) { - $prefs = wfArrayInsertAfter( $prefs, [ - "$name-global" => [ - 'type' => 'toggle', - 'label-message' => 'globalprefs-check-label', - 'default' => in_array( $name, $user->mGlobalPrefs ), - 'section' => $info['section'], - 'cssclass' => 'mw-globalprefs-global-check', - ] - ], $name ); - } elseif ( in_array( $name, self::$badPrefs ) ) { - $prefs[$name]['type'] = 'hidden'; + // Ignore unwanted preferences and types. + if ( ( isset($info['type'] ) && in_array( $info['type'], self::$badTypes ) ) + || in_array( $name, self::$badPrefs )) { + continue; } + + // Ignore this preference if it's already a global-toggle. + if ( substr( $name, -strlen( 'global' ) ) === 'global') { + continue; + } + + // Construct the new global preference. + $newPref = [ + 'type' => 'toggle', + 'label-message' => 'globalprefs-check-label', + 'default' => in_array( $name, $user->mGlobalPrefs ), + 'section' => $info['section'], + 'cssclass' => 'mw-globalprefs-global-check', + ]; + + // Insert new preference before this one. + $globalPrefs["$name-global"] = $newPref; + $globalPrefs[$name] = $info; + } + // $globalPrefs will now only contain pairs of wanted preferences. + $prefs = $globalPrefs; + } elseif ( GlobalPreferences::onLocalPrefsPage() ) { if ( !isset( $user->mGlobalPrefs ) ) { // Just in case the user hasn't been loaded yet. Triggers User::loadOptions. diff --git a/includes/SpecialGlobalPreferences.php b/includes/SpecialGlobalPreferences.php index 8c41fdf..6d93940 100644 --- a/includes/SpecialGlobalPreferences.php +++ b/includes/SpecialGlobalPreferences.php @@ -14,6 +14,14 @@ } /** + * Get the name of the preferences form class to use. + * @return string + */ + protected function getFormClass() { + return GlobalPreferencesForm::class; + } + + /** * Execute the special page. * @param null|string $par The subpage name, if any. * @throws ErrorPageError diff --git a/resources/ext.GlobalPreferences.special.css b/resources/ext.GlobalPreferences.special.css index ef5a087..f62a5b9 100644 --- a/resources/ext.GlobalPreferences.special.css +++ b/resources/ext.GlobalPreferences.special.css @@ -2,8 +2,5 @@ opacity: 0.5; } .globalprefs-hover { - background-color: rgba( 255, 224, 97, 0.4 ); -} -.mw-special-GlobalPreferences form.mw-htmlform table { - border-collapse: collapse; + background-color: rgb(255, 240, 221); } diff --git a/resources/ext.GlobalPreferences.special.js b/resources/ext.GlobalPreferences.special.js index 59658de..51e8b40 100644 --- a/resources/ext.GlobalPreferences.special.js +++ b/resources/ext.GlobalPreferences.special.js @@ -11,17 +11,20 @@ // Is this preference enabled globally? enabled = $( this ).prop( 'checked' ), - // The table rows relating to this preference - // (two or three rows, depending on whether there's a help row). + // This selector is required because there's no common class on these. + fieldSelector = '[class^="mw-htmlform-field-"]', + + // The form 'rows' (which are adjacent divs) relating to this preference + // (two or three rows, depending on whether there's a help row, all contained in $rows). $globalCheckRow, - $labelRow, + $mainFieldRow, $rows; // All the labels for this preference (not all have for=''). - $labels = $( 'label[for^=\'mw-input-' + name + '\']' ) - .closest( 'tr' ) + $labels = $( 'label[for^="mw-input-' + name + '"]' ) + .closest( fieldSelector ) .find( 'label' ) - .not( '[for$=\'-global\']' ); + .not( '[for$="-global"]' ); // Disable or enable the related preferences inputs. $( ':input[name=\'' + name + '\']' ).prop( 'disabled', !enabled ); @@ -31,17 +34,16 @@ $labels.addClass( 'globalprefs-disabled' ); } - // Collect the related rows. The latter two in the $rows array will often be the same element. - $globalCheckRow = $( this ).closest( 'tr' ); - $labelRow = $labels.closest( 'tr' ); - $rows = $( [ - $labelRow[ 0 ], - $labelRow.next()[ 0 ], - $globalCheckRow[ 0 ] - ] ); + // Collect the related rows. The main field row is sometimes followed by a help-tip row. + $globalCheckRow = $( this ).closest( fieldSelector ); + $mainFieldRow = $labels.closest( fieldSelector ); + $rows = $().add( $globalCheckRow ).add( $mainFieldRow ); + if ( $mainFieldRow.next().hasClass( 'htmlform-tip' ) ) { + $rows = $rows.add( $mainFieldRow.next() ); + } // Add a class on hover, to highlight the related rows. - $( this ).add( 'label[for=\'' + $( this ).attr( 'id' ) + '\']' ).hover( function () { + $( this ).add( 'label[for="' + $( this ).attr( 'id' ) + '"]' ).hover( function () { // Hover on. $rows.addClass( 'globalprefs-hover' ); }, function () { diff --git a/resources/ext.GlobalPreferences.special.nojs.css b/resources/ext.GlobalPreferences.special.nojs.css index 71deae3..87dfa42 100644 --- a/resources/ext.GlobalPreferences.special.nojs.css +++ b/resources/ext.GlobalPreferences.special.nojs.css @@ -1,6 +1,28 @@ -input.mw-globalprefs-global-check { - margin-left: 2em; + +.mw-htmlform-nolabel .mw-label { + display: none; } -tr.mw-globalprefs-global-check { + +.mw-globalprefs-global-check .mw-label, +.mw-globalprefs-global-check label { + display: none; +} + +.mw-htmlform-field-HTMLCheckField, +.mw-htmlform-field-HTMLSelectField, +.mw-htmlform-field-HTMLRadioField, +.mw-htmlform-field-HTMLFloatField, +.mw-htmlform-field-HTMLMultiSelectField, +.mw-htmlform-field-HTMLSelectOrOtherField { + padding-left: 10%; +} +.htmlform-tip { + padding-left: 10% !important; +} + +.mw-htmlform-field-HTMLCheckField.mw-globalprefs-global-check { font-size: smaller; + padding-left: 0; + float: left; + width: 8%; } -- To view, visit https://gerrit.wikimedia.org/r/370152 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3c10dfeacf02367e90f84a3e572ecf3f4048e02a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GlobalPreferences Gerrit-Branch: master Gerrit-Owner: Samwilson <s...@samwilson.id.au> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits