static function newPostMetadataUpdates($data) { $requiredFields = array('talkpage', 'root', 'text', 'subject'); foreach ($requiredFields as $f) { if (!isset($data[$f])) { throw new Exception("Missing required field {$f}"); } } if (isset($data['signature'])) { $signature = $data['signature']; } else { global $wgUser; $signature = LqtView::getUserSignature($wgUser); } $summary = isset($data['summary']) ? $data['summary'] : ''; $talkpage = $data['talkpage']; $root = $data['root']; $subject = $data['subject']; $thread = Thread::create($root, $talkpage, null, Threads::TYPE_NORMAL, $subject, $summary, null, $signature); Hooks::run('LiquidThreadsAfterNewPostMetadataUpdates', array(&$thread)); return $thread; }
function doLazyUpdates() { if ($this->isHistorical()) { return; } // Don't do lazy updates on stored historical threads. // This is an invocation guard to avoid infinite recursion when fixing a // missing ancestor. static $doingUpdates = false; if ($doingUpdates) { return; } $doingUpdates = true; // Fix missing ancestry information. // (there was a bug where this was not saved properly) if ($this->parentId && !$this->ancestorId) { $this->fixMissingAncestor(); } $ancestor = $this->topmostThread(); $set = array(); // Fix missing subject information // (this information only started to be added later) if (!$this->subject && $this->root()) { $detectedSubject = $this->root()->getTitle()->getText(); $parts = self::splitIncrementFromSubject($detectedSubject); $this->subject = $detectedSubject = $parts[1]; // Update in the DB $set['thread_subject'] = $detectedSubject; } // Fix inconsistent subject information // (in some intermediate versions this was not updated when the subject was changed) if ($this->subject() != $ancestor->subject()) { $set['thread_subject'] = $ancestor->subject(); $this->subject = $ancestor->subject(); } // Fix missing authorship information // (this information only started to be added later) if (!$this->authorName) { $author = $this->loadOriginalAuthorFromRevision(); $this->authorId = $author->getId(); $this->authorName = $author->getName(); $set['thread_author_name'] = $this->authorName; $set['thread_author_id'] = $this->authorId; } // Check for article being in subject, not talk namespace. // If the page is non-LiquidThreads and it's in subject-space, we'll assume it's meant // to be on the corresponding talk page, but only if the talk-page is a LQT page. // (Previous versions stored the subject page, for some totally bizarre reason) // Old versions also sometimes store the thread page for trace threads as the // article, not as the root. // Trying not to exacerbate this by moving it to be the 'Thread talk' page. $articleTitle = $this->getTitle(); global $wgLiquidThreadsMigrate; if (!LqtDispatch::isLqtPage($articleTitle) && !$articleTitle->isTalkPage() && LqtDispatch::isLqtPage($articleTitle->getTalkPage()) && $articleTitle->getNamespace() != NS_LQT_THREAD && $wgLiquidThreadsMigrate) { $newTitle = $articleTitle->getTalkPage(); $newArticle = new Article($newTitle); $set['thread_article_namespace'] = $newTitle->getNamespace(); $set['thread_article_title'] = $newTitle->getDbKey(); $this->articleNamespace = $newTitle->getNamespace(); $this->articleTitle = $newTitle->getDbKey(); $this->articleId = $newTitle->getArticleId(); $this->article = $newArticle; } // Check for article corruption from incomplete thread moves. // (thread moves only updated this on immediate replies, not replies to replies etc) if (!$ancestor->getTitle()->equals($this->getTitle())) { $title = $ancestor->getTitle(); $set['thread_article_namespace'] = $title->getNamespace(); $set['thread_article_title'] = $title->getDbKey(); $this->articleNamespace = $title->getNamespace(); $this->articleTitle = $title->getDbKey(); $this->articleId = $title->getArticleId(); $this->article = $ancestor->article(); } // Check for invalid/missing articleId $articleTitle = null; $dbTitle = Title::makeTitleSafe($this->articleNamespace, $this->articleTitle); if ($this->articleId && isset(self::$titleCacheById[$this->articleId])) { // If it corresponds to a title, the article obviously exists. $articleTitle = self::$titleCacheById[$this->articleId]; $this->article = new Article($articleTitle); } elseif ($this->articleId) { $articleTitle = Title::newFromID($this->articleId); } // If still unfilled, the article ID referred to is no longer valid. Re-fill it // from the namespace/title pair if an article ID is provided if (!$articleTitle && ($this->articleId != 0 || $dbTitle->getArticleId() != 0)) { $articleTitle = $dbTitle; $this->articleId = $articleTitle->getArticleId(); $this->article = new Article($dbTitle); $set['thread_article_id'] = $this->articleId; wfDebug("Unfilled or non-existent thread_article_id, refilling to {$this->articleId}\n"); // There are probably problems on the rest of the article, trigger a small update Threads::synchroniseArticleData($this->article, 100, 'cascade'); } elseif ($articleTitle && !$articleTitle->equals($dbTitle)) { // The page was probably moved and this was probably not updated. wfDebug("Article ID/Title discrepancy, resetting NS/Title to article provided by ID\n"); $this->articleNamespace = $articleTitle->getNamespace(); $this->articleTitle = $articleTitle->getDBkey(); $set['thread_article_namespace'] = $articleTitle->getNamespace(); $set['thread_article_title'] = $articleTitle->getDBkey(); // There are probably problems on the rest of the article, trigger a small update Threads::synchroniseArticleData($this->article, 100, 'cascade'); } // Check for unfilled signature field. This field hasn't existed until // recently. if (is_null($this->signature)) { // Grab our signature. $sig = LqtView::getUserSignature($this->author()); $set['thread_signature'] = $sig; $this->setSignature($sig); } if (count($set)) { $dbw = wfGetDB(DB_MASTER); $dbw->update('thread', $set, array('thread_id' => $this->id()), __METHOD__); } // Done $doingUpdates = false; }