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; }
/** * @param $unused * @param $thread Thread * @return Title */ function newReplyTitle($unused, $thread) { return Threads::newReplyTitle($thread, $this->user); }
static function validateSubject($subject, &$title, $replyTo, $article) { $t = null; $ok = true; while (!$t) { try { global $wgUser; if (!$replyTo && $subject) { $t = Threads::newThreadTitle($subject, $article); } elseif ($replyTo) { $t = Threads::newReplyTitle($replyTo, $wgUser); } if ($t) { break; } } catch (Exception $e) { } $subject = md5(mt_rand()); // Just a random title $ok = false; } $title = $t; return $ok; }
public function actionReply($threads, $params) { // Validate thread parameter if (count($threads) > 1) { $this->dieUsage('You may only reply to one thread at a time', 'too-many-threads'); } elseif (count($threads) < 1) { $this->dieUsage('You must specify a thread to reply to', 'no-specified-threads'); } $replyTo = array_pop($threads); // Check if we can reply to that thread. $user = $this->getUser(); $perm_result = $replyTo->canUserReply($user); if ($perm_result !== true) { $this->dieUsage("You cannot reply to this thread, because the " . $perm_result . " is protected from replies.", $perm_result . '-protected'); } // Validate text parameter if (empty($params['text'])) { $this->dieUsage('You must include text in your post', 'no-text'); } $text = $params['text']; $bump = isset($params['bump']) ? $params['bump'] : null; // Generate/pull summary $summary = wfMessage('lqt-reply-summary', $replyTo->subject(), $replyTo->title()->getPrefixedText())->inContentLanguage()->text(); if (!empty($params['reason'])) { $summary = $params['reason']; } $signature = null; if (isset($params['signature'])) { $signature = $params['signature']; } // Grab data from parent $talkpage = $replyTo->article(); // Generate a reply title. $title = Threads::newReplyTitle($replyTo, $user); $article = new Article($title, 0); // Inform hooks what we're doing LqtHooks::$editTalkpage = $talkpage; LqtHooks::$editArticle = $article; LqtHooks::$editThread = null; LqtHooks::$editType = 'reply'; LqtHooks::$editAppliesTo = $replyTo; // Pull token in $token = $params['token']; // All seems in order. Construct an API edit request $requestData = array('action' => 'edit', 'title' => $title->getPrefixedText(), 'text' => $text, 'summary' => $summary, 'token' => $token, 'basetimestamp' => wfTimestampNow(), 'minor' => 0, 'format' => 'json'); if ($user->isAllowed('bot')) { $requestData['bot'] = true; } $editReq = new DerivativeRequest($this->getRequest(), $requestData, true); $internalApi = new ApiMain($editReq, true); $internalApi->execute(); if (defined('ApiResult::META_CONTENT')) { $editResult = $internalApi->getResult()->getResultData(); } else { $editResult = $internalApi->getResultData(); } if ($editResult['edit']['result'] != 'Success') { $result = array('result' => 'EditFailure', 'details' => $editResult); $this->getResult()->addValue(null, $this->getModuleName(), $result); return; } $articleId = $editResult['edit']['pageid']; $article->getTitle()->resetArticleID($articleId); $title->resetArticleID($articleId); $thread = LqtView::replyMetadataUpdates(array('root' => $article, 'replyTo' => $replyTo, 'signature' => $signature, 'summary' => $summary, 'text' => $text, 'bump' => $bump)); $result = array('action' => 'reply', 'result' => 'Success', 'thread-id' => $thread->id(), 'thread-title' => $title->getPrefixedText(), 'parent-id' => $replyTo->id(), 'parent-title' => $replyTo->title()->getPrefixedText(), 'ancestor-id' => $replyTo->topmostThread()->id(), 'ancestor-title' => $replyTo->topmostThread()->title()->getPrefixedText(), 'modified' => $thread->modified()); if (!empty($params['render'])) { $result['html'] = $this->renderThreadPostAction($thread); } $result = array('thread' => $result); $this->getResult()->addValue(null, $this->getModuleName(), $result); }