private function doProcessQueryFor($query, $sep = ",") { $query = str_replace(array("<", ">", "sep=;"), array("<", ">", "sep={$sep};"), $query); $params = explode(";", $query); $f = str_replace(";", "|", $params[0]); $params[0] = $this->parser->replaceVariables($f); if ($this->debugFlag) { error_log(implode("|", $params)); } $values = $this->getFormattedValuesFrom($sep, QueryProcessor::getResultFromFunctionParams($params, SMW_OUTPUT_WIKI)); return json_encode(array("values" => $values, "count" => count($values))); }
/** * * 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; }
/** * 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; }
public function __construct(&$results, SMWPrintRequest $printRequest, SRFFiltered &$queryPrinter) { global $wgParser; parent::__construct($results, $printRequest, $queryPrinter); if (!defined('Maps_VERSION') || version_compare(Maps_VERSION, '1.0', '<')) { throw new FatalError('You need to have the <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a> extension version 1.0 or higher installed in order to use the distance filter.<br />'); } MapsGeocoders::init(); $params = $this->getActualParameters(); if (array_key_exists('distance filter origin', $params)) { $origin = MapsGeocoders::attemptToGeocode($wgParser->recursiveTagParse($params['distance filter origin'])); } else { $origin = array('lat' => '0', 'lon' => '0'); } if (array_key_exists('distance filter unit', $params)) { $this->mUnit = MapsDistanceParser::getValidUnit($wgParser->recursiveTagParse($params['distance filter unit'])); } else { $this->mUnit = MapsDistanceParser::getValidUnit(); } // Is the real position stored in a property? if (array_key_exists('distance filter property', $params)) { $property = trim($wgParser->recursiveTagParse($params['distance filter property'])); $locations = array(); } else { $property = null; $locations = null; } $targetLabel = $printRequest->getLabel(); foreach ($this->getQueryResults() as $id => $filteredItem) { $row = $filteredItem->getValue(); // $filteredItem is of class SRF_Filtered_Item // $row is an array of SMWResultArray foreach ($row as $field) { // $field is an SMWResultArray $label = $field->getPrintRequest()->getLabel(); if ($label === $targetLabel) { $field->reset(); $dataValue = $field->getNextDataValue(); // only use first value if ($dataValue !== false) { $posText = $dataValue->getShortText(SMW_OUTPUT_WIKI, false); if ($property === null) { // position is directly given $pos = MapsGeocoders::attemptToGeocode($posText); } else { // position is given in a property of a page // if we used this page before, just look up the coordinates if (array_key_exists($posText, $locations)) { $pos = $locations[$posText]; } else { // query the position's page for the coordinates or address $posText = SMWQueryProcessor::getResultFromFunctionParams(array($posText, '?' . $property), SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, true); // if ($posText !== '') { // geocode $pos = MapsGeocoders::attemptToGeocode($posText); } else { $pos = array('lat' => '0', 'lon' => '0'); } // store coordinates in case we need them again $locations[$posText] = $pos; } } if (is_array($pos)) { $distance = round(MapsGeoFunctions::calculateDistance($origin, $pos) / MapsDistanceParser::getUnitRatio($this->mUnit)); if ($distance > $this->mMaxDistance) { $this->mMaxDistance = $distance; } } else { $distance = -1; } } else { $distance = -1; // no location given } $filteredItem->setData('distance-filter', $distance); break; } } } if (array_key_exists('distance filter max distance', $params) && is_numeric($maxDist = trim($wgParser->recursiveTagParse($params['distance filter max distance'])))) { // this assignation ^^^ is ugly, but intentional $this->mMaxDistance = $maxDist; } else { if ($this->mMaxDistance > 1) { $base = pow(10, floor(log10($this->mMaxDistance))); $this->mMaxDistance = ceil($this->mMaxDistance / $base) * $base; } } }
public function select($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { global $wgScriptSelectCount, $sfgFieldNum, $wgUser; $selectField = array(); $values = null; $staticvalue = false; if (array_key_exists("query", $other_args)) { $query = $other_args["query"]; $query = str_replace(array("~", "(", ")"), array("=", "[", "]"), $query); $selectField["query"] = $query; if (strpos($query, '@@@@') === false) { $params = explode(";", $query); $params[0] = $this->parser->replaceVariables($params[0]); $values = QueryProcessor::getResultFromFunctionParams($params, SMW_OUTPUT_WIKI); $staticvalue = true; } } elseif (array_key_exists("function", $other_args)) { $query = $other_args["function"]; $query = '{{#' . $query . '}}'; $query = str_replace(array("~", "(", ")"), array("=", "[", "]"), $query); $selectField["function"] = $query; if (strpos($query, '@@@@') === false) { $f = str_replace(";", "|", $query); $values = $this->parser->replaceVariables($f); $staticvalue = true; } } $data = array(); if ($staticvalue) { $values = explode(",", $values); $values = array_map("trim", $values); $values = array_unique($values); } else { if ($wgScriptSelectCount == 0) { Output::addModule('ext.sf_select.scriptselect'); } $wgScriptSelectCount++; $data["selectismultiple"] = array_key_exists("part_of_multiple", $other_args); $index = strpos($input_name, "["); $data['selecttemplate'] = substr($input_name, 0, $index); // Does hit work for multiple template? $index = strrpos($input_name, "["); $data['selectfield'] = substr($input_name, $index + 1, strlen($input_name) - $index - 2); $valueField = array(); $data["valuetemplate"] = array_key_exists("sametemplate", $other_args) ? $data['selecttemplate'] : $other_args["template"]; $data["valuefield"] = $other_args["field"]; $data['selectrm'] = array_key_exists('rmdiv', $other_args); $data['label'] = array_key_exists('label', $other_args); $data['sep'] = array_key_exists('sep', $other_args) ? $other_args["sep"] : ','; if (array_key_exists("query", $selectField)) { $data['selectquery'] = $selectField['query']; } else { $data['selectfunction'] = $selectField['function']; } self::$data[] = $data; } $extraatt = ""; $is_list = false; // TODO This needs clean-up if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) { $is_list = true; } if ($is_list) { $extraatt = ' multiple="multiple" '; } if (array_key_exists("size", $other_args)) { $extraatt .= " size=\"{$other_args['size']}\""; } $classes = array(); if ($is_mandatory) { $classes[] = "mandatoryField"; } if (array_key_exists("class", $other_args)) { $classes[] = $other_args['class']; } if ($classes) { $cstr = implode(" ", $classes); $extraatt .= " class=\"{$cstr}\""; } $inname = $input_name; if ($is_list) { $inname .= '[]'; } // TODO Use Html:: $spanextra = $is_mandatory ? 'mandatoryFieldSpan' : ''; $ret = "<span class=\"inputSpan {$spanextra}\"><select name='{$inname}' id='input_{$sfgFieldNum}' {$extraatt}>"; $curvalues = null; if ($cur_value) { if ($cur_value === 'current user') { $cur_value = $wgUser->getName(); } if (is_array($cur_value)) { $curvalues = $cur_value; } else { $curvalues = array_map("trim", explode(",", $cur_value)); } } else { $curvalues = array(); } // TODO handle empty value case. $ret .= "<option></option>"; foreach ($curvalues as $cur) { $ret .= "<option selected='selected'>{$cur}</option>"; } if ($staticvalue) { foreach ($values as $val) { if (!in_array($val, $curvalues)) { $ret .= "<option>{$val}</option>"; } } } $ret .= "</select></span>"; $ret .= "<span id=\"info_{$sfgFieldNum}\" class=\"errorMessage\"></span>"; if ($other_args["is_list"]) { $hiddenname = $input_name . '[is_list]'; $ret .= "<input type='hidden' name='{$hiddenname}' value='1' />"; } if (!$staticvalue) { Output::addToHeadItem('sf_select', self::$data); } Output::commitToParserOutput($this->parser->getOutput()); return $ret; }