Esempio n. 1
0
 public function actionEdit($threads, $params)
 {
     if (count($threads) > 1) {
         $this->dieUsage('You may only edit one thread at a time', 'too-many-threads');
     } elseif (count($threads) < 1) {
         $this->dieUsage('You must specify a thread to edit', 'no-specified-threads');
     }
     $thread = array_pop($threads);
     $talkpage = $thread->article();
     $bump = isset($params['bump']) ? $params['bump'] : null;
     // Validate subject
     $subjectOk = true;
     if (!empty($params['subject'])) {
         $subject = $params['subject'];
         $title = null;
         $subjectOk = empty($subject) || Thread::validateSubject($subject, $title, null, $talkpage);
     } else {
         $subject = $thread->subject();
     }
     if (!$subjectOk) {
         $this->dieUsage('The subject you specified is not valid', 'invalid-subject');
     }
     // Check for text
     if (empty($params['text'])) {
         $this->dieUsage('You must include text in your post', 'no-text');
     }
     $text = $params['text'];
     $summary = '';
     if (!empty($params['reason'])) {
         $summary = $params['reason'];
     }
     $article = $thread->root();
     $title = $article->getTitle();
     $signature = null;
     if (isset($params['signature'])) {
         $signature = $params['signature'];
     }
     // Inform hooks what we're doing
     LqtHooks::$editTalkpage = $talkpage;
     LqtHooks::$editArticle = $article;
     LqtHooks::$editThread = $thread;
     LqtHooks::$editType = 'edit';
     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, 'minor' => 0, 'basetimestamp' => wfTimestampNow(), 'format' => 'json');
     if ($this->getUser()->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;
     }
     $thread = LqtView::editMetadataUpdates(array('root' => $article, 'thread' => $thread, 'subject' => $subject, 'signature' => $signature, 'summary' => $summary, 'text' => $text, 'bump' => $bump));
     $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);
 }
Esempio n. 2
0
 /**
  * @param $thread Thread
  */
 function showPostEditingForm($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;
     }
     $html = Xml::openElement('div', array('class' => 'lqt-edit-form'));
     $this->output->addHTML($html);
     $subject = $this->request->getVal('lqt_subject_field', '');
     if (!$subject) {
         $subject = $thread->subject();
     }
     $t = null;
     $subjectOk = Thread::validateSubject($subject, $t, $thread->superthread(), $this->article);
     if (!$subjectOk) {
         $subject = false;
     }
     $article = $thread->root();
     $talkpage = $thread->article();
     Hooks::run('LiquidThreadsEditFormContent', array($thread, &$article, $talkpage));
     LqtHooks::$editTalkpage = $talkpage;
     LqtHooks::$editArticle = $article;
     LqtHooks::$editThread = $thread;
     LqtHooks::$editType = 'edit';
     LqtHooks::$editAppliesTo = $thread;
     $e = new EditPage($article);
     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()) {
             $e->editFormPageTop .= Xml::tags('div', array('class' => 'error'), wfMessage('lqt_invalid_subject')->parse());
         }
     }
     // 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);
     list($signatureEditor, $signatureHTML) = $this->getSignatureEditor($thread);
     $e->editFormTextAfterContent .= $signatureEditor;
     $e->previewTextAfterContent .= Xml::tags('p', null, $signatureHTML);
     if ($thread->isTopmostThread()) {
         $e->editFormTextBeforeContent .= $this->getSubjectEditor($thread->subject(), $subject);
     }
     $e->edit();
     if ($e->didSave) {
         $bump = !$this->request->getCheck('wpBumpThread') || $this->request->getBool('wpBumpThread');
         $signature = $this->request->getVal('wpLqtSignature', null);
         LqtView::editMetadataUpdates(array('thread' => $thread, 'text' => $e->textbox1, 'summary' => $e->summary, 'bump' => $bump, 'subject' => $subject, 'signature' => $signature, 'root' => $article));
         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. 3
0
 /**
  * @param $article Article
  * @param $user User
  * @param $text
  * @param $summary
  * @param $minoredit
  * @param $watchthis
  * @param $sectionanchor
  * @param $flags
  * @param $revision
  * @param $status Status
  * @param $baseRevId
  * @return bool
  */
 static function onArticleSaveComplete(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId)
 {
     if (!$status->isGood()) {
         // Failed
         return true;
     }
     $title = $article->getTitle();
     if ($title->getNamespace() != NS_LQT_THREAD) {
         // Not a thread
         return true;
     }
     if (!$baseRevId) {
         // New page
         return true;
     }
     $thread = Threads::withRoot($article);
     if (!$thread) {
         // No matching thread.
         return true;
     }
     LqtView::editMetadataUpdates(array('root' => $article, 'thread' => $thread, 'summary' => $summary, 'text' => $text));
     return true;
 }