/** * @see SMWResultPrinter::buildResult * * @since 1.8 * * @param SMWQueryResult $results * * @return string */ protected function buildResult(SMWQueryResult $results) { // Intro/outro are not planned to work with the widget option if ($this->params['intro'] !== '' && $this->params['widget'] !== '') { return $results->addErrors(array(wfMessage('srf-error-option-mix', 'intro/widget')->inContentLanguage()->text())); } elseif ($this->params['outro'] !== '' && $this->params['widget'] !== '') { return $results->addErrors(array(wfMessage('srf-error-option-mix', 'outro/widget')->inContentLanguage()->text())); } return $this->getResultText($results, $this->outputMode); }
/** * Return serialised results in specified format * * @param SMWQueryResult $results * @param $outputmode * * @return string */ public function getResultText(SMWQueryResult $results, $outputmode) { // Check output conditions if ($this->params['widget'] == 'sphere' && $this->params['link'] !== 'all' && $this->params['template'] === '') { return $results->addErrors(array(wfMessage('srf-error-option-link-all', 'sphere')->inContentLanguage()->text())); } // Template support $this->hasTemplates = $this->params['template'] !== ''; // Prioritize HTML setting $this->isHTML = $this->params['widget'] !== ''; $this->isHTML = $this->params['template'] === ''; $outputmode = SMW_OUTPUT_HTML; // Sphere widget if ($this->params['widget'] === 'sphere') { SMWOutputs::requireResource('ext.srf.tagcloud.sphere'); } // Wordcloud widget if ($this->params['widget'] === 'wordcloud') { SMWOutputs::requireResource('ext.srf.tagcloud.wordcloud'); } return $this->getTagCloud($this->getTagSizes($this->getTags($results, $outputmode))); }
/** * Build an SMWQueryResult object from a SMWSparqlResultWrapper. This * function is used to generate instance query results, and the given * result wrapper must have an according format (one result column that * contains URIs of wiki pages). * * @param $sparqlResultWrapper SMWSparqlResultWrapper * @param $query SMWQuery, SMWQueryResults hold a reference to original query * @return SMWQueryResult */ protected function getQueryResultFromSparqlResult(SMWSparqlResultWrapper $sparqlResultWrapper, SMWQuery $query) { $resultDataItems = array(); foreach ($sparqlResultWrapper as $resultRow) { if (count($resultRow) > 0) { $dataItem = SMWExporter::findDataItemForExpElement($resultRow[0]); if (!is_null($dataItem)) { $resultDataItems[] = $dataItem; } } } if ($sparqlResultWrapper->numRows() > $query->getLimit()) { array_pop($resultDataItems); $hasFurtherResults = true; } else { $hasFurtherResults = false; } $result = new SMWQueryResult($query->getDescription()->getPrintrequests(), $query, $resultDataItems, $this->m_store, $hasFurtherResults); switch ($sparqlResultWrapper->getErrorCode()) { case SMWSparqlResultWrapper::ERROR_NOERROR: break; case SMWSparqlResultWrapper::ERROR_INCOMPLETE: $result->addErrors(array(wfMessage('smw_db_sparqlqueryincomplete')->inContentLanguage()->text())); break; default: $result->addErrors(array(wfMessage('smw_db_sparqlqueryproblem')->inContentLanguage()->text())); break; } return $result; }
protected function getResultText(SMWQueryResult $res, $outputmode) { if ($this->mFormat == 'template' && $this->mTemplate == false) { $res->addErrors(array(wfMessage('smw_notemplategiven')->inContentLanguage()->text())); return ''; } // Determine mark-up strings used around list items: if ($this->mFormat == 'ul' || $this->mFormat == 'ol') { $header = "<" . $this->mFormat . ">\n"; $footer = "</" . $this->mFormat . ">\n"; $rowstart = "\t<li>"; $rowend = "</li>\n"; $plainlist = false; } else { // "list" and "template" format $header = ''; $footer = ''; $rowstart = ''; $rowend = ''; $plainlist = true; } if ($this->mSep !== '') { // always respect custom separator $listsep = $this->mSep; $finallistsep = $listsep; } elseif ($this->mFormat == 'list') { // make default list ", , , and " // TODO: No default separator for "ul" and "ol" to not break // compatibility with SMW pre 1.7.1. But they really should have // default separators, i.e. the check should be for // $this->mFormat !== 'template' $listsep = ', '; $finallistsep = wfMessage('smw_finallistconjunct')->inContentLanguage()->text() . ' '; } else { // no default separators for format "template", "ul", "ol" $listsep = ''; $finallistsep = ''; } // Initialise more values $result = ''; $column_width = 0; $rows_per_column = -1; // usually unnecessary $rows_in_cur_column = -1; // Set up floating divs, if there's more than one column if ($this->mColumns > 1) { $column_width = floor(100 / $this->mColumns); $result .= '<div style="float: left; width: ' . $column_width . '%">' . "\n"; $rows_per_column = ceil($res->getCount() / $this->mColumns); $rows_in_cur_column = 0; } if ($header !== '') { $result .= $header; } if ($this->mIntroTemplate !== '') { $result .= "{{" . $this->mIntroTemplate . "}}"; } // Now print each row $rownum = -1; while ($row = $res->getNext()) { $this->printRow($row, $rownum, $rows_in_cur_column, $rows_per_column, $this->mFormat, $plainlist, $header, $footer, $rowstart, $rowend, $result, $column_width, $res, $listsep, $finallistsep); } if ($this->mOutroTemplate !== '') { $result .= "{{" . $this->mOutroTemplate . "}}"; } // Make label for finding further results if ($this->linkFurtherResults($res) && ($this->mFormat != 'ol' || $this->getSearchLabel(SMW_OUTPUT_WIKI))) { $this->showFurtherResults($result, $res, $rowstart, $rowend, $outputmode); } // Print footer if ($footer !== '') { $result .= $footer; } if ($this->mColumns > 1) { $result .= "</div>\n"; } if ($this->mColumns > 1) { $result .= '<br style="clear: both" />' . "\n"; } // Make sure that if the result set turns empty and if available display default if ($this->params['default'] !== '' && $result === '') { $result = $this->params['default']; } return $result; }
protected function getResultText( SMWQueryResult $res, $outputmode ) { if ( ( $this->mFormat == 'template' ) && ( $this->mTemplate == false ) ) { $res->addErrors( array( wfMsgForContent( 'smw_notemplategiven' ) ) ); return ''; } // Determine mark-up strings used around list items: if ( ( $this->mFormat == 'ul' ) || ( $this->mFormat == 'ol' ) ) { $header = "<" . $this->mFormat . ">\n"; $footer = "</" . $this->mFormat . ">\n"; $rowstart = "\t<li>"; $rowend = "</li>\n"; $plainlist = false; $finallistsep = ''; $listsep = ''; } else { // "list" and "template" format $header = ''; $footer = ''; $rowstart = ''; $rowend = ''; $plainlist = true; if ( $this->mSep !== '' ) { // always respect custom separator $listsep = $this->mSep; $finallistsep = $listsep; } elseif ( $this->mFormat == 'list' ) { // make default list ", , , and " $listsep = ', '; $finallistsep = wfMsgForContent( 'smw_finallistconjunct' ) . ' '; } else { // no default separators for format "template" $listsep = ''; $finallistsep = ''; } } // Initialise more values $result = ''; $column_width = 0; $rows_per_column = -1; // usually unnecessary $rows_in_cur_column = -1; // Set up floating divs, if there's more than one column if ( $this->mColumns > 1 ) { $column_width = floor( 100 / $this->mColumns ); $result .= '<div style="float: left; width: ' . $column_width . '%">' . "\n"; $rows_per_column = ceil( $res->getCount() / $this->mColumns ); $rows_in_cur_column = 0; } if ( $header !== '' ) { $result .= $header; } if ( $this->mIntroTemplate !== '' ) { $result .= "{{" . $this->mIntroTemplate . "}}"; } // Now print each row $rownum = -1; while ( $row = $res->getNext() ) { $this->printRow( $row, $rownum, $rows_in_cur_column, $rows_per_column, $this->mFormat, $plainlist, $header, $footer, $rowstart, $rowend, $result, $column_width, $res, $listsep, $finallistsep ); } if ( $this->mOutroTemplate !== '' ) { $result .= "{{" . $this->mOutroTemplate . "}}"; } // Make label for finding further results if ( $this->linkFurtherResults( $res ) && ( ( $this->mFormat != 'ol' ) || ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) ) ) ) { $this->showFurtherResults( $result, $res, $rowstart, $rowend ); } // Print footer if ( $footer !== '' ) { $result .= $footer; } if ( $this->mColumns > 1 ) { $result .= "</div>\n"; } if ( $this->mColumns > 1 ) { $result .= '<br style="clear: both" />' . "\n"; } return $result; }
/** * Return serialised results in specified format. */ protected function getResultText(SMWQueryResult $res, $outputmode) { if ($this->mTreeProp === null || $this->mTreeProp === '') { $res->addErrors(array(wfMessage('srf-noparentprop')->inContentLanguage()->text())); return ''; } $store = $res->getStore(); // first put everything in a list // elements appearing more than once will be inserted more than once, // but only one instance will be inserted with the hash // only this instance will be considered as a parent element in the tree $list = array(); while ($row = $res->getNext()) { $hash = $row[0]->getResultSubject()->getSerialization(); if (array_key_exists($hash, $list)) { $list[] = new SRFTreeElement($row); } else { $list[$hash] = new SRFTreeElement($row); } } // transfer the listelements into the tree // elements with more than one parent will be cloned for each parent $tree = array(); foreach ($list as $hash => $listElem) { $parents = $store->getPropertyValues($listElem->mRow[0]->getResultSubject(), SMWDIProperty::newFromUserLabel($this->mTreeProp)); // transfer element from list to tree foreach ($parents as $parent) { $parentPageHash = $parent->getSerialization(); if ($hash !== null) { if (array_key_exists($parentPageHash, $list)) { $listElem->mParent = $parentPageHash; } $tree[$hash] = $listElem; $hash = null; } else { $treeElem = clone $listElem; if (array_key_exists($parentPageHash, $list)) { $treeElem->mParent = $parentPageHash; } else { $treeElem->mParent = null; } $tree[] = $treeElem; } } } foreach ($tree as $hash => $value) { } // build pointers from parants to children foreach ($tree as $hash => $treeElem) { if ($treeElem->mParent != null) { $tree[$treeElem->mParent]->mChildren[] = $treeElem; } } // remove children from toplevel foreach ($tree as $hash => $treeElem) { if ($treeElem->mParent != null) { unset($tree[$hash]); } } $result = ''; $rownum = 0; foreach ($tree as $hash => $treeElem) { $this->printElement($result, $treeElem, $row); } return $result; }
/** * Build a feed * * @since 1.8 * * @param SMWQueryResult $results * @param $type * * @return string */ protected function getFeed(SMWQueryResult $results, $type) { global $wgFeedClasses; if (!isset($wgFeedClasses[$type])) { $results->addErrors(array(wfMessage('feed-invalid')->inContentLanguage()->text())); return ''; } // Get feed class instance /** * @var ChannelFeed $feed */ $feed = new $wgFeedClasses[$type]($this->feedTitle(), $this->feedDescription(), $this->feedURL()); // Create feed header $feed->outHeader(); // Create feed items while ($row = $results->getNext()) { $feed->outItem($this->feedItem($row)); } // Create feed footer $feed->outFooter(); return $feed; }
private function makeQueryResultForInstance(FederateResultSet $federateResultSet, Query $query) { $resultDataItems = array(); foreach ($federateResultSet as $resultRow) { if (count($resultRow) > 0) { $dataItem = Exporter::findDataItemForExpElement($resultRow[0]); if (!is_null($dataItem)) { $resultDataItems[] = $dataItem; } } } if ($federateResultSet->numRows() > $query->getLimit()) { array_pop($resultDataItems); $hasFurtherResults = true; } else { $hasFurtherResults = false; } $result = new QueryResult($query->getDescription()->getPrintrequests(), $query, $resultDataItems, $this->store, $hasFurtherResults); switch ($federateResultSet->getErrorCode()) { case FederateResultSet::ERROR_NOERROR: break; case FederateResultSet::ERROR_INCOMPLETE: $result->addErrors(array(wfMessage('smw_db_sparqlqueryincomplete')->inContentLanguage()->text())); break; default: $result->addErrors(array(wfMessage('smw_db_sparqlqueryproblem')->inContentLanguage()->text())); break; } return $result; }
/** * Return serialised results in specified format. */ protected function getResultText(SMWQueryResult $res, $outputmode) { if ($this->mTreeProp === '') { $res->addErrors(array(wfMessage('srf-noparentprop')->inContentLanguage()->text())); return ''; } $store = $res->getStore(); // put everything in a list and set parent hashes // elements appearing more than once will be inserted more than once and // elements with more than one parent will be cloned for each parent, // but only one instance will ever be inserted with the hash and // only this instance will later be considered as a parent element in the tree $tree = array(); while ($row = $res->getNext()) { $element = new SRFTreeElement($row); $hash = $row[0]->getResultSubject()->getSerialization(); if (array_key_exists($hash, $tree)) { $hash = null; } $parents = $store->getPropertyValues($element->mRow[0]->getResultSubject(), SMWDIProperty::newFromUserLabel($this->mTreeProp)); if (empty($parents)) { // no parents: copy into tree as root level item if ($hash !== null) { $tree[$hash] = $element; } else { $tree[] = $element; } } else { // one or more parents: copy one copy per parent into tree foreach ($parents as $parent) { if ($hash !== null) { $tree[$hash] = $element; $hash = null; } else { $element = clone $element; $tree[] = $element; } $element->mParent = $parent->getSerialization(); } } } $rootElements = array(); // build pointers from parents to children and remove pointers to parents that don't exist in the tree foreach ($tree as $hash => $element) { if ($element->mParent !== null) { if (array_key_exists($element->mParent, $tree)) { $tree[$element->mParent]->mChildren[] = $element; } else { $element->mParent = null; $rootElements[$hash] = $element; } } else { $rootElements[$hash] = $element; } } $result = ''; $rownum = 0; // if a specific page was specified as root element of the tree if ($this->mRoot !== '') { // get the title object of the root page $rootTitle = Title::newFromText($this->mRoot); if ($rootTitle === null) { $res->addErrors(array(wfMessage('srf-rootinvalid')->params($this->mRoot)->inContentLanguage()->text())); return ''; } $rootSerialization = SMWDIWikiPage::newFromTitle($rootTitle)->getSerialization(); // find the root page in the tree and print it and its subtree if (array_key_exists($rootSerialization, $tree)) { $this->printElement($result, $tree[$rootSerialization], $rownum, $this->mStartLevel); } } else { // iterate through all tree elements foreach ($rootElements as $hash => $element) { // print current root element and its subtree $this->printElement($result, $element, $rownum, $this->mStartLevel); } } return $result; }