mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
NotifUser: Simplify function signatures for getNotificationCount() and friends
The $cached and $dbSource parameters are now unused, so remove them. This affects get{Notification,Alert,Message}Count and getLastUnread{Notification,Alert,Message}Time. There are some callers in other extensions and in skins, but none of them pass any parameters (except one, which I fixed in Ice42930280da). Change-Id: If6f10c4f163ecb1def5a150656a60d1ab5f44d52
This commit is contained in:
parent
aa984f1b9b
commit
d0714b2928
|
@ -177,27 +177,30 @@ class MWEchoNotifUser {
|
|||
/**
|
||||
* Get message count for this user.
|
||||
*
|
||||
* @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true)
|
||||
* @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA)
|
||||
* @return int
|
||||
*/
|
||||
public function getMessageCount( $cached = true, $dbSource = DB_REPLICA ) {
|
||||
return $this->getNotificationCount( $cached, $dbSource, EchoAttributeManager::MESSAGE );
|
||||
public function getMessageCount() {
|
||||
return $this->getNotificationCount( EchoAttributeManager::MESSAGE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get alert count for this user.
|
||||
*
|
||||
* @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true)
|
||||
* @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA)
|
||||
* @return int
|
||||
*/
|
||||
public function getAlertCount( $cached = true, $dbSource = DB_REPLICA ) {
|
||||
return $this->getNotificationCount( $cached, $dbSource, EchoAttributeManager::ALERT );
|
||||
public function getAlertCount() {
|
||||
return $this->getNotificationCount( EchoAttributeManager::ALERT );
|
||||
}
|
||||
|
||||
public function getLocalNotificationCount( $cached = true, $dbSource = DB_REPLICA, $section = EchoAttributeManager::ALL ) {
|
||||
return $this->getNotificationCount( $cached, $dbSource, $section, false );
|
||||
/**
|
||||
* Get the number of unread local notifications in a given section. This does not include
|
||||
* foreign notifications, even if the user has cross-wiki notifications enabled.
|
||||
*
|
||||
* @param string $section Notification section
|
||||
* @return int
|
||||
*/
|
||||
public function getLocalNotificationCount( $section = EchoAttributeManager::ALL ) {
|
||||
return $this->getNotificationCount( $section, false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,13 +209,11 @@ class MWEchoNotifUser {
|
|||
*
|
||||
* If $wgEchoCrossWikiNotifications is disabled, the $global parameter is ignored.
|
||||
*
|
||||
* @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true)
|
||||
* @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA)
|
||||
* @param string $section Notification section
|
||||
* @param bool|string $global Whether to include foreign notifications. If set to 'preference', uses the user's preference.
|
||||
* @return int
|
||||
*/
|
||||
public function getNotificationCount( $cached = true, $dbSource = DB_REPLICA, $section = EchoAttributeManager::ALL, $global = 'preference' ) {
|
||||
public function getNotificationCount( $section = EchoAttributeManager::ALL, $global = 'preference' ) {
|
||||
if ( $this->mUser->isAnon() ) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -235,23 +236,19 @@ class MWEchoNotifUser {
|
|||
/**
|
||||
* Get the timestamp of the latest unread alert
|
||||
*
|
||||
* @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true)
|
||||
* @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA)
|
||||
* @return bool|MWTimestamp Timestamp of latest unread alert, or false if there are no unread alerts.
|
||||
*/
|
||||
public function getLastUnreadAlertTime( $cached = true, $dbSource = DB_REPLICA ) {
|
||||
return $this->getLastUnreadNotificationTime( $cached, $dbSource, EchoAttributeManager::ALERT );
|
||||
public function getLastUnreadAlertTime() {
|
||||
return $this->getLastUnreadNotificationTime( EchoAttributeManager::ALERT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the timestamp of the latest unread message
|
||||
*
|
||||
* @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true)
|
||||
* @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA)
|
||||
* @return bool|MWTimestamp
|
||||
*/
|
||||
public function getLastUnreadMessageTime( $cached = true, $dbSource = DB_REPLICA ) {
|
||||
return $this->getLastUnreadNotificationTime( $cached, $dbSource, EchoAttributeManager::MESSAGE );
|
||||
public function getLastUnreadMessageTime() {
|
||||
return $this->getLastUnreadNotificationTime( EchoAttributeManager::MESSAGE );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -259,13 +256,11 @@ class MWEchoNotifUser {
|
|||
*
|
||||
* If $wgEchoCrossWikiNotifications is disabled, the $global parameter is ignored.
|
||||
*
|
||||
* @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true)
|
||||
* @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA)
|
||||
* @param string $section Notification section
|
||||
* @param bool|string $global Whether to include foreign notifications. If set to 'preference', uses the user's preference.
|
||||
* @return bool|MWTimestamp Timestamp of latest unread message, or false if there are no unread messages.
|
||||
*/
|
||||
public function getLastUnreadNotificationTime( $cached = true, $dbSource = DB_REPLICA, $section = EchoAttributeManager::ALL, $global = 'preference' ) {
|
||||
public function getLastUnreadNotificationTime( $section = EchoAttributeManager::ALL, $global = 'preference' ) {
|
||||
if ( $this->mUser->isAnon() ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class ApiEchoMarkRead extends ApiBase {
|
|||
];
|
||||
$rawCount = 0;
|
||||
foreach ( EchoAttributeManager::$sections as $section ) {
|
||||
$rawSectionCount = $notifUser->getNotificationCount( /* $tryCache = */true, DB_REPLICA, $section );
|
||||
$rawSectionCount = $notifUser->getNotificationCount( $section );
|
||||
$result[$section]['rawcount'] = $rawSectionCount;
|
||||
$result[$section]['count'] = EchoNotificationController::formatNotificationCount( $rawSectionCount );
|
||||
$rawCount += $rawSectionCount;
|
||||
|
|
|
@ -297,7 +297,7 @@ class ApiEchoNotifications extends ApiCrossWikiBase {
|
|||
|
||||
$totalRawCount = 0;
|
||||
foreach ( $sections as $section ) {
|
||||
$rawCount = $notifUser->getNotificationCount( /* $tryCache = */true, DB_REPLICA, $section, $global );
|
||||
$rawCount = $notifUser->getNotificationCount( $section, $global );
|
||||
if ( $groupBySection ) {
|
||||
$result[$section]['rawcount'] = $rawCount;
|
||||
$result[$section]['count'] = EchoNotificationController::formatNotificationCount( $rawCount );
|
||||
|
|
|
@ -48,11 +48,11 @@ class BackfillUnreadWikis extends Maintenance {
|
|||
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
||||
$uw = EchoUnreadWikis::newFromUser( $user );
|
||||
if ( $uw ) {
|
||||
$alertCount = $notifUser->getNotificationCount( true, DB_REPLICA, EchoAttributeManager::ALERT, false );
|
||||
$alertUnread = $notifUser->getLastUnreadNotificationTime( true, DB_REPLICA, EchoAttributeManager::ALERT, false );
|
||||
$alertCount = $notifUser->getNotificationCount( EchoAttributeManager::ALERT, false );
|
||||
$alertUnread = $notifUser->getLastUnreadNotificationTime( EchoAttributeManager::ALERT, false );
|
||||
|
||||
$msgCount = $notifUser->getNotificationCount( true, DB_REPLICA, EchoAttributeManager::MESSAGE, false );
|
||||
$msgUnread = $notifUser->getLastUnreadNotificationTime( true, DB_REPLICA, EchoAttributeManager::MESSAGE, false );
|
||||
$msgCount = $notifUser->getNotificationCount( EchoAttributeManager::MESSAGE, false );
|
||||
$msgUnread = $notifUser->getLastUnreadNotificationTime( EchoAttributeManager::MESSAGE, false );
|
||||
|
||||
if ( ( $alertCount !== 0 && $alertUnread === false ) || ( $msgCount !== 0 && $msgUnread === false ) ) {
|
||||
// If there are alerts, there should be an alert timestamp (same for messages).
|
||||
|
|
Loading…
Reference in a new issue