http://www.mediawiki.org/wiki/Special:Code/MediaWiki/60534
Revision: 60534 Author: mkroetzsch Date: 2010-01-01 14:42:51 +0000 (Fri, 01 Jan 2010) Log Message: ----------- allow null subjects; added getHash() function that will be useful for avoiding DB writes if data did not change Modified Paths: -------------- trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php =================================================================== --- trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php 2010-01-01 01:35:37 UTC (rev 60533) +++ trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php 2010-01-01 14:42:51 UTC (rev 60534) @@ -39,9 +39,10 @@ static protected $m_propertyprefix = false; /// SMWWikiPageValue object that is the subject of this container. + /// Subjects that are NULL are used to represent "internal objects" only. protected $subject; - public function __construct(SMWWikiPageValue $subject, $noduplicates = true) { + public function __construct($subject, $noduplicates = true) { $this->subject = $subject; $this->m_noduplicates = $noduplicates; $this->stubobject = false; @@ -102,6 +103,25 @@ } /** + * Generate a hash value to simplify the comparison of this data container with other + * containers. The hash uses PHP's md5 implementation, which is among the fastest hash + * algorithms that PHP offers. + */ + public function getHash() { + $ctx = hash_init('md5'); + if ($this->subject !== NULL) { // here and below, use "_#_" to separate values; really not much care needed here + hash_update($ctx, '_#_' . $this->subject->getHash()); + } + foreach ($this->getProperties() as $property) { + hash_update($ctx, '_#_' . $property->getHash() . '##'); + foreach ($this->getPropertyValues($property) as $dv) { + hash_update($ctx, '_#_' . $dv->getHash()); + } + } + return hash_final($ctx); + } + + /** * Return true if there are any visible properties. * @note While called "visible" this check actually refers to the function * SMWPropertyValue::isShown(). The name is kept for compatibility. _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs