public function restore($user, $reason = '')
 {
     $this->unMarkInProps(WPP_WALL_REMOVE);
     $this->unMarkInProps(WPP_WALL_ADMINDELETE);
     $this->customActionNotifyRC($user, 'wall_restore', $reason);
     $wne = $this->getAdminNotificationEntity($user, $reason);
     $wh = F::build('WallHistory', array($this->cityId));
     $wh->add(WH_RESTORE, $wne, $user);
     $this->addWatch($user);
     $wn = new WallNotifications();
     if ($this->isMain()) {
         $wn->unhideNotificationsForUniqueID($this->cityId, $this->getId());
         $this->getWall()->invalidateCache();
         $wna = new WallNotificationsAdmin();
         $wna->removeForThread($this->cityId, $this->getId());
         $wno = new WallNotificationsOwner();
         $wno->removeForThread($this->cityId, $this->getWallOwner()->getId(), $this->getId());
     } else {
         $this->getThread()->invalidateCache();
         $wna = new WallNotificationsAdmin();
         $wna->removeForReply($this->cityId, $this->getId());
         $wno = new WallNotificationsOwner();
         $wno->removeForReply($this->cityId, $this->getWallOwner()->getId(), $this->getId());
     }
 }
 public function brickHeader()
 {
     $this->wg->SuppressPageTitle = true;
     $this->response->setVal('isRemoved', false);
     $this->response->setVal('isAdminDeleted', false);
     $this->response->setVal('isNotifyeveryone', false);
     $this->response->setVal('isClosed', false);
     $path = array();
     $this->response->setVal('path', $path);
     $title = Title::newFromId($this->request->getVal('id'));
     if (empty($title)) {
         $title = Title::newFromID($this->request->getVal('id'), Title::GAID_FOR_UPDATE);
     }
     if (!empty($title) && $title->isTalkPage()) {
         $wallMessage = WallMessage::newFromTitle($title);
         $wallMessageParent = $wallMessage->getTopParentObj();
         if (!empty($wallMessageParent)) {
             $wallMessage = $wallMessageParent;
         }
         $wallMessage->load();
         if ($wallMessage->isWallOwner($this->wg->User)) {
             $wallName = wfMessage('wall-message-mywall')->escaped();
         } else {
             $wallOwner = $wallMessage->getWallOwner()->getName();
             $wallName = wfMessage('wall-message-elseswall', $wallOwner)->parse();
         }
         $wallUrl = $wallMessage->getWallUrl();
         $messageTitle = htmlspecialchars($wallMessage->getMetaTitle());
         $isRemoved = $wallMessage->isRemove();
         $isDeleted = $wallMessage->isAdminDelete();
         $this->response->setVal('isRemoved', $isRemoved);
         $this->response->setVal('isAdminDeleted', $isDeleted);
         $this->response->setVal('isNotifyeveryone', $wallMessage->getNotifyeveryone());
         $this->response->setVal('isClosed', $wallMessage->isArchive());
         if ($isRemoved || $isDeleted) {
             $this->wg->Out->setRobotPolicy("noindex,nofollow");
         }
         $user = $this->app->wg->User;
         // remove admin notification for it if Admin just checked it
         if (in_array('sysop', $user->getEffectiveGroups()) || in_array('staff', $user->getEffectiveGroups())) {
             $wna = new WallNotificationsAdmin();
             $wna->removeForThread($this->app->wg->CityId, $wallMessage->getId());
         }
         $wno = new WallNotificationsOwner();
         $wno->removeForThread($this->app->wg->CityId, $user->getId(), $wallMessage->getId());
         $path[] = array('title' => $wallName, 'url' => $wallUrl);
         $path[] = array('title' => $messageTitle);
         $this->getContext()->getOutput()->setRobotPolicy('index,follow');
         wfRunHooks('WallThreadHeader', array($title, $wallMessage, &$path, &$this->response, &$this->request));
     } else {
         wfRunHooks('WallHeader', array($this->wg->Title, &$path, &$this->response, &$this->request));
     }
     $this->response->setVal('path', $path);
 }
 public function markRead($userId, $wikiId, $id = 0, $ts = 0)
 {
     $updateDBlist = array();
     // we will update database AFTER unlocking
     $wasUnread = false;
     // function returns True if in fact there was unread
     // notification
     $memcSync = $this->getCache($userId, $wikiId);
     do {
         $count = 0;
         //use to set priority of process
         if ($memcSync->lock()) {
             $data = $this->getData($memcSync, $userId, $wikiId);
             if ($id == 0 && !empty($data['relation'])) {
                 $ids = array_keys($data['relation']);
             } else {
                 $ids = array($id);
             }
             foreach ($ids as $value) {
                 if (!empty($data['relation'][$value])) {
                     if ($data['relation'][$value]['read'] == false) {
                         $wasUnread = true;
                         $data['relation'][$value]['read'] = true;
                         $updateDBlist[] = array('user_id' => $userId, 'wiki_id' => $wikiId, 'unique_id' => $value);
                     }
                 }
             }
         } else {
             $this->sleep($count);
         }
         $count++;
     } while (!isset($data) || !$this->setData($memcSync, $data));
     $memcSync->unlock();
     foreach ($updateDBlist as $value) {
         $this->getDB(true)->update('wall_notification', array('is_read' => 1), $value, __METHOD__);
     }
     if ($id === 0) {
         $user = User::newFromId($userId);
         if ($user instanceof User && (in_array('sysop', $user->getEffectiveGroups()) || in_array('staff', $user->getEffectiveGroups()))) {
             $wna = new WallNotificationsAdmin();
             $wasUnread = $wasUnread || $wna->hideAdminNotifications($wikiId, $userId);
         }
         $wno = new WallNotificationsOwner();
         $wasUnread = $wasUnread || $wno->removeAll($wikiId, $userId);
     }
     return $wasUnread;
 }
 public function markRead($userId, $wikiId, $id = 0)
 {
     $updateDBlist = [];
     // we will update database AFTER unlocking
     $wasUnread = false;
     // function returns True if in fact there was unread notification
     $memcSync = $this->getCache($userId, $wikiId);
     $memcSync->lockAndSetData(function () use($memcSync, $userId, $wikiId, $id, &$updateDBlist, &$wasUnread) {
         $data = $this->getData($memcSync, $userId, $wikiId);
         if ($id == 0 && !empty($data['relation'])) {
             $ids = array_keys($data['relation']);
         } else {
             $ids = [$id];
         }
         foreach ($ids as $value) {
             if (!empty($data['relation'][$value])) {
                 if ($data['relation'][$value]['read'] == false) {
                     $wasUnread = true;
                     $data['relation'][$value]['read'] = true;
                     $updateDBlist[] = ['user_id' => $userId, 'wiki_id' => $wikiId, 'unique_id' => $value];
                 }
             }
         }
         return $data;
     }, function () use($memcSync) {
         // Delete the cache if we were unable to update to force a rebuild
         $memcSync->delete();
     });
     $this->purgeCountsCache($userId);
     foreach ($updateDBlist as $value) {
         $this->getDB(true)->update('wall_notification', ['is_read' => 1], $value, __METHOD__);
     }
     if ($id === 0) {
         $user = $this->getUser($userId);
         if ($user instanceof User && (in_array('sysop', $user->getEffectiveGroups()) || in_array('staff', $user->getEffectiveGroups()))) {
             $wna = new WallNotificationsAdmin();
             $wasUnread = $wasUnread || $wna->hideAdminNotifications($wikiId, $userId);
         }
         $wno = new WallNotificationsOwner();
         $wasUnread = $wasUnread || $wno->removeAll($wikiId, $userId);
     }
     return $wasUnread;
 }