Esempio n. 1
0
 public function actionMarkUnread($threads, $params)
 {
     $result = array();
     $user = $this->getUser();
     foreach ($threads as $t) {
         NewMessages::markThreadAsUnreadByUser($t, $user);
         $result[] = array('result' => 'Success', 'action' => 'markunread', 'id' => $t->id(), 'title' => $t->title()->getPrefixedText());
     }
     $this->getResult()->setIndexedTagName($result, 'thread');
     $this->getResult()->addValue(null, 'threadaction', $result);
 }
 function showOnce()
 {
     NewMessages::recacheMessageCount($this->user->getId());
     $this->user->setNewtalk(false);
     if ($this->methodApplies('mark_as_unread')) {
         $ids = explode(',', $this->request->getVal('lqt_operand', ''));
         if ($ids !== false) {
             foreach ($ids as $id) {
                 $tmp_thread = Threads::withId($id);
                 if ($tmp_thread) {
                     NewMessages::markThreadAsUnReadByUser($tmp_thread, $this->user);
                 }
             }
             $this->output->redirect($this->title->getLocalURL());
         }
     } elseif ($this->methodApplies('mark_as_read')) {
         $ids = explode(',', $this->request->getVal('lqt_operand'));
         if ($ids !== false) {
             foreach ($ids as $id) {
                 if ($id == 'all') {
                     NewMessages::markAllReadByUser($this->user);
                 } else {
                     $tmp_thread = Threads::withId($id);
                     if ($tmp_thread) {
                         NewMessages::markThreadAsReadByUser($tmp_thread, $this->user);
                     }
                 }
             }
             $query = 'lqt_method=undo_mark_as_read&lqt_operand=' . implode(',', $ids);
             $this->output->redirect($this->title->getLocalURL($query));
         }
     } elseif ($this->methodApplies('undo_mark_as_read')) {
         $ids = explode(',', $this->request->getVal('lqt_operand', ''));
         $this->output->addHTML($this->getUndoButton($ids));
     }
 }
Esempio n. 3
0
 function commitRevision($change_type, $change_object = null, $reason = "", $bump = null)
 {
     $this->dieIfHistorical();
     global $wgUser;
     global $wgThreadActionsNoBump;
     if (is_null($bump)) {
         $bump = !in_array($change_type, $wgThreadActionsNoBump);
     }
     if ($bump) {
         $this->sortkey = wfTimestamp(TS_MW);
     }
     $original = $this->dbVersion;
     $this->modified = wfTimestampNow();
     $this->updateEditedness($change_type);
     $this->save(__METHOD__ . "/" . wfGetCaller());
     $topmost = $this->topmostThread();
     $topmost->modified = wfTimestampNow();
     if ($bump) {
         $topmost->setSortkey(wfTimestamp(TS_MW));
     }
     $topmost->save();
     ThreadRevision::create($this, $change_type, $change_object, $reason);
     $this->logChange($change_type, $original, $change_object, $reason);
     if ($change_type == Threads::CHANGE_EDITED_ROOT) {
         NewMessages::writeMessageStateForUpdatedThread($this, $change_type, $wgUser);
     }
 }
Esempio n. 4
0
 function moveToPage($title, $reason, $leave_trace)
 {
     global $wgUser;
     if (!$this->isTopmostThread()) {
         throw new Exception("Attempt to move non-toplevel thread to another page");
     }
     $this->dieIfHistorical();
     $dbr = wfGetDB(DB_MASTER);
     $oldTitle = $this->getTitle();
     $newTitle = $title;
     $new_articleNamespace = $title->getNamespace();
     $new_articleTitle = $title->getDBkey();
     $new_articleID = $title->getArticleID();
     if (!$new_articleID) {
         $article = new Article($newTitle, 0);
         Threads::createTalkpageIfNeeded($article);
         $new_articleID = $article->getId();
     }
     // Update on *all* subthreads.
     $dbr->update('thread', array('thread_article_namespace' => $new_articleNamespace, 'thread_article_title' => $new_articleTitle, 'thread_article_id' => $new_articleID), array('thread_ancestor' => $this->id()), __METHOD__);
     $this->articleNamespace = $new_articleNamespace;
     $this->articleTitle = $new_articleTitle;
     $this->articleId = $new_articleID;
     $this->article = null;
     $this->commitRevision(Threads::CHANGE_MOVED_TALKPAGE, null, $reason);
     // Notifications
     NewMessages::writeMessageStateForUpdatedThread($this, $this->type, $wgUser);
     if ($leave_trace) {
         $this->leaveTrace($reason, $oldTitle, $newTitle);
     }
 }
 /**
  * Write a user_message_state for each user who is watching the thread.
  * If the thread is on a user's talkpage, set that user's newtalk.
  */
 static function writeMessageStateForUpdatedThread($t, $type, $changeUser)
 {
     wfDebugLog('LiquidThreads', 'Doing notifications');
     wfProfileIn(__METHOD__);
     // Pull users to update the message state for, including whether or not a
     //  user_message_state row exists for them, and whether or not to send an email
     //  notification.
     $userIds = array();
     $notifyUsers = array();
     $res = self::getRowsObject($t);
     foreach ($res as $row) {
         // Don't notify yourself
         if ($changeUser->getId() == $row->wl_user) {
             continue;
         }
         if (!$row->ums_user || $row->ums_read_timestamp) {
             $userIds[] = $row->wl_user;
             NewMessages::recacheMessageCount($row->wl_user);
         }
         $wantsTalkNotification = true;
         $wantsTalkNotification = $wantsTalkNotification && User::getDefaultOption('lqtnotifytalk');
         if ($wantsTalkNotification || $row->up_value) {
             $notifyUsers[] = $row->wl_user;
         }
     }
     // Add user talk notification
     if ($t->getTitle()->getNamespace() == NS_USER_TALK) {
         $name = $t->getTitle()->getText();
         $user = User::newFromName($name);
         if ($user && $user->getName() != $changeUser->getName()) {
             $user->setNewtalk(true);
             $userIds[] = $user->getId();
             if ($user->getOption('enotifusertalkpages')) {
                 $notifyUsers[] = $user->getId();
             }
         }
     }
     // Do the actual updates
     if (count($userIds)) {
         foreach ($userIds as $u) {
             $insertRows[] = array('ums_user' => $u, 'ums_thread' => $t->id(), 'ums_read_timestamp' => null, 'ums_conversation' => $t->topmostThread()->id());
         }
         $dbw = wfGetDB(DB_MASTER);
         $dbw->replace('user_message_state', array(array('ums_user', 'ums_thread')), $insertRows, __METHOD__);
     }
     global $wgLqtEnotif;
     if (count($notifyUsers) && $wgLqtEnotif) {
         self::notifyUsersByMail($t, $notifyUsers, wfTimestampNow(), $type);
     }
     wfProfileOut(__METHOD__);
 }
