/** * @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) { //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); }
/** * 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); }
/** * @see SMWResultPrinter::getResultText * * @param SMWQueryResult $res * @param $outputMode * * @return string */ protected function getResultText(SMWQueryResult $res, $outputMode) { // Initialize static $statNr = 0; // Get results from SMWListResultPrinter $result = parent::getResultText($res, $outputMode); // Count widgets $widgetID = 'pagewidget-' . ++$statNr; // Container items $result = Html::rawElement('div', array('id' => $widgetID, 'class' => 'container', 'data-embedonly' => $this->params['embedonly'], 'style' => 'display:none;'), $result); // Placeholder $processing = SRFUtils::htmlProcessingElement($this->isHTML); // RL module SMWOutputs::requireResource('ext.srf.pagewidget.carousel'); // Beautify class selector $class = $this->params['class'] ? ' ' . $this->params['class'] : ''; // Wrap results return Html::rawElement('div', array('class' => 'srf-pagewidget' . $class), $processing . $result); }
/** * @see SMWResultPrinter::getResultText * * @param SMWQueryResult $res * @param array $params * @param $outputmode * * @return string */ protected function getResultText(SMWQueryResult $res, $outputmode) { // Initialize static $statNr = 0; //$this->isHTML = true; // Set output type for the parent $this->mFormat = $this->params['listtype'] == 'ordered' || $this->params['listtype'] == 'ol' ? 'ol' : 'ul'; // Get results from SMWListResultPrinter $result = parent::getResultText($res, $outputmode); // Count widgets $listwidgetID = 'listwidget-' . ++$statNr; // OL/UL container items $result = Html::rawElement('div', array('id' => $listwidgetID, 'class' => 'container', 'style' => 'display:none; position: relative; margin-bottom:5px; margin-top:5px;'), $result); // Placeholder $processing = SRFUtils::htmlProcessingElement($this->isHTML); // RL module $resource = 'ext.srf.listwidget.' . $this->params['widget']; SMWOutputs::requireResource($resource); // Wrap results return Html::rawElement('div', array('class' => 'srf-listwidget ' . htmlspecialchars($this->params['class']), 'data-listtype' => $this->mFormat, 'data-widget' => $this->params['widget'], 'data-pageitems' => $this->params['pageitems']), $processing . $result); }
/** * Returns the HTML for the tag cloud. * * @since 1.5.3 * * @param array $tags * * @return string */ protected function getTagCloud(array $tags) { // Initialize static $statNr = 0; $htmlTags = array(); $processing = ''; $htmlSTags = ''; $htmlCTags = ''; // Count actual output and store div identifier $tagID = $this->params['widget'] . '-' . ++$statNr; // Determine HTML element marker $element = $this->params['widget'] !== '' ? 'li' : 'span'; // Add size information foreach ($tags as $name => $size) { $htmlTags[] = Html::rawElement($element, array('style' => "font-size:{$size}%"), $this->tagsHtml[$name]); } // Stringify $htmlSTags = implode(' ', $htmlTags); // Handle sphere/canvas output objects if (in_array($this->params['widget'], array('sphere', 'wordcloud'))) { // Wrap LI/UL elements $htmlCTags = Html::rawElement('ul', array('style' => 'display:none;'), $htmlSTags); // Wrap tags $htmlCTags = Html::rawElement('div', array('id' => $tagID . '-tags'), $htmlCTags); // Wrap everything in a container object $htmlSTags = Html::rawElement('div', array('id' => $tagID . '-container', 'class' => 'container', 'data-width' => $this->params['width'], 'data-height' => $this->params['height'], 'data-font' => $this->params['font']), $htmlCTags); // Processing placeholder $processing = SRFUtils::htmlProcessingElement($this->isHTML); } // Beautify class selector $class = $this->params['widget'] ? '-' . $this->params['widget'] . ' ' : ''; $class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class; // General placeholder $attribs = array('class' => 'srf-tagcloud' . $class, 'align' => 'justify'); return Html::rawElement('div', $attribs, $processing . $htmlSTags); }
/** * 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); }
/** * @see SMWResultPrinter::getResultText * * @param $results SMWQueryResult * @param $fullParams array * @param $outputmode integer * * @return string */ public function getResultText(SMWQueryResult $results, $outputmode) { $ig = new ImageGallery(); $ig->setShowBytes(false); $ig->setShowFilename(false); $ig->setCaption($this->mIntro); // set caption to IQ header // No need for a special page to use the parser but for the "normal" page // view we have to ensure caption text is parsed correctly through the parser if (!$this->isSpecialPage()) { $ig->setParser($GLOBALS['wgParser']); } // Initialize static $statNr = 0; $html = ''; $processing = ''; if ($this->params['widget'] == 'carousel') { // Carousel widget $ig->setAttributes($this->getCarouselWidget()); } elseif ($this->params['widget'] == 'slideshow') { // Slideshow widget $ig->setAttributes($this->getSlideshowWidget()); } else { // Standard gallery attributes $attribs = array('id' => uniqid(), 'class' => $this->getImageOverlay()); $ig->setAttributes($attribs); } // Only use redirects where the overlay option is not used and redirect // thumb images towards a different target if ($this->params['redirects'] !== '' && !$this->params['overlay']) { SMWOutputs::requireResource('ext.srf.gallery.redirect'); } // For the carousel widget, the perrow option should not be set if ($this->params['perrow'] !== '' && $this->params['widget'] !== 'carousel') { $ig->setPerRow($this->params['perrow']); } if ($this->params['widths'] !== '') { $ig->setWidths($this->params['widths']); } if ($this->params['heights'] !== '') { $ig->setHeights($this->params['heights']); } $printReqLabels = array(); $redirectType = ''; /** * @var SMWPrintRequest $printReq */ foreach ($results->getPrintRequests() as $printReq) { $printReqLabels[] = $printReq->getLabel(); // Get redirect type if ($this->params['redirects'] === $printReq->getLabel()) { $redirectType = $printReq->getTypeID(); } } if ($this->params['imageproperty'] !== '' && in_array($this->params['imageproperty'], $printReqLabels) || $this->params['redirects'] !== '' && in_array($this->params['redirects'], $printReqLabels)) { $this->addImageProperties($results, $ig, $this->params['imageproperty'], $this->params['captionproperty'], $this->params['redirects'], $outputmode); } else { $this->addImagePages($results, $ig); } // SRF Global settings SRFUtils::addGlobalJSVariables(); // Display a processing image as long as the DOM is no ready if ($this->params['widget'] !== '') { $processing = SRFUtils::htmlProcessingElement(); } // Beautify the class selector $class = $this->params['widget'] ? '-' . $this->params['widget'] . ' ' : ''; $class = $this->params['redirects'] !== '' && $this->params['overlay'] === false ? $class . ' srf-redirect' . ' ' : $class; $class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class; // Separate content from result output if (!$ig->isEmpty()) { $attribs = array('class' => 'srf-gallery' . $class, 'align' => 'justify', 'data-redirect-type' => $redirectType); $html = Html::rawElement('div', $attribs, $processing . $ig->toHTML()); } // If available, create a link that points to further results if ($this->linkFurtherResults($results)) { $html .= $this->getLink($results, SMW_OUTPUT_HTML)->getText(SMW_OUTPUT_HTML, $this->mLinker); } return array($html, 'nowiki' => true, 'isHTML' => true); }
/** * 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); }
/** * 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); }
/** * 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); }