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__);
 }
示例#2
0
 /**
  * static constructor
  *
  * @static
  * @access public
  */
 public static function newFromUserName($login)
 {
     wfProfileIn(__METHOD__);
     $User = User::newFromName($login);
     if ($User) {
         $User->load();
         $Avatar = new Masthead($User);
     } else {
         /**
          * anonymous
          */
         $Avatar = Masthead::newFromUserID(0);
     }
     wfProfileOut(__METHOD__);
     return $Avatar;
 }
 /**
  * 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();
     }
 }
 /**
  * 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;
 }
示例#7
0
 public static function getUserAvatar($userId, $width = 50, $height = 50)
 {
     global $wgStylePath, $wgBlankImgUrl;
     wfProfileIn(__METHOD__);
     if (class_exists('Masthead')) {
         $avatar = Masthead::newFromUserID($userId);
         $avatar->getDefaultAvatars();
         $avatar->mDefaultAvatars = array("{$wgStylePath}/answers/images/default_avatar.png?1");
         $img = $avatar->getImageTag($width, $height);
     } else {
         $avatarImgSrc = $wgBlankImgUrl;
         $img = Xml::element('img', array('src' => $avatarImgSrc, 'height' => $height, 'width' => $width));
     }
     wfProfileOut(__METHOD__);
     return $img;
 }
 /**
  * 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;
     }
 }
 public function getTopUsers($tag_id, $lang, $limit = 5, $force_reload = false)
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     $mcKey = wfSharedMemcKey("auto_hubs", "users", $tag_id, $lang, $limit, __METHOD__);
     if (!$force_reload) {
         $out = $wgMemc->get($mcKey);
         if (!empty($out)) {
             wfProfileOut(__METHOD__);
             return $out;
         }
     }
     if (empty($this->dbEnabled)) {
         wfProfileOut(__METHOD__);
         return array("value" => array(), "age" => time());
     }
     $tag_id = (int) $tag_id;
     $res = $this->dbs->select(array('specials.summary_tags_top_users'), array('user_id, tag_id, username, groups, all_count'), array('tag_id' => $tag_id, 'city_lang' => $lang, 'user_id <> 0'), __METHOD__, array('ORDER BY' => 'all_count desc', 'LIMIT' => 100));
     $out = array();
     $count = 0;
     while ($row = $this->dbs->fetchRow($res)) {
         if ($this->filterBanUsers($row)) {
             $out[] = $row;
             $count++;
         }
         if ($count == $limit) {
             break;
         }
     }
     // get avatars and fix usernames for the users
     foreach ($out as $key => $val) {
         $u = User::newFromId($val['user_id']);
         $out[$key]['username'] = $u->getName();
         $userWiki = $this->getUserWiki($val['user_id']);
         if ($userWiki !== false) {
             list($wikiUrl, $pageUrl) = array_values($userWiki);
             $avatar = Masthead::newFromUserId($val['user_id']);
             $avatar->setUserPageUrl($pageUrl);
             $out[$key]['avatar'] = $avatar->display(30, 30);
             $out[$key]['userpage'] = $pageUrl;
         }
     }
     $out = array("value" => $out, "age" => time());
     $wgMemc->set($mcKey, $out, 60 * 60);
     wfProfileOut(__METHOD__);
     return $out;
 }
示例#10
0
 /**
  * @param Masthead $masthead
  * @param int $width
  * @param $timestamp
  * @return \Wikia\Vignette\UrlGenerator
  */
 public static function getVignetteUrl(Masthead $masthead, $width, $timestamp)
 {
     $relativePath = $masthead->mUser->getGlobalAttribute(AVATAR_USER_OPTION_NAME);
     if ($relativePath) {
         if (strpos($relativePath, '/') !== false) {
             // custom avatar
             $url = self::vignetteCustomUrl($width, $relativePath, $timestamp);
         } else {
             // wikia-provided avatars
             $hash = FileRepo::getHashPathForLevel($relativePath, 2);
             $bucket = VignetteRequest::parseBucket($masthead->mDefaultPath);
             $relativePath = $hash . $relativePath;
             $url = self::buildVignetteUrl($width, $bucket, $relativePath, $timestamp, false);
         }
     } else {
         // default avatar
         $legacyDefaultUrl = $masthead->getDefaultAvatars('thumb/')[0];
         $bucket = VignetteRequest::parseBucket($legacyDefaultUrl);
         $relativePath = VignetteRequest::parseRelativePath($legacyDefaultUrl);
         $url = self::buildVignetteUrl($width, $bucket, $relativePath, $timestamp, false);
     }
     return $url;
 }
