function wfCommentVote($comment_id, $vote_value, $vg, $page_id)
{
    global $wgUser;
    // Blocked users cannot vote, obviously
    if ($wgUser->isBlocked()) {
        return '';
    }
    if (is_numeric($comment_id) && is_numeric($vote_value)) {
        $dbr = wfGetDB(DB_SLAVE);
        $res = $dbr->select('Comments', array('comment_page_id', 'comment_user_id', 'comment_username'), array('CommentID' => $comment_id), __METHOD__);
        $row = $dbr->fetchObject($res);
        if ($row) {
            $PageID = $row->comment_page_id;
            $comment = new Comment($PageID);
            $comment->CommentID = $comment_id;
            $comment->setCommentVote($vote_value);
            $comment->setVoting($vg);
            $comment->addVote();
            $out = $comment->getCommentScore();
            if (class_exists('UserStatsTrack')) {
                $stats = new UserStatsTrack($wgUser->getID(), $wgUser->getName());
                // Must update stats for user doing the voting
                if ($vote_value == 1) {
                    $stats->incStatField('comment_give_plus');
                }
                if ($vote_value == -1) {
                    $stats->incStatField('comment_give_neg');
                }
                // Also must update the stats for user receiving the vote
                $stats_comment_owner = new UserStatsTrack($row->comment_user_id, $row->comment_username);
                $stats_comment_owner->updateCommentScoreRec($vote_value);
                $stats_comment_owner->updateTotalPoints();
                if ($vote_value === 1) {
                    $stats_comment_owner->updateWeeklyPoints($stats_comment_owner->point_values['comment_plus']);
                    $stats_comment_owner->updateMonthlyPoints($stats_comment_owner->point_values['comment_plus']);
                }
            }
            return $out;
        }
    }
}
 /**
  * Show the special page
  *
  * @param $par Mixed: parameter passed to the special page or null
  */
 public function execute($par)
 {
     global $wgOut, $wgUser, $wgRequest, $wgContLang;
     // If the user can't create blog posts, display an error
     if (!$wgUser->isAllowed('createblogpost')) {
         $wgOut->permissionRequired('createblogpost');
         return;
     }
     // Show a message if the database is in read-only mode
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     // If user is blocked, s/he doesn't need to access this page
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage(false);
         return false;
     }
     // Set page title, robot policies, etc.
     $this->setHeaders();
     // Add CSS & JS
     $wgOut->addModules('ext.blogPage.create');
     // If the request was POSTed, we haven't submitted a request yet AND
     // we have a title, create the page...otherwise just display the
     // creation form
     if ($wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false) {
         $_SESSION['alreadysubmitted'] = true;
         // Protect against cross-site request forgery (CSRF)
         if (!$wgUser->matchEditToken($wgRequest->getVal('wpEditToken'))) {
             $wgOut->addHTML(wfMsg('sessionfailure'));
             return;
         }
         // Create a Title object, or try to, anyway
         $userSuppliedTitle = $wgRequest->getVal('title2');
         $title = Title::makeTitleSafe(NS_BLOG, $userSuppliedTitle);
         // @todo CHECKME: are these still needed? The JS performs these
         // checks already but then again JS is also easy to fool...
         // The user didn't supply a title? Ask them to supply one.
         if (!$userSuppliedTitle) {
             $wgOut->setPageTitle(wfMsg('errorpagetitle'));
             $wgOut->addWikiMsg('blog-create-error-need-title');
             $wgOut->addReturnTo($this->getTitle());
             return;
         }
         // The user didn't supply the blog post text? Ask them to supply it.
         if (!$wgRequest->getVal('pageBody')) {
             $wgOut->setPageTitle(wfMsg('errorpagetitle'));
             $wgOut->addWikiMsg('blog-create-error-need-content');
             $wgOut->addReturnTo($this->getTitle());
             return;
         }
         // Localized variables that will be used when creating the page
         $localizedCatNS = $wgContLang->getNsText(NS_CATEGORY);
         $today = $wgContLang->date(wfTimestampNow());
         // Create the blog page if it doesn't already exist
         $article = new Article($title, 0);
         if ($article->exists()) {
             $wgOut->setPageTitle(wfMsg('errorpagetitle'));
             $wgOut->addWikiMsg('blog-create-error-page-exists');
             $wgOut->addReturnTo($this->getTitle());
             return;
         } else {
             // The blog post will be by default categorized into two
             // categories, "Articles by User $1" and "(today's date)",
             // but the user may supply some categories themselves, so
             // we need to take those into account, too.
             $categories = array('[[' . $localizedCatNS . ':' . wfMsgForContent('blog-by-user-category', wfMsgForContent('blog-category')) . wfMsgForContent('word-separator') . $wgUser->getName() . ']]', "[[{$localizedCatNS}:{$today}]]");
             $userSuppliedCategories = $wgRequest->getVal('pageCtg');
             if (!empty($userSuppliedCategories)) {
                 // Explode along commas so that we will have an array that
                 // we can loop over
                 $userSuppliedCategories = explode(',', $userSuppliedCategories);
                 foreach ($userSuppliedCategories as $cat) {
                     $cat = trim($cat);
                     // GTFO@excess whitespace
                     if (!empty($cat)) {
                         $categories[] = "[[{$localizedCatNS}:{$cat}]]";
                     }
                 }
             }
             // Convert the array into a string
             $wikitextCategories = implode("\n", $categories);
             // Perform the edit
             $article->doEdit('<vote />' . "\n" . '<!--start text-->' . "\n" . $wgRequest->getVal('pageBody') . "\n\n" . '<comments />' . "\n\n" . $wikitextCategories . "\n__NOEDITSECTION__", wfMsgForContent('blog-create-summary'));
             $articleId = $article->getID();
             // Add a vote for the page
             // This was originally in its own global function,
             // wfFinishCreateBlog and after that in the BlogHooks class but
             // it just wouldn't work with Special:CreateBlogPost so I
             // decided to move it here since this is supposed to be like
             // the primary way of creating new blog posts...
             // Using OutputPageBeforeHTML hook, which, according to its
             // manual page, runs on *every* page view was such a stupid
             // idea IMHO.
             $vote = new Vote($articleId);
             $vote->insert(1);
             $stats = new UserStatsTrack($wgUser->getID(), $wgUser->getName());
             $stats->updateWeeklyPoints($stats->point_values['opinions_created']);
             $stats->updateMonthlyPoints($stats->point_values['opinions_created']);
             //if( $wgEnableFacebook ) {
             //	BlogHooks::updateFacebookProfile();
             //}
             //if( $wgSendNewArticleToFriends ) {
             //	$invite = SpecialPage::getTitleFor( 'EmailNewArticle' );
             //	$wgOut->redirect(
             //		$invite->getFullURL( 'page=' . $title->getPrefixedText() )
             //	);
             //}
             // Redirect the user to the new blog post they just created
             $wgOut->redirect($title->getFullURL());
         }
     } else {
         $_SESSION['alreadysubmitted'] = false;
         // Start building the HTML
         $output = '';
         // Show the blog rules, if the message containing them ain't empty
         $message = trim(wfMsgExt('blog-create-rules', array('parse', 'content')));
         // Yes, the strlen() is needed, I dunno why wfEmptyMsg() won't work
         if (!wfEmptyMsg('blog-create-rules', $message) && strlen($message) > 0) {
             $output .= $message . '<br />';
         }
         // Main form
         $output .= $this->displayForm();
         // Show everything to the user
         $wgOut->addHTML($output);
     }
 }