function setTypeAndPossibleValues() { // The presence of "-" at the beginning of a property name // (which happens if SF tries to parse an inverse query) // leads to an error in SMW - just exit if that's the case. if (strpos($this->mSemanticProperty, '-') === 0) { return; } $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty); if ($proptitle === null) { return; } $store = SFUtils::getSMWStore(); // this returns an array of objects $allowed_values = SFUtils::getSMWPropertyValues($store, $proptitle, "Allows value"); $label_formats = SFUtils::getSMWPropertyValues($store, $proptitle, "Has field label format"); $propValue = SMWDIProperty::newFromUserLabel($this->mSemanticProperty); $this->mPropertyType = $propValue->findPropertyTypeID(); foreach ($allowed_values as $allowed_value) { // HTML-unencode each value $this->mPossibleValues[] = html_entity_decode($allowed_value); if (count($label_formats) > 0) { $label_format = $label_formats[0]; $prop_instance = SMWDataValueFactory::findTypeID($this->mPropertyType); $label_value = SMWDataValueFactory::newTypeIDValue($prop_instance, $wiki_value); $label_value->setOutputFormat($label_format); $this->mValueLabels[$wiki_value] = html_entity_decode($label_value->getWikiValue()); } } // HACK - if there were any possible values, set the property // type to be 'enumeration', regardless of what the actual type is if (count($this->mPossibleValues) > 0) { $this->mPropertyType = 'enumeration'; } }
public static function getAllPropertyNames() { $all_properties = array(); // Set limit on results - we don't want a massive dropdown // of properties, if there are a lot of properties in this wiki. // getProperties() functions stop requiring a limit $options = new SMWRequestOptions(); $options->limit = 500; $used_properties = SFUtils::getSMWStore()->getPropertiesSpecial($options); if ($used_properties instanceof SMW\SQLStore\PropertiesCollector) { // SMW 1.9+ $used_properties = $used_properties->runCollector(); } foreach ($used_properties as $property) { // Skip over properties that are errors. (This // shouldn't happen, but it sometimes does.) if (!method_exists($property[0], 'getKey')) { continue; } $propName = $property[0]->getKey(); if ($propName[0] != '_') { $all_properties[] = str_replace('_', ' ', $propName); } } $unused_properties = SFUtils::getSMWStore()->getUnusedPropertiesSpecial($options); if ($unused_properties instanceof SMW\SQLStore\UnusedPropertiesCollector) { // SMW 1.9+ $unused_properties = $unused_properties->runCollector(); } foreach ($unused_properties as $property) { // Skip over properties that are errors. (This // shouldn't happen, but it sometimes does.) if (!method_exists($property, 'getKey')) { continue; } $all_properties[] = str_replace('_', ' ', $property->getKey()); } // Sort properties list alphabetically, and get unique values // (for SQLStore3, getPropertiesSpecial() seems to get unused // properties as well). sort($all_properties); $all_properties = array_unique($all_properties); return $all_properties; }
/** * Gets the forms specified, if any, of either type "default form", * "alternate form", or "default form for page", for a specific page * (which should be a category, property, or namespace page) */ static function getFormsThatPagePointsTo($page_name, $page_namespace, $form_connection_type) { if ($page_name == NULL) { return array(); } // Check if we've already gotten the set of forms for this // combination of page and "form connection type" (default, // alternate or "creates pages with"). If so, use that - // otherwise, prepare the array so that we can add this // data to it. $page_key = "{$page_namespace}:{$page_name}"; if (array_key_exists($page_key, self::$mLinkedForms)) { if (array_key_exists($form_connection_type, self::$mLinkedForms[$page_key])) { return self::$mLinkedForms[$page_key][$form_connection_type]; } else { // Do nothing - an entry with this key will // be added at the end of this method. } } else { self::$mLinkedForms[$page_key] = array(); } if ($form_connection_type == self::DEFAULT_FORM) { $prop_smw_id = '_SF_DF'; $backup_prop_smw_id = '_SF_DF_BACKUP'; } elseif ($form_connection_type == self::ALTERNATE_FORM) { $prop_smw_id = '_SF_AF'; $backup_prop_smw_id = '_SF_AF_BACKUP'; } elseif ($form_connection_type == self::PAGE_DEFAULT_FORM) { $prop_smw_id = '_SF_PDF'; $backup_prop_smw_id = '_SF_PDF_BACKUP'; } elseif ($form_connection_type == self::AUTO_CREATE_FORM) { $prop_smw_id = '_SF_CP'; $backup_prop_smw_id = '_SF_CP_BACKUP'; } else { return array(); } global $sfgContLang; $store = SFUtils::getSMWStore(); $subject = Title::makeTitleSafe($page_namespace, $page_name); $form_names = SFUtils::getSMWPropertyValues($store, $subject, $prop_smw_id); // If we're using a non-English language, check for the English // string as well. if (!class_exists('SF_LanguageEn') || !$sfgContLang instanceof SF_LanguageEn) { $backup_form_names = SFUtils::getSMWPropertyValues($store, $subject, $backup_prop_smw_id); $form_names = array_merge($form_names, $backup_form_names); } // These form names will all start with "Form:" - remove the // namespace prefix. foreach ($form_names as $i => $form_name) { $form_names[$i] = preg_replace('/^Form:/', '', $form_name); } // Add this data to the "cache". self::$mLinkedForms[$page_key][$form_connection_type] = $form_names; return $form_names; }
/** * returns an array of pages that are result of the semantic query * @param $rawQueryString string - the query string like [[Category:Trees]][[age::>1000]] * @return array of SMWDIWikiPage objects representing the result */ public static function getAllPagesForQuery($rawQuery) { $rawQueryArray = array($rawQuery); SMWQueryProcessor::processFunctionParams($rawQueryArray, $queryString, $processedParams, $printouts); SMWQueryProcessor::addThisPrintout($printouts, $processedParams); $processedParams = SMWQueryProcessor::getProcessedParams($processedParams, $printouts); $queryObj = SMWQueryProcessor::createQuery($queryString, $processedParams, SMWQueryProcessor::SPECIAL_PAGE, '', $printouts); $res = SFUtils::getSMWStore()->getQueryResult($queryObj); $pages = $res->getResults(); return $pages; }