/** * Returns an SMWInfolink object with the QueryResults print requests as parameters. * * @since 1.8 * * @return SMWInfolink */ public function getLink() { $params = array(trim($this->mQuery->getQueryString())); foreach ($this->mQuery->getExtraPrintouts() as $printout) { $serialization = $printout->getSerialisation(); // TODO: this is a hack to get rid of the mainlabel param in case it was automatically added // by SMWQueryProcessor::addThisPrintout. Should be done nicer when this link creation gets redone. if ($serialization !== '?#') { $params[] = $serialization; } } // Note: the initial : prevents SMW from reparsing :: in the query string. return SMWInfolink::newInternalLink('', ':Special:Ask', false, $params); }
/** * Create an SMWInfolink object representing a link to further query results. * This link can then be serialised or extended by further params first. * The optional $caption can be used to set the caption of the link (though this * can also be changed afterwards with SMWInfolink::setCaption()). If empty, the * message 'smw_iq_moreresults' is used as a caption. * * TODO: have this work for all params without manually overriding and adding everything * (this is possible since the param handling changes in 1.7) * * @param string|false $caption * * @return SMWInfolink */ public function getQueryLink($caption = false) { $params = array(trim($this->mQuery->getQueryString())); foreach ($this->mQuery->getExtraPrintouts() as $printout) { $serialization = $printout->getSerialisation(); // TODO: this is a hack to get rid of the mainlabel param in case it was automatically added // by SMWQueryProcessor::addThisPrintout. Should be done nicer when this link creation gets redone. if ($serialization !== '?#') { $params[] = $serialization; } } if ($this->mQuery->getMainLabel() !== false) { $params['mainlabel'] = $this->mQuery->getMainLabel(); } $params['offset'] = $this->mQuery->getOffset() + count($this->mResults); if ($params['offset'] === 0) { unset($params['offset']); } if ($this->mQuery->getLimit() > 0) { $params['limit'] = $this->mQuery->getLimit(); } if (count($this->mQuery->sortkeys) > 0) { $order = implode(',', $this->mQuery->sortkeys); $sort = implode(',', array_keys($this->mQuery->sortkeys)); if ($sort !== '' || $order != 'ASC') { $params['order'] = $order; $params['sort'] = $sort; } } if ($caption == false) { $caption = ' ' . wfMsgForContent('smw_iq_moreresults'); // The space is right here, not in the QPs! } // Note: the initial : prevents SMW from reparsing :: in the query string. $result = SMWInfolink::newInternalLink($caption, ':Special:Ask', false, $params); return $result; }
/** * Serializes parameters and extraprintouts of SMWQuery. * These informations are needed to generate a correct SPARQL query. * * @param SMWQuery $query * @return string */ protected function serializeParams($query) { $result = ""; $first = true; foreach ($query->getExtraPrintouts() as $printout) { if (!$first) { $result .= "|"; } if ($printout->getData() == NULL) { $result .= "?=" . $printout->getLabel(); } else { if ($printout->getData() instanceof Title) { $outputFormat = $printout->getOutputFormat() !== NULL ? "#" . $printout->getOutputFormat() : ""; $result .= "?" . $printout->getData()->getDBkey() . $outputFormat . "=" . $printout->getLabel(); } else { if ($printout->getData() instanceof SMWPropertyValue) { $outputFormat = $printout->getOutputFormat() !== NULL ? "#" . $printout->getOutputFormat() : ""; $result .= "?" . array_shift($printout->getData()->getDBkeys()) . $outputFormat . "=" . $printout->getLabel(); } } } $first = false; } if ($query->getLimit() != NULL) { if (!$first) { $result .= "|"; } $result .= "limit=" . $query->getLimit(); $first = false; } if ($query->getOffset() != NULL) { if (!$first) { $result .= "|"; } $result .= "offset=" . $query->getOffset(); $first = false; } if ($query->sort) { if (!$first) { $result .= "|"; } $first = false; $sort = "sort="; $order = "order="; $firstsort = true; foreach ($query->sortkeys as $sortkey => $orderkey) { if (!$firstsort) { $sort .= ","; $order .= ","; } $sort .= $sortkey; $order .= $orderkey; $firstsort = false; } $result .= $sort . "|" . $order; } if ($query->mergeResults === false) { if (!$first) { $result .= "|"; } $result .= 'merge=false'; $first = false; } if (isset($query->params) && isset($query->params['dataspace'])) { if (!$first) { $result .= "|"; } $result .= 'dataspace=' . trim($query->params['dataspace']); $first = false; } return $result; }