本文整理汇总了PHP中SMWQueryProcessor类的典型用法代码示例。如果您正苦于以下问题:PHP SMWQueryProcessor类的具体用法?PHP SMWQueryProcessor怎么用?PHP SMWQueryProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMWQueryProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$params = $this->extractRequestParams();
$rawParams = preg_split("/(?<=[^\\|])\\|(?=[^\\|])/", $params['query']);
list($queryString, $this->parameters, $printouts) = SMWQueryProcessor::getComponentsFromFunctionParams($rawParams, false);
$queryResult = $this->getQueryResult($this->getQuery($queryString, $printouts));
$this->addQueryResult($queryResult);
}
示例2: doManipulation
/**
* @see ItemParameterManipulation::doManipulation
*
* @since 1.6.2
*/
public function doManipulation(&$value, Parameter $parameter, array &$parameters)
{
// Make sure the format value is valid.
$value = self::getValidFormatName($value);
// Add the formats parameters to the parameter list.
$queryPrinter = SMWQueryProcessor::getResultPrinter($value);
$parameters = array_merge($parameters, $queryPrinter->getValidatorParameters());
}
示例3: execute
public function execute()
{
$params = $this->extractRequestParams();
// TODO: this prevents doing [[Category:Foo||bar||baz]], must document.
$rawParams = explode('|', $params['query']);
$queryString = '';
$printouts = array();
SMWQueryProcessor::processFunctionParams($rawParams, $queryString, $this->parameters, $printouts);
$queryResult = $this->getQueryResult($this->getQuery($queryString, $printouts));
$this->addQueryResult($queryResult);
}
示例4: execute
public function execute()
{
$params = $this->extractRequestParams();
$this->requireParameters($params, array('query'));
$rawParams = explode('|', $params['query']);
$queryString = '';
$printouts = array();
SMWQueryProcessor::processFunctionParams($rawParams, $queryString, $this->parameters, $printouts);
$queryResult = $this->getQueryResult($this->getQuery($queryString, $printouts));
$this->addQueryResult($queryResult);
}
示例5: getQuery
/**
*
* @return SMWQuery
*/
protected function getQuery( $queryString, array $printouts ) {
SMWQueryProcessor::addThisPrintout( $printouts, $this->parameters );
return SMWQueryProcessor::createQuery(
$queryString,
SMWQueryProcessor::getProcessedParams( $this->parameters, $printouts ),
SMWQueryProcessor::SPECIAL_PAGE,
'',
$printouts
);
}
示例6: testExcelQueryPrinter
function testExcelQueryPrinter()
{
$params = array();
$context = SMWQueryProcessor::INLINE_QUERY;
$format = "exceltable";
$extraprintouts = array();
$querystring = "[[Category:Car]]";
$query = SMWQueryProcessor::createQuery($querystring, $params, $context, $format, $extraprintouts);
$res = smwfGetStore()->getQueryResult($query);
$result = SMWQueryProcessor::getResultFromQuery($query, $params, $extraprintouts, SMW_OUTPUT_FILE, $context, $format);
$this->assertFileContentsIgnoringWhitespaces("testcases/resources/excel_qp_result.dat", $result);
}
示例7: showFormatOptions
/**
* Display a form section showing the options for a given format,
* based on the getParameters() value for that format's query printer.
*
* @since 1.8
*
* @param string $format
* @param array $paramValues The current values for the parameters (name => value)
*
* @return string
*/
protected function showFormatOptions($format, array $paramValues)
{
$definitions = SMWQueryProcessor::getFormatParameters($format);
$optionsHtml = array();
/**
* @var ParamProcessor\ParamDefinition $definition
*/
foreach ($definitions as $name => $definition) {
// Ignore the format parameter, as we got a special control in the GUI for it already.
if ($name == 'format') {
continue;
}
// Maybe there is a better way but somehow I couldn't find one therefore
// 'source' display will be omitted where no alternative source was found or
// a source that was marked as default but had no other available options
$allowedValues = $definition->getAllowedValues();
if ($name == 'source' && (count($allowedValues) == 0 || in_array('default', $allowedValues) && count($allowedValues) < 2)) {
continue;
}
$currentValue = array_key_exists($name, $paramValues) ? $paramValues[$name] : false;
$dataInfo = $definition->getMessage() !== null ? $this->msg($definition->getMessage())->text() : '';
$optionsHtml[] = '<td>' . Html::rawElement('span', array('class' => $this->isTooltipDisplay() == true ? 'smw-ask-info' : '', 'word-wrap' => 'break-word', 'data-info' => $dataInfo), htmlspecialchars($name) . ': ') . '</td>' . $this->showFormatOption($definition, $currentValue);
}
$i = 0;
$n = 0;
$rowHtml = '';
$resultHtml = '';
// Top info text for a collapsed option box
if ($this->isTooltipDisplay() == true) {
$resultHtml .= Html::element('div', array('style' => 'margin-bottom:10px;'), wfMessage('smw-ask-otheroptions-info')->text());
}
// Table
$resultHtml .= Html::openElement('table', array('class' => 'smw-ask-otheroptions', 'width' => '100%'));
$resultHtml .= Html::openElement('tbody');
while ($option = array_shift($optionsHtml)) {
$i++;
// Collect elements for a row
$rowHtml .= $option;
// Create table row
if ($i % 3 == 0) {
$resultHtml .= Html::rawElement('tr', array('style' => 'background: ' . ($i % 6 == 0 ? 'white' : '#eee')), $rowHtml);
$rowHtml = '';
$n++;
}
}
// Ensure left over elements are collected as well
$resultHtml .= Html::rawElement('tr', array('style' => 'background: ' . ($n % 2 == 0 ? '#eee' : 'white')), $rowHtml);
$resultHtml .= Html::closeElement('tbody');
$resultHtml .= Html::closeElement('table');
return $resultHtml;
}
示例8: render
/**
* Method for handling the ask concept function.
*
* @todo The possible use of this in an HTML or Specal page context needs to be revisited. The code mentions it, but can this actually happen?
* @todo The escaping of symbols in concept queries needs to be revisited.
*
* @since 1.5.3
*
* @param Parser $parser
*/
public static function render(Parser &$parser)
{
global $wgContLang, $wgTitle;
$title = $parser->getTitle();
$pconc = new SMWDIProperty('_CONC');
if ($title->getNamespace() != SMW_NS_CONCEPT) {
$result = smwfEncodeMessages(array(wfMsgForContent('smw_no_concept_namespace')));
SMWOutputs::commitToParser($parser);
return $result;
} elseif (count(SMWParseData::getSMWdata($parser)->getPropertyValues($pconc)) > 0) {
$result = smwfEncodeMessages(array(wfMsgForContent('smw_multiple_concepts')));
SMWOutputs::commitToParser($parser);
return $result;
}
// process input:
$params = func_get_args();
array_shift($params);
// We already know the $parser ...
// Use first parameter as concept (query) string.
$concept_input = str_replace(array('>', '<'), array('>', '<'), array_shift($params));
// second parameter, if any, might be a description
$concept_docu = array_shift($params);
// NOTE: the str_replace above is required in MediaWiki 1.11, but not in MediaWiki 1.14
$query = SMWQueryProcessor::createQuery($concept_input, SMWQueryProcessor::getProcessedParams(array('limit' => 20, 'format' => 'list')), SMWQueryProcessor::CONCEPT_DESC);
$concept_text = $query->getDescription()->getQueryString();
if (!is_null(SMWParseData::getSMWData($parser))) {
$diConcept = new SMWDIConcept($concept_text, $concept_docu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth());
SMWParseData::getSMWData($parser)->addPropertyObjectValue($pconc, $diConcept);
}
// display concept box:
$rdflink = SMWInfolink::newInternalLink(wfMsgForContent('smw_viewasrdf'), $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . $title->getPrefixedText(), 'rdflink');
SMWOutputs::requireResource('ext.smw.style');
// TODO: escape output, preferably via Html or Xml class.
$result = '<div class="smwfact"><span class="smwfactboxhead">' . wfMsgForContent('smw_concept_description', $title->getText()) . (count($query->getErrors()) > 0 ? ' ' . smwfEncodeMessages($query->getErrors()) : '') . '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<br />' . ($concept_docu ? "<p>{$concept_docu}</p>" : '') . '<pre>' . str_replace('[', '[', $concept_text) . "</pre>\n</div>";
if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
global $wgOut;
SMWOutputs::commitToOutputPage($wgOut);
} else {
SMWOutputs::commitToParser($parser);
}
return $result;
}
示例9: getSemanticInternalObjects
/**
*
* Retrieve all internal objects and their properties.
* @param String $pagename
* @param String $internalproperty
* @return an array. Each element is an associative array and represents an internal object.
*
* E.G: {{#ptest:Chross|Is a parameter in an application}}
*
*/
public static function getSemanticInternalObjects($pagename, $internalproperty, $namespace = NS_MAIN)
{
$params = array("[[{$internalproperty}::{$pagename}]]", "format=list", "link=none", "headers=hide", "sep=;", "limit=5000");
$result = SMWQueryProcessor::getResultFromFunctionParams($params, SMW_OUTPUT_WIKI);
$result = trim($result);
$sios = array();
if ($result) {
$sios = explode(";", $result);
}
$ret = array();
foreach ($sios as $sio) {
#remove namespace prefix.
$sio = preg_replace("/^[^:]+:/", "", $sio);
$sio = str_replace(" ", "_", $sio);
#remove fragment to -
#$sio=str_replace("#", "-23", $sio);
array_push($ret, self::loadSemanticProperties($sio, $namespace, true));
}
return $ret;
}
示例10: render
/**
* Method for handling the ask parser function.
*
* @since 1.5.3
*
* @param Parser $parser
*/
public static function render(Parser &$parser)
{
global $smwgQEnabled, $smwgIQRunningNumber, $wgTitle;
if ($smwgQEnabled) {
$smwgIQRunningNumber++;
$params = func_get_args();
array_shift($params);
// We already know the $parser ...
$result = SMWQueryProcessor::getResultFromFunctionParams($params, SMW_OUTPUT_WIKI);
} else {
$result = smwfEncodeMessages(array(wfMessage('smw_iq_disabled')->inContentLanguage()->text()));
}
if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
global $wgOut;
SMWOutputs::commitToOutputPage($wgOut);
} else {
SMWOutputs::commitToParser($parser);
}
return $result;
}
示例11: execute
function execute($p)
{
global $wgOut, $wgRequest, $smwgQEnabled, $smwgRSSEnabled, $smwgMW_1_14;
wfProfileIn('doSpecialAskTSC (SMWHalo)');
$this->extractQueryParameters($p);
$format = $this->getResultFormat($this->m_params);
$query = SMWSPARQLQueryProcessor::createQuery($this->m_querystring, $this->m_params, SMWQueryProcessor::SPECIAL_PAGE, $format, $this->m_printouts);
$res = smwfGetStore()->getQueryResult($query);
$printer = SMWQueryProcessor::getResultPrinter($format, SMWQueryProcessor::SPECIAL_PAGE, $res);
$result_mime = $printer->getMimeType($res);
if ($result_mime == false) {
if ($res->getCount() > 0) {
$result = '<div style="text-align: center;">';
$result .= '</div>' . $printer->getResult($res, $this->m_params, SMW_OUTPUT_HTML);
$result .= '<div style="text-align: center;"></div>';
} else {
$result = '<div style="text-align: center;">' . wfMsg('smw_result_noresults') . '</div>';
}
} else {
// make a stand-alone file
$result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_FILE);
$result_name = $printer->getFileName($res);
// only fetch that after initialising the parameters
}
if ($result_mime == false) {
if ($this->m_querystring) {
$wgOut->setHTMLtitle($this->m_querystring);
} else {
$wgOut->setHTMLtitle(wfMsg('ask'));
}
$wgOut->addHTML($result);
} else {
$wgOut->disable();
header("Content-type: {$result_mime}; charset=UTF-8");
if ($result_name !== false) {
header("Content-Disposition: attachment; filename={$result_name}");
}
print $result;
}
wfProfileOut('doSpecialAskTSC (SMWHalo)');
}
示例12: render
/**
* Method for handling the show parser function.
*
* @since 1.5.3
*
* @param Parser $parser
*/
public static function render(Parser &$parser)
{
global $smwgQEnabled, $smwgIQRunningNumber, $wgTitle;
if ($smwgQEnabled) {
$smwgIQRunningNumber++;
$rawParams = func_get_args();
array_shift($rawParams);
// We already know the $parser ...
list($query, $params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, true);
$result = SMWQueryProcessor::getResultFromQuery($query, $params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY);
$queryKey = hash('md4', implode('|', $rawParams), false);
SMWAsk::addQueryData($queryKey, $query, $params, $parser);
} else {
$result = smwfEncodeMessages(array(wfMessage('smw_iq_disabled')->inContentLanguage()->text()));
}
if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
global $wgOut;
SMWOutputs::commitToOutputPage($wgOut);
} else {
SMWOutputs::commitToParser($parser);
}
return $result;
}
示例13: get_ask_feed
function get_ask_feed() {
global $wgSitename, $wgTitle, $wgRequest;
// check for semantic wiki:
if ( !defined( 'SMW_VERSION' ) ) {
return false;
}
// bootstrap off of SMWAskPage:
$SMWAskPage = new SMWAskPage();
$SMWAskPage->extractQueryParameters( $wgRequest->getVal( 'q' ) );
// print 'query string: ' . $SMWAskPage->m_querystring . "\n<br />";
// print 'm_params: ' . print_r($SMWAskPage->m_params) . "\n<br />";
// print 'print outs: ' .print_r($SMWAskPage->m_printouts) . "\n<br />";
// set up the feed:
$this->feed = new mvRSSFeed(
$wgSitename . ' - ' . wfMsg( 'mediasearch' ) . ' : ' . strip_tags( $SMWAskPage->m_querystring ), // title
strip_tags( $SMWAskPage->m_querystring ), // description
$wgTitle->getFullUrl() // link
);
$this->feed->outHeader();
$queryobj = SMWQueryProcessor::createQuery( $SMWAskPage->m_querystring, $SMWAskPage->m_params, false, '', $SMWAskPage->m_printouts );
$res = smwfGetStore()->getQueryResult( $queryobj );
$row = $res->getNext();
while ( $row !== false ) {
$wikititle = $row[0]->getNextObject();
$this->feed->outPutItem( $wikititle->getTitle() );
$row = $res->getNext();
}
$this->feed->outFooter();
}
示例14: getAnnotations
function getAnnotations($annotatedImage)
{
global $wgExtensionCredits;
$new = false;
foreach ($wgExtensionCredits['semantic'] as $elem) {
if ($elem['name'] == 'Semantic MediaWiki') {
$vers = $elem['version'];
$new = version_compare($vers, '1.7', '>=');
}
}
$returnString = '{"shapes":[';
$queryString = '[[SIAannotatedImage::' . $annotatedImage . ']]';
$params = array();
$params['link'] = 'none';
$params['mainlabel'] = 'result';
#$params = ['order'];
#$params = ['sort'];
if ($new) {
$params['order'] = array('asc');
$params['sort'] = array('SIAannotatedImage');
} else {
$params['order'] = 'asc';
$params['sort'] = 'SIAannotatedImage';
}
//Generate all the extra printouts, eg all properties to retrieve:
$printmode = SMWPrintRequest::PRINT_PROP;
$customPrintouts = array('coordinates' => 'SIArectangleCoordinates', 'text' => 'ImageAnnotationText');
$extraprintouts = array();
foreach ($customPrintouts as $label => $property) {
$extraprintouts[] = new SMWPrintRequest($printmode, $label, SMWPropertyValue::makeUserProperty($property));
}
$format = 'table';
$context = SMWQueryProcessor::INLINE_QUERY;
$query = SMWQueryProcessor::createQuery($queryString, $params, $context, $format, $extraprintouts);
$store = smwfGetStore();
// default store
$res = $store->getQueryResult($query);
$shapeCounter = 0;
while (($resArrayArray = $res->getNext()) != false) {
//Array of SMWResultArray Objects, eg. all retrieved Pages
$shapeCounter++;
if ($shapeCounter > 1) {
$returnString .= ',';
}
$returnString .= '{';
foreach ($resArrayArray as $resArray) {
//SMWResultArray-Object, column of resulttable (pagename or propertyvalue)
$currentPrintRequestLabel = $resArray->getPrintRequest()->getLabel();
//The label as defined in the above array
if ($currentPrintRequestLabel == 'coordinates') {
$currentResultPage = $resArray->getResultSubject();
$currentID = $currentResultPage->getTitle()->getFullText();
$currentCoords = $resArray->getNextDataItem()->getSerialization();
$returnString .= '"coords":"' . $currentCoords . '","id":"' . $currentID . '"';
}
}
$returnString .= '}';
}
$returnString .= ']}';
return $returnString;
}
示例15: getResultText
/**
* This method renders the result set provided by SMW according to the printer
*
* @param res SMWQueryResult, result set of the ask query provided by SMW
* @param outputmode ?
* @return String, rendered HTML output of this printer for the ask-query
*
*/
protected function getResultText($res, $outputmode)
{
global $wgContLang;
// content language object
$result = '';
$m_outlineLevel = 0;
$hasChildren = array();
$m_outlineLevel++;
$m_seedCategory = "";
$m_seedName = "";
$m_categories = $this->m_projectmanagementclass->getCategories();
$m_properties = $this->m_projectmanagementclass->getProperties();
if ($outputmode == SMW_OUTPUT_FILE) {
$queryparts = preg_split("/]]/", $res->getQueryString());
$taskname = str_replace("[[", "", $queryparts[0]);
if (strpos($taskname, "Category:") === false) {
//case: [[{{PAGENAME}}]]
if ($res->getCount() == 1) {
$m_seedName = trim(str_replace("[[", "", str_replace("]]", "", $res->getQueryString())));
$firstQuery = smwfGetStore()->getQueryResult(SMWQueryProcessor::createQuery('[[' . $m_seedName . ']]', array(), SMWQueryProcessor::INLINE_QUERY, '', $res->getPrintRequests()));
//$firstQuery = smwfGetStore()->getQueryResult(SMWQueryProcessor::createQuery('[[Part of::'.$m_seedName.']]',array(),SMWQueryProcessor::INLINE_QUERY,'',$res->getPrintRequests()));
} else {
return "<html><body>ERROR: Query: " . $res->getQueryString() . "is invalid! Valid formats: [[Category:SampleCategory]] or: [[{{PAGENAME}}]]</body></html>";
}
} else {
$m_seedCategory = trim(str_replace("Category:", "", $taskname));
if (in_array($m_seedCategory, $m_categories)) {
$firstQuery = smwfGetStore()->getQueryResult(SMWQueryProcessor::createQuery('[[Category:' . $m_seedCategory . ']]', array(), SMWQueryProcessor::INLINE_QUERY, '', $res->getPrintRequests()));
} else {
return "<html><body>ERROR: Category: " . $m_seedCategory . " has not been defined on Special:SemanticProjectManagement </body></html>";
}
}
$this->m_projectmanagementclass->setName("ProjectManagementClass");
// echo "First Query: ".$firstQuery->getQueryString()."<br/>";
//generate seed task
$task = $this->m_projectmanagementclass->makeTask("seed", 0);
$task->addWBS(0, 0);
$task->setUid(0);
$hasChildren = $this->m_projectmanagementclass->getTaskResults($firstQuery, $outputmode, $m_outlineLevel, $task);
$processedChildren = array();
$hasChild = true;
while ($hasChild) {
$hasChild = false;
$allTempChildren = array();
$m_outlineLevel++;
foreach ($hasChildren as $child) {
if (in_array($child, $processedChildren)) {
} else {
if (isset($m_properties[$child->getLevel()]) && isset($m_categories[$child->getLevel()])) {
//build new Query
if ($child->getLevel() != 0) {
$res2 = smwfGetStore()->getQueryResult(SMWQueryProcessor::createQuery('[[Category:' . $m_categories[$child->getLevel()] . ']] [[' . $m_properties[$child->getLevel()] . '::' . $child->getPage() . ']]', array(), SMWQueryProcessor::INLINE_QUERY, '', $res->getPrintRequests()));
} else {
if (isset($m_properties[1])) {
$res2 = smwfGetStore()->getQueryResult(SMWQueryProcessor::createQuery('[[Category:' . $m_categories[0] . ']] [[' . $m_properties[1] . '::' . $child->getPage() . ']]', array(), SMWQueryProcessor::INLINE_QUERY, '', $res->getPrintRequests()));
} else {
$res2 = smwfGetStore()->getQueryResult(SMWQueryProcessor::createQuery('[[' . $child->getPage() . ']]', array(), SMWQueryProcessor::INLINE_QUERY, '', $res->getPrintRequests()));
}
}
// echo "Next Query: ".$res2->getQueryString()." Level: ".$m_outlineLevel."<br/>";
$queryresults = $this->m_projectmanagementclass->getTaskResults($res2, $outputmode, $m_outlineLevel, $child);
$processedChildren[] = $child;
foreach ($queryresults as $temp) {
$allTempChildren[] = $temp;
}
}
}
}
$hasChildren = $allTempChildren;
if (count($hasChildren) > 0) {
$hasChild = true;
}
}
$task->addWBS(1, 0);
$result .= $this->m_projectmanagementclass->getXML();
} else {
// just make xml file
if ($this->getSearchLabel($outputmode)) {
$label = $this->getSearchLabel($outputmode);
} else {
$label = wfMsgForContent('spm_wbs_link');
}
$link = $res->getQueryLink($label);
$link->setParameter('wbs', 'format');
if ($this->getSearchLabel(SMW_OUTPUT_WIKI) != '') {
$link->setParameter($this->getSearchLabel(SMW_OUTPUT_WIKI), 'searchlabel');
}
if (array_key_exists('limit', $this->m_params)) {
$link->setParameter($this->m_params['limit'], 'limit');
} else {
// use a reasonable default limit
$link->setParameter(500, 'limit');
//.........这里部分代码省略.........