/**
  * Handle different types of page requests
  */
 function execute($sub)
 {
     global $wgOut, $wgUser, $wgRequest;
     // Begin output
     $this->setHeaders();
     // Output ResourceLoader module for styling and javascript functions
     $wgOut->addModules('ext.centralNotice.interface');
     // Check permissions
     $this->editable = $wgUser->isAllowed('centralnotice-admin');
     // Initialize error variable
     $this->centralNoticeError = false;
     // Show summary
     $wgOut->addWikiMsg('centralnotice-summary');
     // Show header
     CentralNotice::printHeader();
     // Begin Banners tab content
     $wgOut->addHTML(Html::openElement('div', array('id' => 'preferences')));
     $method = $wgRequest->getVal('wpMethod');
     // Handle form submissions
     if ($this->editable && $wgRequest->wasPosted()) {
         // Check authentication token
         if ($wgUser->matchEditToken($wgRequest->getVal('authtoken'))) {
             // Handle removing banners
             $toRemove = $wgRequest->getArray('removeTemplates');
             if (isset($toRemove)) {
                 // Remove banners in list
                 foreach ($toRemove as $template) {
                     $this->removeTemplate($template);
                 }
             }
             // Handle translation message update
             $update = $wgRequest->getArray('updateText');
             if (isset($update)) {
                 foreach ($update as $lang => $messages) {
                     foreach ($messages as $text => $translation) {
                         // If we actually have text
                         if ($translation) {
                             $this->updateMessage($text, $translation, $lang);
                         }
                     }
                 }
             }
             // Handle adding banner
             if ($method == 'addTemplate') {
                 $newTemplateName = $wgRequest->getText('templateName');
                 $newTemplateBody = $wgRequest->getText('templateBody');
                 if ($newTemplateName != '' && $newTemplateBody != '') {
                     $this->addTemplate($newTemplateName, $newTemplateBody, $wgRequest->getBool('displayAnon'), $wgRequest->getBool('displayAccount'), $wgRequest->getBool('fundraising'), $wgRequest->getBool('autolink'), $wgRequest->getVal('landingPages'));
                     $sub = 'view';
                 } else {
                     $this->showError('centralnotice-null-string');
                 }
             }
             // Handle editing banner
             if ($method == 'editTemplate') {
                 $this->editTemplate($wgRequest->getText('template'), $wgRequest->getText('templateBody'), $wgRequest->getBool('displayAnon'), $wgRequest->getBool('displayAccount'), $wgRequest->getBool('fundraising'), $wgRequest->getBool('autolink'), $wgRequest->getVal('landingPages'));
                 $sub = 'view';
             }
         } else {
             $this->showError('sessionfailure');
         }
     }
     // Handle viewing of a banner in all languages
     if ($sub == 'view' && $wgRequest->getVal('wpUserLanguage') == 'all') {
         $template = $wgRequest->getVal('template');
         $this->showViewAvailable($template);
         $wgOut->addHTML(Html::closeElement('div'));
         return;
     }
     // Handle viewing a specific banner
     if ($sub == 'view' && $wgRequest->getText('template') != '') {
         $this->showView();
         $wgOut->addHTML(Html::closeElement('div'));
         return;
     }
     if ($this->editable) {
         // Handle showing "Add a banner" interface
         if ($sub == 'add') {
             $this->showAdd();
             $wgOut->addHTML(Html::closeElement('div'));
             return;
         }
         // Handle cloning a specific banner
         if ($sub == 'clone') {
             // Check authentication token
             if ($wgUser->matchEditToken($wgRequest->getVal('authtoken'))) {
                 $oldTemplate = $wgRequest->getVal('oldTemplate');
                 $newTemplate = $wgRequest->getVal('newTemplate');
                 // We use the returned name in case any special characters had to be removed
                 $template = $this->cloneTemplate($oldTemplate, $newTemplate);
                 $wgOut->redirect($this->getTitle('view')->getLocalUrl("template={$template}"));
                 return;
             } else {
                 $this->showError('sessionfailure');
             }
         }
     }
     // Show list of banners by default
     $this->showList();
     // End Banners tab content
     $wgOut->addHTML(Html::closeElement('div'));
 }
 /**
  * Handle different types of page requests
  */
 function execute($sub)
 {
     global $wgOut, $wgLang, $wgRequest, $wgNoticeProjects, $wgLanguageCode, $wgNoticeProject;
     $this->project = $wgRequest->getText('project', $wgNoticeProject);
     $this->language = $wgRequest->getText('language', $wgLanguageCode);
     // If the form has been submitted, the country code should be passed along.
     $locationSubmitted = $wgRequest->getVal('country');
     $this->location = $locationSubmitted ? $locationSubmitted : $this->location;
     // Convert submitted location to boolean value. If it true, showList() will be called.
     $locationSubmitted = (bool) $locationSubmitted;
     // Begin output
     $this->setHeaders();
     // Output ResourceLoader module for styling and javascript functions
     $wgOut->addModules(array('ext.centralNotice.interface', 'ext.centralNotice.bannerStats'));
     // Initialize error variable
     $this->centralNoticeError = false;
     // Show summary
     $wgOut->addWikiMsg('centralnotice-summary');
     // Show header
     CentralNotice::printHeader();
     // Begin Banners tab content
     $wgOut->addHTML(Html::openElement('div', array('id' => 'preferences')));
     $htmlOut = '';
     // Begin Allocation selection fieldset
     $htmlOut .= Html::openElement('fieldset', array('class' => 'prefsection'));
     $htmlOut .= Html::openElement('form', array('method' => 'get'));
     $htmlOut .= Html::element('h2', null, wfMsg('centralnotice-view-allocation'));
     $htmlOut .= Xml::tags('p', null, wfMsg('centralnotice-allocation-instructions'));
     $htmlOut .= Html::openElement('table', array('id' => 'envpicker', 'cellpadding' => 7));
     $htmlOut .= Html::openElement('tr');
     $htmlOut .= Xml::tags('td', array('style' => 'width: 20%;'), wfMsg('centralnotice-project-name'));
     $htmlOut .= Html::openElement('td');
     $htmlOut .= Html::openElement('select', array('name' => 'project'));
     foreach ($wgNoticeProjects as $value) {
         $htmlOut .= Xml::option($value, $value, $value === $this->project);
     }
     $htmlOut .= Html::closeElement('select');
     $htmlOut .= Html::closeElement('td');
     $htmlOut .= Html::closeElement('tr');
     $htmlOut .= Html::openElement('tr');
     $htmlOut .= Xml::tags('td', array('valign' => 'top'), wfMsg('centralnotice-project-lang'));
     $htmlOut .= Html::openElement('td');
     // Make sure the site language is in the list; a custom language code
     // might not have a defined name...
     $languages = Language::getLanguageNames(true);
     if (!array_key_exists($wgLanguageCode, $languages)) {
         $languages[$wgLanguageCode] = $wgLanguageCode;
     }
     ksort($languages);
     $htmlOut .= Html::openElement('select', array('name' => 'language'));
     foreach ($languages as $code => $name) {
         $htmlOut .= Xml::option(wfMsg('centralnotice-language-listing', $code, $name), $code, $code === $this->language);
     }
     $htmlOut .= Html::closeElement('select');
     $htmlOut .= Html::closeElement('td');
     $htmlOut .= Html::closeElement('tr');
     $htmlOut .= Html::openElement('tr');
     $htmlOut .= Xml::tags('td', array(), wfMsg('centralnotice-country'));
     $htmlOut .= Html::openElement('td');
     $userLanguageCode = $wgLang->getCode();
     $countries = CentralNoticeDB::getCountriesList($userLanguageCode);
     $htmlOut .= Html::openElement('select', array('name' => 'country'));
     foreach ($countries as $code => $name) {
         $htmlOut .= Xml::option($name, $code, $code === $this->location);
     }
     $htmlOut .= Html::closeElement('select');
     $htmlOut .= Html::closeElement('td');
     $htmlOut .= Html::closeElement('tr');
     $htmlOut .= Html::closeElement('table');
     $htmlOut .= Xml::tags('div', array('class' => 'cn-buttons'), Xml::submitButton(wfMsg('centralnotice-view')));
     $htmlOut .= Html::closeElement('form');
     // End Allocation selection fieldset
     $htmlOut .= Html::closeElement('fieldset');
     $wgOut->addHTML($htmlOut);
     // Handle form submissions
     if ($locationSubmitted) {
         $this->showList();
     }
     // End Banners tab content
     $wgOut->addHTML(Html::closeElement('div'));
 }
 /**
  * Handle different types of page requests
  */
 function execute($sub)
 {
     global $wgOut, $wgRequest, $wgExtensionAssetsPath;
     $this->logType = $wgRequest->getText('log', 'campaignsettings');
     // Begin output
     $this->setHeaders();
     // Output ResourceLoader module for styling and javascript functions
     $wgOut->addModules('ext.centralNotice.interface');
     // Initialize error variable
     $this->centralNoticeError = false;
     // Show summary
     $wgOut->addWikiMsg('centralnotice-summary');
     // Show header
     CentralNotice::printHeader();
     // Begin Banners tab content
     $wgOut->addHTML(Xml::openElement('div', array('id' => 'preferences')));
     $htmlOut = '';
     // Begin log selection fieldset
     $htmlOut .= Xml::openElement('fieldset', array('class' => 'prefsection'));
     $title = SpecialPage::getTitleFor('CentralNoticeLogs');
     $actionUrl = $title->getLocalURL();
     $htmlOut .= Xml::openElement('form', array('method' => 'get', 'action' => $actionUrl));
     $htmlOut .= Xml::element('h2', null, wfMsg('centralnotice-view-logs'));
     $htmlOut .= Xml::openElement('div', array('id' => 'cn-log-switcher'));
     $title = SpecialPage::getTitleFor('CentralNoticeLogs');
     $fullUrl = wfExpandUrl($title->getFullUrl(), PROTO_CURRENT);
     // Build the radio buttons for switching the log type
     $htmlOut .= $this->getLogSwitcher('campaignsettings', 'campaignSettings', 'centralnotice-campaign-settings', $fullUrl);
     $htmlOut .= $this->getLogSwitcher('bannersettings', 'bannerSettings', 'centralnotice-banner-settings', $fullUrl);
     $htmlOut .= $this->getLogSwitcher('bannercontent', 'bannerContent', 'centralnotice-banner-content', $fullUrl);
     $htmlOut .= $this->getLogSwitcher('bannermessages', 'bannerMessages', 'centralnotice-banner-messages', $fullUrl);
     $htmlOut .= Xml::closeElement('div');
     if ($this->logType == 'campaignsettings') {
         $reset = $wgRequest->getVal('centralnoticelogreset');
         $campaign = $wgRequest->getVal('campaign');
         $user = $wgRequest->getVal('user');
         $startYear = $this->getDateValue('start_year');
         $startMonth = $this->getDateValue('start_month');
         $startDay = $this->getDateValue('start_day');
         $endYear = $this->getDateValue('end_year');
         $endMonth = $this->getDateValue('end_month');
         $endDay = $this->getDateValue('end_day');
         $htmlOut .= Xml::openElement('div', array('id' => 'cn-log-filters-container'));
         if ($campaign || $user || $startYear || $startMonth || $startDay || $endYear || $endMonth || $endDay) {
             // filters on
             $htmlOut .= '<a href="javascript:toggleFilterDisplay()">' . '<img src="' . $wgExtensionAssetsPath . '/CentralNotice/collapsed.png" id="cn-collapsed-filter-arrow" style="display:none;position:relative;top:-2px;"/>' . '<img src="' . $wgExtensionAssetsPath . '/CentralNotice/uncollapsed.png" id="cn-uncollapsed-filter-arrow" style="display:inline-block;position:relative;top:-2px;"/>' . '</a>';
             $htmlOut .= Xml::tags('span', array('style' => 'margin-left: 0.3em;'), wfMsg('centralnotice-filters'));
             $htmlOut .= Xml::openElement('div', array('id' => 'cn-log-filters'));
         } else {
             // filters off
             $htmlOut .= '<a href="javascript:toggleFilterDisplay()">' . '<img src="' . $wgExtensionAssetsPath . '/CentralNotice/collapsed.png" id="cn-collapsed-filter-arrow" style="display:inline-block;position:relative;top:-2px;"/>' . '<img src="' . $wgExtensionAssetsPath . '/CentralNotice/uncollapsed.png" id="cn-uncollapsed-filter-arrow" style="display:none;position:relative;top:-2px;"/>' . '</a>';
             $htmlOut .= Xml::tags('span', array('style' => 'margin-left: 0.3em;'), wfMsg('centralnotice-filters'));
             $htmlOut .= Xml::openElement('div', array('id' => 'cn-log-filters', 'style' => 'display:none;'));
         }
         $htmlOut .= Xml::openElement('table');
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::openElement('td');
         $htmlOut .= Xml::label(wfMsg('centralnotice-start-date'), 'month', array('class' => 'cn-log-filter-label'));
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::openElement('td');
         if ($reset) {
             $htmlOut .= $this->dateSelector('start');
         } else {
             $htmlOut .= $this->dateSelector('start', $startYear, $startMonth, $startDay);
         }
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::closeElement('tr');
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::openElement('td');
         $htmlOut .= Xml::label(wfMsg('centralnotice-end-date'), 'month', array('class' => 'cn-log-filter-label'));
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::openElement('td');
         if ($reset) {
             $htmlOut .= $this->dateSelector('end');
         } else {
             $htmlOut .= $this->dateSelector('end', $endYear, $endMonth, $endDay);
         }
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::closeElement('tr');
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::openElement('td');
         $htmlOut .= Xml::label(wfMsg('centralnotice-notice'), 'campaign', array('class' => 'cn-log-filter-label'));
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::openElement('td');
         $htmlOut .= Xml::input('campaign', 25, $reset ? '' : $campaign);
         $htmlOut .= Xml::closeElement('span');
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::closeElement('tr');
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::openElement('td');
         $htmlOut .= Xml::label(wfMsg('centralnotice-user'), 'user', array('class' => 'cn-log-filter-label'));
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::openElement('td');
         $htmlOut .= Xml::input('user', 25, $reset ? '' : $user);
         $htmlOut .= Xml::closeElement('span');
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::closeElement('tr');
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::openElement('td', array('colspan' => 2));
         $htmlOut .= Xml::submitButton(wfMsg('centralnotice-apply-filters'), array('id' => 'centralnoticesubmit', 'name' => 'centralnoticesubmit', 'class' => 'cn-filter-buttons'));
         $link = $title->getLinkUrl();
         $htmlOut .= Xml::submitButton(wfMsg('centralnotice-clear-filters'), array('id' => 'centralnoticelogreset', 'name' => 'centralnoticelogreset', 'class' => 'cn-filter-buttons', 'onclick' => "window.location = '{$link}'; return false;"));
         $htmlOut .= Xml::closeElement('td');
         $htmlOut .= Xml::closeElement('tr');
         $htmlOut .= Xml::closeElement('table');
         $htmlOut .= Xml::closeElement('div');
         $htmlOut .= Xml::closeElement('div');
     }
     $htmlOut .= Xml::closeElement('form');
     // End log selection fieldset
     //$htmlOut .= Xml::closeElement( 'fieldset' );
     $wgOut->addHTML($htmlOut);
     $this->showLog($this->logType);
     // End Banners tab content
     $wgOut->addHTML(Xml::closeElement('div'));
 }