44 use Wikimedia\IPUtils;
71 private $formattedComments = [];
101 parent::__construct( $context, $linkRenderer );
102 $this->blockActionInfo = $blockActionInfo;
103 $this->blockRestrictionStore = $blockRestrictionStore;
104 $this->blockUtils = $blockUtils;
105 $this->commentStore = $commentStore;
106 $this->linkBatchFactory = $linkBatchFactory;
107 $this->rowCommentFormatter = $rowCommentFormatter;
108 $this->specialPageFactory = $specialPageFactory;
114 static $headers =
null;
116 if ( $headers ===
null ) {
118 'ipb_timestamp' =>
'blocklist-timestamp',
119 'ipb_target' =>
'blocklist-target',
120 'ipb_expiry' =>
'blocklist-expiry',
121 'ipb_by' =>
'blocklist-by',
122 'ipb_params' =>
'blocklist-params',
123 'ipb_reason' =>
'blocklist-reason',
125 foreach ( $headers as $key => $val ) {
126 $headers[$key] = $this->
msg( $val )->text();
141 if ( $msg ===
null ) {
144 'createaccountblock',
147 'blocklist-nousertalk',
151 'blocklist-editing-sitewide',
154 foreach ( $keys as $key ) {
155 $msg[$key] = $this->
msg( $key )->text();
158 '@phan-var string[] $msg';
170 case 'ipb_timestamp':
171 $formatted = htmlspecialchars( $language->userTimeAndDate( $value, $this->getUser() ) );
175 if ( $row->ipb_auto ) {
176 $formatted = $this->
msg(
'autoblockid', $row->ipb_id )->parse();
178 [ $target, ] = $this->blockUtils->parseBlockTarget( $row->ipb_address );
180 if ( is_string( $target ) ) {
181 if ( IPUtils::isValidRange( $target ) ) {
184 $formatted = $target;
201 $formatted = htmlspecialchars( $language->formatExpiry(
209 if ( $row->ipb_auto ) {
210 $links[] = $linkRenderer->makeKnownLink(
211 $this->specialPageFactory->getTitleForAlias(
'Unblock' ),
214 [
'wpTarget' =>
"#{$row->ipb_id}" ]
217 $links[] = $linkRenderer->makeKnownLink(
218 $this->specialPageFactory->getTitleForAlias(
'Unblock/' . $row->ipb_address ),
221 $links[] = $linkRenderer->makeKnownLink(
222 $this->specialPageFactory->getTitleForAlias(
'Block/' . $row->ipb_address ),
223 $msg[
'change-blocklink']
228 [
'class' =>
'mw-blocklist-actions' ],
229 $this->
msg(
'parentheses' )->rawParams(
230 $language->pipeList( $links ) )->escaped()
233 if ( $value !==
'infinity' ) {
235 $formatted .=
'<br />' . $this->
msg(
236 'ipb-blocklist-duration-left',
237 $language->formatDuration(
238 (
int)$timestamp->getTimestamp( TS_UNIX ) - MWTimestamp::time(),
263 if ( $row->ipb_sitewide ) {
264 $properties[] = htmlspecialchars( $msg[
'blocklist-editing-sitewide'] );
267 if ( !$row->ipb_sitewide && $this->restrictions ) {
268 $list = $this->getRestrictionListHTML( $row );
270 $properties[] = htmlspecialchars( $msg[
'blocklist-editing'] ) . $list;
274 if ( $row->ipb_anon_only ) {
275 $properties[] = htmlspecialchars( $msg[
'anononlyblock'] );
277 if ( $row->ipb_create_account ) {
278 $properties[] = htmlspecialchars( $msg[
'createaccountblock'] );
280 if ( $row->ipb_user && !$row->ipb_enable_autoblock ) {
281 $properties[] = htmlspecialchars( $msg[
'noautoblockblock'] );
284 if ( $row->ipb_block_email ) {
285 $properties[] = htmlspecialchars( $msg[
'emailblock'] );
288 if ( !$row->ipb_allow_usertalk ) {
289 $properties[] = htmlspecialchars( $msg[
'blocklist-nousertalk'] );
295 implode(
'', array_map(
static function ( $prop ) {
306 $formatted =
"Unable to format $name";
320 private function getRestrictionListHTML( stdClass $row ) {
324 foreach ( $this->restrictions as $restriction ) {
325 if ( $restriction->getBlockId() !== (
int)$row->ipb_id ) {
329 switch ( $restriction->getType() ) {
331 '@phan-var PageRestriction $restriction';
332 if ( $restriction->getTitle() ) {
336 $linkRenderer->makeLink( $restriction->getTitle() )
341 $text = $restriction->getValue() ===
NS_MAIN
342 ? $this->
msg(
'blanknamespace' )->text()
344 $restriction->getValue()
350 $linkRenderer->makeLink(
351 $this->specialPageFactory->getTitleForAlias(
'Allpages' ),
355 'namespace' => $restriction->getValue()
362 $actionName = $this->blockActionInfo->getActionFromId( $restriction->getValue() );
363 $enablePartialActionBlocks =
365 if ( $actionName && $enablePartialActionBlocks ) {
369 $this->
msg(
'ipb-action-' .
370 $this->blockActionInfo->getActionFromId( $restriction->getValue() ) )->escaped()
382 foreach ( $items as $key => $value ) {
389 implode(
'', $value )
402 $commentQuery = $this->commentStore->getJoin(
'ipb_reason' );
405 'tables' => array_merge(
406 [
'ipblocks',
'ipblocks_by_actor' =>
'actor' ],
407 $commentQuery[
'tables']
413 'ipb_by' =>
'ipblocks_by_actor.actor_user',
414 'ipb_by_text' =>
'ipblocks_by_actor.actor_name',
418 'ipb_create_account',
419 'ipb_enable_autoblock',
425 'ipb_allow_usertalk',
427 ] + $commentQuery[
'fields'],
430 'ipblocks_by_actor' => [
'JOIN',
'actor_id=ipb_by_actor' ]
431 ] + $commentQuery[
'joins']
434 # Filter out any expired blocks
436 $info[
'conds'][] =
'ipb_expiry > ' . $db->addQuotes( $db->timestamp() );
438 # Is the user allowed to see hidden blocks?
439 if ( !$this->
getAuthority()->isAllowed(
'hideuser' ) ) {
440 $info[
'conds'][
'ipb_deleted'] = 0;
453 return (
int)$dbr->newSelectQueryBuilder()
454 ->select(
'COUNT(*)' )
456 ->where( [
'ipb_auto' =>
'1',
'ipb_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ), ] )
457 ->caller( __METHOD__ )->fetchField();
461 return parent::getTableClass() .
' mw-blocklist';
465 return [ [
'ipb_timestamp',
'ipb_id' ] ];
482 $lb = $this->linkBatchFactory->newLinkBatch();
483 $lb->setCaller( __METHOD__ );
486 foreach ( $result as $row ) {
487 $lb->add(
NS_USER, $row->ipb_address );
490 if ( $row->ipb_by ??
null ) {
491 $lb->add(
NS_USER, $row->ipb_by_text );
495 if ( !$row->ipb_sitewide ) {
496 $partialBlocks[] = (int)$row->ipb_id;
500 if ( $partialBlocks ) {
503 $this->restrictions = $this->blockRestrictionStore->loadByBlockId( $partialBlocks );
505 foreach ( $this->restrictions as $restriction ) {
507 '@phan-var PageRestriction $restriction';
508 $title = $restriction->getTitle();
510 $lb->addObj( $title );
520 $this->formattedComments = $this->rowCommentFormatter->formatRows( $result,
'ipb_reason' );
529 class_alias( BlockListPager::class,
'BlockListPager' );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
A class containing constants representing the names of configuration variables.
const EnablePartialActionBlocks
Name constant for the EnablePartialActionBlocks setting, for use with Config::get()
Factory for handling the special page list and generating SpecialPage objects.
Interface for objects which can provide a MediaWiki context on request.