|
|
|
@ -171,33 +171,57 @@ class IsekaiOIDCAuthHooks {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function onGetUserAvatar(&$avatarUrl, $size, $user) {
|
|
|
|
|
/**
|
|
|
|
|
* Get avatar url for users
|
|
|
|
|
* @param array &$avatars
|
|
|
|
|
* @param \User[] $users
|
|
|
|
|
* @param int $size
|
|
|
|
|
*/
|
|
|
|
|
public static function onGetUsersAvatar(&$avatars, array $users, $size = 128) {
|
|
|
|
|
if (!is_array($avatars)) {
|
|
|
|
|
$avatars = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$config = $services->getMainConfig();
|
|
|
|
|
$wgIsekaiOIDC = $config->get('IsekaiOIDC');
|
|
|
|
|
|
|
|
|
|
if (isset($wgIsekaiOIDC['avatarUrl'])) {
|
|
|
|
|
list($subject, $accessToken, $refreshToken) = IsekaiOIDCAuth::findOidcDataByUserId($user->getId());
|
|
|
|
|
$avatarFinded = false;
|
|
|
|
|
if ($subject) {
|
|
|
|
|
$avatarUrl = str_replace(['{openid}', '{username}'], [urlencode($subject), urlencode($user->getName())], $wgIsekaiOIDC['avatarUrl']);
|
|
|
|
|
$avatarFinded = true;
|
|
|
|
|
} else {
|
|
|
|
|
if (isset($wgIsekaiOIDC['defaultAvatarUrl'])) {
|
|
|
|
|
$avatarUrl = $wgIsekaiOIDC['defaultAvatarUrl'];
|
|
|
|
|
$avatarFinded = true;
|
|
|
|
|
$userIds = array_map(function($user) {
|
|
|
|
|
return $user->getId();
|
|
|
|
|
}, $users);
|
|
|
|
|
|
|
|
|
|
$subjects = IsekaiOIDCAuth::findOidcSubjectsByUserIds($userIds);
|
|
|
|
|
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
$subject = null;
|
|
|
|
|
if (isset($subjects[$user->getId()])) {
|
|
|
|
|
$subject = $subjects[$user->getId()];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($avatarFinded) {
|
|
|
|
|
if ($size <= 64) {
|
|
|
|
|
$avatarUrl = "$avatarUrl?size=md";
|
|
|
|
|
} else if ($size <= 128) {
|
|
|
|
|
$avatarUrl = "$avatarUrl?size=lg";
|
|
|
|
|
} else if ($size <= 256) {
|
|
|
|
|
$avatarUrl = "$avatarUrl?size=xl";
|
|
|
|
|
$avatarFinded = false;
|
|
|
|
|
if ($subject) {
|
|
|
|
|
$avatarUrl = str_replace(['{openid}', '{username}'], [urlencode($subject), urlencode($user->getName())], $wgIsekaiOIDC['avatarUrl']);
|
|
|
|
|
$avatarFinded = true;
|
|
|
|
|
} else {
|
|
|
|
|
$avatarUrl = "$avatarUrl?size=xxl";
|
|
|
|
|
if (isset($wgIsekaiOIDC['defaultAvatarUrl'])) {
|
|
|
|
|
$avatarUrl = $wgIsekaiOIDC['defaultAvatarUrl'];
|
|
|
|
|
$avatarFinded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($avatarFinded) {
|
|
|
|
|
if ($size <= 64) {
|
|
|
|
|
$avatarUrl = "$avatarUrl?size=md";
|
|
|
|
|
} else if ($size <= 128) {
|
|
|
|
|
$avatarUrl = "$avatarUrl?size=lg";
|
|
|
|
|
} else if ($size <= 256) {
|
|
|
|
|
$avatarUrl = "$avatarUrl?size=xl";
|
|
|
|
|
} else {
|
|
|
|
|
$avatarUrl = "$avatarUrl?size=xxl";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$avatars[$user->getId()] = $avatarUrl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|