MediaWiki master
SpecialAutoblockList.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
13use MediaWiki\Cache\LinkBatchFactory;
18use MediaWiki\Pager\BlockListPager;
22
30
31 private LinkBatchFactory $linkBatchFactory;
32 private BlockRestrictionStore $blockRestrictionStore;
33 private IConnectionProvider $dbProvider;
34 private CommentStore $commentStore;
35 private BlockTargetFactory $blockTargetFactory;
36 private HideUserUtils $hideUserUtils;
37 private BlockActionInfo $blockActionInfo;
38 private RowCommentFormatter $rowCommentFormatter;
39
40 public function __construct(
41 LinkBatchFactory $linkBatchFactory,
42 BlockRestrictionStore $blockRestrictionStore,
43 IConnectionProvider $dbProvider,
44 CommentStore $commentStore,
45 BlockTargetFactory $blockTargetFactory,
46 HideUserUtils $hideUserUtils,
47 BlockActionInfo $blockActionInfo,
48 RowCommentFormatter $rowCommentFormatter
49 ) {
50 parent::__construct( 'AutoblockList' );
51
52 $this->linkBatchFactory = $linkBatchFactory;
53 $this->blockRestrictionStore = $blockRestrictionStore;
54 $this->dbProvider = $dbProvider;
55 $this->commentStore = $commentStore;
56 $this->blockTargetFactory = $blockTargetFactory;
57 $this->hideUserUtils = $hideUserUtils;
58 $this->blockActionInfo = $blockActionInfo;
59 $this->rowCommentFormatter = $rowCommentFormatter;
60 }
61
65 public function execute( $par ) {
66 $this->setHeaders();
67 $this->outputHeader();
68 $out = $this->getOutput();
69 $out->setPageTitleMsg( $this->msg( 'autoblocklist' ) );
70 $this->addHelpLink( 'Autoblock' );
71 $out->addModuleStyles( [ 'mediawiki.special' ] );
72
73 # setup BlockListPager here to get the actual default Limit
74 $pager = $this->getBlockListPager();
75
76 # Just show the block list
77 $fields = [
78 'Limit' => [
79 'type' => 'limitselect',
80 'label-message' => 'table_pager_limit_label',
81 'options' => $pager->getLimitSelectList(),
82 'name' => 'limit',
83 'default' => $pager->getLimit(),
84 ]
85 ];
86
87 $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
88 $form->setMethod( 'get' )
89 ->setTitle( $this->getPageTitle() ) // Remove subpage
90 ->setFormIdentifier( 'blocklist' )
91 ->setWrapperLegendMsg( 'autoblocklist-legend' )
92 ->setSubmitTextMsg( 'autoblocklist-submit' )
93 ->prepareForm()
94 ->displayForm( false );
95
96 $this->showList( $pager );
97 }
98
103 protected function getBlockListPager() {
104 $conds = [
105 $this->dbProvider->getReplicaDatabase()->expr( 'bl_parent_block_id', '!=', null ),
106 ];
107 # Is the user allowed to see hidden blocks?
108 if ( !$this->getAuthority()->isAllowed( 'hideuser' ) ) {
109 $conds['bl_deleted'] = 0;
110 }
111
112 return new BlockListPager(
113 $this->getContext(),
114 $this->blockActionInfo,
115 $this->blockRestrictionStore,
116 $this->blockTargetFactory,
117 $this->hideUserUtils,
118 $this->commentStore,
119 $this->linkBatchFactory,
120 $this->getLinkRenderer(),
121 $this->dbProvider,
122 $this->rowCommentFormatter,
123 $this->getSpecialPageFactory(),
124 $conds
125 );
126 }
127
132 protected function showList( BlockListPager $pager ) {
133 $out = $this->getOutput();
134
135 # Check for other blocks, i.e. global/tor blocks
136 $otherAutoblockLink = [];
137 $this->getHookRunner()->onOtherAutoblockLogLink( $otherAutoblockLink );
138
139 # Show additional header for the local block only when other blocks exists.
140 # Not necessary in a standard installation without such extensions enabled
141 if ( count( $otherAutoblockLink ) ) {
142 $out->addHTML(
143 Html::rawElement( 'h2', [], $this->msg( 'autoblocklist-localblocks',
144 $pager->getNumRows() )->parse() )
145 . "\n"
146 );
147 }
148
149 if ( $pager->getNumRows() ) {
150 $out->addParserOutputContent(
151 $pager->getFullOutput(),
152 ParserOptions::newFromContext( $this->getContext() )
153 );
154 } else {
155 $out->addWikiMsg( 'autoblocklist-empty' );
156 }
157
158 if ( count( $otherAutoblockLink ) ) {
159 $out->addHTML(
160 Html::rawElement(
161 'h2',
162 [],
163 $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse()
164 ) . "\n"
165 );
166 $list = '';
167 foreach ( $otherAutoblockLink as $link ) {
168 $list .= Html::rawElement( 'li', [], $link ) . "\n";
169 }
170 $out->addHTML(
171 Html::rawElement(
172 'ul',
173 [ 'class' => 'mw-autoblocklist-otherblocks' ],
174 $list
175 ) . "\n"
176 );
177 }
178 }
179
181 protected function getGroupName() {
182 return 'users';
183 }
184}
185
187class_alias( SpecialAutoblockList::class, 'SpecialAutoblockList' );
Defines the actions that can be blocked by a partial block.
Factory for BlockTarget objects.
Helpers for building queries that determine whether a user is hidden.
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.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:195
This class is a collection of static functions that serve two purposes:
Definition Html.php:43
Set options of the Parser.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getPageTitle( $subpage=false)
Get a self-referential title object.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getAuthority()
Shortcut to get the Authority executing this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
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, BlockTargetFactory $blockTargetFactory, HideUserUtils $hideUserUtils, BlockActionInfo $blockActionInfo, RowCommentFormatter $rowCommentFormatter)
Provide primary and replica IDatabase connections.