http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88542
Revision: 88542
Author: jeroendedauw
Date: 2011-05-21 19:55:13 +0000 (Sat, 21 May 2011)
Log Message:
-----------
follow up to r88534
Modified Paths:
--------------
trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
Added Paths:
-----------
trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChange.php
trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChanges.php
Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
2011-05-21 19:55:05 UTC (rev 88541)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
2011-05-21 19:55:13 UTC (rev 88542)
@@ -24,8 +24,8 @@
*
* @return true
*/
- public static function onDataChanged( SMWStore $store, SMWChangeSet
$changes ) {
- $changes = new SWLChangeSet( $changes );
+ public static function onDataUpdate( SMWStore $store, SMWSemanticData
$newData ) {
+ $changes = SWLChangeSet::newFromSemanticData(
$store->getSemanticData( $newData->getSubject() ), $newData );
$groups = SWLGroups::getMatchingWatchGroups(
$changes->getTitle() );
$wasInserted = $changes->writeToStore( $groups ) != 0;
@@ -213,6 +213,12 @@
) );
$updater->addExtensionUpdate( array(
'addTable',
+ 'swl_edits_per_group',
+ dirname( __FILE__ ) . '/SemanticWatchlist.sql',
+ true
+ ) );
+ $updater->addExtensionUpdate( array(
+ 'addTable',
'swl_sets_per_group',
dirname( __FILE__ ) . '/SemanticWatchlist.sql',
true
Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.php 2011-05-21
19:55:05 UTC (rev 88541)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.php 2011-05-21
19:55:13 UTC (rev 88542)
@@ -66,6 +66,8 @@
$wgAutoloadClasses['SWLEmailer'] =
dirname( __FILE__ ) . '/includes/SWL_Emailer.php';
$wgAutoloadClasses['SWLGroup'] =
dirname( __FILE__ ) . '/includes/SWL_Group.php';
$wgAutoloadClasses['SWLGroups']
= dirname( __FILE__ ) . '/includes/SWL_Groups.php';
+$wgAutoloadClasses['SWLPropertyChange'] =
dirname( __FILE__ ) . '/includes/SWL_PropertyChange.php';
+$wgAutoloadClasses['SWLPropertyChanges'] = dirname(
__FILE__ ) . '/includes/SWL_PropertyChanges.php';
$wgAutoloadClasses['SpecialSemanticWatchlist'] = dirname( __FILE__ ) .
'/specials/SpecialSemanticWatchlist.php';
$wgAutoloadClasses['SpecialWatchlistConditions'] = dirname( __FILE__ ) .
'/specials/SpecialWatchlistConditions.php';
@@ -83,7 +85,7 @@
$wgHooks['LoadExtensionSchemaUpdates'][] = 'SWLHooks::onSchemaUpdate';
-$wgHooks['SMWStore::dataChanged'][] = 'SWLHooks::onDataChanged';
+$wgHooks['SMWStore::updateDataBefore'][] = 'SWLHooks::onDataUpdate';
$wgHooks['GetPreferences'][] = 'SWLHooks::onGetPreferences';
Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql 2011-05-21
19:55:05 UTC (rev 88541)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql 2011-05-21
19:55:13 UTC (rev 88542)
@@ -38,6 +38,13 @@
set_time CHAR(14) binary NOT NULL default '' -- The time
the chages where made
) /*$wgDBTableOptions*/;
+-- Links edits to watchlist groups.
+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_edits_per_group (
+ epg_group_id SMALLINT unsigned NOT NULL, -- Foreign key:
swl_groups.group_id
+ epg_edit_id INT(10) unsigned NOT NULL, -- Edit ID
+ PRIMARY KEY (epg_group_id,epg_edit_id)
+) /*$wgDBTableOptions*/;
+
-- Links change sets to watchlist groups.
CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_sets_per_group (
spg_group_id SMALLINT unsigned NOT NULL, -- Foreign key:
swl_groups.group_id
Modified: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
2011-05-21 19:55:05 UTC (rev 88541)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
2011-05-21 19:55:13 UTC (rev 88542)
@@ -15,16 +15,34 @@
class SWLChangeSet {
/**
- * Base object to which calls to unknown methods get routed via __call.
- * This is to emulate SWLChangSet deriving from SMWChangeSet, but at the
- * same time makes it possible to go from the SMW version to the SWL
version
- * by passing the former to the constructor of the later.
+ * The subject the changes apply to.
*
- * @var SMWChangeSet
+ * @var SMWDIWikiPage
*/
- protected $changeSet;
+ 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 SWLPropertyChanges
+ */
+ protected $changes;
+
+ /**
* The user that made the changes.
*
* @var User
@@ -90,7 +108,7 @@
$changeSet->addChange(
$property,
- SMWPropertyChange::newFromSerialization(
$property, $change->change_old_value, $change->change_new_value )
+ SWLPropertyChange::newFromSerialization(
$property, $change->change_old_value, $change->change_new_value )
);
}
@@ -125,7 +143,7 @@
foreach ( $changes as $change ) {
$changeSet->addChange(
$property,
- SMWPropertyChange::newFromSerialization(
+ SWLPropertyChange::newFromSerialization(
$property,
array_key_exists( 'old',
$change ) ? $change['old'] : null,
array_key_exists( 'new',
$change ) ? $change['new'] : null
@@ -145,36 +163,255 @@
}
/**
- * Constructor.
+ * Creates and returns a new SMWChangeSet from 2 SMWSemanticData
objects.
*
- * @since 0.1
+ * @param SMWSemanticData $old
+ * @param SMWSemanticData $new
*
- * @param SMWChangeSet $changeSet
- * @param User $user
- * @param integer $time
- * @param integer $id
+ * @return SMWChangeSet
*/
- public function __construct( SMWChangeSet $changeSet, /* User */ $user
= null, $time = null, $id = null ) {
- $this->changeSet = $changeSet;
+ public static function newFromSemanticData( SMWSemanticData $old,
SMWSemanticData $new ) {
+ $subject = $old->getSubject();
+
+ if ( $subject != $new->getSubject() ) {
+ return new self( $subject );
+ }
+
+ $changes = new SWLPropertyChanges();
+ $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 SWLPropertyChange( $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 SWLPropertyChanges $changes Can be null
+ * @param SMWSemanticData $insertions Can be null
+ * @param SMWSemanticData $deletions Can be null
+ */
+ public function __construct( SMWDIWikiPage $subject, /*
SWLPropertyChanges */ $changes = null,
+ /* SMWSemanticData */ $insertions = null, /* SMWSemanticData */
$deletions = null,
+ /* User */ $user = null, $time = null, $id = null ) {
+
+ $this->subject = $subject;
+ $this->changes = is_null( $changes ) ? new SWLPropertyChanges()
: $changes;
+ $this->insertions = is_null( $insertions ) ? new
SMWSemanticData( $subject ): $insertions;
+ $this->deletions = is_null( $deletions ) ? new SMWSemanticData(
$subject ): $deletions;
+
$this->time = is_null( $time ) ? wfTimestampNow() : $time;
$this->user = is_null( $user ) ? $GLOBALS['wgUser'] : $user;
$this->id = $id;
}
/**
- * SMW thinks this class is a SMWResultPrinter, and calls methods that
should
- * be forewarded to $this->queryPrinter on it.
+ * Returns whether the set contains any changes.
*
- * @since 0.1
+ * @param boolean $refresh
*
- * @param string $name
- * @param array $arguments
+ * @return boolean
*/
- public function __call( $name, array $arguments ) {
- return call_user_func_array( array( $this->changeSet, $name ),
$arguments );
+ 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 SWLPropertyChanges object holding all SWLPropertyChange
objects.
+ *
+ * @return SWLPropertyChanges
+ */
+ public function getChanges() {
+ return $this->changes;
+ }
+
+ /**
+ * Returns the subject these changes apply to.
+ *
+ * @return SMWDIWikiPage
+ */
+ public function getSubject() {
+ return $this->subject;
+ }
+
+ /**
+ * Adds a SWLPropertyChange to the set for the specified SMWDIProperty.
+ *
+ * @param SMWDIProperty $property
+ * @param SWLPropertyChange $change
+ */
+ public function addChange( SMWDIProperty $property, SWLPropertyChange
$change ) {
+ switch ( $change->getType() ) {
+ case SWLPropertyChange::TYPE_UPDATE:
+ $this->changes->addPropertyObjectChange(
$property, $change );
+ break;
+ case SWLPropertyChange::TYPE_INSERT:
+ $this->insertions->addPropertyObjectValue(
$property, $change->getNewValue() );
+ break;
+ case SWLPropertyChange::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 SWLPropertyChange
+ */
+ public function getAllPropertyChanges( SMWDIProperty $property ) {
+ $changes = array();
+
+ foreach ( $this->changes->getPropertyChanges( $property ) as /*
SWLPropertyChange */ $change ) {
+ $changes[] = $change;
+ }
+
+ foreach ( $this->insertions->getPropertyValues( $property ) as
/* SMWDataItem */ $dataItem ) {
+ $changes[] = new SWLPropertyChange( null, $dataItem );
+ }
+
+ foreach ( $this->deletions->getPropertyValues( $property ) as
/* SMWDataItem */ $dataItem ) {
+ $changes[] = new SWLPropertyChange( $dataItem, null );
+ }
+
+ return $changes;
+ }
+
+ /**
* Serializes the object as an associative array, which can be passed
* to newFromArray to create a new instance.
*
@@ -191,10 +428,10 @@
'changes' => array()
);
- foreach ( $this->changeSet->getAllProperties() as /*
SMWDIProperty */ $property ) {
+ foreach ( $this->getAllProperties() as /* SMWDIProperty */
$property ) {
$propChanges = array();
- foreach ( $this->changeSet->getAllPropertyChanges(
$property ) as /* SMWPropertyChange */ $change ) {
+ foreach ( $this->getAllPropertyChanges( $property ) as
/* SWLPropertyChange */ $change ) {
$propChange = array();
if ( is_object( $change->getOldValue() ) ) {
@@ -256,7 +493,7 @@
if ( $property->isUserDefined() ) {
$propSerialization =
$property->getSerialization();
- foreach (
$this->getChanges()->getPropertyChanges( $property ) as /* SMWPropertyChange */
$change ) {
+ foreach (
$this->getChanges()->getPropertyChanges( $property ) as /* SWLPropertyChange */
$change ) {
$changes[] = array(
'property' =>
$propSerialization,
'old' =>
$change->getOldValue()->getSerialization(),
@@ -371,9 +608,10 @@
* @param array $properties List of property names
*/
public function filterOnProperties( array $properties ) {
+ // TODO
foreach ( $this->getAllProperties() as /* SMWDIProperty */
$property ) {
if ( !in_array( $property->getSerialization(),
$properties ) ) {
- $this->changeSet->removeChangesForProperty(
$property );
+ //$this->changeSet->removeChangesForProperty(
$property );
}
}
}
Modified: trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php 2011-05-21
19:55:05 UTC (rev 88541)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php 2011-05-21
19:55:13 UTC (rev 88542)
@@ -91,7 +91,7 @@
$deletions = array();
// Convert the changes into a list of insertions and a list of
deletions.
- foreach ( $changes as /* SMWPropertyChange */ $change ) {
+ foreach ( $changes as /* SWLPropertyChange */ $change ) {
if ( !is_null( $change->getOldValue() ) ) {
$deletions[] =
SMWDataValueFactory::newDataItemValue( $change->getOldValue(), $property
)->getShortHTMLText();
}
Added: trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChange.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChange.php
(rev 0)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChange.php
2011-05-21 19:55:13 UTC (rev 88542)
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Represents a change to a semantic property.
+ *
+ * @since 0.1
+ *
+ * @file SWL_PropertyChange.php
+ * @ingroup SemanticWatchlist
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SWLPropertyChange {
+
+ 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 SWLPropertyChange instance from a
serialization.
+ *
+ * @param string|null $oldValue
+ * @param string|null $newValue
+ *
+ * @return SWLPropertyChange
+ */
+ 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 SWLPropertyChange.
+ *
+ * @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 SWLPropertyChange::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
Property changes on:
trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChange.php
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChanges.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChanges.php
(rev 0)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChanges.php
2011-05-21 19:55:13 UTC (rev 88542)
@@ -0,0 +1,178 @@
+<?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 SWLPropertyChange objects, each holding 2 SMWDataItem objects,
+ * instead of SMWDataItem objects.
+ *
+ * @since 0.1
+ *
+ * @file SWL_PropertyChange.php
+ * @ingroup SemanticWatchlist
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SWLPropertyChanges 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 SWLPropertyChange.
+ *
+ * @var array of SWLPropertyChange
+ */
+ 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 SWLPropertyChange
+ */
+ 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 SWLPropertyChange $change
+ */
+ public function addPropertyObjectChange( SMWDIProperty $property,
SWLPropertyChange $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 SWLPropertyChange $change
+ */
+ public function addPropertyChange( $propertyName, SWLPropertyChange
$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
Property changes on:
trunk/extensions/SemanticWatchlist/includes/SWL_PropertyChanges.php
___________________________________________________________________
Added: svn:eol-style
+ native
Modified:
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
2011-05-21 19:55:05 UTC (rev 88541)
+++ trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
2011-05-21 19:55:13 UTC (rev 88542)
@@ -338,7 +338,7 @@
* Returns the HTML for the changes to a single propety.
*
* @param SMWDIProperty $property
- * @param array of SMWPropertyChange $changes
+ * @param array of SWLPropertyChange $changes
*
* @return string
*/
@@ -347,7 +347,7 @@
$deletions = array();
// Convert the changes into a list of insertions and a list of
deletions.
- foreach ( $changes as /* SMWPropertyChange */ $change ) {
+ foreach ( $changes as /* SWLPropertyChange */ $change ) {
if ( !is_null( $change->getOldValue() ) ) {
$deletions[] =
SMWDataValueFactory::newDataItemValue( $change->getOldValue(), $property
)->getLongHTMLText();
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs