r88499 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88498‎ | r88499 | r88500 >
Date:22:38, 20 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added option to remove data associated with a certain property from semanticdata and propertychanges
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php
@@ -135,8 +135,20 @@
136136 }
137137
138138 $this->addPropertyObjectChange( $property, $change );
139 - }
 139+ }
140140
 141+ /**
 142+ * Removes all changes for a certian property.
 143+ *
 144+ * @param SMWDIProperty $property
 145+ */
 146+ public function removeChangesForProperty( SMWDIProperty $property ) {
 147+ if ( array_key_exists( $property->getKey(), $this->changes ) ) {
 148+ unset( $this->changes[$property->getKey()] );
 149+ unset( $this->properties[$property->getKey()] );
 150+ }
 151+ }
 152+
141153 function rewind() {
142154 $this->pos = 0;
143155 $this->currentRow = null;
@@ -161,6 +173,6 @@
162174
163175 function valid() {
164176 return $this->current() !== false;
165 - }
 177+ }
166178
167179 }
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
@@ -198,7 +198,8 @@
199199 *
200200 * @return boolean
201201 */
202 - public function hasVisibleProperties() {
 202+ public function hasVisibleProperties( $refresh = false ) {
 203+ if ( $refresh ) $this->findVisibleProperties();
203204 return $this->mHasVisibleProps;
204205 }
205206
@@ -212,7 +213,8 @@
213214 *
214215 * @return boolean
215216 */
216 - public function hasVisibleSpecialProperties() {
 217+ public function hasVisibleSpecialProperties( $refresh = false ) {
 218+ if ( $refresh ) $this->findVisibleProperties();
217219 return $this->mHasVisibleSpecs;
218220 }
219221
@@ -284,6 +286,47 @@
285287 }
286288
287289 /**
 290+ * Removes all DIs for the specified property.
 291+ * NOTE: calling this method can lead to false positive mHasVisibleProps and mHasVisibleSpecs.
 292+ * Call findVisibleProperties to fix this if needed.
 293+ *
 294+ * @since 1.6
 295+ *
 296+ * @param SMWDIProperty $property
 297+ */
 298+ public function removeDataForProperty( SMWDIProperty $property ) {
 299+ var_dump($property);exit;
 300+ if ( array_key_exists( $property->getKey(), $this->mPropVals ) ) {
 301+ unset( $this->mPropVals[$property->getKey()] );
 302+ }
 303+ if ( array_key_exists( $property->getKey(), $this->mProperties ) ) {
 304+ unset( $this->mProperties[$property->getKey()] );
 305+ }
 306+ }
 307+
 308+ /**
 309+ * Determine if there are visible properties and special properties.
 310+ *
 311+ * @since 1.6
 312+ */
 313+ public function findVisibleProperties() {
 314+ $this->mHasVisibleSpecs = false;
 315+ $this->mHasVisibleProps = false;
 316+
 317+ foreach ( $this->mProperties as /* SMWDIProperty */ $property ) {
 318+ if ( !$property->isUserDefined() ) {
 319+ if ( $property->isShown() ) {
 320+ $this->mHasVisibleSpecs = true;
 321+ $this->mHasVisibleProps = true;
 322+ break;
 323+ }
 324+ } else {
 325+ $this->mHasVisibleProps = true;
 326+ }
 327+ }
 328+ }
 329+
 330+ /**
288331 * Delete all data other than the subject.
289332 */
290333 public function clear() {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php
@@ -171,12 +171,14 @@
172172 /**
173173 * Returns whether the set contains any changes.
174174 *
 175+ * @param boolean $refresh
 176+ *
175177 * @return boolean
176178 */
177 - public function hasChanges() {
 179+ public function hasChanges( $refresh = false ) {
178180 return $this->changes->hasChanges()
179 - || $this->insertions->hasVisibleProperties()
180 - || $this->deletions->hasVisibleProperties();
 181+ || $this->insertions->hasVisibleProperties( $refresh )
 182+ || $this->deletions->hasVisibleProperties( $refresh );
181183 }
182184
183185 /**
@@ -236,8 +238,8 @@
237239 }
238240
239241 /**
 242+ * Returns a list of all properties.
240243 *
241 - *
242244 * @return array of SMWDIProperty
243245 */
244246 public function getAllProperties() {
@@ -249,6 +251,17 @@
250252 }
251253
252254 /**
 255+ * Removes all changes for a certian property.
 256+ *
 257+ * @param SMWDIProperty $property
 258+ */
 259+ public function removeChangesForProperty( SMWDIProperty $property ) {
 260+ $this->getChanges()->removeChangesForProperty( $property );
 261+ $this->getInsertions()->removeDataForProperty( $property );
 262+ $this->getDeletions()->removeDataForProperty( $property );
 263+ }
 264+
 265+ /**
253266 * Returns a list of ALL changes, including isertions and deletions.
254267 *
255268 * @param SMWDIProperty $proprety

Status & tagging log