function __construct()
 {
     parent::__construct('ClickTracking', 'clicktrack');
     wfLoadExtensionMessages('ClickTracking');
     UsabilityInitiativeHooks::initialize();
     UsabilityInitiativeHooks::addStyle('ClickTracking/SpecialClickTracking.css');
     UsabilityInitiativeHooks::addScript('ClickTracking/SpecialClickTracking.js');
 }
 /**
  * Adds JavaScript
  */
 public static function addJS()
 {
     global $wgClickTrackingStyleVersion;
     // HACK: Only add scripts when they're really needed by not initializing UIH here
     //UsabilityInitiativeHooks::initialize();
     UsabilityInitiativeHooks::addScript('ClickTracking/ClickTracking.js', $wgClickTrackingStyleVersion);
     UsabilityInitiativeHooks::addVariables(array('wgTrackingToken' => ClickTrackingHooks::get_session_id(), 'wgClickTrackingIsThrottled' => ClickTrackingHooks::isUserThrottled()));
     return true;
 }
 /**
  * EditPage::showEditForm:initial hook
  * Adds the modules to the edit form
  */
 public static function addModules(&$toolbar)
 {
     global $wgOut, $wgUser, $wgJsMimeType;
     global $wgWikiEditorModules, $wgUsabilityInitiativeResourceMode;
     // Modules
     $preferences = array();
     $enabledModules = array();
     $modules = $wgWikiEditorModules;
     $modules['global'] = true;
     foreach ($modules as $module => $enable) {
         if ($enable['global'] || $enable['user'] && isset(self::$modules[$module]['preferences']['enable']) && $wgUser->getOption(self::$modules[$module]['preferences']['enable']['key']) || $module == 'global') {
             if ($module !== 'global') {
                 UsabilityInitiativeHooks::initialize();
             }
             $enabledModules[$module] = true;
             // Messages
             if (isset(self::$modules[$module]['i18n'], self::$modules[$module]['messages'])) {
                 wfLoadExtensionMessages(self::$modules[$module]['i18n']);
                 UsabilityInitiativeHooks::addMessages(self::$modules[$module]['messages']);
             }
             // Variables
             if (isset(self::$modules[$module]['variables'])) {
                 $variables = array();
                 foreach (self::$modules[$module]['variables'] as $variable) {
                     global ${$variable};
                     $variables[$variable] = ${$variable};
                 }
                 UsabilityInitiativeHooks::addVariables($variables);
             }
             // Preferences
             if (isset(self::$modules[$module]['preferences'])) {
                 foreach (self::$modules[$module]['preferences'] as $name => $preference) {
                     if (!isset($preferences[$module])) {
                         $preferences[$module] = array();
                     }
                     $preferences[$module][$name] = $wgUser->getOption($preference['key']);
                 }
             }
         } else {
             $enabledModules[$module] = false;
         }
     }
     // Load global messages
     wfLoadExtensionMessages('WikiEditor');
     UsabilityInitiativeHooks::addMessages(self::$messages);
     // Add all scripts
     foreach (self::$scripts[$wgUsabilityInitiativeResourceMode] as $script) {
         UsabilityInitiativeHooks::addScript(basename(dirname(__FILE__)) . '/' . $script['src'], $script['version']);
     }
     // Preferences (maybe the UsabilityInitiative class could do most of this for us?)
     $wgOut->addScript(Xml::tags('script', array('type' => $wgJsMimeType), 'var wgWikiEditorPreferences = ' . FormatJson::encode($preferences, true) . ";\n" . 'var wgWikiEditorEnabledModules = ' . FormatJson::encode($enabledModules, true) . ';'));
     return true;
 }
 /**
  * BeforePageDisplay hook
  * Adds the modules to the edit form
  */
 public static function addModules()
 {
     global $wgUser, $wgJsMimeType, $wgOut;
     global $wgVectorModules, $wgUsabilityInitiativeResourceMode;
     // Don't load Vector modules for non-Vector skins
     // They won't work but will throw unused JS in the client's face
     // Using instanceof to catch any skins subclassing Vector
     if (!$wgUser->getSkin() instanceof SkinVector) {
         return true;
     }
     // Modules
     $preferences = array();
     $enabledModules = array();
     foreach ($wgVectorModules as $module => $enable) {
         if ($enable['global'] || $enable['user'] && isset(self::$modules[$module]['preferences']['enable']) && $wgUser->getOption(self::$modules[$module]['preferences']['enable']['key'])) {
             UsabilityInitiativeHooks::initialize();
             $enabledModules[$module] = true;
             // Messages
             if (isset(self::$modules[$module]['i18n'], self::$modules[$module]['messages'])) {
                 wfLoadExtensionMessages(self::$modules[$module]['i18n']);
                 UsabilityInitiativeHooks::addMessages(self::$modules[$module]['messages']);
             }
             // Variables
             if (isset(self::$modules[$module]['variables'])) {
                 $variables = array();
                 foreach (self::$modules[$module]['variables'] as $variable) {
                     global ${$variable};
                     $variables[$variable] = ${$variable};
                 }
                 UsabilityInitiativeHooks::addVariables($variables);
             }
             // Preferences
             if (isset(self::$modules[$module]['preferences'])) {
                 foreach (self::$modules[$module]['preferences'] as $name => $preference) {
                     if (!isset($preferences[$module])) {
                         $preferences[$module] = array();
                     }
                     $preferences[$module][$name] = $wgUser->getOption($preference['key']);
                 }
             }
         } else {
             $enabledModules[$module] = false;
         }
     }
     // Add all scripts
     foreach (self::$scripts[$wgUsabilityInitiativeResourceMode] as $script) {
         UsabilityInitiativeHooks::addScript(basename(dirname(__FILE__)) . '/' . $script['src'], $script['version']);
     }
     // Preferences (maybe the UsabilityInitiative class could do most of this for us?)
     $wgOut->addScript(Xml::tags('script', array('type' => $wgJsMimeType), 'var wgVectorPreferences = ' . FormatJson::encode($preferences, true) . ";\n" . 'var wgVectorEnabledModules = ' . FormatJson::encode($enabledModules, true) . ';'));
     return true;
 }
 private function showSurvey($survey, $submitMsg, $opt, $loadFromDB = false)
 {
     global $wgUser, $wgOut, $wgOptInStyleVersion;
     UsabilityInitiativeHooks::initialize();
     UsabilityInitiativeHooks::addScript('OptIn/OptIn.js', $wgOptInStyleVersion);
     UsabilityInitiativeHooks::addStyle('OptIn/OptIn.css', $wgOptInStyleVersion);
     $loaded = array();
     if ($loadFromDB) {
         $dbr = wfGetDb(DB_SLAVE);
         $res = $dbr->select('optin_survey', array('ois_question', 'ois_answer', 'ois_answer_data'), array('ois_user' => $wgUser->getID(), 'ois_type' => $opt), __METHOD__);
         foreach ($res as $row) {
             $loaded[$row->ois_question] = array($row->ois_answer, $row->ois_answer_data);
         }
     }
     $query = array('from' => $this->mOrigin, 'fromquery' => $this->mOriginQuery);
     $retval = Xml::openElement('form', array('method' => 'post', 'action' => $this->getTitle()->getLinkURL($query), 'id' => 'optin-survey'));
     $retval .= Xml::hidden('opt', $opt);
     $retval .= Xml::hidden('token', $wgUser->editToken());
     $retval .= Xml::openElement('dl');
     foreach ($survey as $id => $question) {
         $answer = isset($loaded[$id]) ? $loaded[$id][0] : null;
         $answerdata = isset($loaded[$id]) ? $loaded[$id][1] : null;
         switch ($question['type']) {
             case 'dropdown':
                 $retval .= Xml::tags('dt', null, wfMsgWikiHtml($question['question']));
                 $retval .= Xml::openElement('dd');
                 $attrs = array('id' => "survey-{$id}", 'name' => "survey-{$id}");
                 if (isset($question['other'])) {
                     $attrs['class'] = 'optin-need-other';
                 }
                 $retval .= Xml::openElement('select', $attrs);
                 foreach ($question['answers'] as $aid => $answer) {
                     $retval .= Xml::option(wfMsg($answer), $aid, $answer === $aid);
                 }
                 if (isset($question['other'])) {
                     $retval .= Xml::option(wfMsg($question['other']), 'other', $answer === 'other');
                 }
                 $retval .= Xml::closeElement('select');
                 if (isset($question['other'])) {
                     $retval .= Xml::tags('div', array(), Xml::input("survey-{$id}-other", false, $answer === 'other' ? $answerdata : false, array('class' => 'optin-other-select', 'id' => "survey-{$id}-other")));
                 }
                 $retval .= Xml::closeElement('dd');
                 break;
             case 'radios':
                 $retval .= Xml::tags('dt', null, wfMsgWikiHtml($question['question']));
                 $retval .= Xml::openElement('dd');
                 $radios = array();
                 foreach ($question['answers'] as $aid => $answer) {
                     $radios[] = Xml::radioLabel(wfMsg($answer), "survey-{$id}", $aid, "survey-{$id}-{$aid}", $answer === $aid);
                 }
                 if (isset($question['other'])) {
                     $radios[] = Xml::radioLabel(wfMsg($question['other']), "survey-{$id}", 'other', "survey-{$id}-other-radio", $answer === 'other') . ' ' . Xml::input("survey-{$id}-other", false, $answer === 'other' ? $answerdata : false, array('class' => 'optin-other-radios'));
                 }
                 $retval .= implode(Xml::element('br'), $radios);
                 $retval .= Xml::closeElement('dd');
                 break;
             case 'checkboxes':
                 $answers = explode(',', $answer);
                 $retval .= Xml::tags('dt', null, wfMsgWikiHtml($question['question']));
                 $retval .= Xml::openElement('dd');
                 $checkboxes = array();
                 foreach ($question['answers'] as $aid => $answer) {
                     $checkboxes[] = Xml::checkLabel(wfMsg($answer), "survey-{$id}[]", "survey-{$id}-{$aid}", in_array($aid, $answers, true), array('value' => $aid));
                 }
                 if (isset($question['other'])) {
                     $checkboxes[] = Xml::checkLabel(wfMsg($question['other']), "survey-{$id}[]", "survey-{$id}-other-check", in_array('other', $answers, true), array('value' => 'other')) . ' ' . Xml::input("survey-{$id}-other", false, in_array('other', $answers, true) ? $answerdata : false, array('class' => 'optin-other-checks'));
                 }
                 $retval .= implode(Xml::element('br'), $checkboxes);
                 $retval .= Xml::closeElement('dd');
                 break;
             case 'yesno':
                 $retval .= Xml::tags('dt', null, wfMsgWikiHtml($question['question']));
                 $retval .= Xml::openElement('dd');
                 $retval .= Xml::radioLabel(wfMsg('optin-survey-yes'), "survey-{$id}", 'yes', "survey-{$id}-yes", $answer === 'yes', array('class' => 'survey-yes'));
                 $retval .= Xml::element('br');
                 $retval .= Xml::radioLabel(wfMsg('optin-survey-no'), "survey-{$id}", 'no', "survey-{$id}-no", $answer === 'no', array('class' => 'survey-no'));
                 $retval .= Xml::closeElement('dd');
                 if (isset($question['ifyes'])) {
                     $retval .= Xml::openElement('blockquote', array('id' => "survey-{$id}-ifyes-row", 'class' => 'survey-ifyes'));
                     $retval .= Xml::tags('dt', null, wfMsgWikiHtml($question['ifyes']));
                     $retval .= Xml::tags('dd', null, Xml::textarea("survey-{$id}-ifyes", $answerdata ? $answerdata : ''));
                     $retval .= Xml::closeElement('blockquote');
                 }
                 if (isset($question['ifno'])) {
                     $retval .= Xml::openElement('blockquote', array('id' => "survey-{$id}-ifno-row", 'class' => 'survey-ifno'));
                     $retval .= Xml::tags('dt', null, wfMsgWikiHtml($question['ifno']));
                     $retval .= Xml::tags('dd', null, Xml::textarea("survey-{$id}-ifno", $answerdata ? $answerdata : ''));
                     $retval .= Xml::closeElement('blockquote');
                 }
                 break;
             case 'resolution':
                 if ($answerdata) {
                     list($x, $y) = explode('x', $answerdata);
                 } else {
                     $x = $y = false;
                 }
                 $retval .= Xml::tags('dt', null, wfMsgWikiHtml($question['question']));
                 $retval .= Xml::openElement('dd');
                 $retval .= Xml::input("survey-{$id}-x", 5, $x, array('class' => 'optin-resolution-x', 'id' => "survey-{$id}-x"));
                 $retval .= ' x ';
                 $retval .= Xml::input("survey-{$id}-y", 5, $y, array('class' => 'optin-resolution-y', 'id' => "survey-{$id}-y"));
                 $retval .= Xml::closeElement('dd');
                 break;
             case 'textarea':
                 $retval .= Xml::tags('dt', null, wfMsgWikiHtml($question['question']));
                 $retval .= Xml::tags('dd', null, Xml::textarea("survey-{$id}", $answerdata ? $answerdata : ''));
                 break;
         }
     }
     $retval .= Xml::tags('dt', array('class' => 'optin-survey-submit'), Xml::element('a', array('id' => 'leave'), '', false) . Xml::submitButton(wfMsg($submitMsg)));
     $retval .= Xml::closeElement('dl');
     $retval .= Xml::closeElement('form');
     $wgOut->addHTML($retval);
 }
 /**
  * Adds variables that will be turned into global variables in JS
  * @param $variables array of "name" => "value"
  */
 public static function addVariables($variables)
 {
     self::$variables = array_merge(self::$variables, $variables);
 }