本文整理汇总了PHP中SMWDIProperty类的典型用法代码示例。如果您正苦于以下问题:PHP SMWDIProperty类的具体用法?PHP SMWDIProperty怎么用?PHP SMWDIProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMWDIProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseUserValue
protected function parseUserValue($value)
{
global $wgContLang;
$this->m_diProperties = array();
$stringValue = '';
$valueList = preg_split('/[\\s]*;[\\s]*/u', trim($value));
foreach ($valueList as $propertyName) {
$propertyNameParts = explode(':', $propertyName, 2);
if (count($propertyNameParts) > 1) {
$namespace = smwfNormalTitleText($propertyNameParts[0]);
$propertyName = $propertyNameParts[1];
$propertyNamespace = $wgContLang->getNsText(SMW_NS_PROPERTY);
if ($namespace != $propertyNamespace) {
$this->addError(wfMessage('smw_wrong_namespace', $propertyNamespace)->inContentLanguage()->text());
}
}
$propertyName = smwfNormalTitleText($propertyName);
try {
$diProperty = SMWDIProperty::newFromUserLabel($propertyName);
} catch (SMWDataItemException $e) {
$diProperty = new SMWDIProperty('Error');
$this->addError(wfMessage('smw_noproperty', $propertyName)->inContentLanguage()->text());
}
$this->m_diProperties[] = $diProperty;
$stringValue .= ($stringValue ? ';' : '') . $diProperty->getKey();
}
$this->m_dataitem = new SMWDIBlob($stringValue);
}
示例2: newFromSerialization
/**
* Creates and returns a new SWLPropertyChange instance from a serialization.
*
* @param string|null $oldValue
* @param string|null $newValue
*
* @return SWLPropertyChange
*/
public static function newFromSerialization(SMWDIProperty $property, $oldValue, $newValue)
{
$diType = SMWDataValueFactory::getDataItemId($property->findPropertyTypeID());
//var_dump($property);
//if($diType!=7) {throw new Exception();exit;}
return new self(is_null($oldValue) ? null : SMWDataItem::newFromSerialization($diType, $oldValue), is_null($newValue) ? null : SMWDataItem::newFromSerialization($diType, $newValue));
}
示例3: newFromSerialization
/**
* Creates and returns a new SWLPropertyChange instance from a serialization.
*
* @param string|null $oldValue
* @param string|null $newValue
*
* @return SWLPropertyChange
*/
public static function newFromSerialization( SMWDIProperty $property, $oldValue, $newValue ) {
$diType = SMWDataValueFactory::getDataItemId( $property->findPropertyTypeID() );
return new self(
is_null( $oldValue ) ? null : SMWDataItem::newFromSerialization( $diType, $oldValue ),
is_null( $newValue ) ? null : SMWDataItem::newFromSerialization( $diType, $newValue )
);
}
示例4: getPropertyCustomText
/**
* Returns an array of CustomTexts set by the admin in WatchlistConditions
* for this group and property.
*
* @since 0.2
*
* @param SMWDIProperty $property
* @param String $newValue
*
* @return String or false
*/
public function getPropertyCustomText(SMWDIProperty $property, $newValue)
{
$this->initCustomTexts();
if (array_key_exists($property->getLabel(), $this->customTexts) && array_key_exists($newValue, $this->customTexts[$property->getLabel()])) {
return $this->customTexts[$property->getLabel()][$newValue];
} else {
return false;
}
}
示例5: SemanticGlossaryRegisterPropertyAliases
function SemanticGlossaryRegisterPropertyAliases()
{
SMWDIProperty::registerPropertyAlias('___glt', wfMsg('semanticglossary-prop-glt'));
SMWDIProperty::registerPropertyAlias('___gld', wfMsg('semanticglossary-prop-gld'));
SMWDIProperty::registerPropertyAlias('___gll', wfMsg('semanticglossary-prop-gll'));
return true;
}
示例6: checkAllowedValues
/**
* Check if property is range restricted and, if so, whether the current value is allowed.
* Creates an error if the value is illegal.
*/
protected function checkAllowedValues()
{
if (!is_null($this->m_property)) {
$propertyDiWikiPage = $this->m_property->getDiWikiPage();
}
if (is_null($this->m_property) || is_null($propertyDiWikiPage) || !isset($this->m_dataitem)) {
return;
// no property known, or no data to check
}
$allowedvalues = \SMW\StoreFactory::getStore()->getPropertyValues($propertyDiWikiPage, new SMWDIProperty('_PVAL'));
if (count($allowedvalues) == 0) {
return;
}
$hash = $this->m_dataitem->getHash();
$testdv = DataValueFactory::getInstance()->newTypeIDValue($this->getTypeID());
$accept = false;
$valuestring = '';
foreach ($allowedvalues as $di) {
if ($di instanceof SMWDIBlob) {
$testdv->setUserValue($di->getString());
if ($hash === $testdv->getDataItem()->getHash()) {
$accept = true;
break;
} else {
if ($valuestring !== '') {
$valuestring .= ', ';
}
$valuestring .= $di->getString();
}
}
}
if (!$accept) {
$this->addError(wfMessage('smw_notinenum', $this->getWikiValue(), $valuestring)->inContentLanguage()->text());
}
}
示例7: initParameters
/**
* @see SMWOrderedListPage::initParameters()
* @note We use a smaller limit here; property pages might become large.
*/
protected function initParameters()
{
global $smwgPropertyPagingLimit;
$this->limit = $smwgPropertyPagingLimit;
$this->mProperty = SMWDIProperty::newFromUserLabel($this->mTitle->getText());
return true;
}
示例8: setTypeAndPossibleValues
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';
}
}
示例9: setTypeAndPossibleValues
function setTypeAndPossibleValues()
{
$proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty);
if ($proptitle === null) {
return;
}
$store = smwfGetStore();
// 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';
}
}
示例10: initParameters
/**
* @see SMWOrderedListPage::initParameters()
* @note We use a smaller limit here; property pages might become large.
*/
protected function initParameters()
{
global $smwgPropertyPagingLimit;
$this->limit = $smwgPropertyPagingLimit;
$this->mProperty = SMWDIProperty::newFromUserLabel($this->mTitle->getText());
$this->store = ApplicationFactory::getInstance()->getStore();
return true;
}
示例11: formatPropertyItem
/**
* Produce a formatted string representation for showing a property and
* its usage count in the list of used properties.
*
* @since 1.8
*
* @param SMWDIProperty $property
* @param integer $useCount
* @return string
*/
protected function formatPropertyItem(SMWDIProperty $property, $useCount)
{
global $wgLang;
$linker = smwfGetLinker();
$errors = array();
$diWikiPage = $property->getDiWikiPage();
$title = !is_null($diWikiPage) ? $diWikiPage->getTitle() : null;
if ($property->isUserDefined() && is_null($title)) {
// Show even messed up property names.
$typestring = '';
$proplink = $property->getLabel();
$errors[] = wfMessage('smw_notitle', $property->getLabel())->escaped();
} elseif ($property->isUserDefined()) {
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;
}
}
示例12: addPropertyAndValue
public function addPropertyAndValue( $propName, $value ) {
// SMW 1.6+
if ( class_exists( 'SMWDIProperty' ) ) {
$property = SMWDIProperty::newFromUserLabel( $propName );
} else {
$property = SMWPropertyValue::makeUserProperty( $propName );
}
$dataValue = SMWDataValueFactory::newPropertyObjectValue( $property, $value );
if ( $dataValue->isValid() ) {
$this->mPropertyValuePairs[] = array( $property, $dataValue );
} // else - show an error message?
}
示例13: loadDataItem
/**
* @see SMWDataValue::loadDataItem()
*
* @param $dataitem SMWDataItem
*
* @return boolean
*/
protected function loadDataItem(SMWDataItem $dataItem)
{
if (!$dataItem instanceof SMWDIBlob) {
return false;
}
$this->m_dataitem = $dataItem;
$this->m_diProperties = array();
foreach (explode(';', $dataItem->getString()) as $propertyKey) {
$property = null;
try {
$property = new SMWDIProperty($propertyKey);
} catch (SMWDataItemException $e) {
$property = new SMWDIProperty('Error');
$this->addError(wfMessage('smw_parseerror')->inContentLanguage()->text());
}
if ($property instanceof SMWDIProperty) {
// Find a possible redirect
$this->m_diProperties[] = $property->getRedirectTarget();
}
}
$this->m_caption = false;
return true;
}
示例14: initProperties
function initProperties()
{
if (class_exists('SMWDIProperty')) {
SMWDIProperty::registerProperty("__SIA_RECTCOORDS", '_str', "SIArectangleCoordinates", true);
SMWDIProperty::registerProperty("__SIA_IMG_URL", '_str', "SIAimageURL", true);
SMWDIProperty::registerProperty("__SIA_ANNOTATED", '_str', "SIAannotatedImage", true);
SMWDIProperty::registerProperty("__SIA_CREATED_BY", '_str', "SIAcreatedBy", true);
} else {
SMWPropertyValue::registerProperty("__SIA_RECTCOORDS", '_str', "SIArectangleCoordinates", true);
SMWPropertyValue::registerProperty("__SIA_IMG_URL", '_str', "SIAimageURL", true);
SMWPropertyValue::registerProperty("__SIA_ANNOTATED", '_str', "SIAannotatedImage", true);
SMWPropertyValue::registerProperty("__SIA_CREATED_BY", '_str', "SIAcreatedBy", true);
}
return true;
}
示例15: writeOrDeleteDataToWiki
/**
* Write (or delte, if $delete is set to true) the data in the object
* variables, to the wiki page corresponding to this page handler
* @param boolean $delete
*/
public function writeOrDeleteDataToWiki( $delete = false ) {
if ( $delete ) {
if ( $this->checkWikiPageExists() ) {
$this->initSMWWriter( $delete = true );
} else {
return;
}
} else {
$this->ensureWikiPageExists();
$this->initSMWWriter();
}
$properties = $this->m_properties;
foreach ( $properties as $cur_prop ) {
$propertystring = $cur_prop['p'];
// TODO: Remove old code:
// $property = SMWPropertyValue::makeUserProperty( $propertystring );
$property_di = SMWDIProperty::newFromUserLabel($propertystring);
$valuestring = RDFIOUtils::sanitizeSMWValue( $cur_prop['v'] );
$value = SMWDataValueFactory::newPropertyObjectValue( $property_di, $valuestring );
$propertyErrorText = $property->getErrorText();
$propertyHasError = ( $propertyErrorText != '' );
if ( $propertyHasError ) {
$this->addError( "<p>In RDFIOPageHandler::writeOrDeleteDataToWiki(): " . $property->getErrorText() . "</p>" );
}
$valueErrorText = $value->getErrorText();
$valueHasError = ( $valueErrorText != '' );
if ( $valueHasError ) {
$this->addError( "<p>Error creating property value object in RDFIOPageHandler::writeOrDeleteDataToWiki():</p><p>" . $value->getErrorText() . "</p>" );
}
if ( $delete ) {
$this->m_smwwriter_remove->addPropertyObjectValue( $property, $value );
$editmessage = "Deleting properties. Last property delete: " . $propertystring . " : " . $valuestring;
} else {
$this->m_smwwriter_add->addPropertyObjectValue( $property, $value );
$editmessage = "Importing properties. Last property added: " . $propertystring . " : " . $valuestring;
}
}
$this->m_smwwriter->update( $this->m_smwwriter_remove, $this->m_smwwriter_add, $editmessage );
$smwWriterError = $this->m_smwwriter->getError();
$smwWriterHasError = ( $smwWriterError != '' );
if ( $smwWriterHasError ) {
$this->addError( "<p>SMWWriter Error: " . $smwWriterError . "</p>" );
}
}