Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / includes / specials / SpecialBlockList.php
index fd27fdc..9f7381c 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\Block\DatabaseBlock;
+
 /**
  * A special page that lists existing blocks
  *
@@ -31,6 +33,8 @@ class SpecialBlockList extends SpecialPage {
 
        protected $options;
 
+       protected $blockType;
+
        function __construct() {
                parent::__construct( 'BlockList' );
        }
@@ -50,6 +54,7 @@ class SpecialBlockList extends SpecialPage {
                $this->target = trim( $request->getVal( 'wpTarget', $par ) );
 
                $this->options = $request->getArray( 'wpOptions', [] );
+               $this->blockType = $request->getVal( 'blockType' );
 
                $action = $request->getText( 'action' );
 
@@ -83,14 +88,33 @@ class SpecialBlockList extends SpecialPage {
                                ],
                                'flatlist' => true,
                        ],
-                       'Limit' => [
-                               'type' => 'limitselect',
-                               'label-message' => 'table_pager_limit_label',
-                               'options' => $pager->getLimitSelectList(),
-                               'name' => 'limit',
-                               'default' => $pager->getLimit(),
-                       ],
                ];
+
+               if ( $this->getConfig()->get( 'EnablePartialBlocks' ) ) {
+                       $fields['BlockType'] = [
+                               'type' => 'select',
+                               'label-message' => 'blocklist-type',
+                               'options' => [
+                                       $this->msg( 'blocklist-type-opt-all' )->escaped() => '',
+                                       $this->msg( 'blocklist-type-opt-sitewide' )->escaped() => 'sitewide',
+                                       $this->msg( 'blocklist-type-opt-partial' )->escaped() => 'partial',
+                               ],
+                               'name' => 'blockType',
+                               'cssclass' => 'mw-field-block-type',
+                       ];
+               }
+
+               $fields['Limit'] = [
+                       'type' => 'limitselect',
+                       'label-message' => 'table_pager_limit_label',
+                       'options' => $pager->getLimitSelectList(),
+                       'name' => 'limit',
+                       'default' => $pager->getLimit(),
+                       'cssclass' => $this->getConfig()->get( 'EnablePartialBlocks' ) ?
+                               'mw-field-limit mw-has-field-block-type' :
+                               'mw-field-limit',
+               ];
+
                $context = new DerivativeContext( $this->getContext() );
                $context->setTitle( $this->getPageTitle() ); // Remove subpage
                $form = HTMLForm::factory( 'ooui', $fields, $context );
@@ -117,28 +141,28 @@ class SpecialBlockList extends SpecialPage {
                }
 
                if ( $this->target !== '' ) {
-                       list( $target, $type ) = Block::parseTarget( $this->target );
+                       list( $target, $type ) = DatabaseBlock::parseTarget( $this->target );
 
                        switch ( $type ) {
-                               case Block::TYPE_ID:
-                               case Block::TYPE_AUTO:
+                               case DatabaseBlock::TYPE_ID:
+                               case DatabaseBlock::TYPE_AUTO:
                                        $conds['ipb_id'] = $target;
                                        break;
 
-                               case Block::TYPE_IP:
-                               case Block::TYPE_RANGE:
+                               case DatabaseBlock::TYPE_IP:
+                               case DatabaseBlock::TYPE_RANGE:
                                        list( $start, $end ) = IP::parseRange( $target );
                                        $conds[] = wfGetDB( DB_REPLICA )->makeList(
                                                [
                                                        'ipb_address' => $target,
-                                                       Block::getRangeCond( $start, $end )
+                                                       DatabaseBlock::getRangeCond( $start, $end )
                                                ],
                                                LIST_OR
                                        );
                                        $conds['ipb_auto'] = 0;
                                        break;
 
-                               case Block::TYPE_USER:
+                               case DatabaseBlock::TYPE_USER:
                                        $conds['ipb_address'] = $target->getName();
                                        $conds['ipb_auto'] = 0;
                                        break;
@@ -159,6 +183,12 @@ class SpecialBlockList extends SpecialPage {
                        $conds[] = "ipb_range_end = ipb_range_start";
                }
 
+               if ( $this->blockType === 'sitewide' ) {
+                       $conds[] = 'ipb_sitewide = 1';
+               } elseif ( $this->blockType === 'partial' ) {
+                       $conds[] = 'ipb_sitewide = 0';
+               }
+
                return new BlockListPager( $this, $conds );
        }