r60534 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60533‎ | r60534 | r60535 >
Date:14:42, 1 January 2010
Author:mkroetzsch
Status:deferred
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
@@ -39,9 +39,10 @@
4040 static protected $m_propertyprefix = false;
4141
4242 /// SMWWikiPageValue object that is the subject of this container.
 43+ /// Subjects that are NULL are used to represent "internal objects" only.
4344 protected $subject;
4445
45 - public function __construct(SMWWikiPageValue $subject, $noduplicates = true) {
 46+ public function __construct($subject, $noduplicates = true) {
4647 $this->subject = $subject;
4748 $this->m_noduplicates = $noduplicates;
4849 $this->stubobject = false;
@@ -102,6 +103,25 @@
103104 }
104105
105106 /**
 107+ * Generate a hash value to simplify the comparison of this data container with other
 108+ * containers. The hash uses PHP's md5 implementation, which is among the fastest hash
 109+ * algorithms that PHP offers.
 110+ */
 111+ public function getHash() {
 112+ $ctx = hash_init('md5');
 113+ if ($this->subject !== NULL) { // here and below, use "_#_" to separate values; really not much care needed here
 114+ hash_update($ctx, '_#_' . $this->subject->getHash());
 115+ }
 116+ foreach ($this->getProperties() as $property) {
 117+ hash_update($ctx, '_#_' . $property->getHash() . '##');
 118+ foreach ($this->getPropertyValues($property) as $dv) {
 119+ hash_update($ctx, '_#_' . $dv->getHash());
 120+ }
 121+ }
 122+ return hash_final($ctx);
 123+ }
 124+
 125+ /**
106126 * Return true if there are any visible properties.
107127 * @note While called "visible" this check actually refers to the function
108128 * SMWPropertyValue::isShown(). The name is kept for compatibility.

Status & tagging log