2020-08-11 20:34:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace EchoPush;
|
|
|
|
|
|
|
|
use CentralIdLookup;
|
2021-06-24 19:21:49 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|