diff --git a/includes/EditPage.php b/includes/EditPage.php index b70a88467ae..0b9fa14104e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1727,7 +1727,12 @@ class EditPage { return false; case self::AS_BLOCKED_PAGE_FOR_USER: - throw new UserBlockedError( $this->context->getUser()->getBlock() ); + throw new UserBlockedError( + $this->context->getUser()->getBlock(), + $this->context->getUser(), + $this->context->getLanguage(), + $request->getIP() + ); case self::AS_IMAGE_REDIRECT_ANON: case self::AS_IMAGE_REDIRECT_LOGGED: diff --git a/includes/actions/Action.php b/includes/actions/Action.php index 6497cab263f..39aef096079 100644 --- a/includes/actions/Action.php +++ b/includes/actions/Action.php @@ -318,7 +318,12 @@ abstract class Action implements MessageLocalizer { if ( $this->requiresUnblock() && $user->isBlockedFrom( $this->getTitle() ) ) { $block = $user->getBlock(); if ( $block ) { - throw new UserBlockedError( $block ); + throw new UserBlockedError( + $block, + $user, + $this->getLanguage(), + $this->getRequest()->getIP() + ); } throw new PermissionsError( $this->getName(), [ 'badaccess-group0' ] ); diff --git a/includes/exception/UserBlockedError.php b/includes/exception/UserBlockedError.php index 4d9a1a8beb4..d418c388070 100644 --- a/includes/exception/UserBlockedError.php +++ b/includes/exception/UserBlockedError.php @@ -30,15 +30,25 @@ use MediaWiki\MediaWikiServices; class UserBlockedError extends ErrorPageError { /** * @param AbstractBlock $block + * @param User|null $user + * @param Language|null $language + * @param string|null $ip */ - public function __construct( AbstractBlock $block ) { - // @todo FIXME: Implement a more proper way to get context here - // such as passing the user, language and IP from the caller. - $context = RequestContext::getMain(); - $user = $context->getUser(); - $language = $context->getLanguage(); - $ip = $context->getRequest()->getIp(); + public function __construct( + AbstractBlock $block, + User $user = null, + Language $language = null, + $ip = null + ) { + if ( $user === null || $language === null || $ip === null ) { + // If any of these are not passed in, use the global context + $context = RequestContext::getMain(); + $user = $context->getUser(); + $language = $context->getLanguage(); + $ip = $context->getRequest()->getIp(); + } + // @todo This should be passed in via the constructor $message = MediaWikiServices::getInstance()->getBlockErrorFormatter() ->getMessage( $block, $user, $language, $ip ); parent::__construct( 'blockedtitle', $message ); diff --git a/includes/specialpage/FormSpecialPage.php b/includes/specialpage/FormSpecialPage.php index b0ab9c2d252..b3ec074e7db 100644 --- a/includes/specialpage/FormSpecialPage.php +++ b/includes/specialpage/FormSpecialPage.php @@ -209,7 +209,12 @@ abstract class FormSpecialPage extends SpecialPage { if ( $this->requiresUnblock() ) { $block = $user->getBlock(); if ( $block && $block->isSitewide() ) { - throw new UserBlockedError( $block ); + throw new UserBlockedError( + $block, + $user, + $this->getLanguage(), + $this->getRequest()->getIP() + ); } } diff --git a/includes/specials/SpecialEditTags.php b/includes/specials/SpecialEditTags.php index 0b4577eb981..b76a70fa1a7 100644 --- a/includes/specials/SpecialEditTags.php +++ b/includes/specials/SpecialEditTags.php @@ -140,7 +140,12 @@ class SpecialEditTags extends UnlistedSpecialPage { // Check blocks if ( $this->permissionManager->isBlockedFrom( $user, $this->targetObj ) ) { - throw new UserBlockedError( $user->getBlock() ); + throw new UserBlockedError( + $user->getBlock(), + $user, + $this->getLanguage(), + $request->getIP() + ); } // Give a link to the logs/hist for this page diff --git a/includes/specials/SpecialRevisionDelete.php b/includes/specials/SpecialRevisionDelete.php index 07bd006d5e0..446246eada6 100644 --- a/includes/specials/SpecialRevisionDelete.php +++ b/includes/specials/SpecialRevisionDelete.php @@ -186,7 +186,12 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { // Check blocks if ( $this->permissionManager->isBlockedFrom( $user, $this->targetObj ) ) { - throw new UserBlockedError( $user->getBlock() ); + throw new UserBlockedError( + $user->getBlock(), + $user, + $this->getLanguage(), + $request->getIP() + ); } $this->typeLabels = self::UI_LABELS[$this->typeName]; diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index a2edca08504..214a5e39dfa 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -177,12 +177,22 @@ class SpecialUpload extends SpecialPage { # Check blocks if ( $user->isBlockedFromUpload() ) { - throw new UserBlockedError( $user->getBlock() ); + throw new UserBlockedError( + $user->getBlock(), + $user, + $this->getLanguage(), + $this->getRequest()->getIP() + ); } // Global blocks if ( $user->isBlockedGlobally() ) { - throw new UserBlockedError( $user->getGlobalBlock() ); + throw new UserBlockedError( + $user->getGlobalBlock(), + $user, + $this->getLanguage(), + $this->getRequest()->getIP() + ); } # Check whether we actually want to allow changing stuff diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php index 28626ea58e3..d9394dd5637 100644 --- a/includes/specials/SpecialUserrights.php +++ b/includes/specials/SpecialUserrights.php @@ -169,7 +169,12 @@ class UserrightsPage extends SpecialPage { ) { $block = $user->getBlock(); if ( $block && $block->isSitewide() ) { - throw new UserBlockedError( $block ); + throw new UserBlockedError( + $block, + $user, + $this->getLanguage(), + $request->getIP() + ); } }