From 326e4d86c4d79dee25f3706d2906e3d15ce8cf0c Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 2 Oct 2008 01:12:07 +0000 Subject: [PATCH] * Pull isLocked() and isHidden() up to User using callbacks * Add quick globalblock check function to User * Add 'locked'/'globally blocked' notices to checkuser (bug 15272) (bug 15792) --- includes/AuthPlugin.php | 7 ++++ includes/User.php | 75 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/includes/AuthPlugin.php b/includes/AuthPlugin.php index 7717e001c2..df2c01982c 100644 --- a/includes/AuthPlugin.php +++ b/includes/AuthPlugin.php @@ -241,4 +241,11 @@ class AuthPlugin { function getCanonicalName( $username ) { return $username; } + + /** + * Adds any functionality to a User object in context of the auth system + */ + function setUserCallbacks( $user, &$callbacks ) { + return true; + } } diff --git a/includes/User.php b/includes/User.php index 966a409d68..f49ebf69a2 100644 --- a/includes/User.php +++ b/includes/User.php @@ -183,7 +183,7 @@ class User { /** * \type{\bool} Whether the cache variables have been loaded. */ - var $mDataLoaded; + var $mDataLoaded, $mAuthLoaded; /** * \type{\string} Initialization data source if mDataLoaded==false. May be one of: @@ -199,7 +199,8 @@ class User { /** @name Lazy-initialized variables, invalidated with clearInstanceCache */ //@{ var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mSkin, $mRights, - $mBlockreason, $mBlock, $mEffectiveGroups; + $mBlockreason, $mBlock, $mEffectiveGroups, $mBlockedGlobally, + $mLocked, $mHideName; //@} /** @@ -252,6 +253,23 @@ class User { } wfProfileOut( __METHOD__ ); } + + protected function callAuthPlugin( $fname /* $args */ ) { + $args = func_get_args(); + array_shift( $args ); + // Load auth plugin conterpart functions for User functions + if( !$this->mAuthLoaded ) { + global $wgAuth; + $this->mAuthCallbacks = array(); + $wgAuth->setUserCallbacks( $this, $this->mAuthCallbacks ); + $this->mAuthLoaded = true; + } + // Try to call the auth plugin version of this function + if( isset($this->mAuthCallbacks[$fname]) && is_callable($this->mAuthCallbacks[$fname]) ) { + return call_user_func_array( $this->mAuthCallbacks[$fname], $args ); + } + return NULL; + } /** * Load user table data, given mId has already been set. @@ -1295,6 +1313,59 @@ class User { $this->getBlockedStatus(); return $this->mBlockreason; } + + /** + * Check if user is blocked on all wikis. + * Do not use for actual edit permission checks! + * This is intented for quick UI checks. + * + * @param $ip \type{\string} IP address, uses current client if none given + * @return \type{\bool} True if blocked, false otherwise + */ + function isBlockedGlobally( $ip = '' ) { + if( $this->mBlockedGlobally !== null ) { + return $this->mBlockedGlobally; + } + // User is already an IP? + if( IP::isIPAddress( $this->getName() ) ) { + $ip = $this->getName(); + } else if( !$ip ) { + $ip = wfGetIP(); + } + $blocked = false; + wfRunHooks( 'UserIsBlockedGlobally', array( &$this, $ip, &$blocked ) ); + $this->mBlockedGlobally = (bool)$blocked; + return $this->mBlockedGlobally; + } + + /** + * Check if user account is locked + * + * @return \type{\bool} True if locked, false otherwise + */ + function isLocked() { + if( $this->mLocked !== null ) { + return $this->mLocked; + } + $this->mLocked = (bool)$this->callAuthPlugin( __FUNCTION__ ); + return $this->mLocked; + } + + /** + * Check if user account is hidden + * + * @return \type{\bool} True if hidden, false otherwise + */ + function isHidden() { + if( $this->mHideName !== null ) { + return $this->mHideName; + } + $this->getBlockedStatus(); + if( !$this->mHideName ) { + $this->mHideName = (bool)$this->callAuthPlugin( __FUNCTION__ ); + } + return $this->mHideName; + } /** * Get the user's ID. -- 2.20.1