/** * @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); }
/** * This method will be called before an article is displayed or previewed. * For display and preview we strip out the semantic properties and append them * at the end of the article. * * @param Parser $parser * @param string $text */ static public function onInternalParseBeforeLinks( &$parser, &$text ) { global $smwgStoreAnnotations, $smwgLinksInValues; SMWParseData::stripMagicWords( $text, $parser ); // Store the results if enabled (we have to parse them in any case, // in order to clean the wiki source for further processing). $smwgStoreAnnotations = smwfIsSemanticsProcessed( $parser->getTitle()->getNamespace() ); SMWParserExtensions::$mTempStoreAnnotations = true; // used for [[SMW::on]] and [[SMW:off]] // Process redirects, if any (it seems that there is indeed no more direct way of getting this info from MW) if ( $smwgStoreAnnotations ) { $rt = Title::newFromRedirect( $text ); if ( !is_null( $rt ) ) { $p = new SMWDIProperty( '_REDI' ); $di = SMWDIWikiPage::newFromTitle( $rt, '__red' ); SMWParseData::getSMWData( $parser )->addPropertyObjectValue( $p, $di ); } } // only used in subsequent callbacks, forgotten afterwards SMWParserExtensions::$mTempParser = $parser; // In the regexp matches below, leading ':' escapes the markup, as known for Categories. // Parse links to extract semantic properties. if ( $smwgLinksInValues ) { // More complex regexp -- lib PCRE may cause segfaults if text is long :-( $semanticLinkPattern = '/\[\[ # Beginning of the link (?:([^:][^]]*):[=:])+ # Property name (or a list of those) ( # After that: (?:[^|\[\]] # either normal text (without |, [ or ]) |\[\[[^]]*\]\] # or a [[link]] |\[[^]]*\] # or an [external link] )*) # all this zero or more times (?:\|([^]]*))? # Display text (like "text" in [[link|text]]), optional \]\] # End of link /xu'; $text = preg_replace_callback( $semanticLinkPattern, array( 'SMWParserExtensions', 'parsePropertiesCallback' ), $text ); } else { // Simpler regexps -- no segfaults found for those, but no links in values. $semanticLinkPattern = '/\[\[ # Beginning of the link (?:([^:][^]]*):[=:])+ # Property name (or a list of those) ([^\[\]]*) # content: anything but [, |, ] \]\] # End of link /xu'; $text = preg_replace_callback( $semanticLinkPattern, array( 'SMWParserExtensions', 'simpleParsePropertiesCallback' ), $text ); } // Add link to RDF to HTML header. // TODO: do escaping via Html or Xml class. SMWOutputs::requireHeadItem( 'smw_rdf', '<link rel="alternate" type="application/rdf+xml" title="' . htmlspecialchars( $parser->getTitle()->getPrefixedText() ) . '" href="' . htmlspecialchars( SpecialPage::getTitleFor( 'ExportRDF', $parser->getTitle()->getPrefixedText() )->getLocalUrl( 'xmlmime=rdf' ) ) . "\" />" ); SMWOutputs::commitToParser( $parser ); return true; // always return true, in order not to stop MW's hook processing! }
/** * 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; } }
/** * 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); }
/** * Includes the JavaScript required for the timeline and eventline formats. * * @since 1.5.3 */ protected function includeJS() { SMWOutputs::requireHeadItem( SMW_HEADER_STYLE ); // MediaWiki 1.17 introduces the Resource Loader. $realFunction = array( 'SMWOutputs', 'requireResource' ); if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) && is_callable( $realFunction ) ) { SMWOutputs::requireResource( 'ext.srf.timeline' ); } else { global $srfgScriptPath; SMWOutputs::requireHeadItem( 'smw_tlhelper', '<script type="text/javascript" src="' . $srfgScriptPath . '/Timeline/SRF_timeline.js"></script>' ); SMWOutputs::requireHeadItem( 'smw_tl', '<script type="text/javascript" src="' . $srfgScriptPath . '/Timeline/SimileTimeline/timeline-api.js"></script>' ); } }
protected function includeJS() { SMWOutputs::requireHeadItem(SMW_HEADER_STYLE); //$wgOut->addModules( 'ext.srf.jitgraph' ); global $srfgScriptPath; SMWOutputs::requireHeadItem('smw_jgcss', '<link rel="stylesheet" type="text/css" href="' . $srfgScriptPath . '/JitGraph/base.css"></link>'); SMWOutputs::requireHeadItem('smw_jgloader', '<script type="text/javascript" src="' . $srfgScriptPath . '/JitGraph/jquery.progressbar.js"></script>'); SMWOutputs::requireHeadItem('smw_jg', '<script type="text/javascript" src="' . $srfgScriptPath . '/JitGraph/Jit/jit.js"></script>'); SMWOutputs::requireHeadItem('smw_jghelper', '<script type="text/javascript" src="' . $srfgScriptPath . '/JitGraph/SRF_JitGraph.js"></script>'); }
/** * Callback function for the hook 'smwShowFactbox'. It is called when SMW creates * the factbox for an article. * This method replaces the whole factbox with a tabbed version that contains * the original factbox in one tab and the derived facts in another. * * @param string $text * The HTML for the tabbed factbox is returned in this parameter * @param SMWSemanticData $semdata * All static facts for the article * @return bool * <false> : This means that SMW's factbox is completely replaced. */ function smwfAddDerivedFacts(&$text, $semdata) { global $smwgHaloScriptPath, $wgContLang; wfLoadExtensionMessages('SemanticMediaWiki'); SMWOutputs::requireHeadItem(SMW_HEADER_STYLE); $rdflink = SMWInfolink::newInternalLink(wfMsgForContent('smw_viewasrdf'), $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . $semdata->getSubject()->getWikiValue(), 'rdflink'); $browselink = SMWInfolink::newBrowsingLink($semdata->getSubject()->getText(), $semdata->getSubject()->getWikiValue(), 'swmfactboxheadbrowse'); $fbText = '<div class="smwfact">' . '<span class="smwfactboxhead">' . wfMsgForContent('smw_factbox_head', $browselink->getWikiText()) . '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<table class="smwfacttable">' . "\n"; foreach ($semdata->getProperties() as $property) { if (!$property->isShown()) { // showing this is not desired, hide continue; } elseif ($property->isUserDefined()) { // user defined property $property->setCaption(preg_replace('/[ ]/u', ' ', $property->getWikiValue(), 2)); /// NOTE: the preg_replace is a slight hack to ensure that the left column does not get too narrow $fbText .= '<tr><td class="smwpropname">' . $property->getLongWikiText(true) . '</td><td class="smwprops">'; } elseif ($property->isVisible()) { // predefined property $fbText .= '<tr><td class="smwspecname">' . $property->getLongWikiText(true) . '</td><td class="smwspecs">'; } else { // predefined, internal property continue; } $propvalues = $semdata->getPropertyValues($property); $l = count($propvalues); $i = 0; foreach ($propvalues as $propvalue) { if ($i != 0) { if ($i > $l - 2) { $fbText .= wfMsgForContent('smw_finallistconjunct') . ' '; } else { $fbText .= ', '; } } $i += 1; $fbText .= $propvalue->getLongWikiText(true) . $propvalue->getInfolinkText(SMW_OUTPUT_WIKI); } $fbText .= '</td></tr>'; } $fbText .= '</table></div>'; $text = '<div id="smw_dft_rendered_boxcontent"> <br />' . '<table>' . '<tr>' . '<td id="dftTab1" class="dftTabActive">' . str_replace(' ', ' ', wfMsg('smw_df_static_tab')) . '</td>' . '<td class="dftTabSpacer"> </td>' . '<td id="dftTab2" class="dftTabInactive">' . str_replace(' ', ' ', wfMsg('smw_df_derived_tab')) . '</td>' . '<td class="dftTabSpacer" width="100%"></td>' . '</tr>' . '<tr>' . '<td colspan="4" class="dftTabCont">' . '<div id="dftTab1Content" >' . $fbText . '</div>' . '<div id="dftTab2Content" style="display:none">' . '<div id="dftTab2ContentInnerDiv">' . wfMsg('smw_df_loading_df') . '</div>' . '</div>' . '</td>' . '</tr>' . '</table>' . '</div>'; return false; }
/** * 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)); }
protected function getResultText($res, $outputmode) { global $smwgIQRunningNumber; SMWOutputs::requireHeadItem(SMW_HEADER_SORTTABLE); // print header if ('broadtable' == $this->mFormat) { $widthpara = ' width="100%"'; } else { $widthpara = ''; } $result = ""; if (defined('SMW_UP_RATING_VERSION')) { $result .= "UpRatingTable___" . $smwgIQRunningNumber . "___elbaTgnitaRpU"; } $result .= "<table class=\"smwtable\"{$widthpara} id=\"querytable" . $smwgIQRunningNumber . "\">\n"; if ($this->mShowHeaders != SMW_HEADERS_HIDE) { // building headers $result .= "\t<tr>\n"; foreach ($res->getPrintRequests() as $pr) { $result .= "\t\t<th>" . $pr->getText($outputmode, $this->mShowHeaders == SMW_HEADERS_PLAIN ? NULL : $this->mLinker) . "</th>\n"; } $result .= "\t</tr>\n"; } // print all result rows while ($row = $res->getNext()) { $result .= "\t<tr>\n"; $firstcol = true; foreach ($row as $field) { $result .= "\t\t<td>"; $first = true; while (($object = $field->getNextObject()) !== false) { if ($object->getTypeID() == '_wpg') { // use shorter "LongText" for wikipage $provURL = $object->getProvenance(); if ($firstcol && !is_null($provURL)) { //$text = $this->createArticleLinkFromProvenance($provURL, $this->getLinker($firstcol)); $text = $object->getLongText($outputmode, $this->getLinker($firstcol)); } else { $text = $object->getLongText($outputmode, $this->getLinker($firstcol)); if (strlen($text) > 0 && !is_null($provURL)) { $text .= $this->createProvenanceLink($provURL); } } } else { $text = $object->getShortText($outputmode, $this->getLinker($firstcol)); if (strlen($text) > 0) { $provURL = $object->getProvenance(); if (!is_null($provURL)) { $text .= $this->createProvenanceLink($provURL); } } } if ($first) { if ($object->isNumeric()) { // use numeric sortkey $result .= '<span class="smwsortkey">' . $object->getNumericValue() . '</span>'; } $first = false; } else { $result .= '<br />'; } $result .= $text; } $result .= "</td>\n"; $firstcol = false; } $result .= "\t</tr>\n"; } // print further results footer if ($this->linkFurtherResults($res)) { $link = $res->getQueryLink(); if ($this->getSearchLabel($outputmode)) { $link->setCaption($this->getSearchLabel($outputmode)); } $result .= "\t<tr class=\"smwfooter\"><td class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> ' . $link->getText($outputmode, $this->mLinker) . "</td></tr>\n"; } $result .= "</table>\n"; // print footer $this->isHTML = $outputmode == SMW_OUTPUT_HTML; // yes, our code can be viewed as HTML if requested, no more parsing needed return $result; }
/** * 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); }
protected function getResultText($res, $outputmode) { global $smwgIQRunningNumber; SMWOutputs::requireHeadItem(SMW_HEADER_SORTTABLE); $cols = array(); //Names of columns // print header if ('broadtable' == $this->mFormat) { $widthpara = ' width="100%"'; } else { $widthpara = ''; } $result = "<table class=\"smwtable\"{$widthpara} id=\"querytable" . $smwgIQRunningNumber . "\">\n"; if ($this->mShowHeaders) { // building headers $result .= "\t<tr>\n"; foreach ($res->getPrintRequests() as $pr) { $title = $pr->getData(); if ($title instanceof Title) { array_push($cols, $title); } else { array_push($cols, ""); } $result .= "\t\t<th>" . $pr->getText($outputmode, $this->mLinker) . "</th>\n"; } $result .= "\t</tr>\n"; } else { foreach ($res->getPrintRequests() as $pr) { $title = $pr->getTitle(); if ($title instanceof Title) { array_push($cols, $title); } else { array_push($cols, ""); } } } // print all result rows while ($row = $res->getNext()) { $result .= "\t<tr>\n"; $firstcol = true; $gIssues = null; $act_column = 0; foreach ($row as $field) { $result .= "\t\t<td>"; $first = true; while (($object = $field->getNextObject()) !== false) { if ($object->getTypeID() == '_wpg') { // use shorter "LongText" for wikipage $text = $object->getLongText($outputmode, $this->getLinker($firstcol)); } else { $text = $object->getShortText($outputmode, $this->getLinker($firstcol)); } if ($first) { $first = false; } else { $result .= '<br />'; } $result .= $text; } $result .= "</td>\n"; $firstcol = false; $act_column++; } $result .= "\t</tr>\n"; } // print further results footer if ($this->linkFurtherResults($res)) { $link = $res->getQueryLink(); if ($this->getSearchLabel($outputmode)) { $link->setCaption($this->getSearchLabel($outputmode)); } $result .= "\t<tr class=\"smwfooter\"><td class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> ' . $link->getText($outputmode, $this->mLinker) . "</td></tr>\n"; } $result .= "</table>\n"; // print footer $this->isHTML = $outputmode == SMW_OUTPUT_HTML; // yes, our code can be viewed as HTML if requested, no more parsing needed return $result; }
protected function getResultText(SMWQueryResult $res, $outputmode) { global $smwgIQRunningNumber, $wgScriptPath, $wgGoogleMapsKey, $srfgScriptPath; if (defined('MW_SUPPORTS_RESOURCE_MODULES')) { SMWOutputs::requireHeadItem('exhibit-compat', Html::linkedScript("{$wgScriptPath}/common/wikibits.js")); } // ////////////////////////////// // ///////REMOTE STUFF/////////// // ////////////////////////////// $remote = false; // in case the remote parameter is set, a link to the JSON export of the remote wiki is included in the header as data source for Exhibit // this section creates the link if (array_key_exists('remote', $this->m_params) && srfgExhibitRemote == true) { $remote = true; // fetch interwiki link $dbr =& wfGetDB(DB_SLAVE); $cl = $dbr->tableName('interwiki'); $dbres = $dbr->select($cl, 'iw_url', "iw_prefix='" . $this->m_params['remote'] . "'", __METHOD__, array()); $row = $dbr->fetchRow($dbres); $extlinkpattern = $row[iw_url]; $dbr->freeResult($dbres); $newheader = '<link rel="exhibit/data" type="application/jsonp" href="'; $link = $res->getQueryLink('JSON Link'); $link->setParameter('json', 'format'); if (array_key_exists('callback', $this->m_params)) { // check if a special name for the callback function is set, if not stick with 'callback' $callbackfunc = $this->m_params['callback']; } else { $callbackfunc = 'callback'; } if (array_key_exists('limit', $this->m_params)) { $link->setParameter($this->m_params['limit'], 'limit'); } $link->setParameter($callbackfunc, 'callback'); $link = $link->getText(2, $this->mLinker); list($link, $trash) = explode('|', $link); $link = str_replace('[[:', '', $link); $newheader .= str_replace('$1', $link, $extlinkpattern); $newheader .= '" ex:jsonp-callback="' . $callbackfunc . '"'; $newheader .= '/>'; SMWOutputs::requireHeadItem('REMOTE', $newheader); } // the following variables indicate the use of special views // the variable's values define the way Exhibit is called $timeline = false; $map = false; /*The javascript file adopted from Wibbit uses a bunch of javascript variables in the header to store information about the Exhibit markup. The following code sequence creates these variables*/ // prepare sources (the sources holds information about the table which contains the information) $colstack = array(); foreach ($res->getPrintRequests() as $pr) { $colstack[] = $this->encodePropertyName($pr->getLabel()) . ':' . (array_key_exists($pr->getTypeID(), $this->m_types) ? $this->m_types[$pr->getTypeID()] : 'text'); } array_shift($colstack); array_unshift($colstack, 'label'); if (SRFExhibit::$exhibitRunningNumber == 0) { $sourcesrc = "var ex_sources = { source" . ($smwgIQRunningNumber - 1) . ": { id: 'querytable" . $smwgIQRunningNumber . "' , columns: '" . implode(',', $colstack) . "'.split(','), hideTable: '1', type: 'Item', label: 'Item', pluralLabel: 'Items' } };"; } else { $sourcesrc = "sources.source" . $smwgIQRunningNumber . " = { id: 'querytable" . $smwgIQRunningNumber . "' , columns: '" . implode(',', $colstack) . "'.split(','), hideTable: '1', type: 'Item', label: 'Item', pluralLabel: 'Items' };"; } $sourcesrc = "<script type=\"text/javascript\">" . $sourcesrc . "</script>"; // prepare facets $facetcounter = 0; if (array_key_exists('facets', $this->m_params)) { $facets = explode(',', $this->m_params['facets']); $facetstack = array(); $params = array('height'); $facparams = array(); foreach ($params as $param) { if (array_key_exists($param, $this->m_params)) { $facparams[] = 'ex:' . $param . '="' . $this->encodePropertyName($this->m_params[$param]) . '" '; } } foreach ($facets as $facet) { $facet = trim($facet); $fieldcounter = 0; if (strtolower($facet) == "search") { // special facet (text search) $facetstack[] = ' facet' . $facetcounter++ . ': { position : "right", innerHTML: \'ex:role="facet" ex:showMissing="false" ex:facetClass="TextSearch" ex:facetLabel="' . $facet . '"\'}'; } else { // usual facet foreach ($res->getPrintRequests() as $pr) { if ($this->encodePropertyName($pr->getLabel()) == $this->encodePropertyName($facet)) { switch ($pr->getTypeID()) { case '_num': $facetstack[] = ' facet' . $facetcounter++ . ': { position : "right", innerHTML: \'ex:role="facet" ex:showMissing="false" ex:expression=".' . $this->encodePropertyName($facet) . '" ex:facetLabel="' . $facet . '" ex:facetClass="Slider"\'}'; break; default: $facetstack[] = ' facet' . $facetcounter++ . ': { position : "right", innerHTML: \'ex:role="facet" ex:showMissing="false" ' . implode(" ", $facparams) . ' ex:expression=".' . $this->encodePropertyName($facet) . '" ex:facetLabel="' . $facet . '"\'}'; } } } } $fieldcounter++; } $facetstring = implode(',', $facetstack); } else { $facetstring = ''; } $facetsrc = "var ex_facets = {" . $facetstring . " };"; // prepare views $stylesrc = ''; $viewcounter = 0; if (array_key_exists('views', $this->m_params)) { $views = explode(',', $this->m_params['views']); } else { $views[] = 'tiles'; } foreach ($views as $view) { switch (trim($view)) { case 'tabular': // table view (the columns are automatically defined by the selected properties) $thstack = array(); foreach ($res->getPrintRequests() as $pr) { $thstack[] = "." . $this->encodePropertyName($pr->getLabel()); } array_shift($thstack); array_unshift($thstack, '.label'); $stylesrc = 'var myStyler = function(table, database) {table.className=\'smwtable\';};'; // assign SMWtable CSS to Exhibit tabular view $viewstack[] = 'ex:role=\'view\' ex:viewClass=\'Tabular\' ex:showSummary=\'false\' ex:sortAscending=\'true\' ex:tableStyler=\'myStyler\' ex:label=\'Table\' ex:columns=\'' . implode(',', $thstack) . '\' ex:sortAscending=\'false\''; break; case 'timeline': // timeline view $timeline = true; $exparams = array('start', 'end', 'proxy', 'colorkey'); // parameters expecting an Exhibit graph expression $usparams = array('timelineheight', 'topbandheight', 'bottombandheight', 'bottombandunit', 'topbandunit'); // parametes expecting a textual or numeric value $tlparams = array(); foreach ($exparams as $param) { if (array_key_exists($param, $this->m_params)) { $tlparams[] = 'ex:' . $param . '=\'.' . $this->encodePropertyName($this->m_params[$param]) . '\' '; } } foreach ($usparams as $param) { if (array_key_exists($param, $this->m_params)) { $tlparams[] = 'ex:' . $param . '=\'' . $this->encodePropertyName($this->m_params[$param]) . '\' '; } } if (!array_key_exists('start', $this->m_params)) { // find out if a start and/or end date is specified $dates = array(); foreach ($res->getPrintRequests() as $pr) { if ($pr->getTypeID() == '_dat') { $dates[] = $pr; if (sizeof($dates) > 2) { break; } } } if (sizeof($dates) == 1) { $tlparams[] = 'ex:start=\'.' . $this->encodePropertyName($dates[0]->getLabel()) . '\' '; } elseif (sizeof($dates) == 2) { $tlparams[] = 'ex:start=\'.' . $this->encodePropertyName($dates[0]->getLabel()) . '\' '; $tlparams[] = 'ex:end=\'.' . $this->encodePropertyName($dates[1]->getLabel()) . '\' '; } } $viewstack[] = 'ex:role=\'view\' ex:viewClass=\'Timeline\' ex:label=\'Timeline\' ex:showSummary=\'false\' ' . implode(" ", $tlparams); break; case 'map': // map view if (isset($wgGoogleMapsKey)) { $map = true; $exparams = array('latlng', 'colorkey'); $usparams = array('type', 'center', 'zoom', 'size', 'scalecontrol', 'overviewcontrol', 'mapheight'); $mapparams = array(); foreach ($exparams as $param) { if (array_key_exists($param, $this->m_params)) { $mapparams[] = 'ex:' . $param . '=\'.' . $this->encodePropertyName($this->m_params[$param]) . '\' '; } } foreach ($usparams as $param) { if (array_key_exists($param, $this->m_params)) { $mapparams[] = 'ex:' . $param . '=\'' . $this->encodePropertyName($this->m_params[$param]) . '\' '; } } if (!array_key_exists('start', $this->m_params) && !array_key_exists('end', $this->m_params)) { // find out if a geographic coordinate is available foreach ($res->getPrintRequests() as $pr) { if ($pr->getTypeID() == '_geo') { $mapparams[] = 'ex:latlng=\'.' . $this->encodePropertyName($pr->getLabel()) . '\' '; break; } } } $viewstack[] .= 'ex:role=\'view\' ex:viewClass=\'Map\' ex:showSummary=\'false\' ex:label=\'Map\' ' . implode(" ", $mapparams); } break; default: case 'tiles': // tile view $sortstring = ''; if (array_key_exists('sort', $this->m_params)) { $sortfields = explode(",", $this->m_params['sort']); foreach ($sortfields as $field) { $sortkeys[] = "." . $this->encodePropertyName(trim($field)); } $sortstring = 'ex:orders=\'' . implode(",", $sortkeys) . '\' '; if (array_key_exists('order', $this->m_params)) { $sortstring .= ' ex:directions=\'' . $this->encodePropertyName($this->m_params['order']) . '\''; } if (array_key_exists('grouped', $this->m_params)) { $sortstring .= ' ex:grouped=\'' . $this->encodePropertyName($this->m_params['grouped']) . '\''; } } $viewstack[] = 'ex:role=\'view\' ex:showSummary=\'false\' ' . $sortstring; break; } } $viewsrc = 'var ex_views = "' . implode("/", $viewstack) . '".split(\'/\');;'; // prepare automatic lenses global $wgParser; $lenscounter = 0; $linkcounter = 0; $imagecounter = 0; if (array_key_exists('lens', $this->m_params)) { // a customized lens is specified via the lens parameter within the query $lenstitle = Title::newFromText("Template:" . $this->m_params['lens']); $lensarticle = new Article($lenstitle); $lenswikitext = $lensarticle->getContent(); if (preg_match_all("/[\\[][\\[][Ii][m][a][g][e][:][{][{][{][1-9A-z\\-[:space:]]*[}][}][}][\\]][\\]]/u", $lenswikitext, $matches)) { foreach ($matches as $match) { foreach ($match as $value) { $strippedvalue = trim(substr($value, 8), "[[{}]]"); $lenswikitext = str_replace($value, '<div class="inlines" id="imagecontent' . $imagecounter . '">' . $this->encodePropertyName(strtolower(str_replace("\n", "", $strippedvalue))) . '</div>', $lenswikitext); $imagecounter++; } } } if (preg_match_all("/[\\[][\\[][{][{][{][1-9A-z\\-[:space:]]*[}][}][}][\\]][\\]]/u", $lenswikitext, $matches)) { foreach ($matches as $match) { foreach ($match as $value) { $strippedvalue = trim($value, "[[{}]]"); $lenswikitext = str_replace($value, '<div class="inlines" id="linkcontent' . $linkcounter . '">' . $this->encodePropertyName(strtolower(str_replace("\n", "", $strippedvalue))) . '</div>', $lenswikitext); $linkcounter++; } } } if (preg_match_all("/[{][{][{][1-9A-z\\:\\|\\/\\=\\-[:space:]]*[}][}][}]/u", $lenswikitext, $matches)) { foreach ($matches as $match) { foreach ($match as $value) { $strippedvalue = trim($value, "{}"); $lenswikitext = str_replace($value, '<div class="inlines" id="lenscontent' . $lenscounter . '">' . $this->encodePropertyName(strtolower(str_replace("\n", "", $strippedvalue))) . '</div>', $lenswikitext); $lenscounter++; } } } $lenshtml = $wgParser->internalParse($lenswikitext); // $wgParser->parse($lenswikitext, $lenstitle, new ParserOptions(), true, true)->getText(); $lenssrc = "var ex_lens = '" . str_replace("\n", "", $lenshtml) . "';ex_lenscounter =" . $lenscounter . ";ex_linkcounter=" . $linkcounter . ";ex_imagecounter=" . $imagecounter . ";"; } else { // generic lens (creates links to further content (property-pages, pages about values) foreach ($res->getPrintRequests() as $pr) { if ($remote) { $wikiurl = str_replace("\$1", "", $extlinkpattern); } else { $wikiurl = $wgScriptPath . "/index.php?title="; } if ($pr->getTypeID() == '_wpg') { $prefix = ''; if ($pr->getLabel() == 'Category') { $prefix = "Category:"; } $lensstack[] = '<tr ex:if-exists=".' . $this->encodePropertyName($pr->getLabel()) . '"><td width="20%">' . $pr->getText(0, $this->mLinker) . '</td><td width="80%" ex:content=".' . $this->encodePropertyName($pr->getLabel()) . '"><a ex:href-subcontent="' . $wikiurl . $prefix . '{{urlencval(value)}}"><div ex:content="value" class="name"></div></a></td></tr>'; } else { $lensstack[] = '<tr ex:if-exists=".' . $this->encodePropertyName($pr->getLabel()) . '"><td width="20%">' . $pr->getText(0, $this->mLinker) . '</td><td width="80%"><div ex:content=".' . $this->encodePropertyName($pr->getLabel()) . '" class="name"></div></td></tr>'; } } array_shift($lensstack); $lenssrc = 'var ex_lens = \'<table width=100% cellpadding=3><tr><th class="head" align=left bgcolor="#DDDDDD"><a ex:href-subcontent="' . $wikiurl . $this->determineNamespace(clone $res) . '{{urlenc(.label)}}" class="linkhead"><div ex:content=".label" class="name"></div></a></th></tr></table><table width="100%" cellpadding=3>' . implode("", $lensstack) . '</table>\'; ex_lenscounter = 0; ex_linkcounter=0; ex_imagecounter=0;'; } if ($remote) { $varremote = 'true'; } else { $varremote = 'false'; } // Handling special formats like date $formatssrc = 'var formats =\'\''; if (array_key_exists('date', $this->m_params)) { $formatssrc = 'var formats = \'ex:formats="date { mode:' . $this->m_params['date'] . '; show:date }"\';'; } // create a URL pointing to the corresponding JSON feed $label = ''; $JSONlink = $res->getQueryLink($label); if ($this->getSearchLabel(SMW_OUTPUT_WIKI) != '') { // used as a file name $link->setParameter($this->getSearchLabel(SMW_OUTPUT_WIKI), 'searchlabel'); } if (array_key_exists('limit', $this->m_params)) { $JSONlink->setParameter(htmlspecialchars($this->m_params['limit']), 'limit'); } $JSONlink->setParameter('json', 'format'); $stringtoedit = explode("|", $JSONlink->getText($outputmode, $this->mLinker)); $stringtoedit = substr($stringtoedit[0], 3); $JSONlinksrc = "var JSONlink = '" . $stringtoedit . "';"; // create script header with variables containing the Exhibit markup $headervars = "<script type='text/javascript'>\n\t\t\t" . $facetsrc . "\n\t\t\t" . $viewsrc . "\n\t\t\t" . $lenssrc . "\n\t\t\t" . $stylesrc . "\n\t\t\t" . $formatssrc . "\n\t\t\t" . $JSONlinksrc . "\n\t\t\t var remote=" . $varremote . ";</script>"; // To run Exhibit some links to the scripts of the API need to be included in the header $ExhibitScriptSrc1 = '<script type="text/javascript" src="' . $srfgScriptPath . '/Exhibit/exhibit/exhibit-api.js?autoCreate=false&safe=true&bundle=false'; if ($timeline) { $ExhibitScriptSrc1 .= '&views=timeline'; } if ($map) { $ExhibitScriptSrc1 .= '&gmapkey=' . $wgGoogleMapsKey; } $ExhibitScriptSrc1 .= '"></script>'; $ExhibitScriptSrc2 = '<script type="text/javascript" src="' . $srfgScriptPath . '/Exhibit/SRF_Exhibit.js"></script>'; $CSSSrc = '<link rel="stylesheet" type="text/css" href="' . $srfgScriptPath . '/Exhibit/SRF_Exhibit.css"></link>'; SMWOutputs::requireHeadItem('CSS', $CSSSrc); // include CSS SMWOutputs::requireHeadItem('EXHIBIT1', $ExhibitScriptSrc1); // include Exhibit API SMWOutputs::requireHeadItem('EXHIBIT2', $ExhibitScriptSrc2); // includes javascript overwriting the Exhibit start-up functions SMWOutputs::requireHeadItem('SOURCES' . $smwgIQRunningNumber, $sourcesrc); // include sources variable SMWOutputs::requireHeadItem('VIEWSFACETS', $headervars); // include views and facets variable if (!$remote) { // print input table // print header if ('broadtable' == $this->mFormat) { $widthpara = ' width="100%"'; } else { $widthpara = ''; } $result = "<table style=\"display:none\" class=\"smwtable\" id=\"querytable" . $smwgIQRunningNumber . "\">\n"; if ($this->mShowHeaders) { // building headers $result .= "\t<tr>\n"; foreach ($res->getPrintRequests() as $pr) { if ($pr->getText($outputmode, $this->getLinker(0)) == '') { $headerlabel = "Name"; } else { $headerlabel = $pr->getText($outputmode, $this->getLinker(0)); } $result .= "\t\t<th>" . $headerlabel . "</th>\n"; } $result .= "\t</tr>\n"; } // print all result rows while ($row = $res->getNext()) { $result .= "\t<tr>\n"; foreach ($row as $field) { $result .= "\t\t<td>"; $textstack = array(); while (($object = $field->getNextDataValue()) !== false) { switch ($object->getTypeID()) { case '_wpg': $textstack[] = $object->getLongText($outputmode, $this->getLinker(0)); break; case '_geo': $c = $object->getDBKeys(); $textstack[] = $c[0] . "," . $c[1]; break; case '_num': if (method_exists($object, 'getValueKey')) { $textstack[] = $object->getValueKey($outputmode, $this->getLinker(0)); } else { $textstack[] = $object->getNumericValue($outputmode, $this->getLinker(0)); } break; case '_dat': $textstack[] = $object->getYear() . "-" . str_pad($object->getMonth(), 2, '0', STR_PAD_LEFT) . "-" . str_pad($object->getDay(), 2, '0', STR_PAD_LEFT) . " " . $object->getTimeString(); break; case '_ema': $textstack[] = $object->getShortWikiText($this->getLinker(0)); break; case '_tel': case '_anu': case '_uri': $textstack[] = $object->getWikiValue(); break; case '__sin': $tmp = $object->getShortText($outputmode, null); if (strpos($tmp, ":")) { $tmp = explode(":", $tmp, 2); $tmp = $tmp[1]; } $textstack[] = $tmp; break; case '_txt': case '_cod': case '_str': $textstack[] = $object->getWikiValue(); break; default: $textstack[] = $object->getLongHTMLText($this->getLinker(0)); } } if ($textstack != null) { $result .= implode(';', $textstack) . "</td>\n"; } else { $result .= "</td>\n"; } } $result .= "\t</tr>\n"; } $result .= "</table>\n"; } if (SRFExhibit::$exhibitRunningNumber == 0) { $result .= "<div id=\"exhibitLocation\"></div>"; } // print placeholder (just print it one time) $this->isHTML = $outputmode == SMW_OUTPUT_HTML; // yes, our code can be viewed as HTML if requested, no more parsing needed SRFExhibit::$exhibitRunningNumber++; return $result; }
protected function getResultText(SMWQueryResult $res, $outputmode) { global $smwgIQRunningNumber, $wgSitename, $wgServer, $smwgRSSEnabled, $wgRequest; $result = ''; if ($outputmode == SMW_OUTPUT_FILE) { // make RSS feed if (!$smwgRSSEnabled) { return ''; } if ($this->m_title === '') { $this->m_title = $wgSitename; } if ($this->m_description === '') { $this->m_description = wfMsg('smw_rss_description', $wgSitename); } // cast printouts into "items" $items = array(); $row = $res->getNext(); while ($row !== false) { $creators = array(); $dates = array(); $wikipage = $row[0]->getNextDataValue(); // get the object foreach ($row as $field) { // for now we ignore everything but creator and date, later we may // add more things like geolocs, categories, and even a generic // mechanism to add whatever you want :) $req = $field->getPrintRequest(); if (strtolower($req->getLabel()) == 'creator') { while ($entry = $field->getNextDataValue()) { $creators[] = $entry->getShortWikiText(); } } elseif (strtolower($req->getLabel()) == 'date' && $req->getTypeID() == '_dat') { while ($entry = $field->getNextDataValue()) { $dates[] = $entry->getXMLSchemaDate(); } } } if ($wikipage instanceof SMWWikiPageValue) { // this should rarely fail, but better be carful ///TODO: It would be more elegant to have type chekcs initially $items[] = new SMWRSSItem($wikipage->getTitle(), $creators, $dates); } $row = $res->getNext(); } $result .= '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $result .= "<rdf:RDF\n"; $result .= "\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; $result .= "\txmlns:content=\"http://purl.org/rss/1.0/modules/content/\"\n"; $result .= "\txmlns:admin=\"http://webns.net/mvcb/\"\n"; $result .= "\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"; $result .= "\txmlns=\"http://purl.org/rss/1.0/\">\n"; $result .= "\t<channel rdf:about=\"" . str_replace('&', '&', $wgRequest->getFullRequestURL()) . "\">\n"; $result .= "\t\t<admin:generatorAgent rdf:resource=\"http://semantic-mediawiki.org/wiki/Special:URIResolver/Semantic_MediaWiki\"/>\n"; $result .= "\t\t<title>" . smwfXMLContentEncode($this->m_title) . "</title>\n"; $result .= "\t\t<link>{$wgServer}</link>\n"; $result .= "\t\t<description>" . smwfXMLContentEncode($this->m_description) . "</description>\n"; if (count($items) > 0) { $result .= "\t\t<items>\n"; $result .= "\t\t\t<rdf:Seq>\n"; foreach ($items as $item) { $result .= "\t\t\t\t<rdf:li rdf:resource=\"" . $item->uri() . "\"/>\n"; } $result .= "\t\t\t</rdf:Seq>\n"; $result .= "\t\t</items>\n"; } $result .= "\t</channel>\n"; foreach ($items as $item) { $result .= $item->text(); } $result .= '</rdf:RDF>'; } else { // just make link to feed if ($this->getSearchLabel($outputmode)) { $label = $this->getSearchLabel($outputmode); } else { $label = wfMsgForContent('smw_rss_link'); } $link = $res->getQueryLink($label); $link->setParameter('rss', 'format'); if ($this->m_title !== '') { $link->setParameter($this->m_title, 'title'); } if ($this->m_description !== '') { $link->setParameter($this->m_description, 'description'); } if (array_key_exists('limit', $this->m_params)) { $link->setParameter($this->m_params['limit'], 'limit'); } else { // use a reasonable deafult limit (10 is suggested by RSS) $link->setParameter(10, 'limit'); } foreach ($res->getPrintRequests() as $printout) { // overwrite given "sort" parameter with printout of label "date" if ($printout->getMode() == SMWPrintRequest::PRINT_PROP && strtolower($printout->getLabel()) == "date" && $printout->getTypeID() == "_dat") { $link->setParameter($printout->getData()->getWikiValue(), 'sort'); } } $result .= $link->getText($outputmode, $this->mLinker); $this->isHTML = $outputmode == SMW_OUTPUT_HTML; // yes, our code can be viewed as HTML if requested, no more parsing needed SMWOutputs::requireHeadItem('rss' . $smwgIQRunningNumber, '<link rel="alternate" type="application/rss+xml" title="' . $this->m_title . '" href="' . $link->getURL() . '" />'); } return $result; }
/** * 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); }
/** * 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)); }
/** * @see SMWDataValue::getLongWikiText * * @since 0.6 */ public function getLongWikiText($linked = null) { if ($this->isValid()) { SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP); // TODO: fix lang keys so they include the space and coordinates. $coordinateSet = $this->m_dataitem->getCoordinateSet(); global $smgQPCoodFormat, $smgQPCoodDirectional; $text = MapsCoordinateParser::formatCoordinates($coordinateSet, $smgQPCoodFormat, $smgQPCoodDirectional); $lines = array(htmlspecialchars(wfMsgExt('semanticmaps-latitude', 'content', $coordinateSet['lat'])), htmlspecialchars(wfMsgExt('semanticmaps-longitude', 'content', $coordinateSet['lon']))); if (array_key_exists('alt', $coordinateSet)) { $lines[] = htmlspecialchars(wfMsgForContent('semanticmaps-altitude', 'content', $coordinateSet['alt'])); } return '<span class="smwttinline">' . htmlspecialchars($text) . '<span class="smwttcontent">' . implode('<br />', $lines) . '</span></span>'; } else { return $this->getErrorText(); } }
/** * 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']; } }
/** * 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); }
/** * @see SMWDataValue::getLongWikiText * * @since 0.6 */ public function getLongWikiText($linked = null) { if ($this->isValid()) { SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP); // TODO: fix lang keys so they include the space and coordinates. $coordinateSet = $this->m_dataitem->getCoordinateSet(); $text = $this->getFormattedCoord($this->m_dataitem); $lines = array(wfMessage('semanticmaps-latitude', $coordinateSet['lat'])->inContentLanguage()->escaped(), wfMessage('semanticmaps-longitude', $coordinateSet['lon'])->inContentLanguage()->escaped()); if (array_key_exists('alt', $coordinateSet)) { $lines[] = wfMessage('semanticmaps-altitude', $coordinateSet['alt'])->inContentLanguage()->escaped(); } return '<span class="smwttinline">' . htmlspecialchars($text) . '<span class="smwttcontent">' . implode('<br />', $lines) . '</span></span>'; } else { return $this->getErrorText(); } }
/** * Includes the necessary Javascript and CSS files for the form * to display and work correctly. * * Accepts an optional Parser instance, or uses $wgOut if omitted. */ public static function addJavascriptAndCSS( $parser = null ) { global $wgOut; if ( !$parser ) { $wgOut->addMeta( 'robots', 'noindex,nofollow' ); } self::addJavascriptFiles( $parser ); // MW 1.17 + if ( class_exists( 'ResourceLoader' ) ) { self::loadJavascriptAndCSS( $parser ); return; } global $sfgScriptPath, $smwgScriptPath, $wgJsMimeType, $sfgUseFormEditPage; global $smwgJQueryIncluded, $smwgJQUIAutoIncluded; // jQuery and jQuery UI are used so often in forms, we might as // well assume they'll always be used, and include them in // every form $smwgJQueryIncluded = true; $smwgJQUIAutoIncluded = true; $css_files = array( "$smwgScriptPath/skins/SMW_custom.css", "$sfgScriptPath/skins/jquery-ui/base/jquery.ui.all.css", "$sfgScriptPath/skins/SemanticForms.css", "$sfgScriptPath/skins/SF_submit.css", "$sfgScriptPath/skins/jquery.fancybox.css" ); foreach ( $css_files as $css_file ) { $link = array( 'rel' => 'stylesheet', 'type' => 'text/css', 'media' => "screen", 'href' => $css_file ); if ( !is_null( $parser ) ) { $parser->getOutput()->addHeadItem( Html::element( 'link', $link ) ); } else { $wgOut->addLink( $link ); } } $scripts = array(); if ( !$sfgUseFormEditPage ) $scripts[] = "$sfgScriptPath/libs/SF_ajax_form_preview.js"; $realFunction = array( 'SMWOutputs', 'requireHeadItem' ); if ( is_callable( $realFunction ) ) { SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP ); SMWOutputs::requireHeadItem( SMW_HEADER_SORTTABLE ); // TODO - should this be called directly here, or is // there a "smarter" (in some way) place to put it? SMWOutputs::commitToOutputPage( $wgOut ); } else { $scripts[] = "$smwgScriptPath/skins/SMW_tooltip.js"; $scripts[] = "$smwgScriptPath/skins/SMW_sorttable.js"; } $realFunction = array( 'OutputPage', 'includeJQuery' ); if ( is_callable( $realFunction ) ) { $wgOut->includeJQuery(); } else { $scripts[] = "$sfgScriptPath/libs/jquery-1.4.2.min.js"; } $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.core.min.js"; $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.widget.min.js"; $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.button.min.js"; $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.position.min.js"; $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.autocomplete.min.js"; $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.mouse.min.js"; $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.sortable.min.js"; $scripts[] = "$sfgScriptPath/libs/jquery.fancybox.js"; $scripts[] = "$sfgScriptPath/libs/SF_imagePreview.js"; $scripts[] = "$sfgScriptPath/libs/SF_autogrow.js"; $scripts[] = "$sfgScriptPath/libs/SF_submit.js"; $scripts[] = "$sfgScriptPath/libs/SemanticForms.js"; global $wgOut; foreach ( $scripts as $js ) { if ( $parser ) { $script = "<script type=\"$wgJsMimeType\" src=\"$js\"></script>\n"; $parser->getOutput()->addHeadItem( $script ); } else { $wgOut->addScriptFile( $js ); } } }