public function getWikiNotifications($userId, $wikiId, $readSlice = 5, $countonly = false, $notifyeveryone = false) { /* if since == null, get all notifications */ /* possibly ignore $wiki at one point and fetch notifications from all wikis */ wfProfileIn(__METHOD__); $memcSync = $this->getCache($userId, $wikiId); $list = $this->getData($memcSync, $userId, $wikiId); if (empty($list)) { wfProfileOut(__METHOD__); return array(); } $read = array(); $unread = array(); foreach (array_reverse($list['notification']) as $listval) { if (!empty($listval)) { if (!$countonly) { $grouped = $this->groupEntity($list['relation'][$listval]['list']); } else { $grouped = array(); } if (!empty($grouped) || $countonly) { if ($list['relation'][$listval]['read']) { if (count($read) < $readSlice) { $read[] = array("grouped" => $grouped, "count" => empty($list['relation'][$listval]['count']) ? count($list['relation'][$listval]['list']) : $list['relation'][$listval]['count']); } elseif ($readSlice > 0) { // so we have more read notifications that we need for display // remove them $this->remNotificationsForUniqueID($userId, $wikiId, $listval); } } else { if (empty($list['relation'][$listval]['notifyeveryone']) || $notifyeveryone) { $unread[] = array("grouped" => $grouped, "count" => empty($list['relation'][$listval]['count']) ? count($list['relation'][$listval]['list']) : $list['relation'][$listval]['count']); } } } } } // we are only ever asked for notifications for Wikis that are on WikiList // so if there are no unread notifications for that Wiki it should not // be on that list (this will save us some work for checking & fetching // notifications that are in fact, empty, since current Wiki is // an exception and is always checked this works for read notification // as well) if (count($unread) == 0) { $this->remWikiFromList($userId, $wikiId); } $user = User::newFromId($userId); if (in_array('sysop', $user->getEffectiveGroups())) { //TODO: ??? $wna = new WallNotificationsAdmin(); $unread = array_merge($wna->getAdminNotifications($wikiId, $userId), $unread); } $wno = new WallNotificationsOwner(); $unread = array_merge($wno->getOwnerNotifications($wikiId, $userId), $unread); $unread = $this->sortByTimestamp($unread); $out = array('unread' => $unread, 'unread_count' => count($unread), 'read' => $read, 'read_count' => count($read)); wfProfileOut(__METHOD__); return $out; }
/** * Get all notifications for a user on a wiki * * @param int $userId The user ID receiving notifications * @param int $wikiId The wikia on which the notifications originated * @param int $readSlice Max number of already read messages to show * @param bool $countOnly Set to true to only return a count. This should be split out to another function * @param bool $notifyEveryone * * @return array|Mixed */ public function getWikiNotifications($userId, $wikiId, $readSlice = 5, $countOnly = false, $notifyEveryone = false) { $list = $this->getWikiNotificationList($userId, $wikiId); if (empty($list)) { return []; } $read = []; $unread = []; $cacheCleared = false; // walk through list of ids from wall_notification table in DB foreach (array_reverse($list['notification']) as $notifyUniqueId) { $notifyRelation = $list['relation'][$notifyUniqueId]; if (empty($notifyUniqueId)) { continue; } $grouped = []; if (!$countOnly) { $grouped = $this->groupEntity($notifyRelation['list']); if (empty($grouped)) { continue; } } if ($notifyRelation['read']) { if (count($read) < $readSlice) { $read[] = ["grouped" => $grouped, "count" => empty($notifyRelation['count']) ? count($notifyRelation['list']) : $notifyRelation['count']]; } elseif ($readSlice > 0) { // so we have more read notifications that we need for display // remove them $this->remNotificationsForUniqueID($userId, $wikiId, $notifyUniqueId); // After removing the notifications above, make sure we don't still // have them in this cache and thus try to remove them again. SOC-815 if (!$cacheCleared) { $this->clearWikiNotificationListCache($userId, $wikiId); $cacheCleared = true; } } } else { if (empty($notifyRelation['notifyeveryone']) || $notifyEveryone) { $unread[] = ["grouped" => $grouped, "count" => empty($notifyRelation['count']) ? count($notifyRelation['list']) : $notifyRelation['count']]; } } } // we are only ever asked for notifications for Wikis that are on WikiList // so if there are no unread notifications for that Wiki it should not // be on that list (this will save us some work for checking & fetching // notifications that are in fact, empty, since current Wiki is // an exception and is always checked this works for read notification // as well) if (count($unread) == 0) { $this->remWikiFromList($userId, $wikiId); } $user = $this->getUser($userId); if (in_array('sysop', $user->getEffectiveGroups())) { $wna = new WallNotificationsAdmin(); $unread = array_merge($wna->getAdminNotifications($wikiId, $userId), $unread); } $wno = new WallNotificationsOwner(); $unread = array_merge($wno->getOwnerNotifications($wikiId, $userId), $unread); $unread = $this->sortByTimestamp($unread); $out = ['unread' => $unread, 'unread_count' => count($unread), 'read' => $read, 'read_count' => count($read)]; return $out; }