Merge "Remove suggestions for negative namespaces in Page Restrictions"
[lhc/web/wiklou.git] / includes / specials / SpecialBlock.php
index 4fd263f..0b37910 100644 (file)
@@ -148,7 +148,6 @@ class SpecialBlock extends FormSpecialPage {
                $suggestedDurations = self::getSuggestedDurations();
 
                $conf = $this->getConfig();
-               $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD;
                $enablePartialBlocks = $conf->get( 'EnablePartialBlocks' );
 
                $a = [];
@@ -178,8 +177,8 @@ class SpecialBlock extends FormSpecialPage {
                                'type' => 'radio',
                                'cssclass' => 'mw-block-editing-restriction',
                                'options' => [
-                                       $this->msg( 'ipb-sitewide' )->text() => 'sitewide',
-                                       $this->msg( 'ipb-partial' )->text() => 'partial',
+                                       $this->msg( 'ipb-sitewide' )->escaped() => 'sitewide',
+                                       $this->msg( 'ipb-partial' )->escaped() => 'partial',
                                ],
                                'section' => 'actions',
                        ];
@@ -190,6 +189,7 @@ class SpecialBlock extends FormSpecialPage {
                                'max' => 10,
                                'cssclass' => 'mw-block-restriction',
                                'showMissing' => false,
+                               'excludeDynamicNamespaces' => true,
                                'input' => [
                                        'autocomplete' => false
                                ],
@@ -243,8 +243,8 @@ class SpecialBlock extends FormSpecialPage {
                        'type' => 'selectandother',
                        // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
                        // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
-                       // Unicode codepoints (or 255 UTF-8 bytes for old schema).
-                       'maxlength' => $oldCommentSchema ? 255 : CommentStore::COMMENT_CHARACTER_LIMIT,
+                       // Unicode codepoints.
+                       'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
                        'maxlength-unit' => 'codepoints',
                        'options-message' => 'ipbreason-dropdown',
                        'section' => 'reason',
@@ -406,7 +406,9 @@ class SpecialBlock extends FormSpecialPage {
                                foreach ( $block->getRestrictions() as $restriction ) {
                                        switch ( $restriction->getType() ) {
                                                case PageRestriction::TYPE:
-                                                       $pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
+                                                       if ( $restriction->getTitle() ) {
+                                                               $pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
+                                                       }
                                                        break;
                                                case NamespaceRestriction::TYPE:
                                                        $namespaceRestrictions[] = $restriction->getValue();
@@ -739,6 +741,9 @@ class SpecialBlock extends FormSpecialPage {
 
                $performer = $context->getUser();
                $enablePartialBlocks = $context->getConfig()->get( 'EnablePartialBlocks' );
+               $isPartialBlock = $enablePartialBlocks &&
+                       isset( $data['EditingRestriction'] ) &&
+                       $data['EditingRestriction'] === 'partial';
 
                // Handled by field validator callback
                // self::validateTargetField( $data['Target'] );
@@ -816,6 +821,10 @@ class SpecialBlock extends FormSpecialPage {
                                return [ 'badaccess-group0' ];
                        }
 
+                       if ( $isPartialBlock ) {
+                               return [ 'ipb_hide_partial' ];
+                       }
+
                        # Recheck params here...
                        if ( $type != Block::TYPE_USER ) {
                                $data['HideUser'] = false; # IP users should not be hidden
@@ -847,12 +856,8 @@ class SpecialBlock extends FormSpecialPage {
                $block->isAutoblocking( $data['AutoBlock'] );
                $block->mHideName = $data['HideUser'];
 
-               if (
-                       $enablePartialBlocks &&
-                       isset( $data['EditingRestriction'] ) &&
-                       $data['EditingRestriction'] === 'partial'
-                ) {
-                        $block->isSitewide( false );
+               if ( $isPartialBlock ) {
+                       $block->isSitewide( false );
                }
 
                $reason = [ 'hookaborted' ];
@@ -868,7 +873,7 @@ class SpecialBlock extends FormSpecialPage {
                                        $title = Title::newFromText( $text );
                                        // Use the link cache since the title has already been loaded when
                                        // the field was validated.
-                                       $restriction = new PageRestriction( 0, $title->getArticleId() );
+                                       $restriction = new PageRestriction( 0, $title->getArticleID() );
                                        $restriction->setTitle( $title );
                                        return $restriction;
                                }, explode( "\n", $data['PageRestrictions'] ) );
@@ -980,10 +985,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