function __construct() { parent::__construct('ClickTracking', 'clicktrack'); wfLoadExtensionMessages('ClickTracking'); UsabilityInitiativeHooks::initialize(); UsabilityInitiativeHooks::addStyle('ClickTracking/SpecialClickTracking.css'); UsabilityInitiativeHooks::addScript('ClickTracking/SpecialClickTracking.js'); }
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); }