From: Dayllan Maza Date: Mon, 3 Dec 2018 13:20:47 +0000 (-0500) Subject: Add new rules when user is blocked for UTP X-Git-Tag: 1.34.0-rc.0~3281^2 X-Git-Url: http://git.cyclocoop.org/data/%7BGarradin/WEBSITE%7D?a=commitdiff_plain;h=05a5b8e749ff751c7ebba39fe1399a771c1fdafa;p=lhc%2Fweb%2Fwiklou.git Add new rules when user is blocked for UTP 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 --- diff --git a/includes/Block.php b/includes/Block.php index eb8214bae1..ec8cae80a5 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -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; diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0acce58339..a63d35212c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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; diff --git a/includes/user/User.php b/includes/user/User.php index 0e0494648b..f15df06612 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -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 ); diff --git a/resources/src/mediawiki.special.block.js b/resources/src/mediawiki.special.block.js index 441b1d6073..255b878adf 100644 --- a/resources/src/mediawiki.special.block.js +++ b/resources/src/mediawiki.special.block.js @@ -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() { @@ -49,6 +50,17 @@ 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 ) { diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index b9289dba52..4f8a7da3af 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -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, + ] + ], ]; }