Ejemplo n.º 1
0
 /**
  * @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>');
 }
Ejemplo n.º 2
0
 function show()
 {
     $this->output->addModules('ext.liquidThreads');
     $article = $this->talkpage;
     if (!LqtDispatch::isLqtPage($article->getTitle())) {
         $this->output->addWikiMsg('lqt-not-discussion-page');
         return false;
     }
     $this->output->setPageTitle($this->title->getPrefixedText());
     // Expose feed links.
     global $wgFeedClasses;
     $apiParams = array('action' => 'feedthreads', 'type' => 'replies|newthreads', 'talkpage' => $this->title->getPrefixedText());
     $urlPrefix = wfScript('api') . '?';
     foreach ($wgFeedClasses as $format => $class) {
         $theseParams = $apiParams + array('feedformat' => $format);
         $url = $urlPrefix . wfArrayToCgi($theseParams);
         $this->output->addFeedLink($format, $url);
     }
     if ($this->request->getBool('lqt_inline')) {
         $this->doInlineEditForm();
         return false;
     }
     $this->output->addHTML(Xml::openElement('div', array('class' => 'lqt-talkpage')));
     // Search!
     if ($this->request->getCheck('lqt_search')) {
         $q = $this->request->getText('lqt_search');
         $q .= ' ondiscussionpage:' . $article->getTitle()->getPrefixedText();
         $params = array('search' => $q, 'fulltext' => 1, 'ns' . NS_LQT_THREAD => 1, 'srbackend' => 'LuceneSearch');
         $t = SpecialPage::getTitleFor('Search');
         $url = $t->getLocalURL(wfArrayToCgi($params));
         $this->output->redirect($url);
         return true;
     }
     if ($this->shouldShow('header')) {
         $this->showHeader();
     }
     global $wgLang;
     // This closes the div of mw-content-ltr/rtl containing lang and dir attributes
     $this->output->addHTML(Html::closeElement('div') . Html::openElement('div', array('class' => 'lqt-talkpage', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir())));
     $html = '';
     // Set up a per-page header for new threads, search box, and sorting stuff.
     $talkpageHeader = '';
     if (Thread::canUserPost($this->user, $this->talkpage)) {
         $newThreadText = wfMessage('lqt_new_thread')->parse();
         $newThreadLink = Linker::link($this->title, $newThreadText, array('lqt_talkpage' => $this->talkpage->getTitle()->getPrefixedText()), array('lqt_method' => 'talkpage_new_thread'), array('known'));
         $newThreadLink = Xml::tags('strong', array('class' => 'lqt_start_discussion'), $newThreadLink);
         $talkpageHeader .= $newThreadLink;
     }
     global $wgSearchTypeAlternatives, $wgSearchType;
     if ($wgSearchType == "LuceneSearch" || in_array("LuceneSearch", $wgSearchTypeAlternatives ?: array())) {
         $talkpageHeader .= $this->getSearchBox();
     }
     $talkpageHeader .= $this->showTalkpageViewOptions($article);
     $talkpageHeader = Xml::tags('div', array('class' => 'lqt-talkpage-header'), $talkpageHeader);
     if ($this->shouldShow('options')) {
         $this->output->addHTML($talkpageHeader);
     } elseif ($this->shouldShow('simplenew')) {
         $this->output->addHTML($newThreadLink);
     }
     if ($this->methodApplies('talkpage_new_thread')) {
         $this->showNewThreadForm($this->talkpage);
     } else {
         $this->output->addHTML(Xml::tags('div', array('class' => 'lqt-new-thread lqt-edit-form'), ''));
     }
     $pager = $this->getPager();
     $threads = $this->getPageThreads($pager);
     if (count($threads) > 0 && $this->shouldShow('toc')) {
         $html .= $this->getTOC($threads);
     } elseif (count($threads) == 0) {
         $html .= Xml::tags('div', array('class' => 'lqt-no-threads'), wfMessage('lqt-no-threads')->parse());
     }
     $html .= $pager->getNavigationBar();
     $html .= Xml::openElement('div', array('class' => 'lqt-threads lqt-talkpage-threads'));
     $this->output->addHTML($html);
     foreach ($threads as $t) {
         $this->showThread($t);
     }
     $this->output->addHTML(Xml::closeElement('div') . $pager->getNavigationBar() . Xml::closeElement('div'));
     return false;
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 function show()
 {
     $this->output->addModules('ext.liquidThreads');
     $article = $this->talkpage;
     if (!LqtDispatch::isLqtPage($article->getTitle())) {
         $this->output->addWikiMsg('lqt-not-discussion-page');
         return false;
     }
     $this->output->setPageTitle($this->title->getPrefixedText());
     // Expose feed links.
     global $wgFeedClasses;
     $apiParams = array('action' => 'feedthreads', 'type' => 'replies|newthreads', 'talkpage' => $this->title->getPrefixedText());
     $urlPrefix = wfScript('api') . '?';
     foreach ($wgFeedClasses as $format => $class) {
         $theseParams = $apiParams + array('feedformat' => $format);
         $url = $urlPrefix . wfArrayToCGI($theseParams);
         $this->output->addFeedLink($format, $url);
     }
     $linker = class_exists('DummyLinker') ? new DummyLinker() : new Linker();
     if ($this->request->getBool('lqt_inline')) {
         $this->doInlineEditForm();
         return false;
     }
     $this->output->addHTML(Xml::openElement('div', array('class' => 'lqt-talkpage')));
     // Search!
     if ($this->request->getCheck('lqt_search')) {
         $q = $this->request->getText('lqt_search');
         $q .= ' ondiscussionpage:' . $article->getTitle()->getPrefixedText();
         $params = array('search' => $q, 'fulltext' => 1, 'ns' . NS_LQT_THREAD => 1);
         $t = SpecialPage::getTitleFor('Search');
         $url = $t->getLocalURL(wfArrayToCGI($params));
         $this->output->redirect($url);
         return true;
     }
     if ($this->shouldShow('header')) {
         $this->showHeader();
     }
     global $wgLang, $wgBetterDirectionality;
     if ($wgBetterDirectionality) {
         // This closes the div of mw-content-ltr/rtl containing lang and dir attributes
         $this->output->addHTML(Html::closeElement('div') . Html::openElement('div', array('class' => 'lqt-talkpage', 'lang' => $wgLang->getCode(), 'dir' => wfUILang()->getDir())));
     }
     $html = '';
     // Set up a per-page header for new threads, search box, and sorting stuff.
     $talkpageHeader = '';
     if (Thread::canUserPost($this->user, $this->talkpage)) {
         $newThreadText = wfMsgExt('lqt_new_thread', 'parseinline');
         $newThreadLink = $linker->link($this->title, $newThreadText, array('lqt_talkpage' => $this->talkpage->getTitle()->getPrefixedText()), array('lqt_method' => 'talkpage_new_thread'), array('known'));
         $newThreadLink = Xml::tags('strong', array('class' => 'lqt_start_discussion'), $newThreadLink);
         $talkpageHeader .= $newThreadLink;
     }
     $talkpageHeader .= $this->getSearchBox();
     $talkpageHeader .= $this->showTalkpageViewOptions($article);
     $talkpageHeader = Xml::tags('div', array('class' => 'lqt-talkpage-header'), $talkpageHeader);
     if ($this->shouldShow('options')) {
         $this->output->addHTML($talkpageHeader);
     } elseif ($this->shouldShow('simplenew')) {
         $this->output->addHTML($newThreadLink);
     }
     if ($this->methodApplies('talkpage_new_thread')) {
         $params = array('class' => 'lqt-new-thread lqt-edit-form');
         $this->output->addHTML(Xml::openElement('div', $params));
         $this->showNewThreadForm($this->talkpage);
         $this->output->addHTML(Xml::closeElement('div'));
     } else {
         $this->output->addHTML(Xml::tags('div', array('class' => 'lqt-new-thread lqt-edit-form'), ''));
     }
     $pager = $this->getPager();
     $threads = $this->getPageThreads($pager);
     if (count($threads) > 0 && $this->shouldShow('toc')) {
         $html .= $this->getTOC($threads);
     } elseif (count($threads) == 0) {
         $html .= Xml::tags('div', array('class' => 'lqt-no-threads'), wfMsgExt('lqt-no-threads', 'parseinline'));
     }
     $html .= $pager->getNavigationBar();
     $html .= Xml::openElement('div', array('class' => 'lqt-threads lqt-talkpage-threads'));
     $this->output->addHTML($html);
     foreach ($threads as $t) {
         $this->showThread($t);
     }
     $this->output->addHTML(Xml::closeElement('div') . $pager->getNavigationBar() . Xml::closeElement('div'));
     // Workaround for bug 25077
     global $wgOut, $wgUser;
     # Skin::setTitle was removed in 1.18, it already shares the same source of title with $wgOut.
     if (method_exists('Skin', 'setTitle')) {
         $sk = $wgUser->getSkin();
         $sk->setTitle($wgOut->getTitle());
     }
     return false;
 }