Index: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.js |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +/** |
| 3 | + * JavasSript for Special:SemanticWatchlist in the Semantic Watchlist extension. |
| 4 | + * @see http://www.mediawiki.org/wiki/Extension:Semantic_Watchlist |
| 5 | + * |
| 6 | + * @licence GNU GPL v3 or later |
| 7 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 8 | + */ |
| 9 | + |
| 10 | +(function($) { $( document ).ready( function() { |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +} ); })(jQuery); |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 15 | + native |
Index: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css |
— | — | @@ -0,0 +1 @@ |
| 2 | +@CHARSET "UTF-8"; |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 3 | + native |
Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php |
— | — | @@ -62,7 +62,54 @@ |
63 | 63 | return; |
64 | 64 | } |
65 | 65 | |
| 66 | + $this->displayWatchlist(); |
| 67 | + } |
| 68 | + |
| 69 | + protected function displayWatchlist() { |
| 70 | + foreach ( $this->getChangeSets() as $set ) { |
| 71 | + $this->displayChangeSet( $set ); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + protected function getChangeSets() { |
| 76 | + global $wgUser; |
66 | 77 | |
| 78 | + $dbr = wfGetDb( DB_SLAVE ); |
| 79 | + |
| 80 | + $sets = $dbr->select( |
| 81 | + array( 'swl_sets', 'swl_sets_per_group', 'swl_users_per_group' ), |
| 82 | + array( |
| 83 | + 'set_id', |
| 84 | + 'set_user_name', |
| 85 | + 'set_page_id', |
| 86 | + 'set_time', |
| 87 | + ), |
| 88 | + array( |
| 89 | + 'upg_user_id' => $wgUser->getId() |
| 90 | + ), |
| 91 | + 'DatabaseBase::select', |
| 92 | + array( |
| 93 | + 'LIMIT' => 2, |
| 94 | + 'ORDER BY' => 'set_time', |
| 95 | + 'SORT DESC' |
| 96 | + ), |
| 97 | + array( |
| 98 | + 'swl_sets_per_group' => array( 'LEFT JOIN', array( 'set_id=spg_set_id' ) ), |
| 99 | + 'swl_users_per_group' => array( 'LEFT JOIN', array( 'spg_group_id=upg_group_id' ) ), |
| 100 | + ) |
| 101 | + ); |
| 102 | + |
| 103 | + $changeSets = array(); |
| 104 | + |
| 105 | + foreach ( $sets as $set ) { |
| 106 | + $changeSets[] = SWLChangeSet::newFromDBResult( $set ); |
| 107 | + } |
| 108 | + |
| 109 | + return $changeSets; |
67 | 110 | } |
68 | 111 | |
| 112 | + protected function displayChangeSet( SWLChangeSet $changeSet ) { |
| 113 | + |
| 114 | + } |
| 115 | + |
69 | 116 | } |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql |
— | — | @@ -18,29 +18,31 @@ |
19 | 19 | --INSERT INTO mw_swl_groups (group_name,group_categories,group_namespaces,group_properties,group_concepts) VALUES ('bar', '', 102, '', ''); |
20 | 20 | --INSERT INTO mw_swl_groups (group_name,group_categories,group_namespaces,group_properties,group_concepts) VALUES ('baz', 'Customers', 102, 'Has contract status', ''); |
21 | 21 | --INSERT INTO mw_swl_users_per_group (upg_group_id,upg_user_id) VALUES(1,1); |
| 22 | +--INSERT INTO mw_swl_sets (set_user_name,set_page_id,set_time) VALUES('jeroen',1,1); |
| 23 | +--INSERT INTO mw_swl_changes (change_set_id,change_property,change_old_value,change_new_value) VALUES(1,'has foobar','baz','bar'); |
22 | 24 | |
23 | 25 | -- List of all changes made to properties. |
24 | 26 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes ( |
25 | 27 | change_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY, |
26 | | - change_group_id INT(10) unsigned NOT NULL, -- Foreign key: swl_change_groups.cg_id |
| 28 | + change_set_id INT(10) unsigned NOT NULL, -- Foreign key: swl_sets.set_id |
27 | 29 | change_property VARCHAR(255) NOT NULL, -- Name of the property of which a value was changed |
28 | 30 | change_old_value BLOB NULL, -- The old value of the property (null for an adittion) |
29 | 31 | change_new_value BLOB NULL -- The new value of the property (null for a deletion) |
30 | 32 | ) /*$wgDBTableOptions*/; |
31 | 33 | |
32 | | -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_change_groups ( |
33 | | - cg_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY, |
34 | | - cg_user_name VARCHAR(255) NOT NULL, -- The person that made the modification (account name or ip) |
35 | | - cg_page_id INT(10) unsigned NOT NULL, -- The id of the page the modification was on |
36 | | - cg_time CHAR(14) binary NOT NULL default '' -- The time the chages where made |
| 34 | +-- Sets of changes, as in the set you get when editing a page. |
| 35 | +CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_sets ( |
| 36 | + set_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY, |
| 37 | + set_user_name VARCHAR(255) NOT NULL, -- The person that made the modification (account name or ip) |
| 38 | + set_page_id INT(10) unsigned NOT NULL, -- The id of the page the modification was on |
| 39 | + set_time CHAR(14) binary NOT NULL default '' -- The time the chages where made |
37 | 40 | ) /*$wgDBTableOptions*/; |
38 | 41 | |
39 | | -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes_per_group ( |
40 | | - cpg_group_id SMALLINT unsigned NOT NULL, -- Foreign key: swl_groups.group_id |
41 | | - cpg_change_group_id INT(10) unsigned NOT NULL, -- Foreign key: swl_change_groups.cg_id |
42 | | - PRIMARY KEY (cpg_group_id,cpg_change_group_id) |
| 42 | +-- Links change sets to watchlist groups. |
| 43 | +CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_sets_per_group ( |
| 44 | + spg_group_id SMALLINT unsigned NOT NULL, -- Foreign key: swl_groups.group_id |
| 45 | + spg_set_id INT(10) unsigned NOT NULL, -- Foreign key: swl_sets.set_id |
| 46 | + PRIMARY KEY (spg_group_id,spg_set_id) |
43 | 47 | ) /*$wgDBTableOptions*/; |
44 | 48 | |
45 | 49 | -- Links users to watchlist groups. |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php |
— | — | @@ -25,6 +25,8 @@ |
26 | 26 | |
27 | 27 | protected $concepts; |
28 | 28 | |
| 29 | + protected $watchingUsers = false; |
| 30 | + |
29 | 31 | public static function newFromDBResult( $group ) { |
30 | 32 | return new SWLGroup( |
31 | 33 | $group->group_id, |
— | — | @@ -226,28 +228,45 @@ |
227 | 229 | * @return array of integer |
228 | 230 | */ |
229 | 231 | public function getWatchingUsers() { |
230 | | - $dbr = wfGetDB( DB_SLAVE ); |
231 | | - |
232 | | - $users = $dbr->select( |
233 | | - 'swl_users_per_group', |
234 | | - array( |
235 | | - 'upg_user_id' |
236 | | - ), |
237 | | - array( |
238 | | - 'upg_group_id' => $this->getId() |
239 | | - ) |
240 | | - ); |
241 | | - |
242 | | - $userIds = array(); |
243 | | - |
244 | | - foreach ( $users as $user ) { |
245 | | - $userIds[] = $user->upg_user_id; |
| 232 | + if ( $this->watchingUsers == false ) { |
| 233 | + $dbr = wfGetDB( DB_SLAVE ); |
| 234 | + |
| 235 | + $users = $dbr->select( |
| 236 | + 'swl_users_per_group', |
| 237 | + array( |
| 238 | + 'upg_user_id' |
| 239 | + ), |
| 240 | + array( |
| 241 | + 'upg_group_id' => $this->getId() |
| 242 | + ) |
| 243 | + ); |
| 244 | + |
| 245 | + $userIds = array(); |
| 246 | + |
| 247 | + foreach ( $users as $user ) { |
| 248 | + $userIds[] = $user->upg_user_id; |
| 249 | + } |
| 250 | + |
| 251 | + $this->watchingUsers = $userIds; |
246 | 252 | } |
247 | 253 | |
248 | | - return $userIds; |
| 254 | + return $this->watchingUsers; |
249 | 255 | } |
250 | 256 | |
251 | 257 | /** |
| 258 | + * Returns if the group is watched by the specified user or not. |
| 259 | + * |
| 260 | + * @since 0.1 |
| 261 | + * |
| 262 | + * @param User $user |
| 263 | + * |
| 264 | + * @return boolean |
| 265 | + */ |
| 266 | + public function isWatchedByUser( User $user ) { |
| 267 | + return in_array( $user->getId(), $this->getWatchingUsers() ); |
| 268 | + } |
| 269 | + |
| 270 | + /** |
252 | 271 | * Gets all the watching users and passes them, together with the specified |
253 | 272 | * changes and the group object itself, to the SWLGroupNotify hook. |
254 | 273 | * |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Groups.php |
— | — | @@ -57,12 +57,12 @@ |
58 | 58 | * |
59 | 59 | * @param Title $title |
60 | 60 | * |
61 | | - * @return array |
| 61 | + * @return array of SWLGroup |
62 | 62 | */ |
63 | 63 | public static function getMatchingWatchGroups( Title $title ) { |
64 | 64 | $matchingGroups = array(); |
65 | 65 | |
66 | | - foreach ( self::getAll() as $group ) { |
| 66 | + foreach ( self::getAll() as /* SWLGroup */ $group ) { |
67 | 67 | if ( $group->coversPage( $title ) ) { |
68 | 68 | $matchingGroups[] = $group; |
69 | 69 | } |
— | — | @@ -72,6 +72,27 @@ |
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
| 76 | + * Returns all watchlist groups that are watched by the specified user. |
| 77 | + * |
| 78 | + * @since 0.1 |
| 79 | + * |
| 80 | + * @param User $user |
| 81 | + * |
| 82 | + * @return array of SWLGroup |
| 83 | + */ |
| 84 | + public static function getGroupsForUser( User $user ) { |
| 85 | + $matchingGroups = array(); |
| 86 | + |
| 87 | + foreach ( self::getAll() as /* SWLGroup */ $group ) { |
| 88 | + if ( $group->isWatchedByUser( $user ) ) { |
| 89 | + $matchingGroups[] = $group; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + return $matchingGroups; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
76 | 97 | * Notifies all users that are watching a group and that should be notified |
77 | 98 | * of the provided changes. |
78 | 99 | * |
— | — | @@ -91,19 +112,6 @@ |
92 | 113 | } |
93 | 114 | |
94 | 115 | /** |
95 | | - * Returns the list of users watching the specified watchlist group. |
96 | | - * |
97 | | - * @since 0.1 |
98 | | - * |
99 | | - * @param $group |
100 | | - * |
101 | | - * @return array |
102 | | - */ |
103 | | - protected static function getUsersForGroup( $group ) { |
104 | | - |
105 | | - } |
106 | | - |
107 | | - /** |
108 | 116 | * Determines and returns if a certain user should be notified of changes |
109 | 117 | * or not (in case this already happened, so this extension doesn't spam). |
110 | 118 | * |
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php |
— | — | @@ -3,8 +3,11 @@ |
4 | 4 | class SWLChangeSet { |
5 | 5 | |
6 | 6 | /** |
| 7 | + * Base object to which calls to unknown methods get routed via __call. |
| 8 | + * This is to emulate SWLChangSet deriving from SMWChangeSet, but at the |
| 9 | + * same time makes it possible to go from the SMW version to the SWL version |
| 10 | + * by passing the former to the constructor of the later. |
7 | 11 | * |
8 | | - * |
9 | 12 | * @var SMWChangeSet |
10 | 13 | */ |
11 | 14 | protected $changeSet; |
— | — | @@ -24,7 +27,7 @@ |
25 | 28 | protected $time; |
26 | 29 | |
27 | 30 | /** |
28 | | - * DB ID of the change set (swl_change_groups.cg_id). |
| 31 | + * DB ID of the change set (swl_sets.set_id). |
29 | 32 | * |
30 | 33 | * @var integer |
31 | 34 | */ |
— | — | @@ -46,7 +49,7 @@ |
47 | 50 | */ |
48 | 51 | public static function newFromDBResult( $set ) { |
49 | 52 | $changeSet = new SMWChangeSet( |
50 | | - SMWDIWikiPage::newFromTitle( Title::newFromID( $set->cg_page_id ) ) |
| 53 | + SMWDIWikiPage::newFromTitle( Title::newFromID( $set->set_page_id ) ) |
51 | 54 | ); |
52 | 55 | |
53 | 56 | $dbr = wfGetDb( DB_SLAVE ); |
— | — | @@ -60,7 +63,7 @@ |
61 | 64 | 'change_new_value' |
62 | 65 | ), |
63 | 66 | array( |
64 | | - 'change_group_id' => $set->cg_id |
| 67 | + 'change_set_id' => $set->set_id |
65 | 68 | ) |
66 | 69 | ); |
67 | 70 | |
— | — | @@ -68,11 +71,11 @@ |
69 | 72 | $changeSet->addChange( $change->change_property, SMWPropertyChange( $change->change_old_value, $change->change_new_value ) ); |
70 | 73 | } |
71 | 74 | |
72 | | - $changeSet = new SWLChangeSet( // swl_change_groups |
| 75 | + $changeSet = new SWLChangeSet( // swl_sets |
73 | 76 | $changeSet, |
74 | | - User::newFromName( $set->cg_user_name ), |
75 | | - $set->cg_time, |
76 | | - $set->cg_id |
| 77 | + User::newFromName( $set->set_user_name ), |
| 78 | + $set->set_time, |
| 79 | + $set->set_id |
77 | 80 | ); |
78 | 81 | |
79 | 82 | return $changeSet; |
— | — | @@ -107,7 +110,7 @@ |
108 | 111 | } |
109 | 112 | |
110 | 113 | /** |
111 | | - * Save the |
| 114 | + * Save the change set to the database. |
112 | 115 | * |
113 | 116 | * @since 0.1 |
114 | 117 | * |
— | — | @@ -117,11 +120,11 @@ |
118 | 121 | $dbw = wfGetDB( DB_MASTER ); |
119 | 122 | |
120 | 123 | $dbw->insert( |
121 | | - 'swl_change_groups', |
| 124 | + 'swl_sets', |
122 | 125 | array( |
123 | | - 'cg_user_name' => $this->getUser()->getName(), |
124 | | - 'cg_page_id' => $this->getTitle()->getArticleID(), |
125 | | - 'cg_time' => is_null( $this->getTime() ) ? $dbw->timestamp() : $this->getTime() |
| 126 | + 'set_user_name' => $this->getUser()->getName(), |
| 127 | + 'set_page_id' => $this->getTitle()->getArticleID(), |
| 128 | + 'set_time' => is_null( $this->getTime() ) ? $dbw->timestamp() : $this->getTime() |
126 | 129 | ) |
127 | 130 | ); |
128 | 131 | |
— | — | @@ -166,10 +169,17 @@ |
167 | 170 | } |
168 | 171 | |
169 | 172 | foreach ( $changes as $change ) { |
| 173 | + if ( $change['property'] == '' ) { |
| 174 | + // When removing the last value for a property of a page, |
| 175 | + // for some reason it gets inserted for a property without |
| 176 | + // name, so skip that. Better to fix higher up though. |
| 177 | + continue; |
| 178 | + } |
| 179 | + |
170 | 180 | $dbw->insert( |
171 | 181 | 'swl_changes', |
172 | 182 | array( |
173 | | - 'change_group_id' => $id, |
| 183 | + 'change_set_id' => $id, |
174 | 184 | 'change_property' => $change['property'], |
175 | 185 | 'change_old_value' => $change['old'], |
176 | 186 | 'change_new_value' => $change['new'] |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php |
— | — | @@ -88,12 +88,18 @@ |
89 | 89 | ) ); |
90 | 90 | $updater->addExtensionUpdate( array( |
91 | 91 | 'addTable', |
92 | | - 'swl_changes_per_group', |
| 92 | + 'swl_sets', |
93 | 93 | dirname( __FILE__ ) . '/SemanticWatchlist.sql', |
94 | 94 | true |
95 | 95 | ) ); |
96 | 96 | $updater->addExtensionUpdate( array( |
97 | 97 | 'addTable', |
| 98 | + 'swl_sets_per_group', |
| 99 | + dirname( __FILE__ ) . '/SemanticWatchlist.sql', |
| 100 | + true |
| 101 | + ) ); |
| 102 | + $updater->addExtensionUpdate( array( |
| 103 | + 'addTable', |
98 | 104 | 'swl_users_per_group', |
99 | 105 | dirname( __FILE__ ) . '/SemanticWatchlist.sql', |
100 | 106 | true |