本文整理汇总了PHP中SMWDIProperty::newFromUserLabel方法的典型用法代码示例。如果您正苦于以下问题:PHP SMWDIProperty::newFromUserLabel方法的具体用法?PHP SMWDIProperty::newFromUserLabel怎么用?PHP SMWDIProperty::newFromUserLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMWDIProperty
的用法示例。
在下文中一共展示了SMWDIProperty::newFromUserLabel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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';
}
}
示例4: 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';
}
}
示例5: 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;
}
示例6: 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?
}
示例7: 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>" );
}
}
示例8: getProperties
/**
* Get an array key => value of genealogical properties as SMWDIProperty
* @throws MWException
*/
public static function getProperties()
{
static $properties;
if ($properties !== null) {
return $properties;
}
global $wgGenealogicalProperties, $wgOut;
$properties = array();
if (!is_array($wgGenealogicalProperties)) {
throw new MWException('Configuration variable $wgGenealogicalProperties must be an array !');
}
foreach ($wgGenealogicalProperties as $key => $value) {
if ($value) {
$properties[$key] = SMWDIProperty::newFromUserLabel($value);
}
}
return $properties;
}
示例9: getSMWPropertyValues
/**
* Helper function to handle getPropertyValues() in both SMW 1.6
* and earlier versions.
*/
public static function getSMWPropertyValues($store, $subject, $propID, $requestOptions = null)
{
// SMWDIProperty was added in SMW 1.6
if (class_exists('SMWDIProperty')) {
if (is_null($subject)) {
$page = null;
} else {
$page = SMWDIWikiPage::newFromTitle($subject);
}
$property = SMWDIProperty::newFromUserLabel($propID);
$res = $store->getPropertyValues($page, $property, $requestOptions);
$values = array();
foreach ($res as $value) {
if ($value instanceof SMWDIUri) {
$values[] = $value->getURI();
} else {
// getSortKey() seems to return the
// correct value for all the other
// data types.
$values[] = str_replace('_', ' ', $value->getSortKey());
}
}
return $values;
} else {
$property = SMWPropertyValue::makeProperty($propID);
$res = $store->getPropertyValues($subject, $property, $requestOptions);
$values = array();
foreach ($res as $value) {
if (method_exists($value, 'getTitle')) {
$valueTitle = $value->getTitle();
if (!is_null($valueTitle)) {
$values[] = $valueTitle->getText();
}
} else {
$values[] = str_replace('_', ' ', $value->getWikiValue());
}
}
return array_unique($values);
}
}
示例10: getSMWPropertyValues
/**
* Helper function to handle getPropertyValues().
*/
public static function getSMWPropertyValues($store, $subject, $propID, $requestOptions = null)
{
if (is_null($subject)) {
$page = null;
} else {
$page = SMWDIWikiPage::newFromTitle($subject);
}
$property = SMWDIProperty::newFromUserLabel($propID);
$res = $store->getPropertyValues($page, $property, $requestOptions);
$values = array();
foreach ($res as $value) {
if ($value instanceof SMWDIUri) {
$values[] = $value->getURI();
} else {
// getSortKey() seems to return the
// correct value for all the other
// data types.
$values[] = str_replace('_', ' ', $value->getSortKey());
}
}
return $values;
}
示例11: getSMWPropertyValues
/**
* Helper function to handle getPropertyValues().
*/
public static function getSMWPropertyValues($store, $subject, $propID, $requestOptions = null)
{
// If SMW is not installed, exit out.
if (!class_exists('SMWDIWikiPage')) {
return array();
}
if (is_null($subject)) {
$page = null;
} else {
$page = SMWDIWikiPage::newFromTitle($subject);
}
$property = SMWDIProperty::newFromUserLabel($propID);
$res = $store->getPropertyValues($page, $property, $requestOptions);
$values = array();
foreach ($res as $value) {
if ($value instanceof SMWDIUri) {
$values[] = $value->getURI();
} elseif ($value instanceof SMWDIWikiPage) {
$realValue = str_replace('_', ' ', $value->getDBKey());
if ($value->getNamespace() != 0) {
$realValue = MWNamespace::getCanonicalName($value->getNamespace()) . ":{$realValue}";
}
$values[] = $realValue;
} else {
// getSortKey() seems to return the correct
// value for all the other data types.
$values[] = str_replace('_', ' ', $value->getSortKey());
}
}
return $values;
}
示例12: getResultText
/**
* Return serialised results in specified format.
*/
protected function getResultText(SMWQueryResult $res, $outputmode)
{
if ($this->mTreeProp === null || $this->mTreeProp === '') {
$res->addErrors(array(wfMessage('srf-noparentprop')->inContentLanguage()->text()));
return '';
}
$store = $res->getStore();
// first put everything in a list
// elements appearing more than once will be inserted more than once,
// but only one instance will be inserted with the hash
// only this instance will be considered as a parent element in the tree
$list = array();
while ($row = $res->getNext()) {
$hash = $row[0]->getResultSubject()->getSerialization();
if (array_key_exists($hash, $list)) {
$list[] = new SRFTreeElement($row);
} else {
$list[$hash] = new SRFTreeElement($row);
}
}
// transfer the listelements into the tree
// elements with more than one parent will be cloned for each parent
$tree = array();
foreach ($list as $hash => $listElem) {
$parents = $store->getPropertyValues($listElem->mRow[0]->getResultSubject(), SMWDIProperty::newFromUserLabel($this->mTreeProp));
// transfer element from list to tree
foreach ($parents as $parent) {
$parentPageHash = $parent->getSerialization();
if ($hash !== null) {
if (array_key_exists($parentPageHash, $list)) {
$listElem->mParent = $parentPageHash;
}
$tree[$hash] = $listElem;
$hash = null;
} else {
$treeElem = clone $listElem;
if (array_key_exists($parentPageHash, $list)) {
$treeElem->mParent = $parentPageHash;
} else {
$treeElem->mParent = null;
}
$tree[] = $treeElem;
}
}
}
foreach ($tree as $hash => $value) {
}
// build pointers from parants to children
foreach ($tree as $hash => $treeElem) {
if ($treeElem->mParent != null) {
$tree[$treeElem->mParent]->mChildren[] = $treeElem;
}
}
// remove children from toplevel
foreach ($tree as $hash => $treeElem) {
if ($treeElem->mParent != null) {
unset($tree[$hash]);
}
}
$result = '';
$rownum = 0;
foreach ($tree as $hash => $treeElem) {
$this->printElement($result, $treeElem, $row);
}
return $result;
}
示例13: getXMLForPage
//.........这里部分代码省略.........
if ($c == "|" || $c == "}") {
$template_name = str_replace(' ', '_', trim($template_name));
$template_name = str_replace('&', '&', $template_name);
if ($simplified_format) {
$text .= "<" . $template_name . ">";
} else {
$text .= "<{$template_label} {$name_str}=\"{$template_name}\">";
}
$creating_template_name = false;
$creating_field_name = true;
$field_id = 1;
} else {
$template_name .= $c;
}
} else {
if ($c == "|" || $c == "}") {
if ($field_has_name) {
$field_value = str_replace('&', '&', $field_value);
if ($simplified_format) {
$field_name = str_replace(' ', '_', trim($field_name));
$text .= "<" . $field_name . ">";
$text .= trim($field_value);
$text .= "</" . $field_name . ">";
} else {
$text .= "<{$field_str} {$name_str}=\"" . trim($field_name) . "\">";
$text .= trim($field_value);
$text .= "</{$field_str}>";
}
$field_value = "";
$field_has_name = false;
} else {
// "field_name" is actually the value
if ($simplified_format) {
$field_name = str_replace(' ', '_', $field_name);
// add "Field" to the beginning of the file name, since
// XML tags that are simply numbers aren't allowed
$text .= "<" . $field_str . '_' . $field_id . ">";
$text .= trim($field_name);
$text .= "</" . $field_str . '_' . $field_id . ">";
} else {
$text .= "<{$field_str} {$name_str}=\"{$field_id}\">";
$text .= trim($field_name);
$text .= "</{$field_str}>";
}
$field_id++;
}
$creating_field_name = true;
$field_name = "";
} elseif ($c == "=") {
// handle case of = in value
if (!$creating_field_name) {
$field_value .= $c;
} else {
$creating_field_name = false;
$field_has_name = true;
}
} elseif ($creating_field_name) {
$field_name .= $c;
} else {
$field_value .= $c;
}
}
}
}
}
// handle groupings, if any apply here; first check if SMW is installed
global $smwgIP;
if (isset($smwgIP)) {
$store = smwfGetStore();
foreach ($groupings as $pair) {
list($property_page, $grouping_label) = $pair;
$options = new SMWRequestOptions();
$options->sort = "subject_title";
// get actual property from the wiki-page of the property
if (class_exists('SMWDIProperty')) {
$wiki_page = new SMWDIWikiPage($page_title, $page_namespace, null);
$property = SMWDIProperty::newFromUserLabel($property_page->getTitle()->getText());
} else {
$wiki_page = SMWDataValueFactory::newTypeIDValue('_wpg', $page_title);
$property = SMWPropertyValue::makeProperty($property_page->getTitle()->getText());
}
$res = $store->getPropertySubjects($property, $wiki_page, $options);
$num = count($res);
if ($num > 0) {
$grouping_label = str_replace(' ', '_', $grouping_label);
$text .= "<{$grouping_label}>\n";
foreach ($res as $subject) {
$subject_title = $subject->getTitle();
$text .= self::getXMLForPage($subject_title, $simplified_format, $groupings, $depth + 1);
}
$text .= "</{$grouping_label}>\n";
}
}
}
$text .= "</{$page_str}>\n";
// escape back the curly brackets that were escaped out at the beginning
$text = str_replace('&#123;', '{', $text);
$text = str_replace('&#125;', '}', $text);
return $text;
}
示例14: getSemanticWebData
/**
*
* Similar to getSemanticData(), but in this case regarding the Semantic Web.
* @param String $uri
*/
private function getSemanticWebData( $graph, $uri ) {
// Several possibilities: URI with redirect to RDF, URL with RDFa (but talking about what?),...
// $data is of type SMWSemanticData
$semanticDataResult = new SMWSemanticData( $this->subject->getDataItem() );
// I want to show all incoming and outcoming links
// ...ideally in the same style
// Get the representation of the URI
$theResource = $graph->resource( $uri );
// Outgoing
$theOutgoingProperties = $graph->propertyUris( $theResource );
// for each, ask for the objects
foreach ( $theOutgoingProperties as $outProp ) {
$outPropResult = $this->getArrayObjects( $graph, $theResource, $outProp );
// now, we have the subject, the property, the object (uri/literal)
foreach ( $outPropResult as $outPropObject ) {
/*
* The question now is, what kind of propert.
* If there is a page in the wiki, we simply use it as property.
* Otherwise, we need to invent a new page with the URI as name
*/
$uriPageName = $this->getInternalMapping( $outProp );
$dataProperty = null;
if ( !isset( $uriPageName ) || $uriPageName == null) {
// There is no, we create a new property page
/*
* TODO: maybe register new property type that can display the property more
* conveniently, e.g., with browse further: smwInitProperties
*/
$dataProperty = SMWDIProperty::newFromUserLabel( $outProp );
} else {
$dataProperty = SMWDIProperty::newFromUserLabel( $uriPageName );
}
// SMWDataItem, we only distinguish uri and literal
// TODO: Maybe distinguish more, later, e.g., language
$dataValue = null;
if ( $outPropObject["type"] == "uri" ) {
/*
* If there is a page in the wiki with the value as equivalent URI, we
* just use this page.
*/
$uriPageName = $this->getInternalMapping( $outPropObject["value"] );
if ( !isset( $uriPageName ) && $uriPageName == null ) {
// URI value
$dataValue = SMWDataValueFactory::newTypeIDValue( '_rur', $outPropObject["value"], $property = $dataProperty );
} else {
$dataValue = SMWDataValueFactory::newTypeIDValue( '_wpg', $uriPageName, $property = $dataProperty );
}
} else {
// literal
$this->debug($outPropObject["value"],"vis:");
$dataValue = SMWDataValueFactory::newTypeIDValue( '_txt', $outPropObject["value"], $property = $dataProperty );
//$dataItem = new SMWDIString($outPropObject["value"]);
}
// some objects have invalid type and print warning triangle instead of object info
//in this case object has class SMWDIError
// in this case this object wouldn't be printed
if( !( get_class( $dataValue->getDataItem() ) == "SMWDIError" ) ){
$semanticDataResult->addPropertyObjectValue( $dataProperty, $dataValue->getDataItem() );
}
}
}
return $semanticDataResult;
}
示例15: getXMLForPage
static function getXMLForPage($title, $simplified_format, $groupings, $depth = 0)
{
if ($depth > 5) {
return "";
}
global $wgContLang, $dtgContLang;
// if this page belongs to the exclusion category, exit
$parent_categories = $title->getParentCategoryTree(array());
$dt_props = $dtgContLang->getPropertyLabels();
// $exclusion_category = $title->newFromText($dt_props[DT_SP_IS_EXCLUDED_FROM_XML], NS_CATEGORY);
$exclusion_category = $wgContLang->getNSText(NS_CATEGORY) . ':' . str_replace(' ', '_', $dt_props[DT_SP_IS_EXCLUDED_FROM_XML]);
if (self::treeContainsElement($parent_categories, $exclusion_category)) {
return "";
}
$pageStructure = DTPageStructure::newFromTitle($title);
$text = $pageStructure->toXML($simplified_format);
// handle groupings, if any apply here; first check if SMW is installed
global $smwgIP;
if (isset($smwgIP)) {
$store = smwfGetStore();
$page_title = $title->getText();
$page_namespace = $title->getNamespace();
// Escaping is needed for SMWSQLStore3 - this may be a bug in SMW.
$escaped_page_title = str_replace(' ', '_', $page_title);
foreach ($groupings as $pair) {
list($property_page, $grouping_label) = $pair;
$options = new SMWRequestOptions();
$options->sort = "subject_title";
// get actual property from the wiki-page of the property
if (class_exists('SMWDIProperty')) {
$wiki_page = new SMWDIWikiPage($escaped_page_title, $page_namespace, null);
$property = SMWDIProperty::newFromUserLabel($property_page->getTitle()->getText());
} else {
$wiki_page = SMWDataValueFactory::newTypeIDValue('_wpg', $escaped_page_title);
$property = SMWPropertyValue::makeProperty($property_page->getTitle()->getText());
}
$res = $store->getPropertySubjects($property, $wiki_page, $options);
$num = count($res);
if ($num > 0) {
$grouping_label = str_replace(' ', '_', $grouping_label);
$text .= "<{$grouping_label}>\n";
foreach ($res as $subject) {
$subject_title = $subject->getTitle();
$text .= self::getXMLForPage($subject_title, $simplified_format, $groupings, $depth + 1);
}
$text .= "</{$grouping_label}>\n";
}
}
}
// escape back the curly brackets that were escaped out at the beginning
$text = str_replace('&#123;', '{', $text);
$text = str_replace('&#125;', '}', $text);
return $text;
}