Add a user preference to opt in or out of a confirmation prompt for rollbacks.
authortzhelyazkova <tonina.zhelyazkova@wikimedia.de>
Tue, 19 Feb 2019 13:37:14 +0000 (14:37 +0100)
committertzhelyazkova <tonina.zhelyazkova@wikimedia.de>
Wed, 6 Mar 2019 15:44:09 +0000 (16:44 +0100)
This should not be visible on production until the feature of rollback confirmation prompt has been deployed.

Bug: T199537

Change-Id: I8a49143f662b8412f74c06627c2285ab3c3b8cff

includes/preferences/DefaultPreferencesFactory.php
languages/i18n/en.json
languages/i18n/qqq.json
tests/phpunit/includes/preferences/DefaultPreferencesFactoryTest.php

index 512a6b3..7c0e88b 100644 (file)
@@ -121,7 +121,7 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                $this->skinPreferences( $user, $context, $preferences );
                $this->datetimePreferences( $user, $context, $preferences );
                $this->filesPreferences( $context, $preferences );
-               $this->renderingPreferences( $context, $preferences );
+               $this->renderingPreferences( $user, $context, $preferences );
                $this->editingPreferences( $user, $context, $preferences );
                $this->rcPreferences( $user, $context, $preferences );
                $this->watchlistPreferences( $user, $context, $preferences );
@@ -801,10 +801,15 @@ class DefaultPreferencesFactory implements PreferencesFactory {
        }
 
        /**
+        * @param User $user
         * @param MessageLocalizer $l10n
         * @param array &$defaultPreferences
         */
-       protected function renderingPreferences( MessageLocalizer $l10n, &$defaultPreferences ) {
+       protected function renderingPreferences(
+               User $user,
+               MessageLocalizer $l10n,
+               &$defaultPreferences
+       ) {
                # # Diffs ####################################
                $defaultPreferences['diffonly'] = [
                        'type' => 'toggle',
@@ -859,6 +864,14 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                        'section' => 'rendering/advancedrendering',
                        'label-message' => 'tog-numberheadings',
                ];
+
+               if ( $user->isAllowed( 'rollback' ) ) {
+                       $defaultPreferences['showrollbackconfirmation'] = [
+                               'type' => 'toggle',
+                               'section' => 'rendering/advancedrendering',
+                               'label-message' => 'tog-showrollbackconfirmation',
+                       ];
+               }
        }
 
        /**
index c371cc2..118bf32 100644 (file)
@@ -46,6 +46,7 @@
        "tog-norollbackdiff": "Don't show diff after performing a rollback",
        "tog-useeditwarning": "Warn me when I leave an edit page with unsaved changes",
        "tog-prefershttps": "Always use a secure connection while logged in",
+       "tog-showrollbackconfirmation": "Show a confirmation prompt when clicking on a rollback link",
        "underline-always": "Always",
        "underline-never": "Never",
        "underline-default": "Skin or browser default",
index 6860220..60fdf43 100644 (file)
        "tog-norollbackdiff": "Option in [[Special:Preferences]], 'Misc' tab. Only shown for users with the rollback right. By default a diff is shown below the return screen of a rollback. Checking this preference toggle will suppress that. {{Gender}}\n{{Identical|Rollback}}",
        "tog-useeditwarning": "Used as label for the checkbox in [[Special:Preferences#mw-prefsection-editing|Special:Preferences]].",
        "tog-prefershttps": "Toggle option used in [[Special:Preferences]] that indicates if the user wants to use a secure connection when logged in",
+       "tog-showrollbackconfirmation": "Toggle option used in [[Special:Preferences]] to enable/disable rollback confirmation prompt. Should be visible only to users with rollback rights",
        "underline-always": "Used in [[Special:Preferences#mw-prefsection-rendering|Preferences]].\n\nThis option means \"always underline links\", there are also options {{msg-mw|Underline-never}} and {{msg-mw|Underline-default}}.\n\n{{Gender}}\n{{Identical|Always}}",
        "underline-never": "Used in [[Special:Preferences#mw-prefsection-rendering|Preferences]].\n\nThis option means \"never underline links\", there are also options {{msg-mw|Underline-always}} and {{msg-mw|Underline-default}}.\n\n{{Gender}}\n{{Identical|Never}}",
        "underline-default": "Used in [[Special:Preferences#mw-prefsection-rendering|Preferences]].\n\nThis option means \"underline links as in your user skin or your browser\", there are also options {{msg-mw|Underline-never}} and {{msg-mw|Underline-always}}.\n\n{{Gender}}\n{{Identical|Browser default}}",
index 2eec5ce..94c0667 100644 (file)
@@ -27,7 +27,7 @@ use Wikimedia\TestingAccessWrapper;
 /**
  * @group Preferences
  */
-class DefaultPreferencesFactoryTest extends MediaWikiTestCase {
+class DefaultPreferencesFactoryTest extends \MediaWikiTestCase {
 
        /** @var IContextSource */
        protected $context;
@@ -83,6 +83,50 @@ class DefaultPreferencesFactoryTest extends MediaWikiTestCase {
                $this->assertEquals( $cssClass, $prefs['emailauthentication']['cssclass'] );
        }
 
+       /**
+        * @covers MediaWiki\Preferences\DefaultPreferencesFactory::renderingPreferences()
+        */
+       public function testShowRollbackConfIsHiddenForUsersWithoutRollbackRights() {
+               $userMock = $this->getMockBuilder( User::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $userMock->method( 'isAllowed' )
+                       ->willReturn( false );
+               $userMock->method( 'getEffectiveGroups' )
+                       ->willReturn( [] );
+               $userMock->method( 'getGroupMemberships' )
+                       ->willReturn( [] );
+               $userMock->method( 'getOptions' )
+                       ->willReturn( [ 'test' => 'yes' ] );
+
+               $prefs = $this->getPreferencesFactory()->getFormDescriptor( $userMock, $this->context );
+               $this->assertArrayNotHasKey( 'showrollbackconfirmation', $prefs );
+       }
+
+       /**
+        * @covers MediaWiki\Preferences\DefaultPreferencesFactory::renderingPreferences()
+        */
+       public function testShowRollbackConfIsShownForUsersWithRollbackRights() {
+               $userMock = $this->getMockBuilder( User::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $userMock->method( 'isAllowed' )
+                       ->willReturn( true );
+               $userMock->method( 'getEffectiveGroups' )
+                       ->willReturn( [] );
+               $userMock->method( 'getGroupMemberships' )
+                       ->willReturn( [] );
+               $userMock->method( 'getOptions' )
+                       ->willReturn( [ 'test' => 'yes' ] );
+
+               $prefs = $this->getPreferencesFactory()->getFormDescriptor( $userMock, $this->context );
+               $this->assertArrayHasKey( 'showrollbackconfirmation', $prefs );
+               $this->assertEquals(
+                       'rendering/advancedrendering',
+                       $prefs['showrollbackconfirmation']['section']
+               );
+       }
+
        public function emailAuthenticationProvider() {
                $userNoEmail = new User;
                $userEmailUnauthed = new User;