Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php |
— | — | @@ -0,0 +1,147 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * A collection of semantic properties and changes changes made to them. |
| 6 | + * This class is based on SMWSemanticData and can be seen as a simplified |
| 7 | + * version with SMWPropertyChange objects, each holding 2 SMWDataItem objects, |
| 8 | + * instead of SMWDataItem objects. |
| 9 | + * |
| 10 | + * @since 1.6 |
| 11 | + * |
| 12 | + * @file SMW_PropertyChange.php |
| 13 | + * @ingroup SMW |
| 14 | + * |
| 15 | + * @licence GNU GPL v3 or later |
| 16 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 17 | + */ |
| 18 | +class SMWPropertyChanges implements Iterator { |
| 19 | + |
| 20 | + protected $pos = 0; |
| 21 | + protected $currentRow = null; |
| 22 | + |
| 23 | + /** |
| 24 | + * Cache for the localized version of the namespace prefix "Property:". |
| 25 | + * |
| 26 | + * @var string |
| 27 | + */ |
| 28 | + static protected $mPropertyPrefix = ''; |
| 29 | + |
| 30 | + /** |
| 31 | + * Array mapping property keys (string) to arrays of SMWPropertyChange. |
| 32 | + * |
| 33 | + * @var array of SMWPropertyChange |
| 34 | + */ |
| 35 | + protected $changes; |
| 36 | + |
| 37 | + /** |
| 38 | + * Array mapping property keys (string) to SMWDIProperty objects. |
| 39 | + * |
| 40 | + * @var array of SMWDIProperty |
| 41 | + */ |
| 42 | + protected $properties; |
| 43 | + |
| 44 | + /** |
| 45 | + * Get the array of all properties that have changes. |
| 46 | + * |
| 47 | + * @return array of SMWDIProperty |
| 48 | + */ |
| 49 | + public function getProperties() { |
| 50 | + return $this->properties; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Get the array of all stored values for some property. |
| 55 | + * |
| 56 | + * @param $property SMWDIProperty |
| 57 | + * |
| 58 | + * @return array of SMWPropertyChange |
| 59 | + */ |
| 60 | + public function getPropertyValues( SMWDIProperty $property ) { |
| 61 | + if ( array_key_exists( $property->getKey(), $this->changes ) ) { |
| 62 | + return $this->mPropVals[$property->getKey()]; |
| 63 | + } else { |
| 64 | + return array(); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Store a value for a property identified by its SMWDataItem object. |
| 70 | + * |
| 71 | + * @note There is no check whether the type of the given data item |
| 72 | + * agrees with the type of the property. Since property types can |
| 73 | + * change, all parts of SMW are prepared to handle mismatched data item |
| 74 | + * types anyway. |
| 75 | + * |
| 76 | + * @param SMWDIProperty $property |
| 77 | + * @param SMWPropertyChange $change |
| 78 | + */ |
| 79 | + public function addPropertyObjectChange( SMWDIProperty $property, SMWPropertyChange $change ) { |
| 80 | + if ( $property->isInverse() ) { // inverse properties cannot be used for annotation |
| 81 | + return; |
| 82 | + } |
| 83 | + |
| 84 | + if ( !array_key_exists( $property->getKey(), $this->changes ) ) { |
| 85 | + $this->changes[$property->getKey()] = array(); |
| 86 | + $this->properties[$property->getKey()] = $property; |
| 87 | + } |
| 88 | + |
| 89 | + $this->changes[$property->getKey()][] = $change; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Store a value for a given property identified by its text label |
| 94 | + * (without namespace prefix). |
| 95 | + * |
| 96 | + * @param string $propertyName |
| 97 | + * @param SMWPropertyChange $change |
| 98 | + */ |
| 99 | + public function addPropertyChange( $propertyName, SMWPropertyChange $change ) { |
| 100 | + $propertyKey = smwfNormalTitleDBKey( $propertyName ); |
| 101 | + |
| 102 | + if ( array_key_exists( $propertyKey, $this->mProperties ) ) { |
| 103 | + $property = $this->mProperties[$propertyKey]; |
| 104 | + } else { |
| 105 | + if ( self::$mPropertyPrefix == '' ) { |
| 106 | + global $wgContLang; |
| 107 | + self::$mPropertyPrefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':'; |
| 108 | + } // explicitly use prefix to cope with things like [[Property:User:Stupid::somevalue]] |
| 109 | + |
| 110 | + $propertyDV = SMWPropertyValue::makeUserProperty( self::$mPropertyPrefix . $propertyName ); |
| 111 | + |
| 112 | + if ( !$propertyDV->isValid() ) { // error, maybe illegal title text |
| 113 | + return; |
| 114 | + } |
| 115 | + |
| 116 | + $property = $propertyDV->getDataItem(); |
| 117 | + } |
| 118 | + |
| 119 | + $this->addPropertyObjectChange( $property, $change ); |
| 120 | + } |
| 121 | + |
| 122 | + function rewind() { |
| 123 | + $this->pos = 0; |
| 124 | + $this->currentRow = null; |
| 125 | + } |
| 126 | + |
| 127 | + function current() { |
| 128 | + if ( is_null( $this->currentRow ) ) { |
| 129 | + $this->next(); |
| 130 | + } |
| 131 | + return $this->currentRow; |
| 132 | + } |
| 133 | + |
| 134 | + function key() { |
| 135 | + return $this->pos; |
| 136 | + } |
| 137 | + |
| 138 | + function next() { |
| 139 | + $this->pos++; |
| 140 | + $this->currentRow = array_key_exists( $this->pos, $this->changes ) ? $this->changes[$this->pos] : false; |
| 141 | + return $this->currentRow; |
| 142 | + } |
| 143 | + |
| 144 | + function valid() { |
| 145 | + return $this->current() !== false; |
| 146 | + } |
| 147 | + |
| 148 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 149 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php |
— | — | @@ -279,8 +279,8 @@ |
280 | 280 | |
281 | 281 | global $smwgCheckChangesBeforeUpdate; |
282 | 282 | if ( $smwgCheckChangesBeforeUpdate && $data->hasVisibleProperties() ) { |
283 | | - // TODO |
284 | | - // wfRunHooks( 'SWLGroupNotify', array( ) ); |
| 283 | + // TODO: create a $newData object by doing a read query |
| 284 | + wfRunHooks( 'SMWStore::dataChanged', array( $this, SMWChangeSet::newFromSemanticData( $data, $data ) ) ); |
285 | 285 | } |
286 | 286 | |
287 | 287 | // Invalidate the page, so data stored on it gets displayed immediately in queries. |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChange.php |
— | — | @@ -0,0 +1,58 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Represents a change to a semantic property. |
| 6 | + * |
| 7 | + * @since 1.6 |
| 8 | + * |
| 9 | + * @file SMW_PropertyChange.php |
| 10 | + * @ingroup SMW |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class SMWPropertyChange { |
| 16 | + |
| 17 | + const TYPE_INSERT = 0; |
| 18 | + const TYPE_UPDATE = 1; |
| 19 | + const TYPE_DELETE = 2; |
| 20 | + |
| 21 | + /** |
| 22 | + * |
| 23 | + * @var SMWDataItem |
| 24 | + */ |
| 25 | + protected $oldValue; |
| 26 | + |
| 27 | + /** |
| 28 | + * |
| 29 | + * @var SMWDataItem |
| 30 | + */ |
| 31 | + protected $newValue; |
| 32 | + |
| 33 | + public function __construct( SMWDataItem $oldValue, SMWDataItem $newValue ) { |
| 34 | + $this->oldValue = $oldValue; |
| 35 | + $this->newValue = $newValue; |
| 36 | + } |
| 37 | + |
| 38 | + public function getOldValue() { |
| 39 | + return $this->oldValue; |
| 40 | + } |
| 41 | + |
| 42 | + public function getNewValue() { |
| 43 | + return $this->newValue; |
| 44 | + } |
| 45 | + |
| 46 | + public function getType() { |
| 47 | + if ( is_null( $this->oldValue ) ) { |
| 48 | + return self::TYPE_INSERT; |
| 49 | + } |
| 50 | + else if ( is_null( $this->newValue ) ) { |
| 51 | + return self::TYPE_DELETE; |
| 52 | + } |
| 53 | + else { |
| 54 | + return self::TYPE_UPDATE; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | +} |
| 59 | + |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChange.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 60 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -99,17 +99,21 @@ |
100 | 100 | $wgExtensionAliasesFiles['SemanticMediaWiki'] = $smwgIP . 'languages/SMW_Aliases.php'; |
101 | 101 | |
102 | 102 | // Set up autoloading; essentially all classes should be autoloaded! |
103 | | - $wgAutoloadClasses['SMWParserExtensions'] = $smwgIP . 'includes/SMW_ParserExtensions.php'; |
104 | | - $wgAutoloadClasses['SMWInfolink'] = $smwgIP . 'includes/SMW_Infolink.php'; |
105 | | - $wgAutoloadClasses['SMWFactbox'] = $smwgIP . 'includes/SMW_Factbox.php'; |
106 | | - $wgAutoloadClasses['SMWParseData'] = $smwgIP . 'includes/SMW_ParseData.php'; |
107 | | - $wgAutoloadClasses['SMWOutputs'] = $smwgIP . 'includes/SMW_Outputs.php'; |
108 | | - $wgAutoloadClasses['SMWSemanticData'] = $smwgIP . 'includes/SMW_SemanticData.php'; |
109 | | - $wgAutoloadClasses['SMWResultPrinter'] = $smwgIP . 'includes/SMW_QueryPrinter.php'; |
110 | | - $wgAutoloadClasses['SMWDataValueFactory'] = $smwgIP . 'includes/SMW_DataValueFactory.php'; |
111 | | - $wgAutoloadClasses['SMWDataValue'] = $smwgIP . 'includes/SMW_DataValue.php'; |
112 | | - $wgAutoloadClasses['SMWQueryLanguage'] = $smwgIP . 'includes/SMW_QueryLanguage.php'; |
113 | | - $wgAutoloadClasses['SMWCompatibilityHelpers'] = $smwgIP . 'includes/SMW_CompatibilityHelpers.php'; |
| 103 | + $incDir = $smwgIP . 'includes/'; |
| 104 | + $wgAutoloadClasses['SMWChangeSet'] = $incDir . 'SMW_ChangeSet.php'; |
| 105 | + $wgAutoloadClasses['SMWCompatibilityHelpers'] = $incDir . 'SMW_CompatibilityHelpers.php'; |
| 106 | + $wgAutoloadClasses['SMWDataValue'] = $incDir . 'SMW_DataValue.php'; |
| 107 | + $wgAutoloadClasses['SMWDataValueFactory'] = $incDir . 'SMW_DataValueFactory.php'; |
| 108 | + $wgAutoloadClasses['SMWFactbox'] = $incDir . 'SMW_Factbox.php'; |
| 109 | + $wgAutoloadClasses['SMWInfolink'] = $incDir . 'SMW_Infolink.php'; |
| 110 | + $wgAutoloadClasses['SMWOutputs'] = $incDir . 'SMW_Outputs.php'; |
| 111 | + $wgAutoloadClasses['SMWParseData'] = $incDir . 'SMW_ParseData.php'; |
| 112 | + $wgAutoloadClasses['SMWParserExtensions'] = $incDir . 'SMW_ParserExtensions.php'; |
| 113 | + $wgAutoloadClasses['SMWPropertyChange'] = $incDir . 'SMW_PropertyChange.php'; |
| 114 | + $wgAutoloadClasses['SMWPropertyChanges'] = $incDir . 'SMW_PropertyChanges.php'; |
| 115 | + $wgAutoloadClasses['SMWQueryLanguage'] = $incDir . 'SMW_QueryLanguage.php'; |
| 116 | + $wgAutoloadClasses['SMWResultPrinter'] = $incDir . 'SMW_QueryPrinter.php'; |
| 117 | + $wgAutoloadClasses['SMWSemanticData'] = $incDir . 'SMW_SemanticData.php'; |
114 | 118 | |
115 | 119 | // Article pages |
116 | 120 | $apDir = $smwgIP . 'includes/articlepages/'; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php |
— | — | @@ -0,0 +1,139 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * |
| 6 | + * |
| 7 | + * @since 1.6 |
| 8 | + * |
| 9 | + * @file SMW_ChangeSet.php |
| 10 | + * @ingroup SMW |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class SMWChangeSet { |
| 16 | + |
| 17 | + /** |
| 18 | + * |
| 19 | + * |
| 20 | + * @var SMWDIWikiPage |
| 21 | + */ |
| 22 | + protected $subject; |
| 23 | + |
| 24 | + /** |
| 25 | + * |
| 26 | + * |
| 27 | + * @var SMWSemanticData |
| 28 | + */ |
| 29 | + protected $insertions; |
| 30 | + |
| 31 | + /** |
| 32 | + * |
| 33 | + * |
| 34 | + * @var SMWSemanticData |
| 35 | + */ |
| 36 | + protected $deletions; |
| 37 | + |
| 38 | + /** |
| 39 | + * List of all changes(, not including insertions and deletions). |
| 40 | + * |
| 41 | + * @var SMWPropertyChanges |
| 42 | + */ |
| 43 | + protected $changes; |
| 44 | + |
| 45 | + /** |
| 46 | + * |
| 47 | + * @param SMWSemanticData $old |
| 48 | + * @param SMWSemanticData $new |
| 49 | + * |
| 50 | + * @return SMWChangeSet |
| 51 | + */ |
| 52 | + public static function newFromSemanticData( SMWSemanticData $old, SMWSemanticData $new ) { |
| 53 | + $subject = $old->getSubject(); |
| 54 | + |
| 55 | + if ( $subject != $new->getSubject() ) { |
| 56 | + return new self( $subject ); |
| 57 | + } |
| 58 | + |
| 59 | + $changes = new SMWPropertyChanges(); |
| 60 | + $insertions = new SMWSemanticData( $subject ); |
| 61 | + $deletions = new SMWSemanticData( $subject ); |
| 62 | + |
| 63 | + $oldProperties = $old->getProperties(); |
| 64 | + $newProperties = $new->getProperties(); |
| 65 | + |
| 66 | + // Find the deletions. |
| 67 | + self::findSingleDirectionChanges( $deletions, $oldProperties, $newProperties ); |
| 68 | + |
| 69 | + // Find the insertions. |
| 70 | + self::findSingleDirectionChanges( $insertions, $newProperties, $oldProperties ); |
| 71 | + |
| 72 | + // TODO: find one-to-one changes |
| 73 | + |
| 74 | + return new self( $subject, $changes, $insertions, $deletions ); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Finds the inserts or deletions and adds them to the passed SMWSemanticData object. |
| 79 | + * These values will also be removed from the first list of properties and their values, |
| 80 | + * so it can be used for one-to-one change finding later on. |
| 81 | + * |
| 82 | + * @param SMWSemanticData $changeSet |
| 83 | + * @param array $oldProperties |
| 84 | + * @param array $newProperties |
| 85 | + */ |
| 86 | + protected static function findSingleDirectionChanges( SMWSemanticData &$changeSet, array &$oldProperties, array $newProperties ) { |
| 87 | + $deletionKeys = array(); |
| 88 | + |
| 89 | + foreach ( $oldProperties as $propertyKey => /* SMWDIProperty */ $diProperty ) { |
| 90 | + if ( !array_key_exists( $propertyKey, $newProperties ) ) { |
| 91 | + foreach ( $old->getPropertyValues( $diProperty ) as /* SMWDataItem */ $dataItem ) { |
| 92 | + $changeSet->addPropertyObjectValue( $diProperty, $dataItem ); |
| 93 | + } |
| 94 | + $deletionKeys[] = $propertyKey; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + foreach ( $deletionKeys as $key ) { |
| 99 | + unset( $oldProperties[$propertyKey] ); |
| 100 | + } |
| 101 | + |
| 102 | + // TODO: handle props with multiple values (of which only some got inserted/removed) correctly |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Create a new instance of a change set. |
| 107 | + * |
| 108 | + * @param SMWDIWikiPage $subject |
| 109 | + * @param array $changes Can be null |
| 110 | + * @param SMWSemanticData $insertions Can be null |
| 111 | + * @param SMWSemanticData $deletions Can be null |
| 112 | + */ |
| 113 | + public function __construct( SMWDIWikiPage $subject, |
| 114 | + /* SMWSemanticData */ SMWPropertyChanges $changes = null, $insertions = null, /* SMWSemanticData */ $deletions = null ) { |
| 115 | + |
| 116 | + $this->subject = $subject; |
| 117 | + $this->changes = is_null( $changes ) ? new SMWPropertyChanges() : $changes; |
| 118 | + $this->insertions = is_null( $insertions ) ? new SMWSemanticData( $subject ): $insertions; |
| 119 | + $this->deletions = is_null( $deletions ) ? new SMWSemanticData( $subject ): $deletions; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Returns a list of ALL changes, including isertions and deletions. |
| 124 | + * |
| 125 | + * @return array of |
| 126 | + */ |
| 127 | + public function getAllChanges() { |
| 128 | + return array(); // TODO: implement |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Returns the subject these changes apply to. |
| 133 | + * |
| 134 | + * @return SMWDIWikiPage |
| 135 | + */ |
| 136 | + public function getSubject() { |
| 137 | + return $this->subject; |
| 138 | + } |
| 139 | + |
| 140 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 141 | + native |