Esempio n. 1
0
 /**
  * @param $thread Thread
  */
 function showSummarizeForm($thread)
 {
     $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->summary()) {
         $article = $thread->summary();
     } else {
         $t = $this->newSummaryTitle($thread);
         $article = new Article($t, 0);
     }
     $html = Xml::openElement('div', array('class' => 'lqt-edit-form lqt-summarize-form'));
     $this->output->addHTML($html);
     $this->output->addWikiMsg('lqt-summarize-intro');
     $talkpage = $thread->article();
     LqtHooks::$editTalkpage = $talkpage;
     LqtHooks::$editArticle = $article;
     LqtHooks::$editThread = $thread;
     LqtHooks::$editType = 'summarize';
     LqtHooks::$editAppliesTo = $thread;
     $e = new EditPage($article);
     // Add an offset so it works if it's on the wrong page.
     $dbr = wfGetDB(DB_SLAVE);
     $offset = wfTimestamp(TS_UNIX, $thread->topmostThread()->sortkey());
     $offset++;
     $offset = $dbr->timestamp($offset);
     $e->suppressIntro = true;
     $e->editFormTextBeforeContent .= $this->perpetuate('lqt_method', 'hidden') . $this->perpetuate('lqt_operand', 'hidden') . Html::hidden('lqt_nonce', MWCryptRand::generateHex(32)) . Html::hidden('offset', $offset);
     $e->edit();
     if ($e->didSave) {
         $bump = !$this->request->getCheck('wpBumpThread') || $this->request->getBool('wpBumpThread');
         LqtView::summarizeMetadataUpdates(array('thread' => $thread, 'article' => $article, 'summary' => $e->summary, 'bump' => $bump));
         if ($submitted_nonce && $nonce_key) {
             global $wgMemc;
             $wgMemc->set($nonce_key, 1, 3600);
         }
     }
     if ($this->output->getRedirect() != '') {
         $redirectTitle = clone $talkpage->getTitle();
         $redirectTitle->setFragment('#' . $this->anchorName($thread));
         $this->output->redirect($this->title->getLocalURL());
     }
     $this->output->addHTML('</div>');
 }
Esempio n. 2
0
 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);
 }