MediaWiki  master
SpecialAutoblockList.php
Go to the documentation of this file.
1 <?php
30 
38 
40  private $linkBatchFactory;
41 
43  private $blockRestrictionStore;
44 
46  private $loadBalancer;
47 
49  private $commentStore;
50 
52  private $blockUtils;
53 
55  private $blockActionInfo;
56 
58  private $rowCommentFormatter;
59 
69  public function __construct(
70  LinkBatchFactory $linkBatchFactory,
71  BlockRestrictionStore $blockRestrictionStore,
72  ILoadBalancer $loadBalancer,
73  CommentStore $commentStore,
74  BlockUtils $blockUtils,
75  BlockActionInfo $blockActionInfo,
76  RowCommentFormatter $rowCommentFormatter
77  ) {
78  parent::__construct( 'AutoblockList' );
79 
80  $this->linkBatchFactory = $linkBatchFactory;
81  $this->blockRestrictionStore = $blockRestrictionStore;
82  $this->loadBalancer = $loadBalancer;
83  $this->commentStore = $commentStore;
84  $this->blockUtils = $blockUtils;
85  $this->blockActionInfo = $blockActionInfo;
86  $this->rowCommentFormatter = $rowCommentFormatter;
87  }
88 
92  public function execute( $par ) {
93  $this->setHeaders();
94  $this->outputHeader();
95  $out = $this->getOutput();
96  $out->setPageTitle( $this->msg( 'autoblocklist' ) );
97  $this->addHelpLink( 'Autoblock' );
98  $out->addModuleStyles( [ 'mediawiki.special' ] );
99 
100  # setup BlockListPager here to get the actual default Limit
101  $pager = $this->getBlockListPager();
102 
103  # Just show the block list
104  $fields = [
105  'Limit' => [
106  'type' => 'limitselect',
107  'label-message' => 'table_pager_limit_label',
108  'options' => $pager->getLimitSelectList(),
109  'name' => 'limit',
110  'default' => $pager->getLimit(),
111  ]
112  ];
113 
114  $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
115  $form->setMethod( 'get' )
116  ->setTitle( $this->getPageTitle() ) // Remove subpage
117  ->setFormIdentifier( 'blocklist' )
118  ->setWrapperLegendMsg( 'autoblocklist-legend' )
119  ->setSubmitTextMsg( 'autoblocklist-submit' )
120  ->prepareForm()
121  ->displayForm( false );
122 
123  $this->showTotal( $pager );
124  $this->showList( $pager );
125  }
126 
131  protected function getBlockListPager() {
132  $conds = [
133  'ipb_parent_block_id IS NOT NULL',
134  // ipb_parent_block_id <> 0 because of T282890
135  'ipb_parent_block_id <> 0',
136  ];
137  # Is the user allowed to see hidden blocks?
138  if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
139  $conds['ipb_deleted'] = 0;
140  }
141 
142  return new BlockListPager(
143  $this->getContext(),
144  $this->blockActionInfo,
145  $this->blockRestrictionStore,
146  $this->blockUtils,
147  $this->commentStore,
148  $this->linkBatchFactory,
149  $this->getLinkRenderer(),
150  $this->loadBalancer,
151  $this->rowCommentFormatter,
152  $this->getSpecialPageFactory(),
153  $conds
154  );
155  }
156 
162  protected function showTotal( BlockListPager $pager ) {
163  $out = $this->getOutput();
164  $out->addHTML(
165  Html::rawElement( 'div', [ 'style' => 'font-weight: bold;' ],
166  $this->msg( 'autoblocklist-total-autoblocks', $pager->getTotalAutoblocks() )->parse() )
167  . "\n"
168  );
169  }
170 
175  protected function showList( BlockListPager $pager ) {
176  $out = $this->getOutput();
177 
178  # Check for other blocks, i.e. global/tor blocks
179  $otherAutoblockLink = [];
180  $this->getHookRunner()->onOtherAutoblockLogLink( $otherAutoblockLink );
181 
182  # Show additional header for the local block only when other blocks exists.
183  # Not necessary in a standard installation without such extensions enabled
184  if ( count( $otherAutoblockLink ) ) {
185  $out->addHTML(
186  Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
187  $pager->getNumRows() )->parse() )
188  . "\n"
189  );
190  }
191 
192  if ( $pager->getNumRows() ) {
193  $out->addParserOutputContent( $pager->getFullOutput() );
194  } else {
195  $out->addWikiMsg( 'autoblocklist-empty' );
196  }
197 
198  if ( count( $otherAutoblockLink ) ) {
199  $out->addHTML(
201  'h2',
202  [],
203  $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
204  ) . "\n"
205  );
206  $list = '';
207  foreach ( $otherAutoblockLink as $link ) {
208  $list .= Html::rawElement( 'li', [], $link ) . "\n";
209  }
210  $out->addHTML(
212  'ul',
213  [ 'class' => 'mw-autoblocklist-otherblocks' ],
214  $list
215  ) . "\n"
216  );
217  }
218  }
219 
220  protected function getGroupName() {
221  return 'users';
222  }
223 }
getTotalAutoblocks()
Get total number of autoblocks at any given time.
Handle database storage of comments such as edit summaries and log reasons.
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:349
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:214
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:735
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 ...
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.
__construct(LinkBatchFactory $linkBatchFactory, BlockRestrictionStore $blockRestrictionStore, ILoadBalancer $loadBalancer, CommentStore $commentStore, BlockUtils $blockUtils, BlockActionInfo $blockActionInfo, RowCommentFormatter $rowCommentFormatter)
showTotal(BlockListPager $pager)
Show total number of autoblocks on top of the table.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Parent class for all special pages.
Definition: SpecialPage.php:44
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:107
Create and track the database connections and transactions for a given database cluster.