/**
  * 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'));
 }
 /**
  * Generates a multiple select list of all countries.
  * @param $selected The country codes of the selected countries
  * @return multiple select list
  */
 function geoMultiSelector($selected = array())
 {
     global $wgLang;
     $userLanguageCode = $wgLang->getCode();
     $countries = CentralNoticeDB::getCountriesList($userLanguageCode);
     $options = "\n";
     foreach ($countries as $code => $name) {
         $options .= Xml::option($name, $code, in_array($code, $selected)) . "\n";
     }
     $htmlOut = '';
     if ($this->editable) {
         $htmlOut .= Xml::tags('select', array('multiple' => 'multiple', 'size' => 6, 'id' => 'geo_countries[]', 'name' => 'geo_countries[]'), $options);
     } else {
         $htmlOut .= Xml::tags('select', array('multiple' => 'multiple', 'size' => 6, 'id' => 'geo_countries[]', 'name' => 'geo_countries[]', 'disabled' => 'disabled'), $options);
     }
     return $htmlOut;
 }