This should not be visible on production until the feature of rollback confirmation prompt has been deployed.
Bug: T199537
Change-Id: I8a49143f662b8412f74c06627c2285ab3c3b8cff
$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 );
}
/**
+ * @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',
'section' => 'rendering/advancedrendering',
'label-message' => 'tog-numberheadings',
];
+
+ if ( $user->isAllowed( 'rollback' ) ) {
+ $defaultPreferences['showrollbackconfirmation'] = [
+ 'type' => 'toggle',
+ 'section' => 'rendering/advancedrendering',
+ 'label-message' => 'tog-showrollbackconfirmation',
+ ];
+ }
}
/**
"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",
"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}}",
/**
* @group Preferences
*/
-class DefaultPreferencesFactoryTest extends MediaWikiTestCase {
+class DefaultPreferencesFactoryTest extends \MediaWikiTestCase {
/** @var IContextSource */
protected $context;
$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;