Esempio n. 6
0
 static function onPersonalUrls(&$personal_urls, &$title)
 {
     global $wgUser;
     if ($wgUser->isAnon()) {
         return true;
     }
     global $wgLiquidThreadsEnableNewMessages;
     if ($wgLiquidThreadsEnableNewMessages) {
         $newMessagesCount = NewMessages::newMessageCount($wgUser);
         // Add new messages link.
         $url = SpecialPage::getTitleFor('NewMessages')->getLocalURL();
         $msg = $newMessagesCount ? 'lqt-newmessages-n' : 'lqt_newmessages';
         $newMessagesLink = array('href' => $url, 'text' => wfMessage($msg)->numParams($newMessagesCount)->text(), 'active' => $newMessagesCount > 0);
         $insertUrls = array('newmessages' => $newMessagesLink);
         if (in_array('watchlist', array_keys($personal_urls))) {
             // User has viewmywatchlist permission
             $personal_urls = wfArrayInsertAfter($personal_urls, $insertUrls, 'watchlist');
         } else {
             $personal_urls = wfArrayInsertAfter($personal_urls, $insertUrls, 'preferences');
         }
     }
     return true;
 }
Esempio n. 7
0
 static function onPersonalUrls(&$personal_urls, &$title)
 {
     global $wgUser, $wgLang;
     if ($wgUser->isAnon()) {
         return true;
     }
     $newMessagesCount = NewMessages::newMessageCount($wgUser);
     // Add new messages link.
     $url = SpecialPage::getTitleFor('NewMessages')->getLocalURL();
     $msg = $newMessagesCount ? 'lqt-newmessages-n' : 'lqt_newmessages';
     $newMessagesLink = array('href' => $url, 'text' => wfMsg($msg, $wgLang->formatNum($newMessagesCount)), 'active' => $newMessagesCount > 0);
     $insertUrls = array('newmessages' => $newMessagesLink);
     $personal_urls = wfArrayInsertAfter($personal_urls, $insertUrls, 'watchlist');
     return true;
 }
Esempio n. 8
0
 static function getNotifyUsers($t, $changeUser)
 {
     // Pull users to update the message state for, including whether or not a
     //  user_message_state row exists for them, and whether or not to send an email
     //  notification.
     $userIds = array();
     $notifyUsers = array();
     $res = self::getRowsObject($t);
     foreach ($res as $row) {
         // Don't notify yourself
         if ($changeUser->getId() == $row->wl_user) {
             continue;
         }
         if (!$row->ums_user || $row->ums_read_timestamp) {
             $userIds[] = $row->wl_user;
             NewMessages::recacheMessageCount($row->wl_user);
         }
         global $wgHiddenPrefs;
         if (!in_array('lqtnotifytalk', $wgHiddenPrefs) && isset($row->up_value)) {
             $wantsTalkNotification = (bool) $row->wl_user;
         } else {
             $wantsTalkNotification = User::getDefaultOption('lqtnotifytalk');
         }
         if ($wantsTalkNotification) {
             $notifyUsers[] = $row->wl_user;
         }
     }
     // Add user talk notification
     if ($t->getTitle()->getNamespace() == NS_USER_TALK) {
         $name = $t->getTitle()->getText();
         $user = User::newFromName($name);
         if ($user && $user->getName() != $changeUser->getName()) {
             $user->setNewtalk(true);
             $userIds[] = $user->getId();
             if ($user->getOption('enotifusertalkpages')) {
                 $notifyUsers[] = $user->getId();
             }
         }
     }
     return array('notify' => $userIds, 'email' => $notifyUsers);
 }