예제 #1
0
 function writeOutput($par)
 {
     global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
     global $wgRequest, $wgSitename, $wgLanguageCode;
     global $wgFeedClasses, $wgFilterCallback, $wgWhitelistEdit, $wgParser;
     wfLoadExtensionMessages('Postcomment');
     $wgOut->setRobotpolicy("noindex,nofollow");
     $fname = "wfSpecialPostcomment";
     //echo "topic: " . $wgRequest->getVal("topic_name") . "<BR>";
     //echo "title: " . $wgRequest->getVal("title") . "<BR>";
     //echo "comment: " . $wgRequest->getVal("comment_text") . "<BR>";
     //echo "new_topic id " . $wgRequest->getVal("new_topic") . "<BR>";
     $target = !empty($par) ? $par : $wgRequest->getVal("target");
     $t = Title::newFromDBKey($target);
     $update = true;
     if (!$t || !$t->userCanEdit()) {
         return;
     }
     if (!$wgUser->isAllowed('edit')) {
         return;
     }
     if ($t == null) {
         $wgOut->errorPage('postcomment', 'postcomment_invalidrequest');
         return;
     }
     $article = new Article($t);
     $user = $wgUser->getName();
     $real_name = User::whoIsReal($wgUser->getID());
     if ($real_name == "") {
         $real_name = $user;
     }
     $dateStr = $wgLang->timeanddate(wfTimestampNow());
     $comment = $wgRequest->getVal("comment_text");
     foreach ($wgRequest->getValues() as $key => $value) {
         if (strpos($key, "comment_text") === 0) {
             $comment = $value;
             break;
         }
     }
     $topic = $wgRequest->getVal("topic_name");
     //echo "$dateStr<br/>";
     // remove leading space, tends to be a problem with a lot of talk page comments as it breaks the
     // HTML on the page
     $comment = preg_replace('/\\n[ ]*/', "\n", trim($comment));
     // Check to see if the user is also getting a thumbs up. If so, append the thumbs message and give a thumbs up
     if ($wgRequest->getVal('thumb')) {
         $comment .= "\n\n" . wfMsg('qn_thumbs_up');
         $userName = explode(":", $wgRequest->getVal('target'));
         ThumbsUp::quickNoteThumb($wgRequest->getVal('revold'), $wgRequest->getVal('revnew'), $wgRequest->getVal('pageid'), $userName[1]);
     }
     $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $user, $real_name, $comment);
     if ($wgRequest->getVal('fromajax') == 'true') {
         $wgOut->setArticleBodyOnly(true);
     }
     $text = "";
     $r = Revision::newFromTitle($t);
     if ($r) {
         $text = $r->getText();
     }
     $text .= "\n\n{$formattedComment}\n\n";
     $wgOut->setStatusCode(500);
     //echo "updating with text:<br/> $text";
     //exit;
     $tmp = "";
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     if (!$wgUser->getID() && $wgWhitelistEdit) {
         $this->userNotLoggedInPage();
         return;
     }
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     if ($target == "Spam-Blacklist") {
         $wgOut->readOnlyPage();
         return;
     }
     if ($wgUser->pingLimiter()) {
         $wgOut->rateLimited();
         return;
     }
     if ($wgFilterCallback && $wgFilterCallback($t, $text, $tmp)) {
         # Error messages or other handling should be performed by the filter function
         return;
     }
     $matches = array();
     $preg = "/http:\\/\\/[^] \n'\">]*/";
     $mod = str_ireplace('http://www.wikihow.com', '', $comment);
     preg_match_all($preg, $mod, $matches);
     if (sizeof($matches[0]) > 2) {
         $wgOut->errorPage("postcomment", "postcomment_urls_limit");
         return;
     }
     if (trim(strip_tags($comment)) == "") {
         $wgOut->errorpage("postcomment", "postcomment_nopostingtoadd");
         return;
     }
     if (!$t->userCanEdit()) {
         $wgOut->errorpage("postcomment", "postcomment_discussionprotected");
         return;
     }
     $watch = false;
     if ($wgUser->getID() > 0) {
         $watch = $wgUser->isWatched($t);
     }
     $fc = new FancyCaptcha();
     $pass_captcha = $fc->passCaptcha();
     if (!$pass_captcha && $wgUser->getID() == 0) {
         $wgOut->addHTML("Sorry, please enter the correct word. Click <a onclick='window.location.reload(true);'>here</a> to get a new one.<br/><br/>");
         return;
     }
     $article->doEdit($text, "");
     if ($wgRequest->getVal('jsonresponse') == 'true') {
         $article->loadLastEdit(true);
         $this->revId = $article->getRevIdFetched();
     }
     //XX Vu added to notify users of usertalk updates
     if ($t->getNamespace() == NS_USER_TALK) {
         AuthorEmailNotification::notifyUserTalk($t->getArticleID(), $wgUser->getID(), $comment);
     }
     $wgOut->setStatusCode(200);
     if ($wgRequest->getVal('fromajax') == 'true') {
         $wgOut->redirect('');
         $wgTitle = $t;
         $formattedComment = $wgParser->preSaveTransform($formattedComment, $t, $wgUser, new ParserOptions());
         $wgOut->addHTML($wgOut->parse("\n" . $formattedComment));
         return;
     }
 }
 function writeOutput($par)
 {
     global $wgLang, $wgMemc, $wgDBname, $wgUser;
     global $wgSitename, $wgLanguageCode;
     global $wgFeedClasses, $wgFilterCallback, $wgWhitelistEdit, $wgParser;
     $this->getOutput()->setRobotpolicy("noindex,nofollow");
     $target = !empty($par) ? $par : $this->getRequest()->getVal("target");
     $t = Title::newFromDBKey($target);
     $update = true;
     if (!$t || !$t->userCan('edit')) {
         return;
     }
     if (!$this->getUser()->isAllowed('edit')) {
         return;
     }
     $article = new Article($t);
     $user = $this->getUser()->getName();
     $real_name = User::whoIsReal($this->getUser()->getID());
     if ($real_name == "") {
         $real_name = $user;
     }
     $dateStr = $wgLang->timeanddate(wfTimestampNow());
     $comment = $this->getRequest()->getVal("comment_text");
     foreach ($this->getRequest()->getValues() as $key => $value) {
         if (strpos($key, "comment_text") === 0) {
             $comment = $value;
             break;
         }
     }
     $topic = $this->getRequest()->getVal("topic_name");
     //echo "$dateStr<br/>";
     // remove leading space, tends to be a problem with a lot of talk page comments as it breaks the
     // HTML on the page
     $comment = preg_replace('/\\n[ ]*/', "\n", trim($comment));
     // Check to see if the user is also getting a thumbs up. If so, append the thumbs message and give a thumbs up
     if ($this->getRequest()->getVal('thumb')) {
         $comment .= "\n\n" . wfMsg('qn_thumbs_up');
         $userName = explode(":", $this->getRequest()->getVal('target'));
         ThumbsUp::quickNoteThumb($this->getRequest()->getVal('revold'), $this->getRequest()->getVal('revnew'), $this->getRequest()->getVal('pageid'), $userName[1]);
     }
     $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $user, $real_name, $comment);
     if ($this->getRequest()->getVal('fromajax') == 'true') {
         $this->getOutput()->setArticleBodyOnly(true);
     }
     $text = "";
     $r = Revision::newFromTitle($t);
     if ($r) {
         $text = $r->getText();
     }
     $text .= "\n\n{$formattedComment}\n\n";
     $this->getOutput()->setStatusCode(409);
     //echo "updating with text:<br/> $text";
     //exit;
     $tmp = "";
     if ($this->getUser()->isBlocked()) {
         $this->getOutput()->blockedPage();
         return;
     }
     if (!$this->getUser()->getID() && $wgWhitelistEdit) {
         $this->userNotLoggedInPage();
         return;
     }
     if (wfReadOnly()) {
         $this->getOutput()->readOnlyPage();
         return;
     }
     if ($target == "Spam-Blacklist") {
         $this->getOutput()->readOnlyPage();
         return;
     }
     if ($this->getUser()->pingLimiter()) {
         $this->getOutput()->rateLimited();
         return;
     }
     $editPage = new EditPage($article);
     $contentModel = $t->getContentModel();
     $handler = ContentHandler::getForModelID($contentModel);
     $contentFormat = $handler->getDefaultFormat();
     $content = ContentHandler::makeContent($text, $t, $contentModel, $contentFormat);
     $status = Status::newGood();
     if (!wfRunHooks('EditFilterMergedContent', array($this->getContext(), $content, &$status, '', $wgUser, false))) {
         return;
     }
     if (!$status->isGood()) {
         $errors = $status->getErrorsArray(true);
         foreach ($errors as $error) {
             if (is_array($error)) {
                 $error = count($error) ? $error[0] : '';
             }
             if (preg_match('@^spamprotection@', $error)) {
                 $message = 'Error: found spam link';
                 $this->getOutput()->addHTML($message);
                 return;
             }
         }
         $message = 'EditFilterMergedContent returned an error -- cannot post comment';
         return;
     }
     $matches = array();
     $preg = "/http:\\/\\/[^] \n'\">]*/";
     $mod = str_ireplace('http://www.wikihow.com', '', $comment);
     preg_match_all($preg, $mod, $matches);
     if (sizeof($matches[0]) > 2) {
         $this->getOutput()->showErrorPage("postcomment", "postcomment_urls_limit");
         return;
     }
     if (trim(strip_tags($comment)) == "") {
         $this->getOutput()->showErrorPage("postcomment", "postcomment_nopostingtoadd");
         return;
     }
     if (!$t->userCan('edit')) {
         $this->getOutput()->showErrorPage("postcomment", "postcomment_discussionprotected");
         return;
     }
     $watch = false;
     if ($this->getUser()->getID() > 0) {
         $watch = $this->getUser()->isWatched($t);
     }
     $fc = new FancyCaptcha();
     $pass_captcha = $fc->passCaptcha();
     if (!$pass_captcha && $this->getUser()->getID() == 0) {
         $this->getOutput()->addHTML("Sorry, please enter the correct word. Click <a onclick='window.location.reload(true);'>here</a> to get a new one.<br/><br/>");
         return;
     }
     $article->doEdit($text, "");
     if ($this->getRequest()->getVal('jsonresponse') == 'true') {
         $this->revId = $article->getRevIdFetched();
     }
     // Notify users of usertalk updates
     if ($t->getNamespace() == NS_USER_TALK) {
         AuthorEmailNotification::notifyUserTalk($t->getArticleID(), $this->getUser()->getID(), $comment);
     }
     $this->getOutput()->setStatusCode(200);
     if ($this->getRequest()->getVal('fromajax') == 'true') {
         $this->getOutput()->redirect('');
         $this->getContext()->setTitle($t);
         $formattedComment = $wgParser->preSaveTransform($formattedComment, $t, $this->getUser(), new ParserOptions());
         $this->getOutput()->addHTML($this->getOutput()->parse("\n" . $formattedComment));
         return;
     }
 }