http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88499

Revision: 88499
Author:   jeroendedauw
Date:     2011-05-20 22:38:41 +0000 (Fri, 20 May 2011)
Log Message:
-----------
added option to remove data associated with a certain property from 
semanticdata and propertychanges

Modified Paths:
--------------
    trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php       
2011-05-20 22:27:05 UTC (rev 88498)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php       
2011-05-20 22:38:41 UTC (rev 88499)
@@ -171,12 +171,14 @@
        /**
         * Returns whether the set contains any changes.
         * 
+        * @param boolean $refresh
+        * 
         * @return boolean
         */
-       public function hasChanges() {
+       public function hasChanges( $refresh = false ) {
                return $this->changes->hasChanges()
-                       || $this->insertions->hasVisibleProperties()
-                       || $this->deletions->hasVisibleProperties();
+                       || $this->insertions->hasVisibleProperties( $refresh )
+                       || $this->deletions->hasVisibleProperties( $refresh );
        }
        
        /**
@@ -236,8 +238,8 @@
        }
        
        /**
+        * Returns a list of all properties.
         * 
-        * 
         * @return array of SMWDIProperty
         */
        public function getAllProperties() {
@@ -249,6 +251,17 @@
        }
        
        /**
+        * Removes all changes for a certian property.
+        * 
+        * @param SMWDIProperty $property
+        */
+       public function removeChangesForProperty( SMWDIProperty $property ) {
+               $this->getChanges()->removeChangesForProperty( $property );
+               $this->getInsertions()->removeDataForProperty( $property );
+               $this->getDeletions()->removeDataForProperty( $property );
+       }
+       
+       /**
         * Returns a list of ALL changes, including isertions and deletions.
         * 
         * @param SMWDIProperty $proprety

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php 
2011-05-20 22:27:05 UTC (rev 88498)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php 
2011-05-20 22:38:41 UTC (rev 88499)
@@ -135,8 +135,20 @@
                }
 
                $this->addPropertyObjectChange( $property, $change );
-       }       
+       }
        
+       /**
+        * Removes all changes for a certian property.
+        * 
+        * @param SMWDIProperty $property
+        */
+       public function removeChangesForProperty( SMWDIProperty $property ) {
+               if ( array_key_exists( $property->getKey(), $this->changes ) ) {
+                       unset( $this->changes[$property->getKey()] );
+                       unset( $this->properties[$property->getKey()] );
+               }
+       }
+       
        function rewind() {
                $this->pos = 0;
                $this->currentRow = null;
@@ -161,6 +173,6 @@
 
        function valid() {
                return $this->current() !== false;
-       }       
+       }
        
 }
\ No newline at end of file

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php    
2011-05-20 22:27:05 UTC (rev 88498)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php    
2011-05-20 22:38:41 UTC (rev 88499)
@@ -198,7 +198,8 @@
         *
         * @return boolean
         */
-       public function hasVisibleProperties() {
+       public function hasVisibleProperties( $refresh = false ) {
+               if ( $refresh ) $this->findVisibleProperties();
                return $this->mHasVisibleProps;
        }
 
@@ -212,7 +213,8 @@
         *
         * @return boolean
         */
-       public function hasVisibleSpecialProperties() {
+       public function hasVisibleSpecialProperties( $refresh = false ) {
+               if ( $refresh ) $this->findVisibleProperties();
                return $this->mHasVisibleSpecs;
        }
 
@@ -284,6 +286,47 @@
        }
 
        /**
+        * Removes all DIs for the specified property.
+        * NOTE: calling this method can lead to false positive 
mHasVisibleProps and mHasVisibleSpecs.
+        * Call findVisibleProperties to fix this if needed.
+        * 
+        * @since 1.6
+        * 
+        * @param SMWDIProperty $property
+        */
+       public function removeDataForProperty( SMWDIProperty $property ) {
+               var_dump($property);exit;
+               if ( array_key_exists( $property->getKey(), $this->mPropVals ) 
) {
+                       unset( $this->mPropVals[$property->getKey()] );
+               }
+               if ( array_key_exists( $property->getKey(), $this->mProperties 
) ) {
+                       unset( $this->mProperties[$property->getKey()] );
+               }
+       }
+       
+       /**
+        * Determine if there are visible properties and special properties.
+        * 
+        * @since 1.6
+        */
+       public function findVisibleProperties() {
+               $this->mHasVisibleSpecs = false;
+               $this->mHasVisibleProps = false;
+               
+               foreach ( $this->mProperties as /* SMWDIProperty */ $property ) 
{
+                       if ( !$property->isUserDefined() ) {
+                               if ( $property->isShown() ) {
+                                       $this->mHasVisibleSpecs = true;
+                                       $this->mHasVisibleProps = true;
+                                       break;
+                               }
+                       } else {
+                               $this->mHasVisibleProps = true;
+                       }
+               }
+       }
+       
+       /**
         * Delete all data other than the subject.
         */
        public function clear() {


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to