Add namespace restrictions to block's log messages
authorDayllan Maza <dmaza@wikimedia.org>
Fri, 25 Jan 2019 04:45:11 +0000 (23:45 -0500)
committerDayllan Maza <dmaza@wikimedia.org>
Fri, 25 Jan 2019 20:46:11 +0000 (15:46 -0500)
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

includes/logging/BlockLogFormatter.php
includes/specials/SpecialBlock.php
languages/i18n/en.json
languages/i18n/qqq.json
tests/phpunit/includes/logging/BlockLogFormatterTest.php

index 6bc3f39..84cf0b2 100644 (file)
@@ -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;
        }
 
index 4fd263f..bab3c8c 100644 (file)
@@ -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
index 460095a..86da5d9 100644 (file)
        "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",
index a2f1c48..58c2b97 100644 (file)
        "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",
index 0041b9c..bc0ca2a 100644 (file)
@@ -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',