Avoid duplicate IDs on Special:Preferences
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 5 Jul 2018 18:35:03 +0000 (20:35 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 5 Jul 2018 18:38:09 +0000 (20:38 +0200)
The value of the 'section' parameter is used to generate some ID
attributes on Special:Preferences. Awkwardly, only the second part
(after the slash) is used, so have to ensure these are unique.

It is also used for the default localisation message for the title of
the section. Override this so that we don't have to rename and
duplicate the messages.

Bug: T198875
Change-Id: I0f22aafc8b2ad860dd42c5373eafdf88e848e3ad

includes/preferences/DefaultPreferencesFactory.php
includes/specials/forms/PreferencesFormLegacy.php
includes/specials/forms/PreferencesFormOOUI.php

index 03e4bdb..bcd15b3 100644 (file)
@@ -1080,7 +1080,7 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                if ( $this->config->get( 'StructuredChangeFiltersShowPreference' ) ) {
                        $defaultPreferences['rcenhancedfilters-disable'] = [
                                'type' => 'toggle',
-                               'section' => 'rc/opt-out',
+                               'section' => 'rc/optoutrc',
                                'label-message' => 'rcfilters-preference-label',
                                'help-message' => 'rcfilters-preference-help',
                        ];
@@ -1283,7 +1283,7 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                if ( $this->config->get( 'StructuredChangeFiltersShowWatchlistPreference' ) ) {
                        $defaultPreferences['wlenhancedfilters-disable'] = [
                                'type' => 'toggle',
-                               'section' => 'watchlist/opt-out',
+                               'section' => 'watchlist/optoutwatchlist',
                                'label-message' => 'rcfilters-watchlist-preference-label',
                                'help-message' => 'rcfilters-watchlist-preference-help',
                        ];
index cae895f..c1f1026 100644 (file)
@@ -130,7 +130,8 @@ class PreferencesFormLegacy extends HTMLForm {
         * @return string
         */
        function getLegend( $key ) {
-               $legend = parent::getLegend( $key );
+               $aliasKey = ( $key === 'optoutwatchlist' || $key === 'optoutrc' ) ? 'opt-out' : $key;
+               $legend = parent::getLegend( $aliasKey );
                Hooks::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
                return $legend;
        }
index 423e2bb..cfa8f8f 100644 (file)
@@ -227,7 +227,8 @@ class PreferencesFormOOUI extends OOUIHTMLForm {
         * @return string
         */
        function getLegend( $key ) {
-               $legend = parent::getLegend( $key );
+               $aliasKey = ( $key === 'optoutwatchlist' || $key === 'optoutrc' ) ? 'opt-out' : $key;
+               $legend = parent::getLegend( $aliasKey );
                Hooks::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
                return $legend;
        }