Exemplo n.º 1
0
 function __construct()
 {
     /// @fixme This preemptive de-quoting can interfere with other web libraries
     ///        and increases our memory footprint. It would be cleaner to do on
     ///        demand; but currently we have no wrapper for $_SERVER etc.
     $this->checkMagicQuotes();
     // POST overrides GET data
     // We don't use $_REQUEST here to avoid interference from cookies...
     $this->data = wfArrayMerge($_GET, $_POST);
 }
 /**
  * Create form for managing campaign settings (start date, end date, languages, etc.)
  */
 function noticeDetailForm($notice)
 {
     global $wgRequest;
     if ($this->editable) {
         $readonly = array();
     } else {
         $readonly = array('disabled' => 'disabled');
     }
     $campaign = CentralNoticeDB::getCampaignSettings($notice);
     if ($campaign) {
         // If there was an error, we'll need to restore the state of the form
         if ($wgRequest->wasPosted()) {
             $startArray = $wgRequest->getArray('start');
             $startTimestamp = $startArray['year'] . $startArray['month'] . $startArray['day'] . $startArray['hour'] . $startArray['min'] . '00';
             $endArray = $wgRequest->getArray('end');
             $endTimestamp = $endArray['year'] . $endArray['month'] . $endArray['day'] . $endArray['hour'] . $endArray['min'] . '00';
             $isEnabled = $wgRequest->getCheck('enabled');
             $isPreferred = $wgRequest->getCheck('preferred');
             $isLocked = $wgRequest->getCheck('locked');
             $noticeProjects = $wgRequest->getArray('projects', array());
             $noticeLanguages = $wgRequest->getArray('project_languages', array());
             $isGeotargeted = $wgRequest->getCheck('geotargeted');
             $countries = $wgRequest->getArray('geo_countries', array());
         } else {
             // Defaults
             $startTimestamp = $campaign['start'];
             $endTimestamp = $campaign['end'];
             $isEnabled = $campaign['enabled'] == '1';
             $isPreferred = $campaign['preferred'] == '1';
             $isLocked = $campaign['locked'] == '1';
             $noticeProjects = CentralNotice::getNoticeProjects($notice);
             $noticeLanguages = CentralNotice::getNoticeLanguages($notice);
             $isGeotargeted = $campaign['geo'] == '1';
             $countries = CentralNotice::getNoticeCountries($notice);
         }
         // Build Html
         $htmlOut = '';
         $htmlOut .= Xml::tags('h2', null, wfMsg('centralnotice-notice-heading', $notice));
         $htmlOut .= Xml::openElement('table', array('cellpadding' => 9));
         // Rows
         // Start Date
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array(), wfMsgHtml('centralnotice-start-date'));
         $htmlOut .= Xml::tags('td', array(), $this->dateSelector('start', $this->editable, $startTimestamp));
         $htmlOut .= Xml::closeElement('tr');
         // Start Time
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array(), wfMsgHtml('centralnotice-start-time'));
         $htmlOut .= Xml::tags('td', array(), $this->timeSelector('start', $this->editable, $startTimestamp));
         $htmlOut .= Xml::closeElement('tr');
         // End Date
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array(), wfMsgHtml('centralnotice-end-date'));
         $htmlOut .= Xml::tags('td', array(), $this->dateSelector('end', $this->editable, $endTimestamp));
         $htmlOut .= Xml::closeElement('tr');
         // End Time
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array(), wfMsgHtml('centralnotice-end-time'));
         $htmlOut .= Xml::tags('td', array(), $this->timeSelector('end', $this->editable, $endTimestamp));
         $htmlOut .= Xml::closeElement('tr');
         // Project
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array('valign' => 'top'), wfMsgHtml('centralnotice-projects'));
         $htmlOut .= Xml::tags('td', array(), $this->projectMultiSelector($noticeProjects));
         $htmlOut .= Xml::closeElement('tr');
         // Languages
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array('valign' => 'top'), wfMsgHtml('centralnotice-languages'));
         $htmlOut .= Xml::tags('td', array(), $this->languageMultiSelector($noticeLanguages));
         $htmlOut .= Xml::closeElement('tr');
         // Countries
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array(), Xml::label(wfMsg('centralnotice-geo'), 'geotargeted'));
         $htmlOut .= Xml::tags('td', array(), Xml::check('geotargeted', $isGeotargeted, wfArrayMerge($readonly, array('value' => $notice, 'id' => 'geotargeted'))));
         $htmlOut .= Xml::closeElement('tr');
         if ($isGeotargeted) {
             $htmlOut .= Xml::openElement('tr', array('id' => 'geoMultiSelector'));
         } else {
             $htmlOut .= Xml::openElement('tr', array('id' => 'geoMultiSelector', 'style' => 'display:none;'));
         }
         $htmlOut .= Xml::tags('td', array('valign' => 'top'), wfMsgHtml('centralnotice-countries'));
         $htmlOut .= Xml::tags('td', array(), $this->geoMultiSelector($countries));
         $htmlOut .= Xml::closeElement('tr');
         // Enabled
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array(), Xml::label(wfMsg('centralnotice-enabled'), 'enabled'));
         $htmlOut .= Xml::tags('td', array(), Xml::check('enabled', $isEnabled, wfArrayMerge($readonly, array('value' => $notice, 'id' => 'enabled'))));
         $htmlOut .= Xml::closeElement('tr');
         // Preferred
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array(), Xml::label(wfMsg('centralnotice-preferred'), 'preferred'));
         $htmlOut .= Xml::tags('td', array(), Xml::check('preferred', $isPreferred, wfArrayMerge($readonly, array('value' => $notice, 'id' => 'preferred'))));
         $htmlOut .= Xml::closeElement('tr');
         // Locked
         $htmlOut .= Xml::openElement('tr');
         $htmlOut .= Xml::tags('td', array(), Xml::label(wfMsg('centralnotice-locked'), 'locked'));
         $htmlOut .= Xml::tags('td', array(), Xml::check('locked', $isLocked, wfArrayMerge($readonly, array('value' => $notice, 'id' => 'locked'))));
         $htmlOut .= Xml::closeElement('tr');
         if ($this->editable) {
             // Locked
             $htmlOut .= Xml::openElement('tr');
             $htmlOut .= Xml::tags('td', array(), Xml::label(wfMsg('centralnotice-remove'), 'remove'));
             $htmlOut .= Xml::tags('td', array(), Xml::check('remove', false, array('value' => $notice, 'id' => 'remove')));
             $htmlOut .= Xml::closeElement('tr');
         }
         $htmlOut .= Xml::closeElement('table');
         return $htmlOut;
     } else {
         return '';
     }
 }
 /**
  * View or edit an individual banner
  */
 private function showView()
 {
     global $wgOut, $wgUser, $wgRequest, $wgLanguageCode, $wgExtensionAssetsPath, $wgLang, $wgNoticeEnableFundraising;
     $scriptPath = "{$wgExtensionAssetsPath}/CentralNotice";
     $sk = $this->getSkin();
     if ($this->editable) {
         $readonly = array();
         $disabled = array();
     } else {
         $readonly = array('readonly' => 'readonly');
         $disabled = array('disabled' => 'disabled');
     }
     // Get user's language
     $wpUserLang = $wgRequest->getVal('wpUserLanguage', $wgLanguageCode);
     // Get current banner
     $currentTemplate = $wgRequest->getText('template');
     $bannerSettings = CentralNoticeDB::getBannerSettings($currentTemplate);
     if (!$bannerSettings) {
         $this->showError('centralnotice-banner-doesnt-exist');
         return;
     } else {
         // Begin building HTML
         $htmlOut = '';
         // Begin View Banner fieldset
         $htmlOut .= Html::openElement('fieldset', array('class' => 'prefsection'));
         $htmlOut .= Html::element('h2', null, wfMsg('centralnotice-banner-heading', $currentTemplate));
         // Show preview of banner
         $render = new SpecialBannerLoader();
         $render->siteName = 'Wikipedia';
         $render->language = $wpUserLang;
         try {
             $preview = $render->getHtmlNotice($wgRequest->getText('template'));
         } catch (SpecialBannerLoaderException $e) {
             $preview = wfMsg('centralnotice-nopreview');
         }
         if ($render->language != '') {
             $htmlOut .= Xml::fieldset(wfMsg('centralnotice-preview') . " ({$render->language})", $preview);
         } else {
             $htmlOut .= Xml::fieldset(wfMsg('centralnotice-preview'), $preview);
         }
         // Pull banner text and respect any inc: markup
         $bodyPage = Title::newFromText("Centralnotice-template-{$currentTemplate}", NS_MEDIAWIKI);
         $curRev = Revision::newFromTitle($bodyPage);
         $body = $curRev ? $curRev->getText() : '';
         // Extract message fields from the banner body
         $fields = array();
         $allowedChars = Title::legalChars();
         preg_match_all("/\\{\\{\\{([{$allowedChars}]+)\\}\\}\\}/u", $body, $fields);
         // If there are any message fields in the banner, display translation tools.
         if (count($fields[0]) > 0) {
             if ($this->editable) {
                 $htmlOut .= Html::openElement('form', array('method' => 'post'));
             }
             $htmlOut .= Xml::fieldset(wfMsg('centralnotice-translate-heading', $currentTemplate), false, array('id' => 'mw-centralnotice-translations-for'));
             $htmlOut .= Html::openElement('table', array('cellpadding' => 9, 'width' => '100%'));
             // Table headers
             $htmlOut .= Html::element('th', array('width' => '15%'), wfMsg('centralnotice-message'));
             $htmlOut .= Html::element('th', array('width' => '5%'), wfMsg('centralnotice-number-uses'));
             $htmlOut .= Html::element('th', array('width' => '40%'), wfMsg('centralnotice-english'));
             $languages = Language::getLanguageNames();
             $htmlOut .= Html::element('th', array('width' => '40%'), $languages[$wpUserLang]);
             // Remove duplicate message fields
             $filteredFields = array();
             foreach ($fields[1] as $field) {
                 $filteredFields[$field] = array_key_exists($field, $filteredFields) ? $filteredFields[$field] + 1 : 1;
             }
             // Table rows
             foreach ($filteredFields as $field => $count) {
                 // Message
                 $message = $wpUserLang == 'en' ? "Centralnotice-{$currentTemplate}-{$field}" : "Centralnotice-{$currentTemplate}-{$field}/{$wpUserLang}";
                 // English value
                 $htmlOut .= Html::openElement('tr');
                 $title = Title::newFromText("MediaWiki:{$message}");
                 $htmlOut .= Xml::tags('td', null, $sk->makeLinkObj($title, htmlspecialchars($field)));
                 $htmlOut .= Html::element('td', null, $count);
                 // English text
                 $englishText = wfMsg('centralnotice-message-not-set');
                 $englishTextExists = false;
                 if (Title::newFromText("Centralnotice-{$currentTemplate}-{$field}", NS_MEDIAWIKI)->exists()) {
                     $englishText = wfMsgExt("Centralnotice-{$currentTemplate}-{$field}", array('language' => 'en'));
                     $englishTextExists = true;
                 }
                 $htmlOut .= Xml::tags('td', null, Html::element('span', array('style' => 'font-style:italic;' . (!$englishTextExists ? 'color:silver' : '')), $englishText));
                 // Foreign text input
                 $foreignText = '';
                 $foreignTextExists = false;
                 if (Title::newFromText($message, NS_MEDIAWIKI)->exists()) {
                     $foreignText = wfMsgExt("Centralnotice-{$currentTemplate}-{$field}", array('language' => $wpUserLang));
                     $foreignTextExists = true;
                 }
                 $htmlOut .= Xml::tags('td', null, Xml::input("updateText[{$wpUserLang}][{$currentTemplate}-{$field}]", '', $foreignText, wfArrayMerge($readonly, array('style' => 'width:100%;' . (!$foreignTextExists ? 'color:red' : '')))));
                 $htmlOut .= Html::closeElement('tr');
             }
             $htmlOut .= Html::closeElement('table');
             if ($this->editable) {
                 $htmlOut .= Html::hidden('wpUserLanguage', $wpUserLang);
                 $htmlOut .= Html::hidden('authtoken', $wgUser->editToken());
                 $htmlOut .= Xml::tags('div', array('class' => 'cn-buttons'), Xml::submitButton(wfMsg('centralnotice-modify'), array('name' => 'update')));
             }
             $htmlOut .= Html::closeElement('fieldset');
             if ($this->editable) {
                 $htmlOut .= Html::closeElement('form');
             }
             // Show language selection form
             $actionTitle = $this->getTitleFor('NoticeTemplate', 'view');
             $actionUrl = $actionTitle->getLocalURL();
             $htmlOut .= Html::openElement('form', array('method' => 'get', 'action' => $actionUrl));
             $htmlOut .= Xml::fieldset(wfMsg('centralnotice-change-lang'));
             $htmlOut .= Html::hidden('template', $currentTemplate);
             $htmlOut .= Html::openElement('table', array('cellpadding' => 9));
             // Retrieve the language list
             list($lsLabel, $lsSelect) = Xml::languageSelector($wpUserLang, true, $wgLang->getCode());
             $newPage = $this->getTitle('view');
             $htmlOut .= Xml::tags('tr', null, Xml::tags('td', null, $lsLabel) . Xml::tags('td', null, $lsSelect) . Xml::tags('td', array('colspan' => 2), Xml::submitButton(wfMsg('centralnotice-modify'))));
             $htmlOut .= Xml::tags('tr', null, Xml::tags('td', null, '') . Xml::tags('td', null, $sk->makeLinkObj($newPage, wfMsgHtml('centralnotice-preview-all-template-translations'), "template={$currentTemplate}&wpUserLanguage=all")));
             $htmlOut .= Html::closeElement('table');
             $htmlOut .= Html::closeElement('fieldset');
             $htmlOut .= Html::closeElement('form');
         }
         // Show edit form
         if ($this->editable) {
             $htmlOut .= Html::openElement('form', array('method' => 'post', 'onsubmit' => 'return validateBannerForm(this)'));
             $htmlOut .= Html::hidden('wpMethod', 'editTemplate');
         }
         // If there was an error, we'll need to restore the state of the form
         if ($wgRequest->wasPosted() && $wgRequest->getVal('mainform')) {
             $displayAnon = $wgRequest->getCheck('displayAnon');
             $displayAccount = $wgRequest->getCheck('displayAccount');
             $fundraising = $wgRequest->getCheck('fundraising');
             $autolink = $wgRequest->getCheck('autolink');
             $landingPages = $wgRequest->getVal('landingPages');
             $body = $wgRequest->getVal('templateBody', $body);
         } else {
             // Use previously stored values
             $displayAnon = $bannerSettings['anon'] == 1;
             $displayAccount = $bannerSettings['account'] == 1;
             $fundraising = $bannerSettings['fundraising'] == 1;
             $autolink = $bannerSettings['autolink'] == 1;
             $landingPages = $bannerSettings['landingpages'];
             // $body default is defined prior to message interface code
         }
         // Show banner settings
         $htmlOut .= Xml::fieldset(wfMsg('centralnotice-settings'));
         $htmlOut .= Html::openElement('p', null);
         $htmlOut .= wfMsg('centralnotice-banner-display');
         $htmlOut .= Xml::check('displayAnon', $displayAnon, wfArrayMerge($disabled, array('id' => 'displayAnon')));
         $htmlOut .= Xml::label(wfMsg('centralnotice-banner-anonymous'), 'displayAnon');
         $htmlOut .= Xml::check('displayAccount', $displayAccount, wfArrayMerge($disabled, array('id' => 'displayAccount')));
         $htmlOut .= Xml::label(wfMsg('centralnotice-banner-logged-in'), 'displayAccount');
         $htmlOut .= Html::closeElement('p');
         // Fundraising settings
         if ($wgNoticeEnableFundraising) {
             // Checkbox for indicating if it is a fundraising banner
             $htmlOut .= Html::openElement('p', null);
             $htmlOut .= Xml::check('fundraising', $fundraising, wfArrayMerge($disabled, array('id' => 'fundraising')));
             $htmlOut .= Xml::label(wfMsg('centralnotice-banner-fundraising'), 'fundraising');
             $htmlOut .= Html::closeElement('p');
             // Checkbox for whether or not to automatically create landing page link
             $htmlOut .= Html::openElement('p', null);
             $htmlOut .= Xml::check('autolink', $autolink, wfArrayMerge($disabled, array('id' => 'autolink')));
             $htmlOut .= Xml::label(wfMsg('centralnotice-banner-autolink'), 'autolink');
             $htmlOut .= Html::closeElement('p');
             // Interface for setting the landing pages
             if ($autolink) {
                 $htmlOut .= Html::openElement('div', array('id' => 'autolinkInterface'));
             } else {
                 $htmlOut .= Html::openElement('div', array('id' => 'autolinkInterface', 'style' => 'display:none;'));
             }
             $htmlOut .= Xml::tags('p', array(), wfMsg('centralnotice-banner-autolink-help', 'id="cn-landingpage-link"', 'JimmyAppeal01'));
             $htmlOut .= Xml::tags('p', array(), Xml::inputLabel(wfMsg('centralnotice-banner-landing-pages'), 'landingPages', 'landingPages', 40, $landingPages, array('maxlength' => 255)));
             $htmlOut .= Html::closeElement('div');
         }
         // Begin banner body section
         $htmlOut .= Html::closeElement('fieldset');
         if ($this->editable) {
             $htmlOut .= Xml::fieldset(wfMsg('centralnotice-edit-template'));
             $htmlOut .= wfMsg('centralnotice-edit-template-summary');
             $buttons = array();
             $buttons[] = '<a href="#" onclick="insertButton(\'close\');return false;">' . wfMsg('centralnotice-close-button') . '</a>';
             $htmlOut .= Xml::tags('div', array('style' => 'margin-bottom: 0.2em;'), '<img src="' . $scriptPath . '/down-arrow.png" ' . 'style="vertical-align:baseline;"/>' . wfMsg('centralnotice-insert', $wgLang->commaList($buttons)));
         } else {
             $htmlOut .= Xml::fieldset(wfMsg('centralnotice-banner'));
         }
         $htmlOut .= Xml::textarea('templateBody', $body, 60, 20, $readonly);
         $htmlOut .= Html::closeElement('fieldset');
         if ($this->editable) {
             // Indicate which form was submitted
             $htmlOut .= Html::hidden('mainform', 'true');
             $htmlOut .= Html::hidden('authtoken', $wgUser->editToken());
             $htmlOut .= Xml::tags('div', array('class' => 'cn-buttons'), Xml::submitButton(wfMsg('centralnotice-save-banner')));
             $htmlOut .= Html::closeElement('form');
         }
         // Show clone form
         if ($this->editable) {
             $htmlOut .= Html::openElement('form', array('method' => 'post', 'action' => $this->getTitle('clone')->getLocalUrl()));
             $htmlOut .= Xml::fieldset(wfMsg('centralnotice-clone-notice'));
             $htmlOut .= Html::openElement('table', array('cellpadding' => 9));
             $htmlOut .= Html::openElement('tr');
             $htmlOut .= Xml::inputLabel(wfMsg('centralnotice-clone-name'), 'newTemplate', 'newTemplate', '25');
             $htmlOut .= Xml::submitButton(wfMsg('centralnotice-clone'), array('id' => 'clone'));
             $htmlOut .= Html::hidden('oldTemplate', $currentTemplate);
             $htmlOut .= Html::closeElement('tr');
             $htmlOut .= Html::closeElement('table');
             $htmlOut .= Html::hidden('authtoken', $wgUser->editToken());
             $htmlOut .= Html::closeElement('fieldset');
             $htmlOut .= Html::closeElement('form');
         }
         // End View Banner fieldset
         $htmlOut .= Html::closeElement('fieldset');
         // Output HTML
         $wgOut->addHTML($htmlOut);
     }
 }
	public function getData( &$group, $savedData ) {
		$defs = $this->readVariable( $group, 'en' );
		$code = $this->language;

		$current = wfArrayMerge( $this->readVariable( $group, $code ), $savedData );

		// Clean up duplicates to definitions from saved data
		$current = $this->cleanData( $defs, $current );

		$chain = $current;
		if ( $this->chainable ) {
			foreach ( Language::getFallbacksFor( $code ) as $code ) {
				$fbdata = $this->readVariable( $group, $code );
				if ( $this->firstMagic ) {
					$fbdata = $this->cleanData( $defs, $fbdata );
				}

				$chain = array_merge_recursive( $chain, $fbdata );
			}
		}

		if ( $this->firstMagic ) {
			$chain = $this->mergeMagic( $defs, $chain );
		}

		$data = $group['data'] = array( $defs, $chain, $current );

		return $data;
	}