Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use wcf\system\database\table\column\IntDatabaseTableColumn;
use wcf\system\database\table\column\MediumtextDatabaseTableColumn;
use wcf\system\database\table\column\VarcharDatabaseTableColumn;
use wcf\system\database\table\index\DatabaseTableForeignKey;
use wcf\system\database\table\index\DatabaseTableIndex;
use wcf\system\database\table\PartialDatabaseTable;
Expand All @@ -26,6 +27,8 @@
IntDatabaseTableColumn::create('avatarFileID')
->length(10)
->defaultValue(null),
VarcharDatabaseTableColumn::create('avatarPathname')
->defaultValue(null),
IntDatabaseTableColumn::create('coverPhotoFileID')
->length(10)
->defaultValue(null),
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions wcfsetup/install/files/lib/data/user/User.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* @property-read string $registrationIpAddress ip address of the user at the time of registration or empty if user has been created manually or if no ip address are logged
* @property-read int|null $avatarID id of the user's avatar or null if they have no avatar
* @property-read int|null $avatarFileID id of the user's avatar core file or null if they have no avatar
* @property-read string|null $avatarPathname pathname of the user's avatar relative to the core itself
* @property-read int $disableAvatar is `1` if the user's avatar has been disabled, otherwise `0`
* @property-read string $disableAvatarReason reason why the user's avatar is disabled
* @property-read int $disableAvatarExpires timestamp at which the user's avatar will automatically be enabled again
Expand Down
16 changes: 3 additions & 13 deletions wcfsetup/install/files/lib/data/user/UserProfile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use wcf\data\user\avatar\AvatarDecorator;
use wcf\data\user\avatar\DefaultAvatar;
use wcf\data\user\avatar\IUserAvatar;
use wcf\data\user\avatar\StaticAvatar;
use wcf\data\user\cover\photo\DefaultUserCoverPhoto;
use wcf\data\user\cover\photo\IUserCoverPhoto;
use wcf\data\user\cover\photo\UserCoverPhoto;
Expand Down Expand Up @@ -353,19 +354,8 @@ public function getAvatar()
$avatar = null;
if (!$this->disableAvatar) {
if ($this->canSeeAvatar()) {
if ($this->avatarFileID !== null) {
$data = UserStorageHandler::getInstance()->getField('avatar', $this->userID);
if ($data === null) {
$avatar = FileRuntimeCache::getInstance()->getObject($this->avatarFileID);

UserStorageHandler::getInstance()->update(
$this->userID,
'avatar',
\serialize($avatar)
);
} else {
$avatar = \unserialize($data);
}
if ($this->avatarPathname !== null) {
$avatar = new StaticAvatar($this->avatarPathname);
} else {
$parameters = ['avatar' => null];
EventHandler::getInstance()->fireAction($this, 'getAvatar', $parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
class UserProfileList extends UserList
{
use TUserAvatarObjectList;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -56,8 +54,6 @@ public function readObjects()

parent::readObjects();

$this->cacheAvatarFiles();

$coverPhotoFileIDs = [];
foreach ($this->objects as $object) {
if ($object->coverPhotoFileID) {
Expand Down
65 changes: 65 additions & 0 deletions wcfsetup/install/files/lib/data/user/avatar/StaticAvatar.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace wcf\data\user\avatar;

use wcf\system\file\processor\UserAvatarFileProcessor;
use wcf\system\WCF;
use wcf\util\StringUtil;

/**
* Constructs an avatar from a static filepath.
*
* @author Alexander Ebert
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
final class StaticAvatar implements IUserAvatar, ISafeFormatAvatar
{
private readonly string $src;

public function __construct(string $pathname)
{
$this->src = WCF::getPath() . $pathname;
}

#[\Override]
public function getImageTag($size = null)
{
if ($size === null) {
$size = UserAvatarFileProcessor::AVATAR_SIZE;
}

return '<img src="' . StringUtil::encodeHTML($this->getURL($size)) . '" width="' . $size . '" height="' . $size . '" alt="" class="userAvatarImage">';
}

#[\Override]
public function getSafeURL(?int $size = null): string
{
return $this->getURL($size);
}

#[\Override]
public function getSafeImageTag(?int $size = null): string
{
return '<img src="' . StringUtil::encodeHTML($this->getSafeURL($size)) . '" width="' . $size . '" height="' . $size . '" alt="" class="userAvatarImage">';
}

#[\Override]
public function getURL($size = null)
{
return $this->src;
}

#[\Override]
public function getHeight()
{
return UserAvatarFileProcessor::AVATAR_SIZE;
}

#[\Override]
public function getWidth()
{
return UserAvatarFileProcessor::AVATAR_SIZE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace wcf\data\user\follow;

use wcf\data\user\TUserAvatarObjectList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;

Expand All @@ -21,8 +20,6 @@
*/
class UserFollowerList extends UserFollowList
{
use TUserAvatarObjectList;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -50,18 +47,10 @@ public function __construct()
{
parent::__construct();

$this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar";
$this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar, user_table.avatarPathname";

$this->sqlJoins .= "
LEFT JOIN wcf1_user user_table
ON user_table.userID = user_follow.userID";
}

#[\Override]
public function readObjects()
{
parent::readObjects();

$this->cacheAvatarFiles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace wcf\data\user\ignore;

use wcf\data\user\TUserAvatarObjectList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;

Expand All @@ -15,8 +14,6 @@
*/
class ViewableUserIgnoreList extends UserIgnoreList
{
use TUserAvatarObjectList;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -58,12 +55,4 @@ public function __construct()

$this->sqlSelects .= ", user_table.*";
}

#[\Override]
public function readObjects()
{
parent::readObjects();

$this->cacheAvatarFiles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use wcf\data\option\OptionAction;
use wcf\data\session\SessionList;
use wcf\data\user\group\UserGroup;
use wcf\data\user\TUserAvatarObjectList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
Expand All @@ -24,8 +23,6 @@
*/
class UsersOnlineList extends SessionList
{
use TUserAvatarObjectList;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -91,8 +88,6 @@ public function readObjects()
}
$this->objectIDs = $this->indexToObject;
$this->rewind();

$this->cacheAvatarFiles();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace wcf\data\user\profile\visitor;

use wcf\data\DatabaseObjectList;
use wcf\data\user\TUserAvatarObjectList;
use wcf\data\user\User;
use wcf\data\user\UserProfile;

Expand All @@ -18,8 +17,6 @@
*/
class UserProfileVisitorList extends DatabaseObjectList
{
use TUserAvatarObjectList;

/**
* @inheritDoc
*/
Expand All @@ -42,18 +39,10 @@ public function __construct()
{
parent::__construct();

$this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar";
$this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar, user_table.avatarPathname";

$this->sqlJoins .= "
LEFT JOIN wcf1_user user_table
ON user_table.userID = user_profile_visitor.userID";
}

#[\Override]
public function readObjects()
{
parent::readObjects();

$this->cacheAvatarFiles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,10 @@ public function getImageCropperConfiguration(): ?ImageCropperConfiguration
// Do not crop images.
return null;
}

#[\Override]
public function replacedWithWebpVariant(File $file): void
{
// There is usually no need to react to this change.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,15 @@ public function convertImageFormat(File $file): File

case 'webp':
$command = new ReplaceWithWebpVariant($file);
return $command();
$newFile = $command();

// The files identity differs if the file has been replaced.
if ($file !== $newFile) {
$processor = $newFile->getProcessor();
$processor?->replacedWithWebpVariant($newFile);
}

return $newFile;

default:
throw new \LogicException("Unreachable");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,12 @@ public function trackDownload(File $file): void;
* @since 6.2
*/
public function getImageCropperConfiguration(): ?ImageCropperConfiguration;

/**
* Notifies the processor that one of its files was replaced with its WebP
* variant.
*
* @since 6.2
*/
public function replacedWithWebpVariant(File $file): void;
}
Loading