示例#11
0
function copyAvatarsToMasthead() {
	global $wgExternalSharedDB, $wgExternalDatawareDB, $wgWikiaLocalSettingsPath ;
	global $wgStylePath, $IP;
	global $USER_FROM, $USER_TO, $USER_TEST;

	$allUsers = array();
	$answersWikis = loadAnswersToCheck();
	$allAnswersWikis = loadAnswersToCheck(1);
	$nycodeWikis = loadWikisToCheck();
	
	buildUserList($allAnswersWikis, $allUsers);
	buildUserList(array_keys($nycodeWikis), $allUsers);

/*	$cnt = 1;
	if ( !empty($allUsers) ) {
		foreach ( $allUsers as $user_id => $listAvatars ) {
			if ( count($listAvatars) > 1 ) {
				$avatar = Masthead::newFromUserID($user_id);
				$path = $avatar->getFullPath();
				$city_id = 0;
				$pathny = $uploaded = false;
				if ( !file_exists( $path ) ) {
					$oUser = User::newFromId($user_id);
					if ( !$oUser instanceof User ) {
						continue;
					}
					__log( $oUser->getName() . " ($user_id): " . implode(", ", $listAvatars ) );
					$cnt++;
				}
			}
		}
	}
	__log ("$cnt users to check \n");
	exit;*/
	
	__log( "Found: " . count($allUsers) );
	if ( !empty($allUsers) ) {
		foreach ( $allUsers as $user_id => $listAvatars ) {
			__log("Processing: ".$user_id . ")");

			# make user 
			$oUser = User::newFromId($user_id);
			if ( !$oUser instanceof User ) {
				__log("Invalid user: $user_id");
				continue;
			}

			# check lang
			$lang = $oUser->getOption('language', 'en');

			$avatar = Masthead::newFromUserID($user_id);
			$path = $avatar->getFullPath();
			$city_id = 0;
			$pathny = $uploaded = false;
			if ( !file_exists( $path ) ) {
				list($pathny, $city_id) = getAnswersAvatar($answersWikis, $user_id, $lang);

				if ( $pathny !== false && $city_id > 0 ) {
					__log("Move Answers Avatar $pathny to $path");
					$uploaded = uploadAvatar($avatar, $oUser, $pathny, $city_id);
					__log("Done with code: " . intval($uploaded));
				} else {
					if ( !empty($nycodeWikis) ) {
						list($pathny, $city_id) = getNYWikisAvatar($nycodeWikis, $user_id);
						if ( $pathny !== false && $city_id > 0 ) {
							__log("Move Wikia NY code Avatar $pathny to $path");
							$uploaded = uploadAvatar($avatar, $oUser, $pathny, $city_id);
						} else {
							if ( !empty($allAnswersWikis) ) {
								list($pathny, $city_id) = getNYWikisAvatar($allAnswersWikis, $user_id);
								if ( $pathny !== false && $city_id > 0 ) {
									__log("Move Avatar (from rest answers pages) $pathny to $path");
									$uploaded = uploadAvatar($avatar, $oUser, $pathny, $city_id);
								} 
							}
						}
					}
				}
				
			} else {
				__log("Avatar: $path exists");
			}
		}
	}
	unset($allUsers);
}
 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;
 }
示例#13
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');
 }
 public static function register($oRecentChange)
 {
     global $wgUser, $wgCityId;
     wfProfileIn(__METHOD__);
     if (FounderEmails::getInstance()->getLastEventType() == 'register') {
         // special case: creating userpage after user registration, ignore event
         wfProfileOut(__METHOD__);
         return true;
     }
     $isRegisteredUser = false;
     $isRegisteredUserFirstEdit = false;
     if ($oRecentChange->getAttribute('rc_user')) {
         $editor = $wgUser->getId() == $oRecentChange->getAttribute('rc_user') ? $wgUser : User::newFromID($oRecentChange->getAttribute('rc_user'));
         $isRegisteredUser = true;
         if (class_exists('Masthead')) {
             $userStats = Masthead::getUserStatsData($editor->getName(), true);
             if ($userStats['editCount'] == 1) {
                 $isRegisteredUserFirstEdit = true;
             }
         }
     } else {
         // Anon user
         $editor = $wgUser->getName() == $oRecentChange->getAttribute('rc_user_text') ? $wgUser : User::newFromName($oRecentChange->getAttribute('rc_user_text'), false);
     }
     $config = FounderEmailsEvent::getConfig('edit');
     if (in_array('staff', $editor->getGroups()) || in_array($editor->getId(), $config['skipUsers'])) {
         // page edited by founder, staff member or excluded user, skipping..
         wfProfileOut(__METHOD__);
         return true;
     }
     if ($editor->isAllowed('bot')) {
         // skip bots
         wfProfileOut(__METHOD__);
         return true;
     }
     $oTitle = Title::makeTitle($oRecentChange->getAttribute('rc_namespace'), $oRecentChange->getAttribute('rc_title'));
     $eventData = array('titleText' => $oTitle->getText(), 'titleUrl' => $oTitle->getFullUrl(), 'editorName' => $editor->getName(), 'editorPageUrl' => $editor->getUserPage()->getFullUrl(), 'editorTalkPageUrl' => $editor->getTalkPage()->getFullUrl(), 'registeredUser' => $isRegisteredUser, 'registeredUserFirstEdit' => $isRegisteredUserFirstEdit, 'myHomeUrl' => Title::newFromText('WikiActivity', NS_SPECIAL)->getFullUrl());
     FounderEmails::getInstance()->registerEvent(new FounderEmailsEditEvent($eventData));
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * 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;
     }
 }