/** * @param $talkpage Thread */ function showNewThreadForm($talkpage) { $submitted_nonce = $this->request->getVal('lqt_nonce'); $nonce_key = wfMemcKey('lqt-nonce', $submitted_nonce, $this->user->getName()); if (!$this->handleNonce($submitted_nonce, $nonce_key)) { return; } if (Thread::canUserPost($this->user, $this->article) !== true) { $this->output->addWikiMsg('lqt-protected-newthread'); return; } $subject = $this->request->getVal('lqt_subject_field', false); $t = null; $subjectOk = Thread::validateSubject($subject, $t, null, $this->article); if (!$subjectOk) { try { $t = $this->newThreadTitle($subject); } catch (Exception $excep) { $t = $this->scratchTitle(); } } $html = Xml::openElement('div', array('class' => 'lqt-edit-form lqt-new-thread')); $this->output->addHTML($html); $article = new Article($t, 0); LqtHooks::$editTalkpage = $talkpage; LqtHooks::$editArticle = $article; LqtHooks::$editThread = null; LqtHooks::$editType = 'new'; LqtHooks::$editAppliesTo = null; $e = new EditPage($article); Hooks::run('LiquidThreadsShowNewThreadForm', array(&$e, $talkpage)); global $wgRequest; // Quietly force a preview if no subject has been specified. if (!$subjectOk) { // Dirty hack to prevent saving from going ahead $wgRequest->setVal('wpPreview', true); if ($this->request->wasPosted()) { if (!$subject) { $msg = 'lqt_empty_subject'; } else { $msg = 'lqt_invalid_subject'; } $e->editFormPageTop .= Xml::tags('div', array('class' => 'error'), wfMessage($msg)->parseAsBlock()); } } $e->suppressIntro = true; $e->editFormTextBeforeContent .= $this->perpetuate('lqt_method', 'hidden') . $this->perpetuate('lqt_operand', 'hidden') . Html::hidden('lqt_nonce', MWCryptRand::generateHex(32)); $e->mShowSummaryField = false; $summary = wfMessage('lqt-newpost-summary', $subject)->inContentLanguage()->text(); $wgRequest->setVal('wpSummary', $summary); list($signatureEditor, $signatureHTML) = $this->getSignatureEditor($this->user); $e->editFormTextAfterContent .= $signatureEditor; $e->previewTextAfterContent .= Xml::tags('p', null, $signatureHTML); $e->editFormTextBeforeContent .= $this->getSubjectEditor('', $subject); Hooks::run('LiquidThreadsAfterShowNewThreadForm', array(&$e, $talkpage)); $e->edit(); if ($e->didSave) { $signature = $this->request->getVal('wpLqtSignature', null); $info = array('talkpage' => $talkpage, 'text' => $e->textbox1, 'summary' => $e->summary, 'signature' => $signature, 'root' => $article, 'subject' => $subject); Hooks::run('LiquidThreadsSaveNewThread', array(&$info, &$e, &$talkpage)); $thread = LqtView::newPostMetadataUpdates($info); if ($submitted_nonce && $nonce_key) { global $wgMemc; $wgMemc->set($nonce_key, 1, 3600); } } if ($this->output->getRedirect() != '') { $redirectTitle = clone $talkpage->getTitle(); if (!empty($thread)) { $redirectTitle->setFragment('#' . $this->anchorName($thread)); } $this->output->redirect($this->title->getLocalURL()); } $this->output->addHTML('</div>'); }
public function actionNewThread($threads, $params) { // Validate talkpage parameters if (!count($params['talkpage'])) { $this->dieUsageMsg(array('missingparam', 'talkpage')); } $talkpageTitle = Title::newFromText($params['talkpage']); if (!$talkpageTitle || !LqtDispatch::isLqtPage($talkpageTitle)) { $this->dieUsage('The talkpage you specified is invalid, or does not ' . 'have discussion threading enabled.', 'invalid-talkpage'); } $talkpage = new Article($talkpageTitle, 0); // Check if we can post. $user = $this->getUser(); if (Thread::canUserPost($user, $talkpage) !== true) { $this->dieUsage('You cannot post to the specified talkpage, ' . 'because it is protected from new posts', 'talkpage-protected'); } // Validate subject, generate a title if (empty($params['subject'])) { $this->dieUsageMsg(array('missingparam', 'subject')); } $subject = $params['subject']; $title = null; $subjectOk = Thread::validateSubject($subject, $title, null, $talkpage); if (!$subjectOk) { $this->dieUsage('The subject you specified is not valid', 'invalid-subject'); } $article = new Article($title, 0); // Check for text if (empty($params['text'])) { $this->dieUsage('You must include text in your post', 'no-text'); } $text = $params['text']; // Generate or pull summary $summary = wfMessage('lqt-newpost-summary', $subject)->inContentLanguage()->text(); if (!empty($params['reason'])) { $summary = $params['reason']; } $signature = null; if (isset($params['signature'])) { $signature = $params['signature']; } // Inform hooks what we're doing LqtHooks::$editTalkpage = $talkpage; LqtHooks::$editArticle = $article; LqtHooks::$editThread = null; LqtHooks::$editType = 'new'; LqtHooks::$editAppliesTo = null; $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::newPostMetadataUpdates(array('root' => $article, 'talkpage' => $talkpage, 'subject' => $subject, 'signature' => $signature, 'summary' => $summary, 'text' => $text)); $result = array('result' => 'Success', 'thread-id' => $thread->id(), 'thread-title' => $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); }