protected function getTypesList() { $html = '<p>' . htmlspecialchars(wfMsg('smw_types_docu')) . "</p><br />\n"; $typeLabels = SMWDataValueFactory::getKnownTypeLabels(); asort($typeLabels, SORT_STRING); $html .= "<ul>\n"; foreach ($typeLabels as $typeId => $label) { $typeValue = SMWTypesValue::newFromTypeId($typeId); $html .= '<li>' . $typeValue->getLongHTMLText(smwfGetLinker()) . "</li>\n"; } $html .= "</ul>\n"; return $html; }
/** * Get Property target proposals. Consider special properties too */ public static function getPropertyTargetProposals($userContext, $match) { // special handling for special relations global $smwgContLang, $smwgHaloContLang, $wgLang; $specialProperties = $smwgContLang->getPropertyLabels(); $specialSchemaProperties = $smwgHaloContLang->getSpecialSchemaPropertyArray(); // special properties if (stripos(strtolower($userContext), strtolower($specialProperties["_SUBP"])) > 0) { $pages = smwfGetAutoCompletionStore()->getPages($match, array(SMW_NS_PROPERTY)); return AutoCompletionRequester::encapsulateAsXML($pages, true); // return namespace too! } else { if (stripos(strtolower($userContext), strtolower($specialSchemaProperties[SMW_SSP_IS_INVERSE_OF])) > 0) { $pages = smwfGetAutoCompletionStore()->getPages($match, array(SMW_NS_PROPERTY)); return AutoCompletionRequester::encapsulateAsXML($pages, true); // return namespace too! } else { if (stripos(strtolower($userContext), strtolower($specialProperties["_TYPE"])) > 0) { // has type relation. First check for user types $pages = smwfGetAutoCompletionStore()->getPages($match, array(SMW_NS_TYPE)); // then check builtin types $typeLabels = array_values(SMWDataValueFactory::getKnownTypeLabels()); $lower_match = strtolower($match); foreach ($typeLabels as $l) { if (strpos(strtolower($l), $lower_match) !== false) { $pages[] = Title::newFromText($l, SMW_NS_TYPE); } } return AutoCompletionRequester::encapsulateAsXML($pages, true); // return namespace too! } else { if (stripos(strtolower($userContext), strtolower($specialSchemaProperties[SMW_SSP_HAS_DOMAIN_AND_RANGE_HINT])) > 0) { // has domain hint relation $pages = smwfGetAutoCompletionStore()->getPages($match, array(NS_CATEGORY)); return AutoCompletionRequester::encapsulateAsXML($pages, true); // return namespace too! } else { $propertyTitle = self::getTitleFromContext($userContext); if (!is_null($propertyTitle)) { $property = Title::newFromText($propertyTitle, SMW_NS_PROPERTY); $domainRangeAnnotations = smwfGetStore()->getPropertyValues($property, smwfGetSemanticStore()->domainRangeHintProp); $pages = smwfGetAutoCompletionStore()->getInstanceAsTarget($match, $domainRangeAnnotations); } if (empty($pages)) { // fallback $pages = smwfGetAutoCompletionStore()->getPages($match, array(NS_MAIN)); } return AutoCompletionRequester::encapsulateAsXML($pages); } } } } }
/** * function smwfGetUserDatatypes * This function returns a comma separated list of all user defined data types */ function smwf_tb_GetUserDatatypes() { $result = "User defined types:"; $db =& wfGetDB(DB_SLAVE); $NStype = SMW_NS_TYPE; $page = $db->tableName('page'); $sql = "SELECT 'Types' as type,\r\n\t{$NStype} as namespace,\r\n\tpage_title as title,\r\n\tpage_title as value,\r\n\t1 as count\r\n\tFROM {$page}\r\n\tWHERE page_namespace = {$NStype}"; $res = $db->query($sql); // Builtin types may appear in the list of user types (if there is an // article for them). They have to be removed from the user types $builtinTypes = SMWDataValueFactory::getKnownTypeLabels(); $userTypes = array(); if ($db->numRows($res) > 0) { while ($row = $db->fetchObject($res)) { $userTypes[] = str_replace("_", " ", $row->title); } } $db->freeResult($res); $userTypes = array_diff($userTypes, $builtinTypes); foreach ($userTypes as $key => $type) { $result .= "," . $type; } return $result; }
function smwf_qi_QIAccess($method, $params) { $p_array = explode(",", $params); global $smwgQEnabled; if ($method == "getPropertyInformation") { return qiGetPropertyInformation($p_array[0]); } else { if ($method == "getPropertyTypes") { $p_array = func_get_args(); $types = "<propertyTypes>"; for ($i = 1; $i < count($p_array); $i++) { $types .= qiGetPropertyInformation($p_array[$i]); } $types .= "</propertyTypes>"; return $types; } else { if ($method == "getNumericTypes") { $numtypes = array(); $types = SMWDataValueFactory::getKnownTypeLabels(); foreach ($types as $v) { $id = SMWDataValueFactory::findTypeID($v); if (SMWDataValueFactory::newTypeIDValue($id)->isNumeric()) { array_push($numtypes, strtolower($v)); } } return implode(",", $numtypes); } else { if ($method == "getQueryResult") { $result = "null"; if ($smwgQEnabled) { // read fix parameters from QI GUI $params = count($p_array) > 1 ? explode("|", $p_array[1]) : array(); $fixparams = array(); foreach ($params as $p) { if (strlen($p) > 0 && strpos($p, "=") !== false) { list($key, $value) = explode("=", $p); $fixparams[trim($key)] = str_replace('%2C', ',', $value); } } // indicate that it comes from an ajax call $fixparams['ajaxCall'] = true; // fix bug 10812: if query string contains a , $p_array[0] = str_replace('%2C', ',', $p_array[0]); // read query with printouts and (possibly) other parameters like sort, order, limit, etc... $pos = strpos($p_array[0], "|?"); if ($pos > 0) { $rawparams[] = trim(substr($p_array[0], 0, $pos)); $ps = explode("|?", trim(substr($p_array[0], $pos + 2))); foreach ($ps as $param) { $rawparams[] = "?" . trim($param); } } else { $ps = preg_split('/[^\\|]{1}\\|{1}(?!\\|)/s', $p_array[0]); if (count($ps) > 1) { // last char of query condition is missing (matched with [^\|]{1}) therefore copy from original $rawparams[] = trim(substr($p_array[0], 0, strlen($ps[0]) + 1)); array_shift($ps); // remove the query condition // add other params for formating etc. foreach ($ps as $param) { $rawparams[] = trim($param); } } else { $rawparams[] = trim($p_array[0]); } } $rawparams = array_merge($rawparams, $fixparams); // set some default values, if params are not set if (!in_array('reasoner', array_keys($fixparams))) { $fixparams['reasoner'] = 'ask'; } if (!in_array('format', array_keys($fixparams))) { $fixparams['format'] = 'table'; } // use SMW classes or TSC classes and parse params and answer query if ($fixparams['reasoner'] == 'ask') { SMWQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts); } else { if ($fixparams['reasoner'] == 'sparql') { SMWSPARQLQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts); } } // check if there is any result and if it corresponds to the selected format $mainlabel = isset($rawparams['mainlabel']) && $rawparams['mainlabel'] == '-'; $invalidRes = smwf_qi_CheckValidResult($printouts, $fixparams['format'], $mainlabel); if ($invalidRes != 0) { return wfMsg('smw_qi_printout_err' . $invalidRes); } // quickfix: unset conflicting params for maps if (in_array($fixparams['format'], array("map", "googlemaps2", "openlayers", "yahoomaps"))) { if (isset($params['reasoner'])) { unset($params['reasoner']); } if (isset($params['ajaxcall'])) { unset($params['ajaxcall']); } if (isset($params['merge'])) { unset($params['merge']); } } // answer query using the SMW classes or TSC classes if ($fixparams['reasoner'] == 'ask') { $result = SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI); } else { if ($fixparams['reasoner'] == 'sparql') { $result = SMWSPARQLQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI); } } // check for empty result if (is_array($result) && trim($result[0]) == '' || trim($result == '')) { return wfMsg('smw_qi_printout_err4'); } switch ($fixparams['format']) { case 'timeline': case 'exhibit': case 'eventline': return $result; break; case 'gallery': case 'googlepie': case 'googlebar': case 'ofc-pie': case 'ofc-bar': case 'ofc-bar_3d': case 'ofc-line': case 'ofc-scatterline': return is_array($result) ? $result[0] : $result; break; case 'map': case 'googlemaps2': case 'openlayers': case 'yahoomaps': return wfMsg('smw_qi_printout_notavailable'); default: } $result = parseWikiText($result); // add target="_new" for all links $pattern = "|<a|i"; $result = preg_replace($pattern, '<a target="_new"', $result); return $result; } } else { if ($method == "getQueryResultForDownload") { $result = "null"; if ($smwgQEnabled) { $params = array('format' => $p_array[1], 'link' => $p_array[2], 'intro' => $p_array[3], 'sort' => $p_array[4], 'limit' => $p_array[5], 'mainlabel' => $p_array[6], 'order' => $p_array[7], 'default' => $p_array[8], 'headers' => $p_array[9]); $result = applyQueryHighlighting($p_array[0], $params); // add target="_new" for all links $pattern = "|<a|i"; $result = preg_replace($pattern, '<a target="_new"', $result); } if ($result != "null" && $result != "") { global $request_query; $request_query = true; } return $result; } else { if ($method == "getSupportedParameters") { global $smwgResultFormats; wfLoadExtensionMessages('SemanticMediaWiki'); $format = $p_array[0]; if (array_key_exists($format, $smwgResultFormats)) { $formatclass = $smwgResultFormats[$format]; } else { $formatclass = "SMWListResultPrinter"; } // fix for missing parameter order $order_missing = true; $intro_missing = true; $outro_missing = true; $qp = new $formatclass($format, false); $params = $qp->getParameters(); // repair some misplaced parameters for ($i = 0; $i < count($params); $i++) { switch ($params[$i]['name']) { case "order": $order_missing = false; break; case "template": if ($format != "template") { array_splice($params, $i, 1); } break; case "intro": if (substr($format, 0, 4) != "ofc-") { $intro_missing = false; } break; case "outro": if (substr($format, 0, 4) != "ofc-") { $outro_missing = false; } break; case "headers": if ($format != "table" && $format != "broadtable") { array_splice($params, $i, 1); } break; } } if ($order_missing) { $params[] = array('name' => 'order', 'type' => 'enumeration', 'description' => wfMsg('smw_qi_tt_order'), 'values' => array('ascending', 'descending')); } if ($intro_missing) { $params[] = array('name' => 'intro', 'type' => 'string', 'description' => wfMsg('smw_qi_tt_intro')); } if ($outro_missing) { $params[] = array('name' => 'outro', 'type' => 'string', 'description' => wfMsg('smw_qi_tt_outro')); } $jsonEnc = new Services_JSON(); return $jsonEnc->encode($params); } else { return "false"; } } } } } } }