r88744 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88743‎ | r88744 | r88745 >
Date:20:17, 24 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
changes to hold into account a single edit can have multiple sets of changes when there are more then one matching watchlist groups
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql (modified) (history)
  • /trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Edit.php (added) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Group.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
@@ -209,7 +209,7 @@
210210 $changeSetsHTML = array();
211211
212212 foreach ( $sets as $set ) {
213 - $dayKey = substr( $set->getTime(), 0, 8 ); // Get the YYYYMMDD part.
 213+ $dayKey = substr( $set->getEdit()->getTime(), 0, 8 ); // Get the YYYYMMDD part.
214214
215215 if ( !array_key_exists( $dayKey, $changeSetsHTML ) ) {
216216 $changeSetsHTML[$dayKey] = array();
@@ -278,46 +278,48 @@
279279 protected function getChangeSetHTML( SWLChangeSet $changeSet ) {
280280 global $wgLang;
281281
 282+ $edit = $changeSet->getEdit();
 283+
282284 $html = '';
283285
284286 $html .= '<li>';
285287
286288 $html .=
287289 '<p>' .
288 - $wgLang->time( $changeSet->getTime(), true ) . ' ' .
 290+ $wgLang->time( $edit->getTime(), true ) . ' ' .
289291 Html::element(
290292 'a',
291 - array( 'href' => $changeSet->getTitle()->getLocalURL() ),
292 - $changeSet->getTitle()->getText()
 293+ array( 'href' => $edit->getTitle()->getLocalURL() ),
 294+ $edit->getTitle()->getText()
293295 ) . ' (' .
294296 Html::element(
295297 'a',
296 - array( 'href' => $changeSet->getTitle()->getLocalURL( 'action=history' ) ),
 298+ array( 'href' => $edit->getTitle()->getLocalURL( 'action=history' ) ),
297299 wfMsg( 'hist' )
298300 ) . ') . . ' .
299301 Html::element(
300302 'a',
301 - array( 'href' => $changeSet->getUser()->getUserPage()->getLocalURL() ),
302 - $changeSet->getUser()->getName()
 303+ array( 'href' => $edit->getUser()->getUserPage()->getLocalURL() ),
 304+ $edit->getUser()->getName()
303305 ) . ' (' .
304306 Html::element(
305307 'a',
306 - array( 'href' => $changeSet->getUser()->getTalkPage()->getLocalURL() ),
 308+ array( 'href' => $edit->getUser()->getTalkPage()->getLocalURL() ),
307309 wfMsg( 'talkpagelinktext' )
308310 ) . ' | ' .
309 - ( $changeSet->getUser()->isAnon() ? '' :
 311+ ( $edit->getUser()->isAnon() ? '' :
310312 Html::element(
311313 'a',
312 - array( 'href' => SpecialPage::getTitleFor( 'Contributions', $changeSet->getUser()->getName() )->getLocalURL() ),
 314+ array( 'href' => SpecialPage::getTitleFor( 'Contributions', $edit->getUser()->getName() )->getLocalURL() ),
313315 wfMsg( 'contribslink' )
314316 ) . ' | '
315317 ) .
316318 Html::element(
317319 'a',
318 - array( 'href' => SpecialPage::getTitleFor( 'Block', $changeSet->getUser()->getName() )->getLocalURL() ),
 320+ array( 'href' => SpecialPage::getTitleFor( 'Block', $edit->getUser()->getName() )->getLocalURL() ),
319321 wfMsg( 'blocklink' )
320322 ) . ')' .
321 - ( $changeSet->getTime() > $this->lastViewed ? ' [NEW]' : '' ) .
 323+ ( $edit->getTime() > $this->lastViewed ? ' [NEW]' : '' ) .
322324 '</p>'
323325 ;
324326
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
@@ -14,7 +14,7 @@
1515 group_concepts BLOB NOT NULL -- Concept names
1616 ) /*$wgDBTableOptions*/;
1717
 18+-- Single value changes to a property.
1819 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes (
1920 change_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY,
2021 change_set_id INT(10) unsigned NOT NULL, -- Foreign key: swl_sets.set_id
@@ -31,6 +31,11 @@
3232 edit_time CHAR(14) binary NOT NULL default '' -- The time the chages where made
3333 ) /*$wgDBTableOptions*/;
3434
 35+-- Sets of changes. There can be many such sets for one edit, with overlapping changes.
 36+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_sets (
 37+ set_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY
 38+) /*$wgDBTableOptions*/;
 39+
3540 -- Links change sets their edits.
3641 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_sets_per_edit (
3742 spe_set_id SMALLINT unsigned NOT NULL, -- Foreign key: swl_sets.set_id
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Edit.php
@@ -0,0 +1,237 @@
 2+<?php
 3+
 4+/**
 5+ *
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file SWL_Edit.php
 10+ * @ingroup SemanticWatchlist
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class SWLEdit {
 16+
 17+ /**
 18+ * The ID of the page the edit was made to.
 19+ *
 20+ * @var integer
 21+ */
 22+ protected $pageId;
 23+
 24+ /**
 25+ * The name of the user that made the edit.
 26+ *
 27+ * @var string
 28+ */
 29+ protected $userName;
 30+
 31+ /**
 32+ * The user that made the changes.
 33+ *
 34+ * @var User or false
 35+ */
 36+ protected $user = false;
 37+
 38+ /**
 39+ * The time on which the edit was made.
 40+ *
 41+ * @var integer
 42+ */
 43+ protected $time;
 44+
 45+ /**
 46+ * DB ID of the edit (swl_edits.edit_id).
 47+ *
 48+ * @var integer
 49+ */
 50+ protected $id;
 51+
 52+ /**
 53+ * Creates and returns a new instance of SWLEdit by getting it's info from the database.
 54+ *
 55+ * @since 0.1
 56+ *
 57+ * @param integer $id
 58+ *
 59+ * @return SWLEdit
 60+ */
 61+ public static function newFromId( $id ) {
 62+ $dbr = wfGetDB( DB_SLAVE );
 63+
 64+ return self::newFromDBResult( $dbr->select(
 65+ 'swl_edits',
 66+ array(
 67+ 'edit_id',
 68+ 'edit_user_name',
 69+ 'edit_page_id',
 70+ 'edit_time'
 71+ ),
 72+ array( 'edit_id' => $id )
 73+ ) );
 74+ }
 75+
 76+ /**
 77+ * Creates and returns a new instance of SWLEdit from a database result.
 78+ *
 79+ * @since 0.1
 80+ *
 81+ * @param ResultWrapper $edit
 82+ *
 83+ * @return SWLEdit
 84+ */
 85+ public static function newFromDBResult( $edit ) {
 86+ return new self(
 87+ $edit->edit_page_id,
 88+ $edit->edit_user_name,
 89+ $edit->edit_time,
 90+ $edit->edit_id
 91+ );
 92+ }
 93+
 94+ /**
 95+ * Constructor.
 96+ *
 97+ * @since 0.1
 98+ */
 99+ public function __construct( $pageId, $userName, $time, $id = null ) {
 100+ $this->pageId = $pageId;
 101+ $this->userName = $userName;
 102+ $this->time = $time;
 103+ $this->id = $id;
 104+ }
 105+
 106+ /**
 107+ * Writes the edit to the database, either updating it
 108+ * when it already exists, or inserting it when it doesn't.
 109+ *
 110+ * @since 0.1
 111+ *
 112+ * @return boolean Success indicator
 113+ */
 114+ public function writeToDB() {
 115+ if ( is_null( $this->id ) ) {
 116+ return $this->insertIntoDB();
 117+ }
 118+ else {
 119+ return $this->updateInDB();
 120+ }
 121+ }
 122+
 123+ /**
 124+ * Updates the group in the database.
 125+ *
 126+ * @since 0.1
 127+ *
 128+ * @return boolean Success indicator
 129+ */
 130+ protected function updateInDB() {
 131+ $dbr = wfGetDB( DB_MASTER );
 132+
 133+ return $dbr->update(
 134+ 'swl_edits',
 135+ array(
 136+ 'edit_user_name' => $this->userName,
 137+ 'edit_page_id' => $this->pageId,
 138+ 'edit_time' => $this->time
 139+ ),
 140+ array( 'edit_id' => $this->id )
 141+ );
 142+ }
 143+
 144+ /**
 145+ * Inserts the group into the database.
 146+ *
 147+ * @since 0.1
 148+ *
 149+ * @return boolean Success indicator
 150+ */
 151+ protected function insertIntoDB() {
 152+ $dbr = wfGetDB( DB_MASTER );
 153+
 154+ $result = $dbr->insert(
 155+ 'swl_edits',
 156+ array(
 157+ 'edit_user_name' => $this->userName,
 158+ 'edit_page_id' => $this->pageId,
 159+ 'edit_time' => $this->time
 160+ )
 161+ );
 162+
 163+ $this->id = $dbr->insertId();
 164+
 165+ return $result;
 166+ }
 167+
 168+ /**
 169+ * Returns the edit database id (swl_edits.edit_id).
 170+ *
 171+ * @since 0.1
 172+ *
 173+ * @return integer
 174+ */
 175+ public function getId() {
 176+ return $this->id;
 177+ }
 178+
 179+ /**
 180+ * Returns the ID of the page the edit was made to.
 181+ *
 182+ * @since 0.1
 183+ *
 184+ * @return integer
 185+ */
 186+ public function getPageId() {
 187+ return $this->pageId;
 188+ }
 189+
 190+ /**
 191+ * Gets the title of the page these changes belong to.
 192+ *
 193+ * @since 0.1
 194+ *
 195+ * @return Title
 196+ */
 197+ public function getTitle() {
 198+ return Title::newFromID( $this->pageId );
 199+ }
 200+
 201+ /**
 202+ * Gets the name of the user that made the changes.
 203+ *
 204+ * @since 0.1
 205+ *
 206+ * @return string
 207+ */
 208+ public function getUserName() {
 209+ return $this->userName;
 210+ }
 211+
 212+ /**
 213+ * Gets the user that made the changes.
 214+ *
 215+ * @since 0.1
 216+ *
 217+ * @return User
 218+ */
 219+ public function getUser() {
 220+ if ( $this->user === false ) {
 221+ $this->user = User::newFromName( $this->userName );
 222+ }
 223+
 224+ return $this->user;
 225+ }
 226+
 227+ /**
 228+ * Gets the time on which the changes where made.
 229+ *
 230+ * @since 0.1
 231+ *
 232+ * @return integer
 233+ */
 234+ public function getTime() {
 235+ return $this->time;
 236+ }
 237+
 238+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticWatchlist/includes/SWL_Edit.php
___________________________________________________________________
Added: svn:eol-style
1239 + native
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
@@ -224,7 +224,7 @@
225225 }
226226
227227 /**
228 - * Returns the properties specified by the group.
 228+ * Returns the properties specified by the group as strings (serializations of SMWDIProperty).
229229 *
230230 * @since 0.1
231231 *
@@ -235,6 +235,23 @@
236236 }
237237
238238 /**
 239+ * Returns the properties specified by the group as SMWDIProperty objects.
 240+ *
 241+ * @since 0.1
 242+ *
 243+ * @return array[SMWDIProperty]
 244+ */
 245+ public function getPropertyObjects() {
 246+ $properties = array();
 247+
 248+ foreach ( $this->properties as $property ) {
 249+ $properties[] = SMWDIProperty::newFromSerialization( $property );
 250+ }
 251+
 252+ return $properties;
 253+ }
 254+
 255+ /**
239256 * Returns the concepts specified by the group.
240257 *
241258 * @since 0.1
@@ -421,19 +438,6 @@
422439 }
423440
424441 /**
425 - * Removethe non covered properties.
426 - *
427 - * @since 0.1
428 - *
429 - * @param SWLChangeSet $changes
430 - *
431 - * @return SWLChangeSet
432 - */
433 - public function removeNonCoveredChanges( SWLChangeSet &$changes ) {
434 - $changes->filterOnProperties( $this->getProperties() );
435 - }
436 -
437 - /**
438442 * Gets all the watching users and passes them, together with the specified
439443 * changes and the group object itself, to the SWLGroupNotify hook.
440444 *
@@ -444,8 +448,6 @@
445449 public function notifyWatchingUsers( SWLChangeSet $changes ) {
446450 $users = $this->getWatchingUsers();
447451
448 - $this->removeNonCoveredChanges( $changes );
449 -
450452 if ( $changes->hasChanges( true ) ) {
451453 wfRunHooks( 'SWLGroupNotify', array( $this, $users, $changes ) );
452454 }
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
@@ -1,9 +1,8 @@
22 <?php
33
44 /**
5 - * Wrapper around SMWChangeSet that holds extra info such as user and time,
6 - * and has methods for (un)serialization and database interaction.
75 *
 6+ *
87 * @since 0.1
98 *
109 * @file SWL_ChangeSet.php
@@ -43,20 +42,6 @@
4443 protected $changes;
4544
4645 /**
47 - * The user that made the changes.
48 - *
49 - * @var User
50 - */
51 - protected $user;
52 -
53 - /**
54 - * The time on which the changes where made.
55 - *
56 - * @var integer
57 - */
58 - protected $time;
59 -
60 - /**
6146 * DB ID of the change set (swl_sets.set_id).
6247 *
6348 * @var integer
@@ -74,6 +59,13 @@
7560 protected $title = false;
7661
7762 /**
 63+ * The edit this set of changes belongs to.
 64+ *
 65+ * @var SWLEdit
 66+ */
 67+ protected $edit;
 68+
 69+ /**
7870 * Creates and returns a new SWLChangeSet instance from a database result
7971 * obtained by doing a select on swl_sets.
8072 *
@@ -83,9 +75,19 @@
8476 *
8577 * @return SWLChangeSet
8678 */
87 - public static function newFromDBResult( $set ) {
88 - $changeSet = new SMWChangeSet(
89 - SMWDIWikiPage::newFromTitle( Title::newFromID( $set->set_page_id ) )
 79+ public static function newFromDBResult( $set ) {
 80+ $changeSet = new SWLChangeSet(
 81+ SMWDIWikiPage::newFromTitle( Title::newFromID( $set->edit_page_id ) ),
 82+ null,
 83+ null,
 84+ null,
 85+ $set->spe_set_id,
 86+ new SWLEdit(
 87+ $set->edit_page_id,
 88+ $set->edit_user_name,
 89+ $set->edit_time,
 90+ $set->edit_id
 91+ )
9092 );
9193
9294 $dbr = wfGetDb( DB_SLAVE );
@@ -99,7 +101,7 @@
100102 'change_new_value'
101103 ),
102104 array(
103 - 'change_set_id' => $set->set_id
 105+ 'change_set_id' => $set->spe_set_id
104106 )
105107 );
106108
@@ -112,13 +114,6 @@
113115 );
114116 }
115117
116 - $changeSet = new SWLChangeSet(
117 - $changeSet,
118 - User::newFromName( $set->set_user_name, false ),
119 - $set->set_time,
120 - $set->set_id
121 - );
122 -
123118 return $changeSet;
124119 }
125120
@@ -133,10 +128,20 @@
134129 * @return SWLChangeSet
135130 */
136131 public static function newFromArray( array $changeSetArray ) {
137 - $changeSet = new SMWChangeSet(
138 - SMWDIWikiPage::newFromTitle( Title::newFromID( $changeSetArray['page_id'] ) )
 132+ $changeSet = new SWLChangeSet(
 133+ SMWDIWikiPage::newFromTitle( Title::newFromID( $changeSetArray['page_id'] ) ),
 134+ null,
 135+ null,
 136+ null,
 137+ $changeSetArray['id'],
 138+ new SWLEdit(
 139+ $changeSetArray['page_id'],
 140+ $changeSetArray['user_name'],
 141+ $changeSetArray['time'],
 142+ $changeSetArray['editid']
 143+ )
139144 );
140 -
 145+
141146 foreach ( $changeSetArray['changes'] as $propName => $changes ) {
142147 $property = SMWDIProperty::doUnserialize( $propName, '__pro' );
143148
@@ -150,14 +155,7 @@
151156 )
152157 );
153158 }
154 - }
155 -
156 - $changeSet = new SWLChangeSet(
157 - $changeSet,
158 - User::newFromName( $changeSetArray['user_name'], false ),
159 - $changeSetArray['time'],
160 - $changeSetArray['id']
161 - );
 159+ }
