http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88534
Revision: 88534
Author: jeroendedauw
Date: 2011-05-21 19:31:16 +0000 (Sat, 21 May 2011)
Log Message:
-----------
moving the change related stuff to SWL
Modified Paths:
--------------
trunk/extensions/SemanticMediaWiki/SMW_Settings.php
trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
Removed Paths:
-------------
trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php
trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChange.php
trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php
Modified: trunk/extensions/SemanticMediaWiki/SMW_Settings.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/SMW_Settings.php 2011-05-21 19:22:01 UTC
(rev 88533)
+++ trunk/extensions/SemanticMediaWiki/SMW_Settings.php 2011-05-21 19:31:16 UTC
(rev 88534)
@@ -485,11 +485,3 @@
##
$smwgAutoRefreshSubject = true;
##
-
-###
-# Sets whether or not SMW should check if properties where changed and update
only those
-# instead of not checking what changed and simply updating everything.
-# Introduced in SMW 1.6
-##
-$smwgCheckChangesBeforeUpdate = false;
-##
\ No newline at end of file
Deleted: trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php
2011-05-21 19:22:01 UTC (rev 88533)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_ChangeSet.php
2011-05-21 19:31:16 UTC (rev 88534)
@@ -1,289 +0,0 @@
-<?php
-
-/**
- * This class represents a semantic property diff between 2 versions
- * of a single page.
- *
- * @since 1.6
- *
- * @file SMW_ChangeSet.php
- * @ingroup SMW
- *
- * @licence GNU GPL v3 or later
- * @author Jeroen De Dauw < [email protected] >
- */
-class SMWChangeSet {
-
- /**
- * The subject the changes apply to.
- *
- * @var SMWDIWikiPage
- */
- protected $subject;
-
- /**
- * Object holding semantic data that got inserted.
- *
- * @var SMWSemanticData
- */
- protected $insertions;
-
- /**
- * Object holding semantic data that got deleted.
- *
- * @var SMWSemanticData
- */
- protected $deletions;
-
- /**
- * List of all changes(, not including insertions and deletions).
- *
- * @var SMWPropertyChanges
- */
- protected $changes;
-
- /**
- * Creates and returns a new SMWChangeSet from 2 SMWSemanticData
objects.
- *
- * @param SMWSemanticData $old
- * @param SMWSemanticData $new
- *
- * @return SMWChangeSet
- */
- public static function newFromSemanticData( SMWSemanticData $old,
SMWSemanticData $new ) {
- $subject = $old->getSubject();
-
- if ( $subject != $new->getSubject() ) {
- return new self( $subject );
- }
-
- $changes = new SMWPropertyChanges();
- $insertions = new SMWSemanticData( $subject );
- $deletions = new SMWSemanticData( $subject );
-
- $oldProperties = $old->getProperties();
- $newProperties = $new->getProperties();
-
- // Find the deletions.
- self::findSingleDirectionChanges( $deletions, $oldProperties,
$old, $newProperties );
-
- // Find the insertions.
- self::findSingleDirectionChanges( $insertions, $newProperties,
$new, $oldProperties );
-
- foreach ( $oldProperties as $propertyKey => /* SMWDIProperty */
$diProperty ) {
- $oldDataItems = array();
- $newDataItems = array();
-
- // Populate the data item arrays using keys that are
their hash, so matches can be found.
- // Note: this code assumes there are no duplicates.
- foreach ( $old->getPropertyValues( $diProperty ) as /*
SMWDataItem */ $dataItem ) {
- $oldDataItems[$dataItem->getHash()] = $dataItem;
- }
- foreach ( $new->getPropertyValues( $diProperty ) as /*
SMWDataItem */ $dataItem ) {
- $newDataItems[$dataItem->getHash()] = $dataItem;
- }
-
- $foundMatches = array();
-
- // Find values that are both in the old and new version.
- foreach ( array_keys( $oldDataItems ) as $hash ) {
- if ( array_key_exists( $hash, $newDataItems ) )
{
- $foundMatches[] = $hash;
- }
- }
-
- // Remove the values occuring in both sets, so only
changes remain.
- foreach ( $foundMatches as $foundMatch ) {
- unset( $oldDataItems[$foundMatch] );
- unset( $newDataItems[$foundMatch] );
- }
-
- // Find which group is biggest, so it's easy to loop
over all values of the smallest.
- $oldIsBigger = count( $oldDataItems ) > count (
$newDataItems );
- $bigGroup = $oldIsBigger ? $oldDataItems :
$newDataItems;
- $smallGroup = $oldIsBigger ? $newDataItems :
$oldDataItems;
-
- // Add all one-to-one changes.
- while ( $dataItem = array_shift( $smallGroup ) ) {
- $changes->addPropertyObjectChange( $diProperty,
new SMWPropertyChange( $dataItem, array_shift( $bigGroup ) ) );
- }
-
- // If the bigger group is not-equal to the smaller one,
items will be left,
- // that are either insertions or deletions, depending
on the group.
- if ( count( $bigGroup > 0 ) ) {
- $semanticData = $oldIsBigger ? $deletions :
$insertions;
-
- foreach ( $bigGroup as /* SMWDataItem */
$dataItem ) {
- $semanticData->addPropertyObjectValue(
$diProperty, $dataItem );
- }
- }
- }
-
- return new self( $subject, $changes, $insertions, $deletions );
- }
-
- /**
- * Finds the inserts or deletions and adds them to the passed
SMWSemanticData object.
- * These values will also be removed from the first list of properties
and their values,
- * so it can be used for one-to-one change finding later on.
- *
- * @param SMWSemanticData $changeSet
- * @param array $oldProperties
- * @param SMWSemanticData $oldData
- * @param array $newProperties
- */
- protected static function findSingleDirectionChanges( SMWSemanticData
&$changeSet,
- array &$oldProperties, SMWSemanticData $oldData, array
$newProperties ) {
-
- $deletionKeys = array();
-
- foreach ( $oldProperties as $propertyKey => /* SMWDIProperty */
$diProperty ) {
- if ( !array_key_exists( $propertyKey, $newProperties )
) {
- foreach ( $oldData->getPropertyValues(
$diProperty ) as /* SMWDataItem */ $dataItem ) {
- $changeSet->addPropertyObjectValue(
$diProperty, $dataItem );
- }
- $deletionKeys[] = $propertyKey;
- }
- }
-
- foreach ( $deletionKeys as $key ) {
- unset( $oldProperties[$propertyKey] );
- }
- }
-
- /**
- * Create a new instance of a change set.
- *
- * @param SMWDIWikiPage $subject
- * @param SMWPropertyChanges $changes Can be null
- * @param SMWSemanticData $insertions Can be null
- * @param SMWSemanticData $deletions Can be null
- */
- public function __construct( SMWDIWikiPage $subject, /*
SMWPropertyChanges */ $changes = null,
- /* SMWSemanticData */ $insertions = null, /* SMWSemanticData */
$deletions = null ) {
-
- $this->subject = $subject;
- $this->changes = is_null( $changes ) ? new SMWPropertyChanges()
: $changes;
- $this->insertions = is_null( $insertions ) ? new
SMWSemanticData( $subject ): $insertions;
- $this->deletions = is_null( $deletions ) ? new SMWSemanticData(
$subject ): $deletions;
- }
-
- /**
- * Returns whether the set contains any changes.
- *
- * @param boolean $refresh
- *
- * @return boolean
- */
- public function hasChanges( $refresh = false ) {
- return $this->changes->hasChanges()
- || $this->insertions->hasVisibleProperties( $refresh )
- || $this->deletions->hasVisibleProperties( $refresh );
- }
-
- /**
- * Returns a SMWSemanticData object holding all inserted SMWDataItem
objects.
- *
- * @return SMWSemanticData
- */
- public function getInsertions() {
- return $this->insertions;
- }
-
- /**
- * Returns a SMWSemanticData object holding all deleted SMWDataItem
objects.
- *
- * @return SMWSemanticData
- */
- public function getDeletions() {
- return $this->deletions;
- }
-
- /**
- * Returns a SMWPropertyChanges object holding all SMWPropertyChange
objects.
- *
- * @return SMWPropertyChanges
- */
- public function getChanges() {
- return $this->changes;
- }
-
- /**
- * Returns the subject these changes apply to.
- *
- * @return SMWDIWikiPage
- */
- public function getSubject() {
- return $this->subject;
- }
-
- /**
- * Adds a SMWPropertyChange to the set for the specified SMWDIProperty.
- *
- * @param SMWDIProperty $property
- * @param SMWPropertyChange $change
- */
- public function addChange( SMWDIProperty $property, SMWPropertyChange
$change ) {
- switch ( $change->getType() ) {
- case SMWPropertyChange::TYPE_UPDATE:
- $this->changes->addPropertyObjectChange(
$property, $change );
- break;
- case SMWPropertyChange::TYPE_INSERT:
- $this->insertions->addPropertyObjectValue(
$property, $change->getNewValue() );
- break;
- case SMWPropertyChange::TYPE_DELETE:
- $this->deletions->addPropertyObjectValue(
$property, $change->getOldValue() );
- break;
- }
- }
-
- /**
- * Returns a list of all properties.
- *
- * @return array of SMWDIProperty
- */
- public function getAllProperties() {
- return array_merge(
- $this->getChanges()->getProperties(),
- $this->getInsertions()->getProperties(),
- $this->getDeletions()->getProperties()
- );
- }
-
- /**
- * 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
- *
- * @return array of SMWPropertyChange
- */
- public function getAllPropertyChanges( SMWDIProperty $property ) {
- $changes = array();
-
- foreach ( $this->changes->getPropertyChanges( $property ) as /*
SMWPropertyChange */ $change ) {
- $changes[] = $change;
- }
-
- foreach ( $this->insertions->getPropertyValues( $property ) as
/* SMWDataItem */ $dataItem ) {
- $changes[] = new SMWPropertyChange( null, $dataItem );
- }
-
- foreach ( $this->deletions->getPropertyValues( $property ) as
/* SMWDataItem */ $dataItem ) {
- $changes[] = new SMWPropertyChange( $dataItem, null );
- }
-
- return $changes;
- }
-
-}
Deleted: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChange.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChange.php
2011-05-21 19:22:01 UTC (rev 88533)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChange.php
2011-05-21 19:31:16 UTC (rev 88534)
@@ -1,100 +0,0 @@
-<?php
-
-/**
- * Represents a change to a semantic property.
- *
- * @since 1.6
- *
- * @file SMW_PropertyChange.php
- * @ingroup SMW
- *
- * @licence GNU GPL v3 or later
- * @author Jeroen De Dauw < [email protected] >
- */
-class SMWPropertyChange {
-
- const TYPE_INSERT = 0;
- const TYPE_UPDATE = 1;
- const TYPE_DELETE = 2;
-
- /**
- * The old value.
- *
- * @var SMWDataItem or null
- */
- protected $oldValue;
-
- /**
- * The new value.
- *
- * @var SMWDataItem or null
- */
- protected $newValue;
-
- /**
- * Creates and returns a new SMWPropertyChange instance from a
serialization.
- *
- * @param string|null $oldValue
- * @param string|null $newValue
- *
- * @return SMWPropertyChange
- */
- public static function newFromSerialization( SMWDIProperty $property,
$oldValue, $newValue ) {
- $diType = SMWDataValueFactory::getDataItemId(
$property->findPropertyTypeID() );
- //var_dump($property);
- //if($diType!=7) {throw new Exception();exit;}
- return new self(
- is_null( $oldValue ) ? null :
SMWDataItem::newFromSerialization( $diType, $oldValue ),
- is_null( $newValue ) ? null :
SMWDataItem::newFromSerialization( $diType, $newValue )
- );
- }
-
- /**
- * Create a new SMWPropertyChange.
- *
- * @param SMWDataItem $oldValue
- * @param SMWDataItem $newValue
- */
- public function __construct( /* SMWDataItem */ $oldValue, /*
SMWDataItem */ $newValue ) {
- $this->oldValue = $oldValue;
- $this->newValue = $newValue;
- }
-
- /**
- * Retruns the old value, or null if there is none.
- *
- * @return SMWDataItem or null
- */
- public function getOldValue() {
- return $this->oldValue;
- }
-
-
- /**
- * returns the new value, or null if there is none.
- *
- * @return SMWDataItem or null
- */
- public function getNewValue() {
- return $this->newValue;
- }
-
- /**
- * Returns the type of the change.
- *
- * @return element of the SMWPropertyChange::TYPE_ enum
- */
- public function getType() {
- if ( is_null( $this->oldValue ) ) {
- return self::TYPE_INSERT;
- }
- else if ( is_null( $this->newValue ) ) {
- return self::TYPE_DELETE;
- }
- else {
- return self::TYPE_UPDATE;
- }
- }
-
-}
-
\ No newline at end of file
Deleted: trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php
2011-05-21 19:22:01 UTC (rev 88533)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_PropertyChanges.php
2011-05-21 19:31:16 UTC (rev 88534)
@@ -1,178 +0,0 @@
-<?php
-
-/**
- * A collection of semantic properties and changes changes made to them.
- * This class is based on SMWSemanticData and can be seen as a simplified
- * version with SMWPropertyChange objects, each holding 2 SMWDataItem objects,
- * instead of SMWDataItem objects.
- *
- * @since 1.6
- *
- * @file SMW_PropertyChange.php
- * @ingroup SMW
- *
- * @licence GNU GPL v3 or later
- * @author Jeroen De Dauw < [email protected] >
- */
-class SMWPropertyChanges implements Iterator {
-
- protected $pos = 0;
- protected $currentRow = null;
-
- /**
- * Cache for the localized version of the namespace prefix "Property:".
- *
- * @var string
- */
- static protected $propertyPrefix = '';
-
- /**
- * Array mapping property keys (string) to arrays of SMWPropertyChange.
- *
- * @var array of SMWPropertyChange
- */
- protected $changes = array();
-
- /**
- * Array mapping property keys (string) to SMWDIProperty objects.
- *
- * @var array of SMWDIProperty
- */
- protected $properties = array();
-
- /**
- * Indicates if there are changes in the list.
- *
- * @var boolean
- */
- protected $hasChanges = false;
-
- /**
- * Get the array of all properties that have changes.
- *
- * @return array of SMWDIProperty
- */
- public function getProperties() {
- return $this->properties;
- }
-
- /**
- * Returns if the list contains any changes.
- * This info is cached, so the call is cheaper then doing a count.
- *
- * @return boolean
- */
- public function hasChanges() {
- return $this->hasChanges;
- }
-
- /**
- * Get the array of all stored values for some property.
- *
- * @param $property SMWDIProperty
- *
- * @return array of SMWPropertyChange
- */
- public function getPropertyChanges( SMWDIProperty $property ) {
- if ( array_key_exists( $property->getKey(), $this->changes ) ) {
- return $this->changes[$property->getKey()];
- } else {
- return array();
- }
- }
-
- /**
- * Store a value for a property identified by its SMWDataItem object.
- *
- * @note There is no check whether the type of the given data item
- * agrees with the type of the property. Since property types can
- * change, all parts of SMW are prepared to handle mismatched data item
- * types anyway.
- *
- * @param SMWDIProperty $property
- * @param SMWPropertyChange $change
- */
- public function addPropertyObjectChange( SMWDIProperty $property,
SMWPropertyChange $change ) {
- if ( $property->isInverse() ) { // inverse properties cannot be
used for annotation
- return;
- }
-
- if ( !array_key_exists( $property->getKey(), $this->changes ) )
{
- $this->changes[$property->getKey()] = array();
- $this->properties[$property->getKey()] = $property;
- }
-
- $this->changes[$property->getKey()][] = $change;
-
- $this->hasChanges = true;
- }
-
- /**
- * Store a value for a given property identified by its text label
- * (without namespace prefix).
- *
- * @param string $propertyName
- * @param SMWPropertyChange $change
- */
- public function addPropertyChange( $propertyName, SMWPropertyChange
$change ) {
- $propertyKey = smwfNormalTitleDBKey( $propertyName );
-
- if ( array_key_exists( $propertyKey, $this->properties ) ) {
- $property = $this->properties[$propertyKey];
- } else {
- if ( self::$propertyPrefix == '' ) {
- global $wgContLang;
- self::$propertyPrefix = $wgContLang->getNsText(
SMW_NS_PROPERTY ) . ':';
- } // explicitly use prefix to cope with things like
[[Property:User:Stupid::somevalue]]
-
- $propertyDV = SMWPropertyValue::makeUserProperty(
self::$propertyPrefix . $propertyName );
-
- if ( !$propertyDV->isValid() ) { // error, maybe
illegal title text
- return;
- }
-
- $property = $propertyDV->getDataItem();
- }
-
- $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;
- }
-
- function current() {
- if ( is_null( $this->currentRow ) ) {
- $this->next();
- }
- return $this->currentRow;
- }
-
- function key() {
- return $this->pos;
- }
-
- function next() {
- $this->pos++;
- $this->currentRow = array_key_exists( $this->pos,
$this->changes ) ? $this->changes[$this->pos] : false;
- return $this->currentRow;
- }
-
- function valid() {
- return $this->current() !== false;
- }
-
-}
\ No newline at end of file
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php 2011-05-21
19:22:01 UTC (rev 88533)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php 2011-05-21
19:31:16 UTC (rev 88534)
@@ -100,7 +100,6 @@
// Set up autoloading; essentially all classes should be autoloaded!
$incDir = $smwgIP . 'includes/';
- $wgAutoloadClasses['SMWChangeSet'] = $incDir .
'SMW_ChangeSet.php';
$wgAutoloadClasses['SMWCompatibilityHelpers'] = $incDir .
'SMW_CompatibilityHelpers.php';
$wgAutoloadClasses['SMWDataValueFactory'] = $incDir .
'SMW_DataValueFactory.php';
$wgAutoloadClasses['SMWFactbox'] = $incDir .
'SMW_Factbox.php';
@@ -108,8 +107,6 @@
$wgAutoloadClasses['SMWOutputs'] = $incDir .
'SMW_Outputs.php';
$wgAutoloadClasses['SMWParseData'] = $incDir .
'SMW_ParseData.php';
$wgAutoloadClasses['SMWParserExtensions'] = $incDir .
'SMW_ParserExtensions.php';
- $wgAutoloadClasses['SMWPropertyChange'] = $incDir .
'SMW_PropertyChange.php';
- $wgAutoloadClasses['SMWPropertyChanges'] = $incDir .
'SMW_PropertyChanges.php';
$wgAutoloadClasses['SMWQueryLanguage'] = $incDir .
'SMW_QueryLanguage.php';
$wgAutoloadClasses['SMWSemanticData'] = $incDir .
'SMW_SemanticData.php';
$wgAutoloadClasses['SMWPageLister'] = $incDir .
'SMW_PageLister.php';
Modified: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
2011-05-21 19:22:01 UTC (rev 88533)
+++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
2011-05-21 19:31:16 UTC (rev 88534)
@@ -283,16 +283,6 @@
public function updateData( SMWSemanticData $data ) {
wfRunHooks( 'SMWStore::updateDataBefore', array( $this, $data )
);
- global $smwgCheckChangesBeforeUpdate;
- if ( $smwgCheckChangesBeforeUpdate &&
$data->hasVisibleProperties() ) {
- $oldData = $this->getSemanticData( $data->getSubject()
);
- $changeSet = SMWChangeSet::newFromSemanticData(
$oldData, $data );
-
- if ( $changeSet->hasChanges() ) {
- wfRunHooks( 'SMWStore::dataChanged', array(
$this, $changeSet ) );
- }
- }
-
// Invalidate the page, so data stored on it gets displayed
immediately in queries.
global $smwgAutoRefreshSubject;
if ( $smwgAutoRefreshSubject && !wfReadOnly() ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs