static function lqtThread($parser, $args, $parser, $frame) { $pout = $parser->getOutput(); // Prepare information. $title = Title::newFromText($args['thread']); $thread = null; if ($args['thread']) { if (is_numeric($args['thread'])) { $thread = Threads::withId($args['thread']); } elseif ($title) { $article = new Article($title, 0); $thread = Threads::withRoot($article); } } if (is_null($thread)) { return ''; } $data = array('type' => 'thread', 'args' => $args, 'thread' => $thread->id(), 'title' => $thread->title()); if (!isset($pout->mLqtReplacements)) { $pout->mLqtReplacements = array(); } // Generate a token $tok = wfGenerateToken(); $text = '<!--LQT-THREAD-' . $tok . '-->'; $pout->mLqtReplacements[$text] = $data; return $text; }
function createPost($info, $subject, $super = null) { $userName = $info['user']; if (strpos($userName, '#') !== false) { $pos = strpos($userName, '#'); $userName = substr($userName, 0, $pos); } $user = User::newFromName($userName, false); if (!$user) { throw new MWException("Username " . $info['user'] . " is invalid."); } global $article; if ($super) { $title = Threads::newReplyTitle($super, $user); } else { $title = Threads::newThreadTitle($subject, $article); } print "Creating thread {$title} as a subthread of " . ($super ? $super->title() : 'none') . "\n"; $root = new Article($title); $root->doEdit($info['content'], 'Imported from JSON', EDIT_NEW, false, $user); $t = LqtView::postEditUpdates($super ? 'reply' : 'new', $super, $root, $article, $subject, 'Imported from JSON', null); $t = Threads::withId($t->id()); // Some weirdness. return $t; }
function formatThreadField($field, $threadid) { if (!is_object($threadid)) { $t = Threads::withId($threadid); } else { $t = $threadid; $threadid = $t->id(); } $out = Html::hidden($field, $threadid); $out .= LqtView::permalink($t); return $out; }
private static function writeUserMessageState($thread, $user, $timestamp) { if (is_object($thread)) { $thread_id = $thread->id(); } elseif (is_integer($thread)) { $thread_id = $thread; } else { throw new MWException("writeUserMessageState expected Thread or integer but got {$thread}"); } if (is_object($user)) { $user_id = $user->getID(); } elseif (is_integer($user)) { $user_id = $user; } else { throw new MWException("writeUserMessageState expected User or integer but got {$user}"); } $conversation = Threads::withId($thread_id)->topmostThread()->id(); $dbw = wfGetDB(DB_MASTER); $dbw->replace('user_message_state', array(array('ums_user', 'ums_thread')), array('ums_user' => $user_id, 'ums_thread' => $thread_id, 'ums_read_timestamp' => $timestamp, 'ums_conversation' => $conversation), __METHOD__); self::recacheMessageCount($user_id); }
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)); } }
function getMustShowThreads($threads = array()) { if ($this->request->getCheck('lqt_operand')) { $operands = explode(',', $this->request->getVal('lqt_operand')); $threads = array_merge($threads, $operands); } if ($this->request->getCheck('lqt_mustshow')) { // Check for must-show in the request $specifiedMustShow = $this->request->getVal('lqt_mustshow'); $specifiedMustShow = explode(',', $specifiedMustShow); $threads = array_merge($threads, $specifiedMustShow); } foreach ($threads as $walk_thread) { do { if (!is_object($walk_thread)) { $walk_thread = Threads::withId($walk_thread); } if (!is_object($walk_thread)) { continue; } $threads[$walk_thread->id()] = $walk_thread; $walk_thread = $walk_thread->superthread(); } while ($walk_thread); } return $threads; }
function topmostThread() { if ($this->isTopmostThread()) { return $this->ancestor = $this; } elseif ($this->ancestor) { return $this->ancestor; } else { $this->dieIfHistorical(); $thread = Threads::withId($this->ancestorId); if (!$thread) { $thread = $this->fixMissingAncestor(); } $this->ancestor = $thread; return $thread; } }
public function actionMerge($threads, $params) { if (count($threads) < 1) { $this->dieUsage('You must specify a thread to merge', 'no-specified-threads'); } if (empty($params['newparent'])) { $this->dieUsage('You must specify a new parent thread to merge beneath', 'no-parent-thread'); } $newParent = $params['newparent']; if (is_numeric($newParent)) { $newParent = Threads::withId($newParent); } else { $title = Title::newFromText($newParent); $article = new Article($title, 0); $newParent = Threads::withRoot($article); } $errors = $newParent->title()->getUserPermissionsErrors('lqt-merge', $this->getUser()); if ($errors) { // We don't care about multiple errors, just report one of them $this->dieUsageMsg(reset($errors)); } if (!$newParent) { $this->dieUsage('The parent thread you specified was neither the title ' . 'of a thread, nor a thread ID.', 'invalid-parent-thread'); } // Pull a reason, if applicable. $reason = ''; if (!empty($params['reason'])) { $reason = $params['reason']; } $result = array(); foreach ($threads as $thread) { $thread->moveToParent($newParent, $reason); $result[] = array('result' => 'Success', 'action' => 'merge', 'id' => $thread->id(), 'title' => $thread->title()->getPrefixedText(), 'new-parent-id' => $newParent->id(), 'new-parent-title' => $newParent->title()->getPrefixedText(), 'new-ancestor-id' => $newParent->topmostThread()->id(), 'new-ancestor-title' => $newParent->topmostThread()->title()->getPrefixedText()); } $this->getResult()->setIndexedTagName($result, 'thread'); $this->getResult()->addValue(null, 'threadaction', $result); }
/** * Adds a new response or modifies an existing response. * * The params listed below are the items posted in $params. * @param $comment_id * @param $bullet_id The bullet to which this response addresses * @param $bullet_rev The current revision of the above referenced bullet * @param $response_id If set to valid bullet_id, signals a modification * @param $text The bullet text * @param $signal The accuracy rating for the respective bullet * * @return assoc array with $insert_id as the bullet id and $rev_id as the new rev id */ function addResponse($params) { $dbw = wfGetDB(DB_MASTER); $dbr = wfGetDB(DB_SLAVE); global $wgUser; $user = $wgUser->getName(); $bulletID = $params['bullet_id']; $commentID = $params['comment_id']; $responseText = $params['text']; if ($responseText == '') { return ''; } $signal = (int) $params['signal']; $modify = isset($params['response_id']); if ($modify) { $responseID = $params['response_id']; } else { /* * w/o lock, the following could lead to a race condition * TODO: should $wgAntiLockFlags be used here? */ $dbw->begin(); // start transaction $res = $dbr->query('select MAX(rsp_id)+1 as next_rsp_id from ' . $dbr->tableName('reflect_response_revision')); $responseID = $res->fetchRow(); $responseID = $responseID['next_rsp_id']; if (!$responseID) { $responseID = 0; } } $dbw->insert($table = 'reflect_response_revision', array('rsp_id' => $responseID, 'bl_id' => $bulletID, 'rsp_user' => $user, 'rsp_text' => $responseText, 'rsp_signal' => $signal)); $responseRev = $dbw->insertId(); if (!$modify) { $dbw->commit(); // end transaction } if ($modify) { /* shouldn't lead to race condition as long as * only commenters can update their responses (DEFAULT) */ $dbw->update($table = 'reflect_response_current', $values = array('rsp_rev_id' => $responseRev), $conds = array('rsp_id =' . $responseID)); } else { $dbw->insert($table = 'reflect_response_current', array('rsp_rev_id' => $responseRev, 'rsp_id' => $responseID, 'bl_id' => $bulletID)); } $bullet = $dbr->selectRow($table = 'reflect_bullet_revision', $vars = array('bl_user as user', 'bl_text as text'), $conds = 'bl_rev_id = ' . $params['bullet_rev']); /* send email notification to bullet author that someone * rated the accuracy of their bullet */ global $wgReflectEnotif; if ($wgReflectEnotif && !$modify) { $threadObj = Threads::withId($commentID); $to = User::newFromName($bullet->user); $catalystUser = $threadObj->author(); $this->sendMail($threadObj, $to, $catalystUser, 'reflect-responded', array($responseText, $bullet->text), array()); } return array("insert_id" => $responseID, "rev_id" => $responseRev, "u" => $user, "sig" => $signal); }