public static function newFromTypeId($typeId) { $result = new SMWTypesValue('__typ'); try { $dataItem = self::getTypeUriFromTypeId($typeId); } catch (SMWDataItemException $e) { $dataItem = self::getTypeUriFromTypeId('notype'); } $result->setDataItem($dataItem); return $result; }
protected function getTypesList() { $html = '<p>' . wfMessage('smw_types_docu')->escaped() . "</p><br />\n"; $typeLabels = DataTypeRegistry::getInstance()->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; }
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; }
function formatResult($skin, $result) { $linker = smwfGetLinker(); $proplink = $linker->link($result->getDiWikiPage()->getTitle(), $result->getLabel()); $types = smwfGetStore()->getPropertyValues($result->getDiWikiPage(), new SMWDIProperty('_TYPE')); $errors = array(); if (count($types) >= 1) { $typestring = SMWDataValueFactory::newDataItemValue(current($types), new SMWDIProperty('_TYPE'))->getLongHTMLText($linker); } else { $type = SMWTypesValue::newFromTypeId('_wpg'); $typestring = $type->getLongHTMLText($linker); $errors[] = wfMsg('smw_propertylackstype', $type->getLongHTMLText()); } return wfMsg('smw_unusedproperty_template', $proplink, $typestring) . ' ' . smwfEncodeMessages($errors); }
protected function getTypesList() { $typeLabels = DataTypeRegistry::getInstance()->getKnownTypeLabels(); asort($typeLabels, SORT_STRING); $mwCollaboratorFactory = ApplicationFactory::getInstance()->newMwCollaboratorFactory(); $htmlColumnListRenderer = $mwCollaboratorFactory->newHtmlColumnListRenderer(); foreach ($typeLabels as $typeId => $label) { $typeValue = SMWTypesValue::newFromTypeId($typeId); $startChar = $this->getLanguage()->convert($this->getLanguage()->firstChar($typeValue->getWikiValue())); $contentsByIndex[] = $typeValue->getLongHTMLText(smwfGetLinker()); } $htmlColumnListRenderer->setNumberOfColumns(2); $htmlColumnListRenderer->addContentsByNoIndex($contentsByIndex); $htmlColumnListRenderer->setColumnListClass('smw-sp-types-list'); $html = \Html::rawElement('p', array('class' => 'smw-sp-types-intro'), wfMessage('smw_types_docu')->parse()) . \Html::element('h2', array(), wfMessage('smw-sp-types-list')->escaped()); return $html . $htmlColumnListRenderer->getHtml(); }
/** * Return an SMWTypesValue object representing the datatype of this * property. * @deprecated Types values are not a good way to exchange SMW type information. They are for input only. Use getPropertyTypeID() if you want the type id. This method will vanish in SMW 1.7. */ public function getTypesValue() { $result = SMWTypesValue::newFromTypeId($this->getPropertyTypeID()); if (!$this->isValid()) { $result->addError($this->getErrors()); } return $result; }
function formatResult($skin, $result) { global $wgLang; $linker = smwfGetLinker(); list($property, $useCount) = $result; $errors = array(); $diWikiPage = $property->getDiWikiPage(); $title = !is_null($diWikiPage) ? $diWikiPage->getTitle() : null; if ($property->isUserDefined()) { if ($title === null) { return ''; } if ($useCount <= 5) { $errors[] = wfMessage('smw_propertyhardlyused')->escaped(); } // User defined types default to Page global $smwgPDefaultType; $typeDataValue = SMWTypesValue::newFromTypeId($smwgPDefaultType); $typestring = $typeDataValue->getLongHTMLText($linker); $label = htmlspecialchars($property->getLabel()); if ($title->exists()) { $typeProperty = new SMWDIProperty('_TYPE'); $types = smwfGetStore()->getPropertyValues($diWikiPage, $typeProperty); if (count($types) >= 1) { $typeDataValue = SMWDataValueFactory::newDataItemValue(current($types), $typeProperty); $typestring = $typeDataValue->getLongHTMLText($linker); } else { $errors[] = wfMessage('smw_propertylackstype')->rawParams($typestring)->escaped(); } $proplink = $linker->link($title, $label); } else { $errors[] = wfMessage('smw_propertylackspage')->escaped(); $proplink = $linker->link($title, $label, array(), array('action' => 'view')); } } else { // predefined property $typeid = $property->findPropertyTypeID(); $typeDataValue = SMWTypesValue::newFromTypeId($typeid); $typestring = $typeDataValue->getLongHTMLText($linker); $propertyDataValue = SMWDataValueFactory::newDataItemValue($property, null); $proplink = $propertyDataValue->getShortHtmlText($linker); } $warnings = smwfEncodeMessages($errors, 'warning', '', false); $useCount = $wgLang->formatNum($useCount); if ($typestring === '') { // Builtins have no type // @todo Should use numParams for $useCount? return wfMessage('smw_property_template_notype')->rawParams($proplink)->params($useCount)->text() . ' ' . $warnings; } else { // @todo Should use numParams for $useCount? return wfMessage('smw_property_template')->rawParams($proplink, $typestring)->params($useCount)->escaped() . ' ' . $warnings; } }
/** * Produce a formatted string representation for showing a property in * the list of unused properties. * * @since 1.8 * * @param SMWDIProperty $property * @return string */ protected function formatPropertyItem(SMWDIProperty $property) { $linker = smwfGetLinker(); $errors = array(); if ($property->isUserDefined()) { $proplink = $linker->link($property->getDiWikiPage()->getTitle(), $property->getLabel()); $types = smwfGetStore()->getPropertyValues($property->getDiWikiPage(), new SMWDIProperty('_TYPE')); if (count($types) >= 1) { $typeDataValue = SMWDataValueFactory::newDataItemValue(current($types), new SMWDIProperty('_TYPE')); } else { $typeDataValue = SMWTypesValue::newFromTypeId('_wpg'); $errors[] = wfMessage('smw_propertylackstype', $typeDataValue->getLongHTMLText())->text(); } $typeString = $typeDataValue->getLongHTMLText($linker); } else { $typeid = $property->findPropertyTypeID(); $typeDataValue = SMWTypesValue::newFromTypeId($typeid); $typeString = $typeDataValue->getLongHTMLText($linker); $propertyDataValue = SMWDataValueFactory::newDataItemValue($property, null); $proplink = $propertyDataValue->getShortHtmlText($linker); } return wfMessage('smw_unusedproperty_template', $proplink, $typeString)->text() . ' ' . smwfEncodeMessages($errors); }
/** * Method to create a dataitem from a type ID and array of DB keys. * Throws SMWDataItemException if problems occur, to get our callers * used to it. * * @param $typeid string id for the given type * @param $dbkeys array of mixed * * @return SMWDataItem */ public static function dataItemFromDBKeys($typeid, $dbkeys) { switch (SMWDataValueFactory::getDataItemId($typeid)) { case SMWDataItem::TYPE_ERROR: case SMWDataItem::TYPE_NOTYPE: break; case SMWDataItem::TYPE_NUMBER: return SMWDINumber::doUnserialize($dbkeys[0]); case SMWDataItem::TYPE_STRING: return new SMWDIString($dbkeys[0]); case SMWDataItem::TYPE_BLOB: return new SMWDIBlob($dbkeys[0]); case SMWDataItem::TYPE_BOOLEAN: return new SMWDIBoolean($dbkeys[0] == '1'); case SMWDataItem::TYPE_URI: if ($typeid == '__typ' && $dbkeys[0][0] == '_') { // b/c: old data stored as type ids return SMWTypesValue::getTypeUriFromTypeId($dbkeys[0]); } else { return SMWDIUri::doUnserialize($dbkeys[0]); } case SMWDataItem::TYPE_TIME: $timedate = explode('T', $dbkeys[0], 2); if (count($dbkeys) == 2 && count($timedate) == 2) { $date = reset($timedate); $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false; if (end($timedate) === '' || SMWTimeValue::parseTimeString(end($timedate), $hours, $minutes, $seconds, $timeoffset) == true) { $d = explode('/', $date, 3); if (count($d) == 3) { list($year, $month, $day) = $d; } elseif (count($d) == 2) { list($year, $month) = $d; } elseif (count($d) == 1) { list($year) = $d; } if ($month === '') { $month = false; } if ($day === '') { $day = false; } $calendarmodel = SMWDITime::CM_GREGORIAN; return new SMWDITime($calendarmodel, $year, $month, $day, $hours, $minutes, $seconds); } } break; case SMWDataItem::TYPE_GEO: return new SMWDIGeoCoord(array('lat' => (double) $dbkeys[0], 'lon' => (double) $dbkeys[1])); case SMWDataItem::TYPE_CONTAINER: // provided for backwards compatibility only; // today containers are read from the store as substructures, // not retrieved as single complex values $semanticData = SMWContainerSemanticData::makeAnonymousContainer(); foreach (reset($dbkeys) as $value) { if (is_array($value) && count($value) == 2) { $diP = new SMWDIProperty(reset($value), false); $diV = self::dataItemFromDBKeys($diP->findPropertyTypeID(), end($value)); $semanticData->addPropertyObjectValue($diP, $diV); } } return new SMWDIContainer($semanticData); case SMWDataItem::TYPE_WIKIPAGE: if ($typeid == '__spf') { $pagedbkey = str_replace(' ', '_', $dbkeys[0]); return new SMWDIWikiPage($pagedbkey, SF_NS_FORM, ''); } elseif (count($dbkeys) >= 5) { // with subobject name (and sortkey) return new SMWDIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2], $dbkeys[4]); } elseif (count($dbkeys) >= 3) { // without subobject name (just for b/c) return new SMWDIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2]); } break; case SMWDataItem::TYPE_CONCEPT: if (count($dbkeys) >= 5) { return new SMWDIConcept($dbkeys[0], smwfXMLContentEncode($dbkeys[1]), $dbkeys[2], $dbkeys[3], $dbkeys[4]); } break; case SMWDataItem::TYPE_PROPERTY: return new SMWDIProperty($dbkeys[0], false); } throw new SMWDataItemException('Failed to create data item from DB keys.'); }