jenkins-bot has submitted this change and it was merged.
Change subject: Check for global blocks
......................................................................
Check for global blocks
Depends on GlobalBlocking change I2893b9e24173d21fe518c360f6c6add363cc7b23,
where the Block object is added to the hook.
Before this, it's only possible to check for globalblock status. It is not
possible to print a proper error message without relying on the extension
and manually calling its GlobalBlocking::getUserBlockErrors to fetch the
actual error message.
Bug: T111229
Depends-On: I2893b9e24173d21fe518c360f6c6add363cc7b23
Change-Id: I23d29c1a0e016de4e82d5b51afa94ae9afd70ee4
---
M includes/specials/SpecialUpload.php
M includes/user/User.php
2 files changed, 34 insertions(+), 7 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/specials/SpecialUpload.php
b/includes/specials/SpecialUpload.php
index 82e07fd..75308aa 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -180,6 +180,11 @@
throw new UserBlockedError( $user->getBlock() );
}
+ // Global blocks
+ if ( $user->isBlockedGlobally() ) {
+ throw new UserBlockedError( $user->getGlobalBlock() );
+ }
+
# Check whether we actually want to allow changing stuff
$this->checkReadOnly();
diff --git a/includes/user/User.php b/includes/user/User.php
index 04eba97..8c60199 100644
--- a/includes/user/User.php
+++ b/includes/user/User.php
@@ -275,8 +275,8 @@
protected $mImplicitGroups;
/** @var array */
protected $mFormerGroups;
- /** @var bool */
- protected $mBlockedGlobally;
+ /** @var Block */
+ protected $mGlobalBlock;
/** @var bool */
protected $mLocked;
/** @var bool */
@@ -1992,8 +1992,22 @@
* @return bool True if blocked, false otherwise
*/
public function isBlockedGlobally( $ip = '' ) {
- if ( $this->mBlockedGlobally !== null ) {
- return $this->mBlockedGlobally;
+ return $this->getGlobalBlock( $ip ) instanceof Block;
+ }
+
+ /**
+ * Check if user is blocked on all wikis.
+ * Do not use for actual edit permission checks!
+ * This is intended for quick UI checks.
+ *
+ * @param string $ip IP address, uses current client if none given
+ * @return Block|null Block object if blocked, null otherwise
+ * @throws FatalError
+ * @throws MWException
+ */
+ public function getGlobalBlock( $ip = '' ) {
+ if ( $this->mGlobalBlock !== null ) {
+ return $this->mGlobalBlock ?: null;
}
// User is already an IP?
if ( IP::isIPAddress( $this->getName() ) ) {
@@ -2002,9 +2016,17 @@
$ip = $this->getRequest()->getIP();
}
$blocked = false;
- Hooks::run( 'UserIsBlockedGlobally', [ &$this, $ip, &$blocked ]
);
- $this->mBlockedGlobally = (bool)$blocked;
- return $this->mBlockedGlobally;
+ $block = null;
+ Hooks::run( 'UserIsBlockedGlobally', [ &$this, $ip, &$blocked,
&$block ] );
+
+ if ( $blocked && $block === null ) {
+ // back-compat: UserIsBlockedGlobally didn't have
$block param first
+ $block = new Block;
+ $block->setTarget( $ip );
+ }
+
+ $this->mGlobalBlock = $blocked ? $block : false;
+ return $this->mGlobalBlock ?: null;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/283189
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I23d29c1a0e016de4e82d5b51afa94ae9afd70ee4
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits