From: Dayllan Maza Date: Fri, 25 Jan 2019 04:45:11 +0000 (-0500) Subject: Add namespace restrictions to block's log messages X-Git-Tag: 1.34.0-rc.0~3001^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=85c91cfbf09d67955c7a1230e038187b1ee6fa85;p=lhc%2Fweb%2Fwiklou.git Add namespace restrictions to block's log messages Currently, there are 3 block messages: sitewide, partial with restrictions, and non-editing partial blocks. This will add namespace restrictions to the partial editing blocks message type. Bug: T204985 Change-Id: Ic17d5459e67c267fdee1fb2513d67428148ac85d --- diff --git a/includes/logging/BlockLogFormatter.php b/includes/logging/BlockLogFormatter.php index 6bc3f3969a..84cf0b2f4b 100644 --- a/includes/logging/BlockLogFormatter.php +++ b/includes/logging/BlockLogFormatter.php @@ -81,8 +81,30 @@ class BlockLogFormatter extends LogFormatter { return $this->makePageLink( Title::newFromText( ( $page ) ) ); }, $pages ); - $params[6] = Message::rawParam( $this->context->getLanguage()->listToText( $pages ) ); - $params[7] = count( $pages ); + $namespaces = $params[6]['namespaces'] ?? []; + $namespaces = array_map( function ( $ns ) { + $text = (int)$ns === NS_MAIN + ? $this->msg( 'blanknamespace' )->text() + : $this->context->getLanguage()->getFormattedNsText( $ns ); + $params = [ 'namespace' => $ns ]; + + return $this->makePageLink( SpecialPage::getTitleFor( 'Allpages' ), $params, $text ); + }, $namespaces ); + + $restrictions = []; + if ( $pages ) { + $restrictions[] = $this->msg( 'logentry-partialblock-block-page' ) + ->numParams( count( $pages ) ) + ->rawParams( $this->context->getLanguage()->listToText( $pages ) )->text(); + } + + if ( $namespaces ) { + $restrictions[] = $this->msg( 'logentry-partialblock-block-ns' ) + ->numParams( count( $namespaces ) ) + ->rawParams( $this->context->getLanguage()->listToText( $namespaces ) )->text(); + } + + $params[6] = Message::rawParam( $this->context->getLanguage()->listToText( $restrictions ) ); } } @@ -253,6 +275,10 @@ class BlockLogFormatter extends LogFormatter { ApiResult::setIndexedTagName( $ret['restrictions']['pages'], 'p' ); } + if ( isset( $ret['restrictions']['namespaces'] ) ) { + ApiResult::setIndexedTagName( $ret['restrictions']['namespaces'], 'ns' ); + } + return $ret; } diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 4fd263f664..bab3c8c5a3 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -980,10 +980,14 @@ class SpecialBlock extends FormSpecialPage { $logParams['6::flags'] = self::blockLogFlags( $data, $type ); $logParams['sitewide'] = $block->isSitewide(); - if ( $enablePartialBlocks && $data['PageRestrictions'] !== '' ) { - $logParams['7::restrictions'] = [ - 'pages' => explode( "\n", $data['PageRestrictions'] ), - ]; + if ( $enablePartialBlocks && !$block->isSitewide() ) { + if ( $data['PageRestrictions'] !== '' ) { + $logParams['7::restrictions']['pages'] = explode( "\n", $data['PageRestrictions'] ); + } + + if ( $data['NamespaceRestrictions'] !== '' ) { + $logParams['7::restrictions']['namespaces'] = explode( "\n", $data['NamespaceRestrictions'] ); + } } # Make log entry, if the name is hidden, put it in the suppression log diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 460095ab21..86da5d98d2 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3776,8 +3776,10 @@ "logentry-block-block": "$1 {{GENDER:$2|blocked}} {{GENDER:$4|$3}} with an expiration time of $5 $6", "logentry-block-unblock": "$1 {{GENDER:$2|unblocked}} {{GENDER:$4|$3}}", "logentry-block-reblock": "$1 {{GENDER:$2|changed}} block settings for {{GENDER:$4|$3}} with an expiration time of $5 $6", - "logentry-partialblock-block": "$1 {{GENDER:$2|blocked}} {{GENDER:$4|$3}} from editing {{PLURAL:$8||the pages}} $7 with an expiration time of $5 $6", - "logentry-partialblock-reblock": "$1 {{GENDER:$2|changed}} block settings for {{GENDER:$4|$3}} preventing edits on {{PLURAL:$8||the pages}} $7 with an expiration time of $5 $6", + "logentry-partialblock-block-page": "the {{PLURAL:$1|page|pages}} $2", + "logentry-partialblock-block-ns": "the {{PLURAL:$1|namespace|namespaces}} $2", + "logentry-partialblock-block": "$1 {{GENDER:$2|blocked}} {{GENDER:$4|$3}} from editing $7 with an expiration time of $5 $6", + "logentry-partialblock-reblock": "$1 {{GENDER:$2|changed}} block settings for {{GENDER:$4|$3}} preventing edits on $7 with an expiration time of $5 $6", "logentry-non-editing-block-block": "$1 {{GENDER:$2|blocked}} {{GENDER:$4|$3}} from specified non-editing actions with an expiration time of $5 $6", "logentry-non-editing-block-reblock": "$1 {{GENDER:$2|changed}} block settings for {{GENDER:$4|$3}} for specified non-editing actions with an expiration time of $5 $6", "logentry-suppress-block": "$1 {{GENDER:$2|blocked}} {{GENDER:$4|$3}} with an expiration time of $5 $6", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index a2f1c48758..58c2b9739d 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3981,8 +3981,10 @@ "logentry-block-block": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n\nCf. {{msg-mw|Blocklogentry}}", "logentry-block-unblock": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n\nCf. {{msg-mw|Unblocklogentry}}", "logentry-block-reblock": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n\nCf. {{msg-mw|Reblock-logentry}}", - "logentry-partialblock-block": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n* $7 - list of pages separated by a comma\n* $8 - total number of pages\n\nCf. {{msg-mw|Blocklogentry}}", - "logentry-partialblock-reblock": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n* $7 - list of pages separated by a comma\n* $8 - total number of pages\n\nCf. {{msg-mw|Reblock-logentry}}", + "logentry-partialblock-block-page": "Page portion of {{msg-mw|logentry-partialblock-block}}\n* $1 - number of pages\n* - $2 list of pages", + "logentry-partialblock-block-ns": "Namespace portion of {{msg-mw|logentry-partialblock-block}}\n* $1 - number of namespaces\n* - $2 list of namespaces", + "logentry-partialblock-block": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n* $7 - Restrictions list {{msg-mw|logentry-partialblock-page}} and/or {{msg-mw|logentry-partialblock-block-ns}}\n\nCf. {{msg-mw|Blocklogentry}}", + "logentry-partialblock-reblock": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n* $7 - Restrictions list{{msg-mw|logentry-partialblock-page}} and/or {{msg-mw|logentry-partialblock-block-ns}}\n\nCf. {{msg-mw|Reblock-logentry}}", "logentry-non-editing-block-block": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n\nCf. {{msg-mw|Blocklogentry}}", "logentry-non-editing-block-reblock": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n\nCf. {{msg-mw|Reblock-logentry}}", "logentry-suppress-block": "{{Logentry}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string", diff --git a/tests/phpunit/includes/logging/BlockLogFormatterTest.php b/tests/phpunit/includes/logging/BlockLogFormatterTest.php index 0041b9ce64..bc0ca2ad85 100644 --- a/tests/phpunit/includes/logging/BlockLogFormatterTest.php +++ b/tests/phpunit/includes/logging/BlockLogFormatterTest.php @@ -401,7 +401,8 @@ class BlockLogFormatterTest extends LogFormatterTestCase { 'api' => [ 'duration' => 'infinite', 'flags' => [ 'anononly' ], - 'restrictions' => [ 'pages' => [ + 'restrictions' => [ + 'pages' => [ [ 'page_ns' => 2, 'page_title' => 'User:Test1', @@ -415,6 +416,76 @@ class BlockLogFormatterTest extends LogFormatterTestCase { ], ], ], + [ + [ + 'type' => 'block', + 'action' => 'block', + 'comment' => 'Block comment', + 'user' => 0, + 'user_text' => 'Sysop', + 'namespace' => NS_USER, + 'title' => 'Logtestuser', + 'params' => [ + '5::duration' => 'infinite', + '6::flags' => 'anononly', + '7::restrictions' => [ + 'namespaces' => [ NS_USER ], + ], + 'sitewide' => false, + ], + ], + [ + 'text' => 'Sysop blocked Logtestuser from editing the namespace User' + . ' with an expiration time of indefinite (anonymous users only)', + 'api' => [ + 'duration' => 'infinite', + 'flags' => [ 'anononly' ], + 'restrictions' => [ + 'namespaces' => [ NS_USER ], + ], + 'sitewide' => false, + ], + ], + ], + [ + [ + 'type' => 'block', + 'action' => 'block', + 'comment' => 'Block comment', + 'user' => 0, + 'user_text' => 'Sysop', + 'namespace' => NS_USER, + 'title' => 'Logtestuser', + 'params' => [ + '5::duration' => 'infinite', + '6::flags' => 'anononly', + '7::restrictions' => [ + 'pages' => [ 'Main Page' ], + 'namespaces' => [ NS_USER, NS_MAIN ], + ], + 'sitewide' => false, + ], + ], + [ + 'text' => 'Sysop blocked Logtestuser from editing the page Main Page and the' + . ' namespaces User and (Main) with an expiration time of indefinite' + . ' (anonymous users only)', + 'api' => [ + 'duration' => 'infinite', + 'flags' => [ 'anononly' ], + 'restrictions' => [ + 'pages' => [ + [ + 'page_ns' => 0, + 'page_title' => 'Main Page', + ], + ], + 'namespaces' => [ NS_USER, NS_MAIN ], + ], + 'sitewide' => false, + ], + ], + ], [ [ 'type' => 'block',