Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql |
— | — | @@ -22,14 +22,20 @@ |
23 | 23 | -- List of all changes made to properties. |
24 | 24 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes ( |
25 | 25 | change_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY, |
26 | | - change_group_id INT(10) unsigned NOT NULL, -- This does NOT refer to the swl_groups table, but rather "groups of changes" |
27 | | - change_user_name VARCHAR(255) NOT NULL, -- The person that made the modification (account name or ip) |
28 | | - change_page_id INT(10) unsigned NOT NULL, -- The id of the page the modification was on |
| 26 | + change_group_id INT(10) unsigned NOT NULL, -- Foreign key: swl_change_groups.cg_id |
29 | 27 | change_property VARCHAR(255) NOT NULL, -- Name of the property of which a value was changed |
30 | 28 | change_old_value BLOB NULL, -- The old value of the property (null for an adittion) |
31 | 29 | change_new_value BLOB NULL -- The new value of the property (null for a deletion) |
32 | 30 | ) /*$wgDBTableOptions*/; |
33 | 31 | |
| 32 | +-- Groups of changes, as in the set you get when editing a page. |
| 33 | +CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_change_groups ( |
| 34 | + cg_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY, |
| 35 | + cg_user_name VARCHAR(255) NOT NULL, -- The person that made the modification (account name or ip) |
| 36 | + cg_page_id INT(10) unsigned NOT NULL, -- The id of the page the modification was on |
| 37 | + cg_time CHAR(14) binary NOT NULL default '' -- The time the chages where made |
| 38 | +) /*$wgDBTableOptions*/; |
| 39 | + |
34 | 40 | -- Links changes to watchlist groups. |
35 | 41 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes_per_group ( |
36 | 42 | cpg_group_id SMALLINT unsigned NOT NULL, |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php |
— | — | @@ -226,7 +226,7 @@ |
227 | 227 | * @return array of integer |
228 | 228 | */ |
229 | 229 | public function getWatchingUsers() { |
230 | | - $dbr = wfGetDb( DB_SLAVE ); |
| 230 | + $dbr = wfGetDB( DB_SLAVE ); |
231 | 231 | |
232 | 232 | $users = $dbr->select( |
233 | 233 | 'swl_users_per_group', |
— | — | @@ -255,7 +255,7 @@ |
256 | 256 | * |
257 | 257 | * @param SMWChangeSet $changes |
258 | 258 | */ |
259 | | - public function notifyWatchingUsers( SMWChangeSet $changes ) { |
| 259 | + public function notifyWatchingUsers( SWLChangeSet $changes ) { |
260 | 260 | $users = $this->getWatchingUsers(); |
261 | 261 | |
262 | 262 | wfRunHooks( 'SWLGroupNotify', array( $this, $users, $changes ) ); |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php |
— | — | @@ -0,0 +1,102 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SWLChangeSet { |
| 5 | + |
| 6 | + /** |
| 7 | + * |
| 8 | + * |
| 9 | + * @var SMWChangeSet |
| 10 | + */ |
| 11 | + protected $changeSet; |
| 12 | + |
| 13 | + /** |
| 14 | + * The user that made the changes. |
| 15 | + * |
| 16 | + * @var User |
| 17 | + */ |
| 18 | + protected $user; |
| 19 | + |
| 20 | + /** |
| 21 | + * The time on which the changes where made. |
| 22 | + * |
| 23 | + * @var integer |
| 24 | + */ |
| 25 | + protected $time; |
| 26 | + |
| 27 | + /** |
| 28 | + * The title of the page the changeset holds changes for. |
| 29 | + * |
| 30 | + * @var Title or false |
| 31 | + */ |
| 32 | + protected $title = false; |
| 33 | + |
| 34 | + /** |
| 35 | + * Constructor. |
| 36 | + * |
| 37 | + * @param User $user |
| 38 | + * @param integer $time |
| 39 | + */ |
| 40 | + public function __construct( SMWChangeSet $changeSet, /* User */ $user = null, $time = null ) { |
| 41 | + $this->changeSet = $changeSet; |
| 42 | + $this->time = $time; |
| 43 | + $this->user = is_null( $user ) ? $GLOBALS['wgUser'] : $user; |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * SMW thinks this class is a SMWResultPrinter, and calls methods that should |
| 48 | + * be forewarded to $this->queryPrinter on it. |
| 49 | + * |
| 50 | + * @since 0.1 |
| 51 | + * |
| 52 | + * @param string $name |
| 53 | + * @param array $arguments |
| 54 | + */ |
| 55 | + public function __call( $name, array $arguments ) { |
| 56 | + return call_user_func_array( array( $this->changeSet, $name ), $arguments ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Save the |
| 61 | + * |
| 62 | + * @since 0.1 |
| 63 | + * |
| 64 | + * @return boolean Success indicator |
| 65 | + */ |
| 66 | + public function writeToStore() { |
| 67 | + $dbr = wfGetDB( DB_MASTER ); |
| 68 | + |
| 69 | + $dbr->insert( |
| 70 | + 'swl_change_groups', |
| 71 | + array( |
| 72 | + 'cg_user_name' => $this->getUser(), |
| 73 | + 'cg_page_id' => $this->getTitle(), |
| 74 | + 'cg_time' => is_null( $this->getTime() ) ? $dbw->timestamp() : $this->getTime() |
| 75 | + ) |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + public function getTitle() { |
| 80 | + if ( $this->title === false ) { |
| 81 | + $this->title = Title::makeTitle( $this->getSubject()->getNamespace(), $this->getSubject()->getDBkey() ); |
| 82 | + } |
| 83 | + |
| 84 | + return $this->title; |
| 85 | + } |
| 86 | + |
| 87 | + public function setUser() { |
| 88 | + |
| 89 | + } |
| 90 | + |
| 91 | + public function getUser() { |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | + public function setTime() { |
| 96 | + |
| 97 | + } |
| 98 | + |
| 99 | + public function getTime() { |
| 100 | + |
| 101 | + } |
| 102 | + |
| 103 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 104 | + native |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php |
— | — | @@ -60,6 +60,7 @@ |
61 | 61 | $wgAutoloadClasses['ApiQuerySemanticWatchlist'] = dirname( __FILE__ ) . '/api/ApiQuerySemanticWatchlist.php'; |
62 | 62 | $wgAutoloadClasses['ApiSemanticWatchlist'] = dirname( __FILE__ ) . '/api/ApiSemanticWatchlist.php'; |
63 | 63 | |
| 64 | +$wgAutoloadClasses['SWLChangeSet'] = dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php'; |
64 | 65 | $wgAutoloadClasses['SWLChange'] = dirname( __FILE__ ) . '/includes/SWL_Change.php'; |
65 | 66 | $wgAutoloadClasses['SWLChanges'] = dirname( __FILE__ ) . '/includes/SWL_Changes.php'; |
66 | 67 | $wgAutoloadClasses['SWLChangeSet'] = dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php'; |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php |
— | — | @@ -25,9 +25,9 @@ |
26 | 26 | * @return true |
27 | 27 | */ |
28 | 28 | public static function onDataChanged( SMWStore $store, SMWChangeSet $changes ) { |
29 | | - $title = Title::makeTitle( $changes->getSubject()->getNamespace(), $changes->getSubject()->getDBkey() ); |
| 29 | + $changes = new SWLChangeSet( $changes ); |
30 | 30 | |
31 | | - foreach ( SWLGroups::getMatchingWatchGroups( $title ) as /* SWLGroup */ $group ) { |
| 31 | + foreach ( SWLGroups::getMatchingWatchGroups( $changes->getTitle() ) as /* SWLGroup */ $group ) { |
32 | 32 | $group->notifyWatchingUsers( $changes ); |
33 | 33 | } |
34 | 34 | |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | * |
48 | 48 | * @return true |
49 | 49 | */ |
50 | | - public static function onGroupNotify( SWLGroup $group, array $userIDs, SMWChangeSet $changes ) { |
| 50 | + public static function onGroupNotify( SWLGroup $group, array $userIDs, SWLChangeSet $changes ) { |
51 | 51 | |
52 | 52 | foreach ( $userIDs as $userID ) { |
53 | 53 | self::notifyUser( $group, User::newFromId( $userID ), $changes ); |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | return true; |
57 | 57 | } |
58 | 58 | |
59 | | - protected static function notifyUser( SWLGroup $group, User $user, SMWChangeSet $changes ) { |
| 59 | + protected static function notifyUser( SWLGroup $group, User $user, SWLChangeSet $changes ) { |
60 | 60 | // TODO |
61 | 61 | //var_dump($group);var_dump($user);var_dump($changes);exit; |
62 | 62 | } |