Add new rules when user is blocked for UTP
authorDayllan Maza <dmaza@wikimedia.org>
Mon, 3 Dec 2018 13:20:47 +0000 (08:20 -0500)
committerDayllan Maza <dmaza@wikimedia.org>
Tue, 11 Dec 2018 05:01:29 +0000 (00:01 -0500)
No changes for sitewide blocks when "Prevent user... edit own talk page"
is checked. On partial blocks, this option will be disabled and ignored. All users
will be allowed to edit their own talk page unless a page restriction
for their page is in place.

New rules will be implemented for Namespace restrictions in a different
patch when Namespace blocking is ready.

Bug: T210475
Change-Id: I096edf2887441bccd59f09bf0eceb3988b36db1e

includes/Block.php
includes/DefaultSettings.php
includes/user/User.php
resources/src/mediawiki.special.block.js
tests/phpunit/includes/user/UserTest.php

index eb8214b..ec8cae8 100644 (file)
@@ -1168,7 +1168,12 @@ class Block {
                                $res = $this->isSitewide();
                                break;
                        case 'editownusertalk':
+                               // NOTE: this check is not reliable on partial blocks
+                               // since partially blocked users are always allowed to edit
+                               // their own talk page unless a restriction exists on the
+                               // page or User_talk: namespace
                                $res = wfSetVar( $this->mDisableUsertalk, $x );
+
                                // edit own user talk can be disabled by config
                                if ( !$blockAllowsUTEdit ) {
                                        $res = true;
index 0acce58..a63d352 100644 (file)
@@ -4975,6 +4975,10 @@ $wgAutoblockExpiry = 86400;
 
 /**
  * Set this to true to allow blocked users to edit their own user talk page.
+ *
+ * This only applies to sitewide blocks. Partial blocks always allow users to
+ * edit their own user talk page unless otherwise specified in the block
+ * restrictions.
  */
 $wgBlockAllowsUTEdit = true;
 
index 0e04946..f15df06 100644 (file)
@@ -2311,9 +2311,10 @@ class User implements IDBAccessObject, UserIdentity {
                                        if ( $block->isSitewide() ) {
                                                $blocked = $block->prevents( 'editownusertalk' );
                                        } else {
-                                               // If the block is partial, then only a true value is honored,
-                                               // otherwise fallback to the partial block settings.
-                                               $blocked = $block->prevents( 'editownusertalk' ) ?: $block->appliesToTitle( $title );
+                                               // If the block is partial, ignore 'editownusertalk' unless
+                                               // there is a restriction on the user talk namespace.
+                                               // TODO: To be implemented with Namespace restrictions
+                                               $blocked = $block->appliesToTitle( $title );
                                        }
                                } else {
                                        $blocked = $block->appliesToTitle( $title );
index 441b1d6..255b878 100644 (file)
@@ -20,6 +20,7 @@
                        watchUserField = infuseIfExists( $( '#mw-input-wpWatch' ).closest( '.oo-ui-fieldLayout' ) ),
                        expiryWidget = infuseIfExists( $( '#mw-input-wpExpiry' ) ),
                        editingRestrictionWidget = infuseIfExists( $( '#mw-input-wpEditingRestriction' ) ),
+                       preventTalkPageEdit = infuseIfExists( $( '#mw-input-wpDisableUTEdit' ) ),
                        pageRestrictionsWidget = infuseIfExists( $( '#mw-input-wpPageRestrictions' ) );
 
                function updateBlockOptions() {
                        if ( pageRestrictionsWidget ) {
                                pageRestrictionsWidget.setDisabled( editingRestrictionValue === 'sitewide' );
                        }
+                       if ( preventTalkPageEdit ) {
+                               // TODO: (T210475) this option is disabled for partial blocks unless
+                               // a namespace restriction for User_talk namespace is in place.
+                               // This needs to be updated once Namespace restrictions is available
+                               if ( editingRestrictionValue === 'partial' ) {
+                                       preventTalkPageEdit.setDisabled( true );
+                               } else {
+                                       preventTalkPageEdit.setDisabled( false );
+                               }
+                       }
+
                }
 
                if ( blockTargetWidget ) {
index b9289db..4f8a7da 100644 (file)
@@ -1268,34 +1268,56 @@ class UserTest extends MediaWikiTestCase {
                return [
                        'Basic operation' => [ 'Test page', true ],
                        'User talk page, not allowed' => [ self::USER_TALK_PAGE, true, [
-                               'allowUsertalk' => false,
-                       ] ],
-                       'User talk page, allowed' => [ self::USER_TALK_PAGE, false, [
-                               'allowUsertalk' => true,
-                       ] ],
-                       'User talk page, allowed but $wgBlockAllowsUTEdit is false' => [ self::USER_TALK_PAGE, true, [
-                               'allowUsertalk' => true,
-                               'blockAllowsUTEdit' => false,
-                       ] ],
-
-                       'Partial block, blocking the page' => [ 'Test page', true, [
-                               'pageRestrictions' => [ 'Test page' ],
-                       ] ],
-                       'Partial block, not blocking the page' => [ 'Test page 2', false, [
-                               'pageRestrictions' => [ 'Test page' ],
-                       ] ],
-                       'Partial block, overriding allowUsertalk' => [ self::USER_TALK_PAGE, true, [
-                               'allowUsertalk' => false,
-                               'pageRestrictions' => [ self::USER_TALK_PAGE ],
-                       ] ],
-                       'Partial block, allowing user talk' => [ self::USER_TALK_PAGE, false, [
-                               'allowUsertalk' => true,
-                               'pageRestrictions' => [ 'Test page' ],
-                       ] ],
-                       'Partial block, not allowing user talk' => [ self::USER_TALK_PAGE, true, [
-                               'allowUsertalk' => false,
-                               'pageRestrictions' => [ 'Test page' ],
-                       ] ],
+                                       'allowUsertalk' => false,
+                               ]
+                       ],
+                       'User talk page, allowed' => [
+                                       self::USER_TALK_PAGE, false, [
+                                       'allowUsertalk' => true,
+                               ]
+                       ],
+                       'User talk page, allowed but $wgBlockAllowsUTEdit is false' => [
+                               self::USER_TALK_PAGE, true, [
+                                       'allowUsertalk' => true,
+                                       'blockAllowsUTEdit' => false,
+                               ]
+                       ],
+                       'Partial block, blocking the page' => [
+                               'Test page', true, [
+                                       'pageRestrictions' => [ 'Test page' ],
+                               ]
+                       ],
+                       'Partial block, not blocking the page' => [
+                               'Test page 2', false, [
+                                       'pageRestrictions' => [ 'Test page' ],
+                               ]
+                       ],
+                       'Partial block, allowing user talk' => [
+                               self::USER_TALK_PAGE, false, [
+                                       'allowUsertalk' => false,
+                                       'pageRestrictions' => [ 'Test page' ],
+                               ]
+                       ],
+                       'Partial block, not allowing user talk' => [
+                               self::USER_TALK_PAGE, true, [
+                                       'allowUsertalk' => true,
+                                       'pageRestrictions' => [ self::USER_TALK_PAGE ],
+                               ]
+                       ],
+                       'Partial block, allowing user talk but $wgBlockAllowsUTEdit is false' => [
+                               self::USER_TALK_PAGE, false, [
+                                       'allowUsertalk' => false,
+                                       'pageRestrictions' => [ 'Test page' ],
+                                       'blockAllowsUTEdit' => false,
+                               ]
+                       ],
+                       'Partial block, not allowing user talk with $wgBlockAllowsUTEdit set to false' => [
+                               self::USER_TALK_PAGE, true, [
+                                       'allowUsertalk' => true,
+                                       'pageRestrictions' => [ self::USER_TALK_PAGE ],
+                                       'blockAllowsUTEdit' => false,
+                               ]
+                       ],
                ];
        }