Ejemplo n.º 1
0
 function __construct(User $userObj, $score, $currentRanking = null, $previousRanking = null)
 {
     wfProfileIn(__METHOD__);
     $this->mUserId = $userObj->getID();
     $this->mUsername = $userObj->getName();
     $this->mScore = $score;
     $this->mAvatarURL = Masthead::newFromUser($userObj)->getUrl();
     $this->mUserPageUrl = $userObj->getUserPage()->getLocalURL();
     $this->mCurrentRanking = $currentRanking;
     $this->mPreviousRanking = $previousRanking;
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 2
0
 /**
  * Add user who has avatar to the user list
  *
  * @param integer $userId
  * @param array $userList
  */
 protected function addUserToUserList($userId, &$userList)
 {
     $user = User::newFromId($userId);
     $masthead = Masthead::newFromUser($user);
     if ($masthead->hasAvatar()) {
         $userList[$user->getId()] = $user->getName();
     }
 }
Ejemplo n.º 3
0
 /**
  * Get URL for avatar
  */
 static function getAvatarUrl($user, $avatarSize = 20, $avoidUpscaling = false)
 {
     wfProfileIn(__METHOD__);
     static $avatarsCache;
     if ($user instanceof User) {
         $key = "{$user->getName()}::{$avatarSize}";
     } else {
         //assumes $user is a string with user name
         $key = "{$user}::{$avatarSize}";
     }
     if (isset($avatarsCache[$key])) {
         $avatarUrl = $avatarsCache[$key];
     } else {
         if (!$user instanceof User) {
             $user = self::getUser($user);
         }
         // handle anon users - return default avatar
         if (empty($user) || !class_exists('Masthead')) {
             $avatarUrl = self::getDefaultAvatar($avatarSize);
             wfProfileOut(__METHOD__);
             return $avatarUrl;
         }
         $masthead = Masthead::newFromUser($user);
         $avatarUrl = $masthead->getThumbnail($avatarSize, true, $avoidUpscaling);
         // use per-user cachebuster when custom avatar is used
         $cb = !$masthead->isDefault() ? intval($user->getOption('avatar_rev')) : 0;
         // Make URLs consistent and using no-cookie domain.  We need to pass a
         // stringified zero rather than an actual zero because this function
         // treats them differently o_O  Setting this to string zero matches
         // the anonymous user behavior (BugId:22190)
         $avatarUrl = wfReplaceImageServer($avatarUrl, $cb > 0 ? $cb : "0");
         $avatarsCache[$key] = $avatarUrl;
     }
     wfProfileOut(__METHOD__);
     return $avatarUrl;
 }
/**
 * Called when a user was just created or attached (safe to call at any time later as well).  This
 * function will check to see if the user has a Wikia Avatar and if they don't, it will attempt to
 * use this Facebook-connected user's profile picture as their Wikia Avatar.
 *
 * FIXME: Is there a way to make this fail gracefully if we ever un-include the Masthead extension?
 */
function wikia_fbconnect_considerProfilePic(&$specialConnect)
{
    wfProfileIn(__METHOD__);
    global $wgUser;
    // We need the facebook id to have any chance of getting a profile pic.
    $fb_ids = FBConnectDB::getFacebookIDs($wgUser);
    if (count($fb_ids) > 0) {
        $fb_id = array_shift($fb_ids);
        if (class_exists('Masthead')) {
            // If the useralready has a masthead avatar, don't overwrite it, this function shouldn't alter anything in that case.
            $masthead = Masthead::newFromUser($wgUser);
            if (!$masthead->hasAvatar()) {
                global $wgEnableUserProfilePagesV3;
                if (!empty($wgEnableUserProfilePagesV3)) {
                    //bugId:10580
                    // Attempt to store the facebook profile pic as the Wikia avatar.
                    $picUrl = FBConnectProfilePic::getImgUrlById($fb_id, FB_PIC_BIG);
                } else {
                    // Attempt to store the facebook profile pic as the Wikia avatar.
                    $picUrl = FBConnectProfilePic::getImgUrlById($fb_id, FB_PIC_SQUARE);
                }
                if ($picUrl != "") {
                    if (!empty($wgEnableUserProfilePagesV3)) {
                        //bugId:10580
                        $tmpFile = '';
                        $sUrl = $masthead->uploadByUrlToTempFile($picUrl, $tmpFile);
                        $app = F::app();
                        $userProfilePageV3 = new UserProfilePageController($app);
                        $data->source = 'facebook';
                        $data->file = $tmpFile;
                        $userProfilePageV3->saveUsersAvatar($wgUser->getId(), $data);
                    } else {
                        $errorNo = $masthead->uploadByUrl($picUrl);
                        // Apply this as the user's new avatar if the image-pull went okay.
                        if ($errorNo == UPLOAD_ERR_OK) {
                            $sUrl = $masthead->getLocalPath();
                            if (!empty($sUrl)) {
                                /* set user option */
                                $wgUser->setOption(AVATAR_USER_OPTION_NAME, $sUrl);
                                $wgUser->saveSettings();
                            }
                        }
                    }
                }
            }
        }
    }
    wfProfileOut(__METHOD__);
    return true;
}
 public function removeavatar()
 {
     wfProfileIn(__METHOD__);
     $this->setVal('status', false);
     // macbre: avatars operations are disabled during maintenance
     global $wgAvatarsMaintenance;
     if (!empty($wgAvatarsMaintenance)) {
         $this->setVal('error', wfMessage('user-identity-avatars-maintenance')->escaped());
         wfProfileOut(__METHOD__);
         return true;
     }
     if (!$this->app->wg->User->isAllowed('removeavatar')) {
         wfProfileOut(__METHOD__);
         return true;
     }
     if ($this->request->getVal('avUser')) {
         $avUser = User::newFromName($this->request->getVal('avUser'));
         if ($avUser->getID() !== 0) {
             $avatar = Masthead::newFromUser($avUser);
             if ($avatar->removeFile(true)) {
                 wfProfileOut(__METHOD__);
                 $this->setVal('status', "ok");
                 return true;
             }
         }
     }
     $this->setVal('error', wfMessage('user-identity-remove-fail')->escaped());
     wfProfileOut(__METHOD__);
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Clears the user's password, sets an empty e-mail and marks as disabled
  *
  * @param  User    $user         User account to close
  * @param  string  $changeReason Reason for change
  * @param  string  $mStatusMsg   Main error message
  * @param  string  $mStatusMsg2  Secondary (non-critical) error message
  * @param  boolean $keepEmail    Optionally keep the email address in a
  *                               user option
  * @return boolean               true on success, false on failure
  */
 public static function closeAccount($user = '', $changeReason = '', &$mStatusMsg = '', &$mStatusMsg2 = '', $keepEmail = true)
 {
     if (empty($user)) {
         throw new Exception('User object is invalid.');
     }
     $id = $user->getId();
     # Set flag for Special:Contributions
     # NOTE: requires FlagClosedAccounts.php to be included separately
     if (defined('CLOSED_ACCOUNT_FLAG')) {
         $user->setRealName(CLOSED_ACCOUNT_FLAG);
     } else {
         # magic value not found, so lets at least blank it
         $user->setRealName('');
     }
     // remove users avatar
     if (class_exists('Masthead')) {
         $avatar = Masthead::newFromUser($user);
         if (!$avatar->isDefault()) {
             if (!$avatar->removeFile(false)) {
                 # dont quit here, since the avatar is a non-critical part of closing, but flag for later
                 $mStatusMsg2 = wfMessage('editaccount-remove-avatar-fail')->plain();
             }
         }
     }
     // close account and invalidate cache + cluster data
     Wikia::invalidateUser($user, true, $keepEmail, true);
     // if they are connected from facebook, disconnect them
     self::disconnectFromFacebook($user);
     if ($user->getEmail() == '') {
         $title = Title::newFromText('EditAccount', NS_SPECIAL);
         // Log what was done
         $log = new LogPage('editaccnt');
         $log->addEntry('closeaccnt', $title, $changeReason, array($user->getUserPage()));
         // All clear!
         $mStatusMsg = wfMessage('editaccount-success-close', $user->mName)->plain();
         wfRunHooks('EditAccountClosed', array($user));
         return true;
     } else {
         // There were errors...inform the user about those
         $mStatusMsg = wfMessage('editaccount-error-close', $user->mName)->plain();
         return false;
     }
 }
Ejemplo n.º 7
0
 /**
  * Get URL for avatar
  *
  * @param string|User $user user name
  * @param int $avatarSize
  * @return String avatar's URL
  */
 static function getAvatarUrl($user, $avatarSize = 20)
 {
     global $wgEnableVignette;
     wfProfileIn(__METHOD__);
     static $avatarsCache;
     if ($user instanceof User) {
         $key = "{$user->getName()}::{$avatarSize}";
     } else {
         // assumes $user is a string with user name
         $key = "{$user}::{$avatarSize}";
     }
     if (isset($avatarsCache[$key])) {
         $avatarUrl = $avatarsCache[$key];
     } else {
         if (!$user instanceof User) {
             $user = self::getUser($user);
         }
         // handle anon users - return default avatar
         if (empty($user) || !class_exists('Masthead')) {
             $avatarUrl = self::getDefaultAvatar($avatarSize);
             wfProfileOut(__METHOD__);
             return $avatarUrl;
         }
         $masthead = Masthead::newFromUser($user);
         // use per-user cachebuster when custom avatar is used
         $cb = !$masthead->isDefault() ? intval($user->getGlobalAttribute('avatar_rev')) : 0;
         if ($wgEnableVignette) {
             $avatarUrl = self::getVignetteUrl($masthead, $avatarSize, $cb);
         } else {
             $avatarUrl = $masthead->getThumbnailPurgeUrl($avatarSize);
             // Make URLs consistent and using no-cookie domain.  We need to pass a
             // stringified zero rather than an actual zero because this function
             // treats them differently o_O  Setting this to string zero matches
             // the anonymous user behavior (BugId:22190)
             $avatarUrl = wfReplaceImageServer($avatarUrl, $cb > 0 ? $cb : "0");
             // make avatars as JPG intead of PNGs / GIF but only when it will be a gain (most likely)
             if (intval($avatarSize) > self::PERFORMANCE_JPEG_THRESHOLD) {
                 $avatarUrl = ImagesService::overrideThumbnailFormat($avatarUrl, ImagesService::EXT_JPG);
             }
         }
         $avatarsCache[$key] = $avatarUrl;
     }
     wfProfileOut(__METHOD__);
     return $avatarUrl;
 }
 public function removeavatar()
 {
     wfProfileIn(__METHOD__);
     $this->setVal('status', false);
     if (!$this->app->wg->User->isAllowed('removeavatar')) {
         wfProfileOut(__METHOD__);
         return true;
     }
     if ($this->request->getVal('av_user')) {
         $avUser = User::newFromName($this->request->getVal('av_user'));
         if ($avUser->getID() !== 0) {
             $avatar = Masthead::newFromUser($avUser);
             if ($avatar->removeFile(true)) {
                 wfProfileOut(__METHOD__);
                 $this->setVal('status', "ok");
                 return true;
             }
         }
     }
     $this->setVal('error', wfMsg('user-identity-remove-fail'));
     wfProfileOut(__METHOD__);
     return true;
 }
Ejemplo n.º 9
0
 /**
  * Test Masthead::getPurgeUrl method
  *
  * @group UsingDB
  * @dataProvider getPurgeUrlDataProvider
  *
  * @param $avatarOption string value of 'avatar' user option for mocked User object
  * @param $expectedUrl string expected full avatar URL
  */
 function testGetPurgeUrl($avatarOption, $expectedUrl)
 {
     $user = $this->mockClassWithMethods('User', ['getGlobalAttribute' => $avatarOption]);
     $masthead = Masthead::newFromUser($user);
     $this->assertEquals($expectedUrl, $masthead->getPurgeUrl(), 'Avatar URL should match the expected value');
 }
Ejemplo n.º 10
0
 /**
  * Scrambles the user's password, sets an empty e-mail and marks as disabled
  *
  * @return Boolean: true on success, false on failure
  */
 function closeAccount()
 {
     # Set flag for Special:Contributions
     # NOTE: requires FlagClosedAccounts.php to be included separately
     if (defined('CLOSED_ACCOUNT_FLAG')) {
         $this->mUser->setRealName(CLOSED_ACCOUNT_FLAG);
     } else {
         # magic value not found, so lets at least blank it
         $this->mUser->setRealName('');
     }
     // remove users avatar
     if (class_exists('Masthead')) {
         $avatar = Masthead::newFromUser($this->mUser);
         if (!$avatar->isDefault()) {
             if (!$avatar->removeFile(false)) {
                 # dont quit here, since the avatar is a non-critical part of closing, but flag for later
                 $this->mStatusMsg2 = wfMsgExt('editaccount-remove-avatar-fail');
             }
         }
     }
     // Remove e-mail address and passwor
     $this->mUser->setEmail('');
     $this->mUser->setPassword($newpass = $this->generateRandomScrambledPassword());
     // Save the new settings
     $this->mUser->saveSettings();
     $id = $this->mUser->getId();
     // Reload user
     $this->mUser = User::newFromId($id);
     if ($this->mUser->getEmail() == '') {
         global $wgUser, $wgTitle;
         // Mark as disabled in a more real way, that doesnt depend on the real_name text
         $this->mUser->setOption('disabled', 1);
         // BugId:18085 - setting a new token causes the user to be logged out.
         $this->mUser->setToken(md5(microtime() . mt_rand(0, 0x7fffffff)));
         // Need to save these additional changes
         $this->mUser->saveSettings();
         // Log what was done
         $log = new LogPage('editaccnt');
         $log->addEntry('closeaccnt', $wgTitle, '', array($this->mUser->getUserPage()));
         // All clear!
         $this->mStatusMsg = wfMsg('editaccount-success-close', $this->mUser->mName);
         return true;
     } else {
         // There were errors...inform the user about those
         $this->mStatusMsg = wfMsg('editaccount-error-close', $this->mUser->mName);
         return false;
     }
 }