Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php |
— | — | @@ -209,7 +209,7 @@ |
210 | 210 | $changeSetsHTML = array(); |
211 | 211 | |
212 | 212 | 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. |
214 | 214 | |
215 | 215 | if ( !array_key_exists( $dayKey, $changeSetsHTML ) ) { |
216 | 216 | $changeSetsHTML[$dayKey] = array(); |
— | — | @@ -278,46 +278,48 @@ |
279 | 279 | protected function getChangeSetHTML( SWLChangeSet $changeSet ) { |
280 | 280 | global $wgLang; |
281 | 281 | |
| 282 | + $edit = $changeSet->getEdit(); |
| 283 | + |
282 | 284 | $html = ''; |
283 | 285 | |
284 | 286 | $html .= '<li>'; |
285 | 287 | |
286 | 288 | $html .= |
287 | 289 | '<p>' . |
288 | | - $wgLang->time( $changeSet->getTime(), true ) . ' ' . |
| 290 | + $wgLang->time( $edit->getTime(), true ) . ' ' . |
289 | 291 | Html::element( |
290 | 292 | 'a', |
291 | | - array( 'href' => $changeSet->getTitle()->getLocalURL() ), |
292 | | - $changeSet->getTitle()->getText() |
| 293 | + array( 'href' => $edit->getTitle()->getLocalURL() ), |
| 294 | + $edit->getTitle()->getText() |
293 | 295 | ) . ' (' . |
294 | 296 | Html::element( |
295 | 297 | 'a', |
296 | | - array( 'href' => $changeSet->getTitle()->getLocalURL( 'action=history' ) ), |
| 298 | + array( 'href' => $edit->getTitle()->getLocalURL( 'action=history' ) ), |
297 | 299 | wfMsg( 'hist' ) |
298 | 300 | ) . ') . . ' . |
299 | 301 | Html::element( |
300 | 302 | 'a', |
301 | | - array( 'href' => $changeSet->getUser()->getUserPage()->getLocalURL() ), |
302 | | - $changeSet->getUser()->getName() |
| 303 | + array( 'href' => $edit->getUser()->getUserPage()->getLocalURL() ), |
| 304 | + $edit->getUser()->getName() |
303 | 305 | ) . ' (' . |
304 | 306 | Html::element( |
305 | 307 | 'a', |
306 | | - array( 'href' => $changeSet->getUser()->getTalkPage()->getLocalURL() ), |
| 308 | + array( 'href' => $edit->getUser()->getTalkPage()->getLocalURL() ), |
307 | 309 | wfMsg( 'talkpagelinktext' ) |
308 | 310 | ) . ' | ' . |
309 | | - ( $changeSet->getUser()->isAnon() ? '' : |
| 311 | + ( $edit->getUser()->isAnon() ? '' : |
310 | 312 | Html::element( |
311 | 313 | 'a', |
312 | | - array( 'href' => SpecialPage::getTitleFor( 'Contributions', $changeSet->getUser()->getName() )->getLocalURL() ), |
| 314 | + array( 'href' => SpecialPage::getTitleFor( 'Contributions', $edit->getUser()->getName() )->getLocalURL() ), |
313 | 315 | wfMsg( 'contribslink' ) |
314 | 316 | ) . ' | ' |
315 | 317 | ) . |
316 | 318 | Html::element( |
317 | 319 | 'a', |
318 | | - array( 'href' => SpecialPage::getTitleFor( 'Block', $changeSet->getUser()->getName() )->getLocalURL() ), |
| 320 | + array( 'href' => SpecialPage::getTitleFor( 'Block', $edit->getUser()->getName() )->getLocalURL() ), |
319 | 321 | wfMsg( 'blocklink' ) |
320 | 322 | ) . ')' . |
321 | | - ( $changeSet->getTime() > $this->lastViewed ? ' [NEW]' : '' ) . |
| 323 | + ( $edit->getTime() > $this->lastViewed ? ' [NEW]' : '' ) . |
322 | 324 | '</p>' |
323 | 325 | ; |
324 | 326 | |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | group_concepts BLOB NOT NULL -- Concept names |
16 | 16 | ) /*$wgDBTableOptions*/; |
17 | 17 | |
| 18 | +-- Single value changes to a property. |
18 | 19 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes ( |
19 | 20 | change_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY, |
20 | 21 | change_set_id INT(10) unsigned NOT NULL, -- Foreign key: swl_sets.set_id |
— | — | @@ -31,6 +31,11 @@ |
32 | 32 | edit_time CHAR(14) binary NOT NULL default '' -- The time the chages where made |
33 | 33 | ) /*$wgDBTableOptions*/; |
34 | 34 | |
| 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 | + |
35 | 40 | -- Links change sets their edits. |
36 | 41 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_sets_per_edit ( |
37 | 42 | 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 |
1 | 239 | + native |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php |
— | — | @@ -224,7 +224,7 @@ |
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
228 | | - * Returns the properties specified by the group. |
| 228 | + * Returns the properties specified by the group as strings (serializations of SMWDIProperty). |
229 | 229 | * |
230 | 230 | * @since 0.1 |
231 | 231 | * |
— | — | @@ -235,6 +235,23 @@ |
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
| 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 | + /** |
239 | 256 | * Returns the concepts specified by the group. |
240 | 257 | * |
241 | 258 | * @since 0.1 |
— | — | @@ -421,19 +438,6 @@ |
422 | 439 | } |
423 | 440 | |
424 | 441 | /** |
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 | | - /** |
438 | 442 | * Gets all the watching users and passes them, together with the specified |
439 | 443 | * changes and the group object itself, to the SWLGroupNotify hook. |
440 | 444 | * |
— | — | @@ -444,8 +448,6 @@ |
445 | 449 | public function notifyWatchingUsers( SWLChangeSet $changes ) { |
446 | 450 | $users = $this->getWatchingUsers(); |
447 | 451 | |
448 | | - $this->removeNonCoveredChanges( $changes ); |
449 | | - |
450 | 452 | if ( $changes->hasChanges( true ) ) { |
451 | 453 | wfRunHooks( 'SWLGroupNotify', array( $this, $users, $changes ) ); |
452 | 454 | } |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php |
— | — | @@ -1,9 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Wrapper around SMWChangeSet that holds extra info such as user and time, |
6 | | - * and has methods for (un)serialization and database interaction. |
7 | 5 | * |
| 6 | + * |
8 | 7 | * @since 0.1 |
9 | 8 | * |
10 | 9 | * @file SWL_ChangeSet.php |
— | — | @@ -43,20 +42,6 @@ |
44 | 43 | protected $changes; |
45 | 44 | |
46 | 45 | /** |
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 | | - /** |
61 | 46 | * DB ID of the change set (swl_sets.set_id). |
62 | 47 | * |
63 | 48 | * @var integer |
— | — | @@ -74,6 +59,13 @@ |
75 | 60 | protected $title = false; |
76 | 61 | |
77 | 62 | /** |
| 63 | + * The edit this set of changes belongs to. |
| 64 | + * |
| 65 | + * @var SWLEdit |
| 66 | + */ |
| 67 | + protected $edit; |
| 68 | + |
| 69 | + /** |
78 | 70 | * Creates and returns a new SWLChangeSet instance from a database result |
79 | 71 | * obtained by doing a select on swl_sets. |
80 | 72 | * |
— | — | @@ -83,9 +75,19 @@ |
84 | 76 | * |
85 | 77 | * @return SWLChangeSet |
86 | 78 | */ |
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 | + ) |
90 | 92 | ); |
91 | 93 | |
92 | 94 | $dbr = wfGetDb( DB_SLAVE ); |
— | — | @@ -99,7 +101,7 @@ |
100 | 102 | 'change_new_value' |
101 | 103 | ), |
102 | 104 | array( |
103 | | - 'change_set_id' => $set->set_id |
| 105 | + 'change_set_id' => $set->spe_set_id |
104 | 106 | ) |
105 | 107 | ); |
106 | 108 | |
— | — | @@ -112,13 +114,6 @@ |
113 | 115 | ); |
114 | 116 | } |
115 | 117 | |
116 | | - $changeSet = new SWLChangeSet( |
117 | | - $changeSet, |
118 | | - User::newFromName( $set->set_user_name, false ), |
119 | | - $set->set_time, |
120 | | - $set->set_id |
121 | | - ); |
122 | | - |
123 | 118 | return $changeSet; |
124 | 119 | } |
125 | 120 | |
— | — | @@ -133,10 +128,20 @@ |
134 | 129 | * @return SWLChangeSet |
135 | 130 | */ |
136 | 131 | 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 | + ) |
139 | 144 | ); |
140 | | - |
| 145 | + |
141 | 146 | foreach ( $changeSetArray['changes'] as $propName => $changes ) { |
142 | 147 | $property = SMWDIProperty::doUnserialize( $propName, '__pro' ); |
143 | 148 | |
— | — | @@ -150,14 +155,7 @@ |
151 | 156 | ) |
152 | 157 | ); |
153 | 158 | } |
154 | | - } |
155 | | - |
156 | | - $changeSet = new SWLChangeSet( |
157 | | - $changeSet, |
158 | | - User::newFromName( $changeSetArray['user_name'], false ), |
159 | | - $changeSetArray['time'], |
160 | | - $changeSetArray['id'] |
161 | | - ); |
| 159 | + } |
162 | 160 | |
163 | 161 | return $changeSet; |
164 | 162 | } |
— | — | @@ -167,10 +165,11 @@ |
168 | 166 | * |
169 | 167 | * @param SMWSemanticData $old |
170 | 168 | * @param SMWSemanticData $new |
| 169 | + * @param array $filterProperties Optional list of properties (string serializations) to filter on. Null for no filtering. |
171 | 170 | * |
172 | 171 | * @return SMWChangeSet |
173 | 172 | */ |
174 | | - public static function newFromSemanticData( SMWSemanticData $old, SMWSemanticData $new ) { |
| 173 | + public static function newFromSemanticData( SMWSemanticData $old, SMWSemanticData $new, array $filterProperties = null ) { |
175 | 174 | $subject = $old->getSubject(); |
176 | 175 | |
177 | 176 | if ( $subject != $new->getSubject() ) { |
— | — | @@ -181,14 +180,26 @@ |
182 | 181 | $insertions = new SMWSemanticData( $subject ); |
183 | 182 | $deletions = new SMWSemanticData( $subject ); |
184 | 183 | |
185 | | - $oldProperties = $old->getProperties(); |
186 | | - $newProperties = $new->getProperties(); |
| 184 | + $oldProperties = array(); |
| 185 | + $newProperties = array(); |
187 | 186 | |
| 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 | + |
188 | 199 | // Find the deletions. |
189 | | - self::findSingleDirectionChanges( $deletions, $oldProperties, $old, $newProperties ); |
| 200 | + self::findSingleDirectionChanges( $deletions, $oldProperties, $old, $newProperties, $filterProperties ); |
190 | 201 | |
191 | 202 | // Find the insertions. |
192 | | - self::findSingleDirectionChanges( $insertions, $newProperties, $new, $oldProperties ); |
| 203 | + self::findSingleDirectionChanges( $insertions, $newProperties, $new, $oldProperties, $filterProperties ); |
193 | 204 | |
194 | 205 | foreach ( $oldProperties as $propertyKey => /* SMWDIProperty */ $diProperty ) { |
195 | 206 | $oldDataItems = array(); |
— | — | @@ -254,7 +265,7 @@ |
255 | 266 | */ |
256 | 267 | protected static function findSingleDirectionChanges( SMWSemanticData &$changeSet, |
257 | 268 | array &$oldProperties, SMWSemanticData $oldData, array $newProperties ) { |
258 | | - |
| 269 | + |
259 | 270 | $deletionKeys = array(); |
260 | 271 | |
261 | 272 | foreach ( $oldProperties as $propertyKey => /* SMWDIProperty */ $diProperty ) { |
— | — | @@ -278,32 +289,52 @@ |
279 | 290 | * @param SWLPropertyChanges $changes Can be null |
280 | 291 | * @param SMWSemanticData $insertions Can be null |
281 | 292 | * @param SMWSemanticData $deletions Can be null |
| 293 | + * @param integer $id Can be null |
| 294 | + * @param SWLEdit $edit Can be null |
282 | 295 | */ |
283 | 296 | public function __construct( SMWDIWikiPage $subject, /* SWLPropertyChanges */ $changes = null, |
284 | 297 | /* SMWSemanticData */ $insertions = null, /* SMWSemanticData */ $deletions = null, |
285 | | - /* User */ $user = null, $time = null, $id = null ) { |
| 298 | + $id = null, /* SWLEdit */ $edit = null ) { |
286 | 299 | |
287 | 300 | $this->subject = $subject; |
288 | 301 | $this->changes = is_null( $changes ) ? new SWLPropertyChanges() : $changes; |
289 | 302 | $this->insertions = is_null( $insertions ) ? new SMWSemanticData( $subject ): $insertions; |
290 | 303 | $this->deletions = is_null( $deletions ) ? new SMWSemanticData( $subject ): $deletions; |
291 | 304 | |
292 | | - $this->time = is_null( $time ) ? wfTimestampNow() : $time; |
293 | | - $this->user = is_null( $user ) ? $GLOBALS['wgUser'] : $user; |
294 | 305 | $this->id = $id; |
| 306 | + $this->edit = $edit; |
295 | 307 | } |
296 | 308 | |
297 | 309 | /** |
| 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 | + /** |
298 | 329 | * Returns whether the set contains any changes. |
299 | 330 | * |
300 | | - * @param boolean $refresh |
| 331 | + * @since 0.1 |
301 | 332 | * |
302 | 333 | * @return boolean |
303 | 334 | */ |
304 | | - public function hasChanges( $refresh = false ) { |
| 335 | + public function hasChanges() { |
305 | 336 | return $this->changes->hasChanges() |
306 | | - || $this->insertions->hasVisibleProperties( $refresh ) |
307 | | - || $this->deletions->hasVisibleProperties( $refresh ); |
| 337 | + || $this->insertions->hasVisibleProperties() |
| 338 | + || $this->deletions->hasVisibleProperties(); |
308 | 339 | } |
309 | 340 | |
310 | 341 | /** |
— | — | @@ -422,9 +453,10 @@ |
423 | 454 | public function toArray() { |
424 | 455 | $changeSet = array( |
425 | 456 | '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(), |
429 | 461 | 'changes' => array() |
430 | 462 | ); |
431 | 463 | |
— | — | @@ -457,20 +489,12 @@ |
458 | 490 | * @since 0.1 |
459 | 491 | * |
460 | 492 | * @param array of SWLGroup |
| 493 | + * @param integer $editId |
461 | 494 | * |
462 | 495 | * @return integer ID of the inserted row (0 if nothing was inserted). |
463 | 496 | */ |
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() ) { |
475 | 499 | return 0; |
476 | 500 | } |
477 | 501 | |
— | — | @@ -478,18 +502,22 @@ |
479 | 503 | |
480 | 504 | $dbw->insert( |
481 | 505 | '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() |
487 | 507 | ); |
488 | 508 | |
489 | 509 | $id = $dbw->insertId(); |
490 | 510 | |
| 511 | + $dbw->insert( |
| 512 | + 'swl_sets_per_edit', |
| 513 | + array( |
| 514 | + 'spe_set_id' => $id, |
| 515 | + 'spe_edit_id' => $editId |
| 516 | + ) |
| 517 | + ); |
| 518 | + |
491 | 519 | $changes = array(); |
492 | 520 | |
493 | | - foreach ( $properties as /* SMWDIProperty */ $property ) { |
| 521 | + foreach ( $this->getAllProperties() as /* SMWDIProperty */ $property ) { |
494 | 522 | if ( $property->isUserDefined() ) { |
495 | 523 | $propSerialization = $property->getSerialization(); |
496 | 524 | |
— | — | @@ -554,6 +582,8 @@ |
555 | 583 | /** |
556 | 584 | * Gets the title of the page these changes belong to. |
557 | 585 | * |
| 586 | + * @since 0.1 |
| 587 | + * |
558 | 588 | * @return Title |
559 | 589 | */ |
560 | 590 | public function getTitle() { |
— | — | @@ -565,55 +595,14 @@ |
566 | 596 | } |
567 | 597 | |
568 | 598 | /** |
569 | | - * Sets the user that made the changes. |
| 599 | + * Gets the edit this set of changes belong to. |
570 | 600 | * |
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 | | - * |
607 | 601 | * @since 0.1 |
608 | 602 | * |
609 | | - * @param array $properties List of property names |
| 603 | + * @return SWLEdit |
610 | 604 | */ |
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; |
618 | 607 | } |
619 | 608 | |
620 | 609 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php |
— | — | @@ -65,18 +65,20 @@ |
66 | 66 | * @param string $continue |
67 | 67 | */ |
68 | 68 | 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' ) ); |
70 | 70 | |
71 | 71 | $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' ) ), |
73 | 74 | 'swl_users_per_group' => array( 'INNER JOIN', array( 'spg_group_id=upg_group_id' ) ), |
74 | | - ) ); |
| 75 | + ) ); |
75 | 76 | |
76 | 77 | $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' |
81 | 83 | ) ); |
82 | 84 | |
83 | 85 | $this->addWhere( array( |
— | — | @@ -85,15 +87,15 @@ |
86 | 88 | |
87 | 89 | $this->addOption( 'DISTINCT' ); |
88 | 90 | $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' ); |
90 | 92 | |
91 | 93 | if ( !is_null( $continue ) ) { |
92 | 94 | $continueParams = explode( '-', $continue ); |
93 | 95 | |
94 | 96 | if ( count( $continueParams ) == 2 ) { |
95 | 97 | $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] ) ); |
98 | 100 | } |
99 | 101 | else { |
100 | 102 | // TODO: error |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | $wgAutoloadClasses['ApiQuerySemanticWatchlist'] = dirname( __FILE__ ) . '/api/ApiQuerySemanticWatchlist.php'; |
65 | 65 | |
66 | 66 | $wgAutoloadClasses['SWLChangeSet'] = dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php'; |
| 67 | +$wgAutoloadClasses['SWLEdit'] = dirname( __FILE__ ) . '/includes/SWL_Edit.php'; |
67 | 68 | $wgAutoloadClasses['SWLEmailer'] = dirname( __FILE__ ) . '/includes/SWL_Emailer.php'; |
68 | 69 | $wgAutoloadClasses['SWLGroup'] = dirname( __FILE__ ) . '/includes/SWL_Group.php'; |
69 | 70 | $wgAutoloadClasses['SWLGroups'] = dirname( __FILE__ ) . '/includes/SWL_Groups.php'; |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php |
— | — | @@ -25,17 +25,36 @@ |
26 | 26 | * @return true |
27 | 27 | */ |
28 | 28 | 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() ); |
31 | 32 | |
32 | | - $wasInserted = $changes->writeToStore( $groups ) != 0; |
| 33 | + $groups = SWLGroups::getMatchingWatchGroups( $title ); |
33 | 34 | |
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 | + } |
38 | 57 | } |
39 | | - |
| 58 | + |
40 | 59 | return true; |
41 | 60 | } |
42 | 61 | |