162160
163161 return $changeSet;
164162 }
@@ -167,10 +165,11 @@
168166 *
169167 * @param SMWSemanticData $old
170168 * @param SMWSemanticData $new
 169+ * @param array $filterProperties Optional list of properties (string serializations) to filter on. Null for no filtering.
171170 *
172171 * @return SMWChangeSet
173172 */
174 - public static function newFromSemanticData( SMWSemanticData $old, SMWSemanticData $new ) {
 173+ public static function newFromSemanticData( SMWSemanticData $old, SMWSemanticData $new, array $filterProperties = null ) {
175174 $subject = $old->getSubject();
176175
177176 if ( $subject != $new->getSubject() ) {
@@ -181,14 +180,26 @@
182181 $insertions = new SMWSemanticData( $subject );
183182 $deletions = new SMWSemanticData( $subject );
184183
185 - $oldProperties = $old->getProperties();
186 - $newProperties = $new->getProperties();
 184+ $oldProperties = array();
 185+ $newProperties = array();
187186
 187+ foreach ( $old->getProperties() as $property ) {
 188+ if ( is_null( $filterProperties ) || in_array( $property->getLabel(), $filterProperties ) ) {
 189+ $oldProperties[] = $property;
 190+ }
 191+ }
 192+
 193+ foreach ( $new->getProperties() as $property ) {
 194+ if ( is_null( $filterProperties ) || in_array( $property->getLabel(), $filterProperties ) ) {
 195+ $newProperties[] = $property;
 196+ }
 197+ }
 198+
188199 // Find the deletions.
189 - self::findSingleDirectionChanges( $deletions, $oldProperties, $old, $newProperties );
 200+ self::findSingleDirectionChanges( $deletions, $oldProperties, $old, $newProperties, $filterProperties );
190201
191202 // Find the insertions.
192 - self::findSingleDirectionChanges( $insertions, $newProperties, $new, $oldProperties );
 203+ self::findSingleDirectionChanges( $insertions, $newProperties, $new, $oldProperties, $filterProperties );
193204
194205 foreach ( $oldProperties as $propertyKey => /* SMWDIProperty */ $diProperty ) {
195206 $oldDataItems = array();
@@ -254,7 +265,7 @@
255266 */
256267 protected static function findSingleDirectionChanges( SMWSemanticData &$changeSet,
257268 array &$oldProperties, SMWSemanticData $oldData, array $newProperties ) {
258 -
 269+
259270 $deletionKeys = array();
260271
261272 foreach ( $oldProperties as $propertyKey => /* SMWDIProperty */ $diProperty ) {
@@ -278,32 +289,52 @@
279290 * @param SWLPropertyChanges $changes Can be null
280291 * @param SMWSemanticData $insertions Can be null
281292 * @param SMWSemanticData $deletions Can be null
 293+ * @param integer $id Can be null
 294+ * @param SWLEdit $edit Can be null
282295 */
283296 public function __construct( SMWDIWikiPage $subject, /* SWLPropertyChanges */ $changes = null,
284297 /* SMWSemanticData */ $insertions = null, /* SMWSemanticData */ $deletions = null,
285 - /* User */ $user = null, $time = null, $id = null ) {
 298+ $id = null, /* SWLEdit */ $edit = null ) {
286299
287300 $this->subject = $subject;
288301 $this->changes = is_null( $changes ) ? new SWLPropertyChanges() : $changes;
289302 $this->insertions = is_null( $insertions ) ? new SMWSemanticData( $subject ): $insertions;
290303 $this->deletions = is_null( $deletions ) ? new SMWSemanticData( $subject ): $deletions;
291304
292 - $this->time = is_null( $time ) ? wfTimestampNow() : $time;
293 - $this->user = is_null( $user ) ? $GLOBALS['wgUser'] : $user;
294305 $this->id = $id;
 306+ $this->edit = $edit;
295307 }
296308
297309 /**
 310+ * Rteurns if the change set contains (changes for) user defined properties.
 311+ *
 312+ * @since 0.1
 313+ *
 314+ * @return boolean
 315+ */
 316+ public function hasUserDefinedProperties() {
 317+ $properties = array();
 318+
 319+ foreach ( $this->getAllProperties() as /* SMWDIProperty */ $property ) {
 320+ if ( $property->isUserDefined() ) {
 321+ $properties[] = $property;
 322+ }
 323+ }
 324+
 325+ return count( $properties ) != 0;
 326+ }
 327+
 328+ /**
298329 * Returns whether the set contains any changes.
299330 *
300 - * @param boolean $refresh
 331+ * @since 0.1
301332 *
302333 * @return boolean
303334 */
304 - public function hasChanges( $refresh = false ) {
 335+ public function hasChanges() {
305336 return $this->changes->hasChanges()
306 - || $this->insertions->hasVisibleProperties( $refresh )
307 - || $this->deletions->hasVisibleProperties( $refresh );
 337+ || $this->insertions->hasVisibleProperties()
 338+ || $this->deletions->hasVisibleProperties();
308339 }
309340
310341 /**
@@ -422,9 +453,10 @@
423454 public function toArray() {
424455 $changeSet = array(
425456 'id' => $this->id,
426 - 'user_name' => $this->user->getName(),
427 - 'page_id' => $this->getTitle()->getArticleID(),
428 - 'time' => $this->time,
 457+ 'user_name' => $this->edit->getUserName(),
 458+ 'page_id' => $this->edit->getPageID(),
 459+ 'time' => $this->edit->getTime(),
 460+ 'editid' => $this->edit->getId(),
429461 'changes' => array()
430462 );
431463
@@ -457,20 +489,12 @@
458490 * @since 0.1
459491 *
460492 * @param array of SWLGroup
 493+ * @param integer $editId
461494 *
462495 * @return integer ID of the inserted row (0 if nothing was inserted).
463496 */
464 - public function writeToStore( array $groupsToAssociate ) {
465 - $properties = array();
466 -
467 - foreach ( $this->getAllProperties() as /* SMWDIProperty */ $property ) {
468 - if ( $property->isUserDefined() ) {
469 - $properties[] = $property;
470 - }
471 - }
472 -
473 - // If there are no changed user properties, don't insert a new entry.
474 - if ( count( $properties ) == 0 ) {
 497+ public function writeToStore( array $groupsToAssociate, $editId ) {
 498+ if ( !$this->hasUserDefinedProperties() ) {
475499 return 0;
476500 }
477501
@@ -478,18 +502,22 @@
479503
480504 $dbw->insert(
481505 'swl_sets',
482 - array(
483 - 'set_user_name' => $this->getUser()->getName(),
484 - 'set_page_id' => $this->getTitle()->getArticleID(),
485 - 'set_time' => is_null( $this->getTime() ) ? $dbw->timestamp() : $this->getTime()
486 - )
 506+ array()
487507 );
488508
489509 $id = $dbw->insertId();
490510
 511+ $dbw->insert(
 512+ 'swl_sets_per_edit',
 513+ array(
 514+ 'spe_set_id' => $id,
 515+ 'spe_edit_id' => $editId
 516+ )
 517+ );
 518+
491519 $changes = array();
492520
493 - foreach ( $properties as /* SMWDIProperty */ $property ) {
 521+ foreach ( $this->getAllProperties() as /* SMWDIProperty */ $property ) {
494522 if ( $property->isUserDefined() ) {
495523 $propSerialization = $property->getSerialization();
496524
@@ -554,6 +582,8 @@
555583 /**
556584 * Gets the title of the page these changes belong to.
557585 *
 586+ * @since 0.1
 587+ *
558588 * @return Title
559589 */
560590 public function getTitle() {
@@ -565,55 +595,14 @@
566596 }
567597
568598 /**
569 - * Sets the user that made the changes.
 599+ * Gets the edit this set of changes belong to.
570600 *
571 - * @param User $user
572 - */
573 - public function setUser( User $user ) {
574 - $this->user = $user;
575 - }
576 -
577 - /**
578 - * Gets the user that made the changes.
579 - *
580 - * @return User
581 - */
582 - public function getUser() {
583 - return $this->user;
584 - }
585 -
586 - /**
587 - * Sets the time on which the changes where made.
588 - *
589 - * @param integer $time
590 - */
591 - public function setTime( $time ) {
592 - $this->time = $time;
593 - }
594 -
595 - /**
596 - * Gets the time on which the changes where made.
597 - *
598 - * @return integer
599 - */
600 - public function getTime() {
601 - return $this->time;
602 - }
603 -
604 - /**
605 - * Remove changes to properties not in the porvided list.
606 - *
607601 * @since 0.1
608602 *
609 - * @param array $properties List of property names
 603+ * @return SWLEdit
610604 */
611 - public function filterOnProperties( array $properties ) {
612 - // TODO
613 - foreach ( $this->getAllProperties() as /* SMWDIProperty */ $property ) {
614 - if ( !in_array( $property->getSerialization(), $properties ) ) {
615 - //$this->changeSet->removeChangesForProperty( $property );
616 - }
617 - }
 605+ public function getEdit() {
 606+ return $this->edit;
618607 }
619608
620609 }
\ No newline at end of file
Index: trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
@@ -65,18 +65,20 @@
6666 * @param string $continue
6767 */
6868 protected function setupChangeSetQuery( $userId, $limit, $continue ) {
69 - $this->addTables( array( 'swl_sets', 'swl_sets_per_group', 'swl_users_per_group' ) );
 69+ $this->addTables( array( 'swl_edits', 'swl_sets_per_edit', 'swl_sets_per_group', 'swl_users_per_group' ) );
7070
7171 $this->addJoinConds( array(
72 - 'swl_sets_per_group' => array( 'INNER JOIN', array( 'set_id=spg_set_id' ) ),
 72+ 'swl_sets_per_edit' => array( 'INNER JOIN', array( 'edit_id=spe_edit_id' ) ),
 73+ 'swl_sets_per_group' => array( 'INNER JOIN', array( 'spe_set_id=spg_set_id' ) ),
7374 'swl_users_per_group' => array( 'INNER JOIN', array( 'spg_group_id=upg_group_id' ) ),
74 - ) );
 75+ ) );
7576
7677 $this->addFields( array(
77 - 'set_id',
78 - 'set_user_name',
79 - 'set_page_id',
80 - 'set_time',
 78+ 'spe_set_id',
 79+ 'edit_user_name',
 80+ 'edit_page_id',
 81+ 'edit_time',
 82+ 'edit_id'
8183 ) );
8284
8385 $this->addWhere( array(
@@ -85,15 +87,15 @@
8688
8789 $this->addOption( 'DISTINCT' );
8890 $this->addOption( 'LIMIT', $limit + 1 );
89 - $this->addOption( 'ORDER BY', 'set_time DESC, set_id DESC' );
 91+ $this->addOption( 'ORDER BY', 'edit_time DESC, spe_set_id DESC' );
9092
9193 if ( !is_null( $continue ) ) {
9294 $continueParams = explode( '-', $continue );
9395
9496 if ( count( $continueParams ) == 2 ) {
9597 $dbr = wfGetDB( DB_SLAVE );
96 - $this->addWhere( 'set_time <= ' . $dbr->addQuotes( $continueParams[0] ) );
97 - $this->addWhere( 'set_id <= ' . $dbr->addQuotes( $continueParams[1] ) );
 98+ $this->addWhere( 'edit_time <= ' . $dbr->addQuotes( $continueParams[0] ) );
 99+ $this->addWhere( 'spe_set_id <= ' . $dbr->addQuotes( $continueParams[1] ) );
98100 }
99101 else {
100102 // TODO: error
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
@@ -63,6 +63,7 @@
6464 $wgAutoloadClasses['ApiQuerySemanticWatchlist'] = dirname( __FILE__ ) . '/api/ApiQuerySemanticWatchlist.php';
6565
6666 $wgAutoloadClasses['SWLChangeSet'] = dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php';
 67+$wgAutoloadClasses['SWLEdit'] = dirname( __FILE__ ) . '/includes/SWL_Edit.php';
6768 $wgAutoloadClasses['SWLEmailer'] = dirname( __FILE__ ) . '/includes/SWL_Emailer.php';
6869 $wgAutoloadClasses['SWLGroup'] = dirname( __FILE__ ) . '/includes/SWL_Group.php';
6970 $wgAutoloadClasses['SWLGroups'] = dirname( __FILE__ ) . '/includes/SWL_Groups.php';
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -25,17 +25,36 @@
2626 * @return true
2727 */
2828 public static function onDataUpdate( SMWStore $store, SMWSemanticData $newData ) {
29 - $changeSet = SWLChangeSet::newFromSemanticData( $store->getSemanticData( $newData->getSubject() ), $newData );
30 - $groups = SWLGroups::getMatchingWatchGroups( $changeSet->getTitle() );
 29+ $subject = $newData->getSubject();
 30+ $oldData = $store->getSemanticData( $subject );
 31+ $title = Title::makeTitle( $subject->getNamespace(), $subject->getDBkey() );
3132
32 - $wasInserted = $changes->writeToStore( $groups ) != 0;
 33+ $groups = SWLGroups::getMatchingWatchGroups( $title );
3334
34 - if ( $wasInserted ) {
35 - foreach ( $groups as /* SWLGroup */ $group ) {
36 - $group->notifyWatchingUsers( $changes );
37 - }
 35+ $edit = false;
 36+
 37+ foreach ( $groups as /* SWLGroup */ $group ) {
 38+ $changeSet = SWLChangeSet::newFromSemanticData( $oldData, $newData, $group->getProperties() );
 39+
 40+ if ( $changeSet->hasUserDefinedProperties() ) {
 41+ if ( $edit === false ) {
 42+ $edit = new SWLEdit(
 43+ $title->getArticleID(),
 44+ $GLOBALS['wgUser'],
 45+ wfTimestampNow()
 46+ );
 47+
 48+ $edit->writeToDB();
 49+ }
 50+
 51+ $setId = $changeSet->writeToStore( $groups, $edit->getId() );
 52+
 53+ if ( $setId != 0 ) {
 54+ $group->notifyWatchingUsers( $changeSet );
 55+ }
 56+ }
3857 }
39 -
 58+
4059 return true;
4160 }
4261

Status & tagging log