2020-08-11 20:34:21 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-08 00:38:27 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Push;
|
2020-08-11 20:34:21 +00:00
|
|
|
|
2021-06-24 19:21:49 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\CentralId\CentralIdLookup;
|
2021-06-24 19:21:49 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2020-08-11 20:34:21 +00:00
|
|
|
|
|
|
|
class Utils {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to get a unique ID for the specified user, accounting for installations both with
|
|
|
|
* and without CentralAuth: Return the user's central ID, if available. If there is no central
|
|
|
|
* user associated with the local user (i.e., centralIdFromLocalUser returns 0), fall back to
|
|
|
|
* returning the local user ID.
|
2021-06-24 19:21:49 +00:00
|
|
|
* @param UserIdentity $user
|
2020-08-11 20:34:21 +00:00
|
|
|
* @return int
|
|
|
|
*/
|
2021-06-24 19:21:49 +00:00
|
|
|
public static function getPushUserId( UserIdentity $user ): int {
|
|
|
|
return MediaWikiServices::getInstance()
|
|
|
|
->getCentralIdLookup()
|
|
|
|
->centralIdFromLocalUser(
|
|
|
|
$user,
|
|
|
|
CentralIdLookup::AUDIENCE_RAW
|
|
|
|
) ?: $user->getId();
|
2020-08-11 20:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|