Merge "Allow user, language and IP to be passed to UserBlockedError"
This commit is contained in:
commit
090d20b682
8 changed files with 65 additions and 15 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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' ] );
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue