/** * Prepare data output * * @since 1.8 * * @param array $data label => value */ protected function getFormatOutput(array $data) { //Init $dataObject = array(); static $statNr = 0; $chartID = 'sparkline-' . $this->params['charttype'] . '-' . ++$statNr; $this->isHTML = true; // Prepare data array foreach ($data as $key => $value) { if ($value >= $this->params['min']) { $dataObject['label'][] = $key; $dataObject['value'][] = $value; } } $dataObject['charttype'] = $this->params['charttype']; // Encode data objects $requireHeadItem = array($chartID => FormatJson::encode($dataObject)); SMWOutputs::requireHeadItem($chartID, Skin::makeVariablesScript($requireHeadItem)); // RL module SMWOutputs::requireResource('ext.srf.sparkline'); // Processing placeholder $processing = SRFUtils::htmlProcessingElement(false); // Chart/graph placeholder $chart = Html::rawElement('div', array('id' => $chartID, 'class' => 'container', 'style' => "display:none;"), null); // Beautify class selector $class = $this->params['class'] ? ' ' . $this->params['class'] : ''; // Chart/graph wrappper return Html::rawElement('span', array('class' => 'srf-sparkline' . $class), $processing . $chart); }
/** * @see SMWResultPrinter::getFormatOutput * * @since 1.8 * * @param array $data label => value * @return string */ protected function getFormatOutput(array $data) { // Object count static $statNr = 0; $d3chartID = 'd3-chart-' . ++$statNr; $this->isHTML = true; // Reorganize the raw data foreach ($data as $name => $value) { if ($value >= $this->params['min']) { $dataObject[] = array('label' => $name, 'value' => $value); } } // Ensure right conversion $width = strstr($this->params['width'], "%") ? $this->params['width'] : $this->params['width'] . 'px'; // Prepare transfer objects $d3data = array('data' => $dataObject, 'parameters' => array('colorscheme' => $this->params['colorscheme'] ? $this->params['colorscheme'] : null, 'charttitle' => $this->params['charttitle'], 'charttext' => $this->params['charttext'], 'datalabels' => $this->params['datalabels'])); // Encoding $requireHeadItem = array($d3chartID => FormatJson::encode($d3data)); SMWOutputs::requireHeadItem($d3chartID, Skin::makeVariablesScript($requireHeadItem)); // RL module $resource = 'ext.srf.d3.chart.' . $this->params['charttype']; SMWOutputs::requireResource($resource); // Chart/graph placeholder $chart = Html::rawElement('div', array('id' => $d3chartID, 'class' => 'container', 'style' => 'display:none;'), null); // Processing placeholder $processing = SRFUtils::htmlProcessingElement($this->isHTML); // Beautify class selector $class = $this->params['charttype'] ? '-' . $this->params['charttype'] : ''; $class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class . ' d3-chart-common'; // D3 wrappper return Html::rawElement('div', array('class' => 'srf-d3-chart' . $class, 'style' => "width:{$width}; height:{$this->params['height']}px;"), $processing . $chart); }
/** * Prepare data output * * @since 1.8 * * @param array $data label => value */ protected function getFormatOutput(array $data) { static $statNr = 0; $chartID = 'jqplot-' . $this->params['charttype'] . '-' . ++$statNr; $this->isHTML = true; // Prepare data objects if (in_array($this->params['charttype'], array('bar', 'line'))) { // Parse bar relevant data $dataObject = $this->prepareBarData($data); } elseif (in_array($this->params['charttype'], array('pie', 'donut'))) { //Parse pie/donut relevant data $dataObject = $this->preparePieData($data); } else { // Return with an error return Html::rawElement('span', array('class' => "error"), wfMessage('srf-error-missing-layout')->inContentLanguage()->text()); } // Encode data objects $requireHeadItem = array($chartID => FormatJson::encode($dataObject)); SMWOutputs::requireHeadItem($chartID, Skin::makeVariablesScript($requireHeadItem)); // Processing placeholder $processing = SRFUtils::htmlProcessingElement($this->isHTML); // Ensure right conversion $width = strstr($this->params['width'], "%") ? $this->params['width'] : $this->params['width'] . 'px'; // Chart/graph placeholder $chart = Html::rawElement('div', array('id' => $chartID, 'class' => 'container', 'style' => "display:none; width: {$width}; height: {$this->params['height']}px;"), null); // Beautify class selector $class = $this->params['charttype'] ? '-' . $this->params['charttype'] : ''; $class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class . ' jqplot-common'; // Chart/graph wrappper return Html::rawElement('div', array('class' => 'srf-jqplot' . $class), $processing . $chart); }
/** * Renrder the survey div. * * @since 0.1 * * @param Parser $parser * * @return string */ public function render(Parser $parser) { static $loadedJs = false; if (!$loadedJs) { $parser->getOutput()->addModules('ext.survey.tag'); $parser->getOutput()->addHeadItem(Skin::makeVariablesScript(array('wgSurveyDebug' => SurveySettings::get('JSDebug')))); } return Html::element('span', $this->parameters, $this->contents); }
/** * Handles the request from the parser hook by doing the work that's common for all * mapping services, calling the specific methods and finally returning the resulting output. * * @param array $params * @param Parser $parser * * @return html */ public final function renderMap(array $params, Parser $parser) { $this->handleMarkerData($params, $parser); $mapName = $this->service->getMapId(); $output = $this->getMapHTML($params, $parser, $mapName); $configVars = Skin::makeVariablesScript($this->service->getConfigVariables()); $this->service->addDependencies($parser); $parser->getOutput()->addHeadItem($configVars); return $output; }
public function includeAssets() { global $wgOut; TranslationHelpers::addModules( $wgOut ); $pages = array(); foreach ( $this->collection->getTitles() as $title ) { $pages[] = $title->getPrefixedDBKey(); } $vars = array( 'trlKeys' => $pages ); $wgOut->addScript( Skin::makeVariablesScript( $vars ) ); $wgOut->addModules( 'ext.translate.messagetable' ); }
public function index() { $this->checkGameAllowed(); //AppCache disabled for now, it generates more problems than expected //$this->response->setVal( 'appCacheManifestPath', self::CACHE_MANIFEST_PATH . "&cb={$this->wg->CacheBuster}" );//$this->wg->StyleVersion //Minimize the output size, we don't need all the global variables being exported in MW $jsMsg = F::build('JSMessages'); $jsMsg->enqueuePackage(self::JS_MESSAGES_PACKAGE, JSMessages::INLINE); $jsVars = array('wgCacheBuster' => $this->wg->CacheBuster, 'wgMessages' => $jsMsg->getPackages(array(self::JS_MESSAGES_PACKAGE))); //getting WikiaTracker global JS vars F::build('WikiaTrackerController')->onMakeGlobalVariablesScript($jsVars); $this->response->setVal('globalVariablesScript', Skin::makeVariablesScript($jsVars)); $this->response->setVal('scripts', AssetsManager::getInstance()->getGroupCommonURL('photopop')); $this->response->setVal('dataMain', $this->wg->ExtensionsPath . '/wikia/PhotoPop/shared/lib/main'); $this->response->setVal('cssLink', AssetsManager::getInstance()->getOneCommonURL("extensions/wikia/PhotoPop/shared/css/homescreen.css")); $this->response->setVal('trackingCode', AnalyticsEngine::track('GA_Urchin', AnalyticsEngine::EVENT_PAGEVIEW)); }
/** * Handles the request from the parser hook by doing the work that's common for all * mapping services, calling the specific methods and finally returning the resulting output. * * @param array $params * @param Parser $parser * * @return html */ public final function renderMap(array $params, Parser $parser) { $this->handleMarkerData($params, $parser); $mapName = $this->service->getMapId(); $output = $this->getMapHTML($params, $parser, $mapName) . $this->getJSON($params, $parser, $mapName); $configVars = Skin::makeVariablesScript($this->service->getConfigVariables()); // MediaWiki 1.17 does not play nice with addScript, so add the vars via the globals hook. if (version_compare($GLOBALS['wgVersion'], '1.18', '<')) { $GLOBALS['egMapsGlobalJSVars'] += $this->service->getConfigVariables(); } global $wgTitle; if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) { global $wgOut; $this->service->addDependencies($wgOut); $wgOut->addScript($configVars); } else { $this->service->addDependencies($parser); $parser->getOutput()->addHeadItem($configVars); } return $output; }
/** * Builds a table with all translations of $title. * * @param $title Title (default: null) * @return void */ function showTranslations(Title $title) { global $wgOut, $wgUser, $wgLang; $sk = $wgUser->getSkin(); $namespace = $title->getNamespace(); $message = $title->getDBkey(); $inMessageGroup = TranslateUtils::messageKeyToGroup($title->getNamespace(), $title->getText()); if (!$inMessageGroup) { $wgOut->addWikiMsg('translate-translations-no-message', $title->getPrefixedText()); return; } $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace' => $namespace, 'page_title ' . $dbr->buildLike("{$message}/", $dbr->anyString())), __METHOD__, array('ORDER BY' => 'page_title', 'USE INDEX' => 'name_title')); if (!$res->numRows()) { $wgOut->addWikiMsg('translate-translations-no-message', $title->getPrefixedText()); return; } else { $wgOut->addWikiMsg('translate-translations-count', $wgLang->formatNum($res->numRows())); } // Normal output. $titles = array(); foreach ($res as $s) { $titles[] = $s->page_title; } $pageInfo = TranslateUtils::getContents($titles, $namespace); $tableheader = Xml::openElement('table', array('class' => 'mw-sp-translate-table sortable')); $tableheader .= Xml::openElement('tr'); $tableheader .= Xml::element('th', null, wfMsg('allmessagesname')); $tableheader .= Xml::element('th', null, wfMsg('allmessagescurrent')); $tableheader .= Xml::closeElement('tr'); // Adapted version of TranslateUtils:makeListing() by Nikerabbit. $out = $tableheader; $canTranslate = $wgUser->isAllowed('translate'); $ajaxPageList = array(); $historyText = " <sup>" . wfMsgHtml('translate-translations-history-short') . "</sup> "; foreach ($res as $s) { $key = $s->page_title; $tTitle = Title::makeTitle($s->page_namespace, $key); $ajaxPageList[] = $tTitle->getPrefixedDBkey(); $code = $this->getCode($s->page_title); $text = TranslateUtils::getLanguageName($code, false, $wgLang->getCode()) . " ({$code})"; $text = htmlspecialchars($text); if ($canTranslate) { $tools['edit'] = TranslationHelpers::ajaxEditLink($tTitle, $text); } else { $tools['edit'] = $sk->link($tTitle, $text); } $tools['history'] = $sk->link($tTitle, $historyText, array('action', 'title' => wfMsg('history-title', $tTitle->getPrefixedDBkey())), array('action' => 'history')); if (TranslateEditAddons::isFuzzy($tTitle)) { $class = 'orig'; } else { $class = 'def'; } $leftColumn = $tools['history'] . $tools['edit']; $out .= Xml::tags('tr', array('class' => $class), Xml::tags('td', null, $leftColumn) . Xml::tags('td', array('lang' => $code, 'dir' => Language::factory($code)->getDir()), TranslateUtils::convertWhiteSpaceToHTML($pageInfo[$key][0]))); } $out .= Xml::closeElement('table'); $wgOut->addHTML($out); $vars = array('trlKeys' => $ajaxPageList); $wgOut->addScript(Skin::makeVariablesScript($vars)); }
/** * Execute the subpage. * @param $params array Array of subpage parameters. */ function execute( $params ) { global $wgOut, $wgUser, $wgStylePath; if ( !count( $params ) ) { $wgOut->addWikiMsg( 'securepoll-too-few-params' ); return; } $electionId = intval( $params[0] ); $this->election = $this->context->getElection( $electionId ); if ( !$this->election ) { $wgOut->addWikiMsg( 'securepoll-invalid-election', $electionId ); return; } $this->initLanguage( $wgUser, $this->election ); $wgOut->setPageTitle( wfMsg( 'securepoll-list-title', $this->election->getMessage( 'title' ) ) ); $pager = new SecurePoll_ListPager( $this ); $wgOut->addHTML( $pager->getLimitForm() . $pager->getNavigationBar() . $pager->getBody() . $pager->getNavigationBar() ); if ( $this->election->isAdmin( $wgUser ) ) { $msgStrike = wfMsgHtml( 'securepoll-strike-button' ); $msgUnstrike = wfMsgHtml( 'securepoll-unstrike-button' ); $msgCancel = wfMsgHtml( 'securepoll-strike-cancel' ); $msgReason = wfMsgHtml( 'securepoll-strike-reason' ); $encAction = htmlspecialchars( $this->getTitle()->getLocalUrl() ); $encSpinner = htmlspecialchars( "$wgStylePath/common/images/spinner.gif" ); $script = Skin::makeVariablesScript( array( 'securepoll_strike_button' => wfMsg( 'securepoll-strike-button' ), 'securepoll_unstrike_button' => wfMsg( 'securepoll-unstrike-button' ) ) ); $wgOut->addHTML( <<<EOT $script <div class="securepoll-popup" id="securepoll-popup"> <form id="securepoll-strike-form" action="$encAction" method="post" onsubmit="securepoll_strike('submit');return false;"> <input type="hidden" id="securepoll-vote-id" name="vote_id" value=""/> <input type="hidden" id="securepoll-action" name="action" value=""/> <label for="securepoll-strike-reason">{$msgReason}</label> <input type="text" size="45" id="securepoll-strike-reason"/> <p> <input class="securepoll-confirm-button" type="button" value="$msgCancel" onclick="securepoll_strike('cancel');"/> <input class="securepoll-confirm-button" id="securepoll-strike-button" type="button" value="$msgStrike" onclick="securepoll_strike('strike');" /> <input class="securepoll-confirm-button" id="securepoll-unstrike-button" type="button" value="$msgUnstrike" onclick="securepoll_strike('unstrike');" /> </p> </form> <div id="securepoll-strike-result"></div> <div id="securepoll-strike-spinner"><img src="$encSpinner"/></div> </div> EOT ); } }
/** * Prepare data for the output * * @since 1.8 * * @param array $data * * @return string */ protected function getFormatOutput(array $data, $options) { // Object count static $statNr = 0; $chartID = 'timeseries-' . ++$statNr; $this->isHTML = true; // Reorganize the raw data foreach ($data as $key => $values) { $dataObject[] = array('label' => $key, 'data' => $values); } // Series colour $seriescolors = $this->params['chartcolor'] !== '' ? array_filter(explode(",", $this->params['chartcolor'])) : array(); // Prepare transfer array $chartData = array('data' => $dataObject, 'fcolumntypeid' => '_dat', 'sask' => $options['sask'], 'parameters' => array('width' => $this->params['width'], 'height' => $this->params['height'], 'charttitle' => $this->params['charttitle'], 'charttext' => $this->params['charttext'], 'infotext' => $this->params['infotext'], 'charttype' => $this->params['charttype'], 'gridview' => $this->params['gridview'], 'zoom' => $this->params['zoompane'], 'seriescolors' => $seriescolors)); // Array encoding and output $requireHeadItem = array($chartID => FormatJson::encode($chartData)); SMWOutputs::requireHeadItem($chartID, Skin::makeVariablesScript($requireHeadItem)); // RL module SMWOutputs::requireResource('ext.srf.timeseries.flot'); if ($this->params['gridview'] === 'tabs') { SMWOutputs::requireResource('ext.srf.util.grid'); } // Chart/graph placeholder $chart = Html::rawElement('div', array('id' => $chartID, 'class' => 'container', 'style' => "display:none;"), null); // Processing/loading image $processing = SRFUtils::htmlProcessingElement($this->isHTML); // Beautify class selector $class = $this->params['class'] ? ' ' . $this->params['class'] : ' flot-chart-common'; // General output marker return Html::rawElement('div', array('class' => 'srf-timeseries' . $class), $processing . $chart); }
/** * Builds up and returns the HTML for the map, with the queried coordinate data on it. * * @param SMWQueryResult $res * @param $outputmode * * @return array or string */ public final function getResultText(SMWQueryResult $res, $outputmode) { if ($this->fatalErrorMsg !== false) { return $this->fatalErrorMsg; } /** * @var Parser $wgParser */ global $wgParser; $params = $this->params; $queryHandler = new SMQueryHandler($res, $outputmode); $queryHandler->setLinkStyle($params['link']); $queryHandler->setHeaderStyle($params['headers']); $queryHandler->setShowSubject($params['showtitle']); $queryHandler->setTemplate($params['template']); $queryHandler->setHideNamespace($params['hidenamespace']); $queryHandler->setActiveIcon($params['activeicon']); $this->handleMarkerData($params, $queryHandler); $locationAmount = count($params['locations']); if ($locationAmount > 0) { // We can only take care of the zoom defaulting here, // as not all locations are available in whats passed to Validator. if ($this->fullParams['zoom']->wasSetToDefault() && $locationAmount > 1) { $params['zoom'] = false; } $mapName = $this->service->getMapId(); SMWOutputs::requireHeadItem($mapName, $this->service->getDependencyHtml() . ($configVars = Skin::makeVariablesScript($this->service->getConfigVariables()))); foreach ($this->service->getResourceModules() as $resourceModule) { SMWOutputs::requireResource($resourceModule); } if (array_key_exists('source', $params)) { unset($params['source']); } return $this->getMapHTML($params, $wgParser, $mapName); } else { return $params['default']; } }
/** * Add upload JS to $wgOut * * @param bool $autofill Whether or not to autofill the destination * filename text box */ protected function addUploadJS() { global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI; global $wgOut; $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI; $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds); $wgOut->addScript(Skin::makeVariablesScript($scriptVars)); // For <charinsert> support $wgOut->addScriptFile('edit.js'); $wgOut->addScriptFile('upload.js'); }
/** * Add upload JavaScript to $wgOut */ protected function addUploadJS() { global $wgExtensionsPath, $wgFileExtensions; global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI; $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI; $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds); $out = $this->getOutput(); $out->addScript(Skin::makeVariablesScript($scriptVars)); // changed $out->addScriptFile("{$wgExtensionsPath}/MultiUpload/multiupload.js"); $newscriptVars = array('wgMaxUploadFiles' => MultipleUpload::getMaxUploadFiles(), 'wgFileExtensions' => $wgFileExtensions); $out->addScript(Skin::makeVariablesScript($newscriptVars)); }
/** * Adds some global variables for our use, as well as initializes the UploadWizard * * TODO once bug https://bugzilla.wikimedia.org/show_bug.cgi?id=26901 * is fixed we should package configuration with the upload wizard instead of * in uploadWizard output page. * * @param subpage, e.g. the "foo" in Special:UploadWizard/foo */ public function addJsVars($subPage) { global $wgSitename; $config = UploadWizardConfig::getConfig($this->campaign); $labelPageContent = $this->getPageContent($config['idFieldLabelPage']); if ($labelPageContent !== false) { $config['idFieldLabel'] = $labelPageContent; } $config['thanksLabel'] = $this->getPageContent($config['thanksLabelPage'], true); $defaultLicense = $this->getUser()->getGlobalPreference('upwiz_deflicense'); if ($defaultLicense !== 'default') { $defaultLicense = explode('-', $defaultLicense, 2); $licenseType = $defaultLicense[0]; $defaultLicense = $defaultLicense[1]; if (in_array($defaultLicense, $config['licensesOwnWork']['licenses']) || in_array($defaultLicense, UploadWizardConfig::getThirdPartyLicenses())) { $licenseGroup = $licenseType === 'ownwork' ? 'licensesOwnWork' : 'licensesThirdParty'; $config[$licenseGroup]['defaults'] = array($defaultLicense); $config['defaultLicenseType'] = $licenseType; } } $this->getOutput()->addScript(Skin::makeVariablesScript(array('UploadWizardConfig' => $config) + array('wgSiteName' => $wgSitename))); }
/** * Prepare data for the output * * @since 1.8 * * @param array $data * * @return string */ protected function getFormatOutput($data, $options) { // Object count static $statNr = 0; $chartID = 'srf-dygraphs-' . ++$statNr; $this->isHTML = true; // Reorganize the raw data if ($this->params['datasource'] === 'page') { foreach ($data as $key => $values) { $dataObject[] = array('label' => $key, 'data' => $values); } } else { $dataObject['source'] = $data; } // Prepare transfer array $chartData = array('data' => $dataObject, 'sask' => $options['sask'], 'parameters' => array('width' => $this->params['width'], 'height' => $this->params['height'], 'xlabel' => $this->params['xlabel'], 'ylabel' => $this->params['ylabel'], 'charttitle' => $this->params['charttitle'], 'charttext' => $this->params['charttext'], 'infotext' => $this->params['infotext'], 'datasource' => $this->params['datasource'], 'rollerperiod' => $this->params['mavg'], 'gridview' => $this->params['gridview'], 'errorbar' => $this->params['errorbar'])); // Array encoding and output $requireHeadItem = array($chartID => FormatJson::encode($chartData)); SMWOutputs::requireHeadItem($chartID, Skin::makeVariablesScript($requireHeadItem)); SMWOutputs::requireResource('ext.srf.dygraphs'); if ($this->params['gridview'] === 'tabs') { SMWOutputs::requireResource('ext.srf.util.grid'); } // Chart/graph placeholder $chart = Html::rawElement('div', array('id' => $chartID, 'class' => 'container', 'style' => "display:none;"), null); // Processing/loading image $processing = SRFUtils::htmlProcessingElement($this->isHTML); // Beautify class selector $class = $this->params['class'] ? ' ' . $this->params['class'] : ' dygraphs-common'; // General output marker return Html::rawElement('div', array('class' => 'srf-dygraphs' . $class), $processing . $chart); }
/** * Add JavaScript variables to the output * * @since 1.8 */ public static function addGlobalJSVariables() { $options = array('srfgScriptPath' => $GLOBALS['srfgScriptPath'], 'srfVersion' => SRF_VERSION); $requireHeadItem = array('srf.options' => $options); SMWOutputs::requireHeadItem('srf.options', Skin::makeVariablesScript($requireHeadItem)); }
/** * Attempt to get the contest to be edited or create the one to be added. * If this works, show the form, if not, redirect to special:contests. * * @since 0.1 * * @param string $subPage */ protected function showContent($subPage) { $isNew = $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken($this->getRequest()->getVal('newEditToken')); $this->getOutput()->addScript(Skin::makeVariablesScript(array('ContestDeletionEnabled' => ContestSettings::get('contestDeletionEnabled')))); if ($isNew) { $data = array('name' => $this->getRequest()->getVal('newcontest')); $contest = Contest::s()->selectRow(null, $data); if ($contest === false) { $contest = new Contest($data, true); } else { $this->showWarning('contest-edit-exists-already'); } } else { $contest = Contest::s()->selectRow(null, array('name' => $subPage)); } if ($contest === false) { $this->getOutput()->redirect(SpecialPage::getTitleFor('Contests')->getLocalURL()); } else { if (!$isNew) { $this->getOutput()->addHTML(SpecialContestPage::getNavigation($contest->getField('name'), $this->getUser(), $this->getLanguage(), $this->getName())); } $this->contest = $contest; $this->showForm(); $this->getOutput()->addModules('contest.special.editcontest'); } }
public function includeAssets() { TranslationHelpers::addModules($this->context->getOutput()); $pages = array(); foreach ($this->collection->getTitles() as $title) { $pages[] = $title->getPrefixedDBKey(); } $vars = array('trlKeys' => $pages); $this->context->getOutput()->addScript(Skin::makeVariablesScript($vars)); }
/** * * * @since 1.0 * * @param string $coordinates * @param string $input_name * @param boolean $is_mandatory * @param boolean $is_disabled * @param array $field_args * * @return string */ public function getInputOutput($coordinates, $input_name, $is_mandatory, $is_disabled, array $params) { $parameters = array(); foreach ($params as $key => $value) { if (!is_array($value) && !is_object($value) && !is_null($value)) { $parameters[$key] = $value; } } if (!is_null($coordinates)) { $parameters['locations'] = $coordinates; } $validator = new Validator(wfMessage('maps_' . $this->service->getName())->text(), false); $validator->setParameters($parameters, $this->getParameterInfo()); $validator->validateParameters(); $fatalError = $validator->hasFatalError(); if ($fatalError === false) { global $wgParser; $params = $validator->getParameterValues(); // We can only take care of the zoom defaulting here, // as not all locations are available in whats passed to Validator. if ($params['zoom'] === false && count($params['locations']) <= 1) { $params['zoom'] = $this->service->getDefaultZoom(); } $mapName = $this->service->getMapId(); $params['inputname'] = $input_name; $output = $this->getInputHTML($params, $wgParser, $mapName); $this->service->addResourceModules($this->getResourceModules()); $configVars = Skin::makeVariablesScript($this->service->getConfigVariables()); // MediaWiki 1.17 does not play nice with addScript, so add the vars via the globals hook. if (version_compare($GLOBALS['wgVersion'], '1.18', '<')) { $GLOBALS['egMapsGlobalJSVars'] += $this->service->getConfigVariables(); } if (true) { // TODO global $wgOut; $this->service->addDependencies($wgOut); $wgOut->addScript($configVars); } else { $this->service->addDependencies($wgParser); } return $output; } else { return '<span class="errorbox">' . htmlspecialchars(wfMessage('validator-fatal-error', $fatalError->getMessage())->text()) . '</span>'; } }
/** * Prepare data for the output * * @since 1.8 * * @param array $data * @param array $options * * @return string */ protected function getFormatOutput($data, $options) { // The generated ID is to distinguish similar instances of the same // printer that can appear within the same page static $statNr = 0; $ID = 'srf-boilerplate-' . ++$statNr; // or use the PHP uniqid() to generate an unambiguous ID // $ID = uniqid(); // Used to set that the output and being treated as HTML (opposed to plain wiki text) $this->isHTML = true; // Correct escaping is vital to minimize possibilites of malicious code snippets // and also a coherent string evalution therefore it is recommended // that data transferred to the JS plugin is JSON encoded // Assign the ID to make a data instance readly available and distinguishable // from other content within the same page $requireHeadItem = array($ID => FormatJson::encode($data)); SMWOutputs::requireHeadItem($ID, Skin::makeVariablesScript($requireHeadItem)); // Add resource definitions that has been registered with SRF_Resource.php // Resource definitions contain scripts, styles, messages etc. // SMWOutputs::requireResource( 'ext.srf.boilerplate.namespace' ); SMWOutputs::requireResource('ext.srf.boilerplate.simple'); // Prepares an HTML element showing a rotating spinner indicating that something // will appear at this placeholder. The element will be visible as for as // long as jquery is not loaded and the JS plugin did not hide/removed the element. $processing = SRFUtils::htmlProcessingElement(); // Add two elements a outer wrapper that is assigned a class which the JS plugin // can select and will fetch all instances of the same result printer and an innner // container which is set invisible (display=none) for as long as the JS plugin // holds the content hidden. It is normally the place where the "hard work" // is done hidden from the user until it is ready. // The JS plugin can prepare the output within this container without presenting // unfinished visual content, to avoid screen clutter and improve user experience. return Html::rawElement('div', array('class' => 'srf-boilerplate'), $processing . Html::element('div', array('id' => $ID, 'class' => 'container', 'style' => 'display:none;'), null)); }
/** * Prepare data for the output * * @since 1.8 * * @param array $data * * @return string */ protected function getFormatOutput(array $data) { $this->isHTML = true; static $statNr = 0; $chartID = 'jqplot-series-' . ++$statNr; // Encoding $requireHeadItem = array($chartID => FormatJson::encode($data)); SMWOutputs::requireHeadItem($chartID, Skin::makeVariablesScript($requireHeadItem)); // Add RL resources $this->addResources(); // Processing placeholder $processing = SRFUtils::htmlProcessingElement($this->isHTML); // Conversion due to a string as value that can contain % $width = strstr($this->params['width'], "%") ? $this->params['width'] : $this->params['width'] . 'px'; // Chart/graph placeholder $chart = Html::rawElement('div', array('id' => $chartID, 'class' => 'container', 'style' => "display:none; width: {$width}; height: {$this->params['height']}px;"), null); // Beautify class selector $class = $this->params['charttype'] ? '-' . $this->params['charttype'] : ''; $class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class . ' jqplot-common'; // Chart/graph wrappper return Html::rawElement('div', array('class' => 'srf-jqplot' . $class), $processing . $chart); }
/** * Add upload JS to OutputPage * * @param bool $autofill Whether or not to autofill the destination * filename text box */ protected function addUploadJS($autofill = true) { global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview; global $wgStrictFileExtensions, $wgMaxUploadSize; $scriptVars = array('wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck, 'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview, 'wgUploadAutoFill' => (bool) $autofill && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds, 'wgStrictFileExtensions' => $wgStrictFileExtensions, 'wgCapitalizeUploads' => MWNamespace::isCapitalized(NS_FILE), 'wgMaxUploadSize' => $wgMaxUploadSize); $this->getOutput()->addScript(Skin::makeVariablesScript($scriptVars)); }
/** * Add upload JavaScript to $wgOut */ protected function addUploadJS() { global $wgScriptPath, $wgMaxUploadFiles, $wgFileExtensions; global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI; global $wgOut; $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI; $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds); $wgOut->addScript(Skin::makeVariablesScript($scriptVars)); // For <charinsert> support $wgOut->addScriptFile('edit.js'); // changed $wgOut->addScriptFile("{$wgScriptPath}/extensions/MultiUpload/multiupload.js"); $newscriptVars = array('wgMaxUploadFiles' => $wgMaxUploadFiles, 'wgFileExtensions' => $wgFileExtensions); $wgOut->addScript(Skin::makeVariablesScript($newscriptVars)); }
private function getMapOutput(array $params, $inputName) { global $wgParser; if (is_object($params['centre'])) { $params['centre'] = $params['centre']->getJSONObject(); } // We can only take care of the zoom defaulting here, // as not all locations are available in whats passed to Validator. if ($params['zoom'] === false && count($params['locations']) <= 1) { $params['zoom'] = $this->service->getDefaultZoom(); } $mapName = $this->service->getMapId(); $params['inputname'] = $inputName; $output = $this->getInputHTML($params, $wgParser, $mapName); $this->service->addResourceModules($this->getResourceModules()); $configVars = Skin::makeVariablesScript($this->service->getConfigVariables()); if (true) { // TODO global $wgOut; $this->service->addDependencies($wgOut); $wgOut->addScript($configVars); } else { $this->service->addDependencies($wgParser); } return $output; }
/** * Builds up and returns the HTML for the map, with the queried coordinate data on it. * * @param SMWQueryResult $res * @param $outputmode * * @return array or string */ public final function getResultText( SMWQueryResult $res, $outputmode ) { if ( $this->fatalErrorMsg === false ) { global $wgParser; $params = $this->params; $queryHandler = new SMQueryHandler( $res, $outputmode ); $queryHandler->setShowSubject( $params['showtitle'] ); $queryHandler->setTemplate( $params['template'] ); $this->handleMarkerData( $params, $queryHandler->getLocations() ); $locationAmount = count( $params['locations'] ); if ( $params['forceshow'] || $locationAmount > 0 ) { // We can only take care of the zoom defaulting here, // as not all locations are available in whats passed to Validator. if ( $params['zoom'] === false && $locationAmount <= 1 ) { $params['zoom'] = $this->service->getDefaultZoom(); } $mapName = $this->service->getMapId(); // MediaWiki 1.17 does not play nice with addScript, so add the vars via the globals hook. if ( version_compare( $GLOBALS['wgVersion'], '1.18', '<' ) ) { $GLOBALS['egMapsGlobalJSVars'] += $this->service->getConfigVariables(); } SMWOutputs::requireHeadItem( $mapName, $this->service->getDependencyHtml() . $configVars = Skin::makeVariablesScript( $this->service->getConfigVariables() ) ); foreach ( $this->service->getResourceModules() as $resourceModule ) { SMWOutputs::requireResource( $resourceModule ); } $result = $this->getMapHTML( $params, $wgParser, $mapName ) . $this->getJSON( $params, $wgParser, $mapName ); return array( $result, 'noparse' => true, 'isHTML' => true ); } else { return ''; } } else { return $this->fatalErrorMsg; } }
/** * Display the signup form for this contest. * * @since 0.1 * * @param Contest $contest * @param integer|false $challengeId */ protected function showSignupForm(Contest $contest, $challengeId = false) { $form = new HTMLForm($this->getFormFields($contest, $challengeId), $this->getContext()); $form->setSubmitCallback(array($this, 'handleSubmission')); $form->setSubmitText(wfMsg('contest-signup-submit')); if ($form->show()) { $this->onSuccess($contest); } else { $this->getOutput()->addModules('contest.special.signup'); } $this->getOutput()->addScript(Skin::makeVariablesScript(array('ContestConfig' => array('rules_page' => ContestUtils::getParsedArticleContent($contest->getField('rules_page')))))); }
/** * Add upload JS to $wgOut */ protected function addUploadJS() { global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions; global $wgOut; $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI; $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize(); $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds, 'wgStrictFileExtensions' => $wgStrictFileExtensions, 'wgCapitalizeUploads' => MWNamespace::isCapitalized(NS_FILE), 'wgMaxUploadSize' => $this->mMaxUploadSize); $wgOut->addScript(Skin::makeVariablesScript($scriptVars)); $wgOut->addModules(array('mediawiki.action.edit', 'mediawiki.legacy.upload', 'mediawiki.special.upload')); }
/** * Returns a script tag that stores the amount of time it took MediaWiki to * handle the request in milliseconds as 'wgBackendResponseTime'. * * If $wgShowHostnames is true, the script will also set 'wgHostname' to the * hostname of the server handling the request. * * @return string */ function wfReportTime() { global $wgRequestTime, $wgShowHostnames; $responseTime = round((microtime(true) - $wgRequestTime) * 1000); $reportVars = array('wgBackendResponseTime' => $responseTime); if ($wgShowHostnames) { $reportVars['wgHostname'] = wfHostname(); } return Skin::makeVariablesScript($reportVars); }
/** * Prepare calendar output * * @since 1.8 * * @param array $events * @return string */ protected function getCalendarOutput(array $events) { // Init static $statNr = 0; $calendarID = 'calendar-' . ++$statNr; $this->isHTML = true; // Consistency of names otherwise fullCalendar throws an error $defaultVS = array('day', 'week'); $defaultVR = array('Day', 'Week'); $defaultView = str_replace($defaultVS, $defaultVR, $this->params['defaultview']); // Add options $dataObject['events'] = $events; $dataObject['options'] = array('defaultview' => $defaultView, 'calendarstart' => $this->getCalendarStart($events, $this->params['start']), 'dayview' => $this->params['dayview'], 'firstday' => date('N', strtotime($this->params['firstday'])), 'theme' => in_array($this->params['theme'], array('vector')), 'views' => 'month,' . (strpos($defaultView, 'Week') === false ? 'basicWeek' : $defaultView) . ',' . (strpos($defaultView, 'Day') === false ? 'agendaDay' : $defaultView)); // Encode data objects $requireHeadItem = array($calendarID => FormatJson::encode($dataObject)); SMWOutputs::requireHeadItem($calendarID, Skin::makeVariablesScript($requireHeadItem)); // RL module SMWOutputs::requireResource('ext.srf.eventcalendar'); // Processing placeholder $processing = SRFUtils::htmlProcessingElement($this->isHTML); // Container placeholder $calendar = Html::rawElement('div', array('id' => $calendarID, 'class' => 'container', 'style' => 'display:none;'), null); // Beautify class selector $class = $this->params['class'] ? ' ' . $this->params['class'] : ''; // General wrappper return Html::rawElement('div', array('class' => 'srf-eventcalendar' . $class), $processing . $calendar); }