示例#1
0
 /**
  * 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));
 }
	/**
	 * 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 )
		);
	}
 /**
  * Retrieve the id of the property table that is to be used for storing
  * values for the given property object.
  *
  * @param $diProperty SMWDIProperty
  * @return string
  */
 public static function findPropertyTableID(SMWDIProperty $diProperty)
 {
     $propertyKey = $diProperty->getKey();
     if (array_key_exists($propertyKey, self::$special_tables)) {
         return self::$special_tables[$propertyKey];
     } else {
         return self::findTypeTableId($diProperty->findPropertyTypeID());
     }
 }
示例#4
0
 /**
  * Retrieve the id of the property table that is to be used for storing
  * values for the given property object.
  *
  * @since 1.8
  * @param SMWDIProperty $diProperty
  * @return string
  */
 public static function findPropertyTableID(SMWDIProperty $diProperty)
 {
     $propertyKey = $diProperty->getKey();
     // This is needed to initialize the $fixedPropertyTableIds field
     self::getPropertyTables();
     if (array_key_exists($propertyKey, self::$fixedPropertyTableIds)) {
         return self::$fixedPropertyTableIds[$propertyKey];
     } else {
         return self::findTypeTableId($diProperty->findPropertyTypeID());
     }
 }
 /**
  * @see SMWStore::getPropertySubjects
  *
  * @todo This method cannot retrieve subjects for sortkeys, i.e., for
  * property _SKEY. Only empty arrays will be returned there.
  *
  * @param SMWDIProperty $property
  * @param SMWDataItem|null $value
  * @param SMWRequestOptions|null $requestOptions
  *
  * @return array of DIWikiPage
  */
 public function getPropertySubjects(SMWDIProperty $property, SMWDataItem $value = null, SMWRequestOptions $requestOptions = null)
 {
     /// TODO: should we share code with #ask query computation here? Just use queries?
     if ($property->isInverse()) {
         // inverses are working differently
         $noninverse = new SMW\DIProperty($property->getKey(), false);
         $result = $this->getPropertyValues($value, $noninverse, $requestOptions);
         return $result;
     }
     // #1222, Filter those where types don't match (e.g property = _txt
     // and value = _wpg)
     if ($value !== null && DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID()) !== $value->getDIType()) {
         return array();
     }
     // First build $select, $from, and $where for the DB query
     $where = $from = '';
     $pid = $this->store->smwIds->getSMWPropertyID($property);
     $tableid = $this->store->findPropertyTableID($property);
     if ($pid == 0 || $tableid === '') {
         return array();
     }
     $proptables = $this->store->getPropertyTables();
     $proptable = $proptables[$tableid];
     $db = $this->store->getConnection();
     if ($proptable->usesIdSubject()) {
         // join with ID table to get title data
         $from = $db->tableName(SMWSql3SmwIds::TABLE_NAME) . " INNER JOIN " . $db->tableName($proptable->getName()) . " AS t1 ON t1.s_id=smw_id";
         $select = 'smw_title, smw_namespace, smw_iw, smw_sortkey, smw_subobject';
     } else {
         // no join needed, title+namespace as given in proptable
         $from = $db->tableName($proptable->getName()) . " AS t1";
         $select = 's_title AS smw_title, s_namespace AS smw_namespace, \'\' AS smw_iw, s_title AS smw_sortkey, \'\' AS smw_subobject';
     }
     if (!$proptable->isFixedPropertyTable()) {
         $where .= ($where ? ' AND ' : '') . "t1.p_id=" . $db->addQuotes($pid);
     }
     $this->prepareValueQuery($from, $where, $proptable, $value, 1);
     // ***  Now execute the query and read the results  ***//
     $result = array();
     if (!$proptable->isFixedPropertyTable()) {
         if ($where !== '' && strpos(SMW_SQL3_SMWIW_OUTDATED, $where) === false) {
             $where .= " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWIW_OUTDATED) . " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWDELETEIW);
         } else {
             $where .= " smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWIW_OUTDATED) . " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWDELETEIW);
         }
     }
     $res = $db->select($from, 'DISTINCT ' . $select, $where . $this->store->getSQLConditions($requestOptions, 'smw_sortkey', 'smw_sortkey', $where !== ''), __METHOD__, $this->store->getSQLOptions($requestOptions, 'smw_sortkey'));
     $diHandler = $this->store->getDataItemHandlerForDIType(SMWDataItem::TYPE_WIKIPAGE);
     foreach ($res as $row) {
         try {
             if ($row->smw_iw === '' || $row->smw_iw[0] != ':') {
                 // filter special objects
                 $result[] = $diHandler->dataItemFromDBKeys(array_values((array) $row));
             }
         } catch (DataItemHandlerException $e) {
             // silently drop data, should be extremely rare and will usually fix itself at next edit
         }
     }
     $db->freeResult($res);
     return $result;
 }
示例#6
0
 /**
  * Create a value for the given property, provided as an SMWDIProperty
  * object. If no value is given, an empty container is created, the
  * value of which can be set later on.
  *
  * @param $property SMWDIProperty property object for which this value is made
  * @param $valueString mixed user value string, or false if unknown
  * @param $caption mixed user-defined caption, or false if none given
  * @param $contextPage SMWDIWikiPage that provides a context for parsing the value string, or null
  *
  * @return SMWDataValue
  */
 public static function newPropertyObjectValue(SMWDIProperty $property, $valueString = false, $caption = false, $contextPage = null)
 {
     $typeId = $property->isInverse() ? '_wpg' : $property->findPropertyTypeID();
     return self::newTypeIdValue($typeId, $valueString, $caption, $property, $contextPage);
 }
 /**
  * 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.');
 }
 /**
  * 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;
     }
 }