public function setup()
 {
     global $wgOut, $wgResourceModules, $wgAutoloadClasses, $wgExtensionAssetsPath, $IP, $wgUser, $wgAjaxCommentsPollServer, $wgAjaxCommentsLikeDislike, $wgAjaxCommentsCopyTalkpages, $wgAjaxCommentsAdmins;
     // Determine if the current user is an admin for comments
     self::$admin = count(array_intersect($wgAjaxCommentsAdmins, $wgUser->getEffectiveGroups())) > 0;
     // If options set, hook into the new revisions to change talk page additions to ajaxcomments
     if ($wgAjaxCommentsCopyTalkpages) {
         Hooks::register('PageContentSave', $this);
     }
     // Create a hook to allow external condition for whether there should be comments shown
     $title = array_key_exists('title', $_GET) ? Title::newFromText($_GET['title']) : false;
     if (!array_key_exists('action', $_REQUEST) && self::checkTitle($title)) {
         Hooks::register('BeforePageDisplay', $this);
     } else {
         $wgAjaxCommentsPollServer = -1;
     }
     // Create a hook to allow external condition for whether comments can be added or replied to (default is just user logged in)
     $this->canComment = $wgUser->isLoggedIn();
     Hooks::run('AjaxCommentsCheckWritable', array($title, &$this->canComment));
     // Redirect talk pages with AjaxComments to the comments
     if (is_object($title) && $title->getNamespace() > 0 && $title->getNamespace() & 1) {
         $ret = true;
         Hooks::run('AjaxCommentsCheckTitle', array($userpage, &$ret));
         if ($ret) {
             $userpage = Title::newFromText($title->getText(), $title->getNamespace() - 1);
             global $mediaWiki;
             if (is_object($mediaWiki)) {
                 $mediaWiki->restInPeace();
             }
             $wgOut->disable();
             wfResetOutputBuffers();
             $url = $userpage->getLocalUrl();
             header("Location: {$url}#ajaxcomments");
             wfDebugLog(__CLASS__, "Redirecting to {$url}");
             exit;
         }
     }
     // This gets the remote path even if it's a symlink (MW1.25+)
     $path = $wgExtensionAssetsPath . str_replace("{$IP}/extensions", '', dirname($wgAutoloadClasses[__CLASS__]));
     $wgResourceModules['ext.ajaxcomments']['remoteExtPath'] = $path;
     $wgOut->addModules('ext.ajaxcomments');
     $wgOut->addStyle("{$path}/styles/ajaxcomments.css");
     // Add config vars to client side
     $wgOut->addJsConfigVars('ajaxCommentsPollServer', $wgAjaxCommentsPollServer);
     $wgOut->addJsConfigVars('ajaxCommentsCanComment', $this->canComment);
     $wgOut->addJsConfigVars('ajaxCommentsLikeDislike', $wgAjaxCommentsLikeDislike);
     $wgOut->addJsConfigVars('ajaxCommentsAdmin', self::$admin);
 }
 public function execute()
 {
     // Get the params
     $params = $this->extractRequestParams();
     $type = $params['type'];
     $page = $params['page'];
     $id = array_key_exists('id', $params) ? $params['id'] : 0;
     $data = array_key_exists('data', $params) ? $params['data'] : '';
     // Process the request
     switch ($type) {
         case 'add':
             $result = AjaxComments::add($data, $page);
             break;
         case 'reply':
             $result = AjaxComments::reply($data, $page, $id);
             break;
         case 'edit':
             $result = AjaxComments::edit($data, $page, $id);
             break;
         case 'del':
             $result = AjaxComments::delete($page, $id);
             break;
         case 'like':
             $msg = AjaxComments::like($data, $id);
             $comment = AjaxComments::getComment($id);
             $result = array('like' => $comment['like'], 'dislike' => $comment['dislike']);
             break;
         case 'get':
             $result = AjaxComments::getComments($page, $id);
             break;
         default:
             $result = array('error' => 'unknown action');
     }
     // Return the result data
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
 }
 /**
  * Override SpecialPage::execute($param = '')
  */
 function execute($param)
 {
     global $wgOut, $wgUser, $wgRequest, $wgParser, $wgEmailPageContactsCat, $wgGroupPermissions, $wgSitename, $wgRecordAdminCategory, $wgEmailPageCss, $wgEmailPageAllowAllUsers, $wgEmergencyContact;
     $db = wfGetDB(DB_SLAVE);
     $param = str_replace('_', ' ', $param);
     $this->setHeaders();
     // Get info from request or set to defaults
     $this->title = $wgRequest->getText('ea-title', $param);
     $this->from = $wgRequest->getText('ea-from');
     $this->subject = $wgRequest->getText('ea-subject', wfMessage('ea-pagesend', $this->title, $wgSitename)->text());
     $this->message = $wgRequest->getText('ea-message');
     $this->group = $wgRequest->getText('ea-group');
     $this->to = $wgRequest->getText('ea-to');
     $this->cc = $wgRequest->getText('ea-cc');
     $this->textonly = $wgRequest->getText('ea-textonly', false);
     $this->css = $wgRequest->getText('ea-css', $wgEmailPageCss);
     $this->record = $wgRequest->getText('ea-record', false);
     $this->addcomments = $wgRequest->getText('ea-addcomments', false);
     $this->db = $db;
     // Bail if no page title to send has been specified
     if ($this->title) {
         $wgOut->addWikiText("===" . wfMessage('ea-heading', $this->title)->text() . "===");
     } else {
         return $wgOut->addWikiText(wfMessage('ea-nopage')->text());
     }
     // If the send button was clicked, attempt to send and exit
     if ($wgRequest->getText('ea-send', false)) {
         return $this->send();
     }
     // Render form
     $special = SpecialPage::getTitleFor('EmailPage');
     $wgOut->addHTML(Xml::element('form', array('class' => 'EmailPage', 'action' => $special->getLocalURL('action=submit'), 'method' => 'POST'), null));
     $wgOut->addHTML("<table style=\"padding:0;margin:0;border:none;\">");
     // From (dropdown list of self and wiki addresses)
     $from = "<option>{$wgEmergencyContact}</option>";
     $ue = $wgUser->getEmail();
     $from = Sanitizer::validateEmail($ue) ? "<option>{$ue}</option>{$from}" : $from;
     $wgOut->addHTML("<tr id=\"ea-from\"><th align=\"right\">" . wfMessage('ea-from')->text() . ":</th>");
     $wgOut->addHTML("<td><select name=\"ea-from\">{$from}</select></td></tr>\n");
     // To
     $wgOut->addHTML("<tr id=\"ea-to\"><th align=\"right\" valign=\"top\">" . wfMessage('ea-to')->text() . ":</th>");
     $wgOut->addHTML("<td><textarea name=\"ea-to\" rows=\"2\" style=\"width:100%\">{$this->to}</textarea>");
     $wgOut->addHTML("<br /><small><i>" . wfMessage('ea-to-info')->text() . "</i></small>");
     // To group
     $groups = "<option />";
     foreach (array_keys($wgGroupPermissions) as $group) {
         if ($group != '*' && $group != 'user') {
             $selected = $group == $this->group ? ' selected' : '';
             $groups .= "<option{$selected}>{$group}</option>";
         }
     }
     if ($wgEmailPageAllowAllUsers) {
         $selected = 'user' == $this->group ? ' selected' : '';
         $groups .= "<option{$selected} value=\"user\">" . wfMessage('ea-allusers')->text() . "</option>";
     }
     $wgOut->addHTML("<div id=\"ea-group\"><select name=\"ea-group\">{$groups}</select>");
     $wgOut->addHTML(" <i><small>" . wfMessage('ea-group-info')->text() . "</small></i></div>");
     $wgOut->addHTML("</td></tr>");
     // Cc
     $wgOut->addHTML("<tr id=\"ea-cc\"><th align=\"right\">" . wfMessage('ea-cc')->text() . ":</th>");
     $wgOut->addHTML("<td>" . Xml::element('input', array('type' => 'text', 'name' => 'ea-cc', 'value' => $this->cc ? $this->cc : $ue, 'style' => "width:100%")) . "</td></tr>");
     // Subject
     $wgOut->addHTML("<tr id=\"ea-subject\"><th align=\"right\">" . wfMessage('ea-subject')->text() . ":</th>");
     $wgOut->addHTML("<td>" . Xml::element('input', array('type' => 'text', 'name' => 'ea-subject', 'value' => $this->subject, 'style' => "width:100%")) . "</td></tr>");
     // Message
     $wgOut->addHTML("<tr id=\"ea-message\"><th align=\"right\" valign=\"top\">" . wfMessage('ea-message')->text() . ":</th>");
     $wgOut->addHTML("<td><textarea name=\"ea-message\" rows=\"3\" style=\"width:100%\">{$this->message}</textarea>");
     $wgOut->addHTML("<br /><i><small>" . wfMessage('ea-message-info')->text() . "</small></i></td></tr>");
     // Data
     if (defined('NS_FORM')) {
         $options = "";
         $tbl = $db->tableName('page');
         $res = $db->select($tbl, 'page_id', "page_namespace = " . NS_FORM);
         while ($row = $db->fetchRow($res)) {
             $t = Title::newFromID($row[0])->getText();
             $selected = $t == $this->record ? ' selected' : '';
             $options .= "<option{$selected}>{$t}</option>";
         }
         $db->freeResult($res);
         if ($options) {
             $wgOut->addHTML("<tr id=\"ea-data\"><th align=\"right\">" . wfMessage('ea-data')->text() . ":</th><td>");
             $wgOut->addHTML("<select name=\"ea-record\"><option />{$options}</select>");
             $wgOut->addHTML(" <small><i>" . wfMessage('ea-selectrecord')->text() . "</i></small></td></tr>");
         }
     }
     // Include comments checkbox
     if (defined('AJAXCOMMENTS_VERSION') && AjaxComments::checkTitle($this->title)) {
         $wgOut->addHTML("<tr id=\"ea-addcomments\"><th>&nbsp;</th><td>");
         $wgOut->addHTML("<input type=\"checkbox\" name=\"ea-addcomments\" />&nbsp;" . wfMessage('ea-addcomments')->text() . "</td></tr>");
     }
     // Submit buttons & hidden values
     $wgOut->addHTML("<tr><td colspan=\"2\" align=\"right\">");
     $wgOut->addHTML(Xml::element('input', array('type' => 'hidden', 'name' => 'ea-title', 'value' => $this->title)));
     $wgOut->addHTML(Xml::element('input', array('id' => 'ea-show', 'type' => 'submit', 'name' => 'ea-show', 'value' => wfMessage('ea-show')->text())));
     $wgOut->addHTML("&nbsp;&nbsp;");
     $wgOut->addHTML(Xml::element('input', array('type' => 'submit', 'name' => 'ea-send', 'value' => wfMessage('ea-send')->text())) . '&#160;');
     $wgOut->addHTML("</td></tr>");
     $wgOut->addHTML("</table></form>");
     // If the show button was clicked, render the list
     if (isset($_REQUEST['ea-show'])) {
         return $this->send(false);
     }
 }