/** * 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; }
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; }
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); }