MediaWiki  master
SpecialAutoblockList.php
Go to the documentation of this file.
1 <?php
24 namespace MediaWiki\Specials;
25 
26 use BlockListPager;
27 use HTMLForm;
35 use SpecialPage;
37 
45 
47  private $linkBatchFactory;
48 
50  private $blockRestrictionStore;
51 
53  private $dbProvider;
54 
56  private $commentStore;
57 
59  private $blockUtils;
60 
62  private $blockActionInfo;
63 
65  private $rowCommentFormatter;
66 
76  public function __construct(
77  LinkBatchFactory $linkBatchFactory,
78  BlockRestrictionStore $blockRestrictionStore,
79  IConnectionProvider $dbProvider,
80  CommentStore $commentStore,
81  BlockUtils $blockUtils,
82  BlockActionInfo $blockActionInfo,
83  RowCommentFormatter $rowCommentFormatter
84  ) {
85  parent::__construct( 'AutoblockList' );
86 
87  $this->linkBatchFactory = $linkBatchFactory;
88  $this->blockRestrictionStore = $blockRestrictionStore;
89  $this->dbProvider = $dbProvider;
90  $this->commentStore = $commentStore;
91  $this->blockUtils = $blockUtils;
92  $this->blockActionInfo = $blockActionInfo;
93  $this->rowCommentFormatter = $rowCommentFormatter;
94  }
95 
99  public function execute( $par ) {
100  $this->setHeaders();
101  $this->outputHeader();
102  $out = $this->getOutput();
103  $out->setPageTitle( $this->msg( 'autoblocklist' ) );
104  $this->addHelpLink( 'Autoblock' );
105  $out->addModuleStyles( [ 'mediawiki.special' ] );
106 
107  # setup BlockListPager here to get the actual default Limit
108  $pager = $this->getBlockListPager();
109 
110  # Just show the block list
111  $fields = [
112  'Limit' => [
113  'type' => 'limitselect',
114  'label-message' => 'table_pager_limit_label',
115  'options' => $pager->getLimitSelectList(),
116  'name' => 'limit',
117  'default' => $pager->getLimit(),
118  ]
119  ];
120 
121  $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
122  $form->setMethod( 'get' )
123  ->setTitle( $this->getPageTitle() ) // Remove subpage
124  ->setFormIdentifier( 'blocklist' )
125  ->setWrapperLegendMsg( 'autoblocklist-legend' )
126  ->setSubmitTextMsg( 'autoblocklist-submit' )
127  ->prepareForm()
128  ->displayForm( false );
129 
130  $this->showTotal( $pager );
131  $this->showList( $pager );
132  }
133 
138  protected function getBlockListPager() {
139  $conds = [
140  'ipb_parent_block_id IS NOT NULL',
141  // ipb_parent_block_id <> 0 because of T282890
142  'ipb_parent_block_id <> 0',
143  ];
144  # Is the user allowed to see hidden blocks?
145  if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
146  $conds['ipb_deleted'] = 0;
147  }
148 
149  return new BlockListPager(
150  $this->getContext(),
151  $this->blockActionInfo,
152  $this->blockRestrictionStore,
153  $this->blockUtils,
154  $this->commentStore,
155  $this->linkBatchFactory,
156  $this->getLinkRenderer(),
157  $this->dbProvider,
158  $this->rowCommentFormatter,
159  $this->getSpecialPageFactory(),
160  $conds
161  );
162  }
163 
169  protected function showTotal( BlockListPager $pager ) {
170  $out = $this->getOutput();
171  $out->addHTML(
172  Html::rawElement( 'div', [ 'style' => 'font-weight: bold;' ],
173  $this->msg( 'autoblocklist-total-autoblocks', $pager->getTotalAutoblocks() )->parse() )
174  . "\n"
175  );
176  }
177 
182  protected function showList( BlockListPager $pager ) {
183  $out = $this->getOutput();
184 
185  # Check for other blocks, i.e. global/tor blocks
186  $otherAutoblockLink = [];
187  $this->getHookRunner()->onOtherAutoblockLogLink( $otherAutoblockLink );
188 
189  # Show additional header for the local block only when other blocks exists.
190  # Not necessary in a standard installation without such extensions enabled
191  if ( count( $otherAutoblockLink ) ) {
192  $out->addHTML(
193  Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
194  $pager->getNumRows() )->parse() )
195  . "\n"
196  );
197  }
198 
199  if ( $pager->getNumRows() ) {
200  $out->addParserOutputContent( $pager->getFullOutput() );
201  } else {
202  $out->addWikiMsg( 'autoblocklist-empty' );
203  }
204 
205  if ( count( $otherAutoblockLink ) ) {
206  $out->addHTML(
208  'h2',
209  [],
210  $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
211  ) . "\n"
212  );
213  $list = '';
214  foreach ( $otherAutoblockLink as $link ) {
215  $list .= Html::rawElement( 'li', [], $link ) . "\n";
216  }
217  $out->addHTML(
219  'ul',
220  [ 'class' => 'mw-autoblocklist-otherblocks' ],
221  $list
222  ) . "\n"
223  );
224  }
225  }
226 
227  protected function getGroupName() {
228  return 'users';
229  }
230 }
231 
235 class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );
getTotalAutoblocks()
Get total number of autoblocks at any given time.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:155
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:354
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:729
Defines the actions that can be blocked by a partial block.
Backend class for blocking utils.
Definition: BlockUtils.php:46
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
Handle database storage of comments such as edit summaries and log reasons.
This class is a collection of static functions that serve two purposes:
Definition: Html.php:55
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:219
A special page that lists autoblocks.
getBlockListPager()
Setup a new BlockListPager instance.
showList(BlockListPager $pager)
Show the list of blocked accounts matching the actual filter.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(LinkBatchFactory $linkBatchFactory, BlockRestrictionStore $blockRestrictionStore, IConnectionProvider $dbProvider, CommentStore $commentStore, BlockUtils $blockUtils, BlockActionInfo $blockActionInfo, RowCommentFormatter $rowCommentFormatter)
showTotal(BlockListPager $pager)
Show total number of autoblocks on top of the table.
Parent class for all special pages.
Definition: SpecialPage.php:45
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getFullOutput()
Get the formatted result list, with navigation bars.
Definition: TablePager.php:108
Provide primary and replica IDatabase connections.