r88022 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88021‎ | r88022 | r88023 >
Date:22:07, 13 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some work on Special:SemanticWatchlist and renaming of some db tables and fields to be less confusing
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Group.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Groups.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css (added) (history)
  • /trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.js (added) (history)

Diff [purge]

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
115 + 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
13 + native
Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
@@ -62,7 +62,54 @@
6363 return;
6464 }
6565
 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;
6677
 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;
67110 }
68111
 112+ protected function displayChangeSet( SWLChangeSet $changeSet ) {
 113+
 114+ }
 115+
69116 }
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
@@ -18,29 +18,31 @@
1919 --INSERT INTO mw_swl_groups (group_name,group_categories,group_namespaces,group_properties,group_concepts) VALUES ('bar', '', 102, '', '');
2020 --INSERT INTO mw_swl_groups (group_name,group_categories,group_namespaces,group_properties,group_concepts) VALUES ('baz', 'Customers', 102, 'Has contract status', '');
2121 --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');
2224
2325 -- List of all changes made to properties.
2426 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes (
2527 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
2729 change_property VARCHAR(255) NOT NULL, -- Name of the property of which a value was changed
2830 change_old_value BLOB NULL, -- The old value of the property (null for an adittion)
2931 change_new_value BLOB NULL -- The new value of the property (null for a deletion)
3032 ) /*$wgDBTableOptions*/;
3133
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
3740 ) /*$wgDBTableOptions*/;
3841
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)
4347 ) /*$wgDBTableOptions*/;
4448
4549 -- Links users to watchlist groups.
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
@@ -25,6 +25,8 @@
2626
2727 protected $concepts;
2828
 29+ protected $watchingUsers = false;
 30+
2931 public static function newFromDBResult( $group ) {
3032 return new SWLGroup(
3133 $group->group_id,
@@ -226,28 +228,45 @@
227229 * @return array of integer
228230 */
229231 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;
246252 }
247253
248 - return $userIds;
 254+ return $this->watchingUsers;
249255 }
250256
251257 /**
 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+ /**
252271 * Gets all the watching users and passes them, together with the specified
253272 * changes and the group object itself, to the SWLGroupNotify hook.
254273 *
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Groups.php
@@ -57,12 +57,12 @@
5858 *
5959 * @param Title $title
6060 *
61 - * @return array
 61+ * @return array of SWLGroup
6262 */
6363 public static function getMatchingWatchGroups( Title $title ) {
6464 $matchingGroups = array();
6565
66 - foreach ( self::getAll() as $group ) {
 66+ foreach ( self::getAll() as /* SWLGroup */ $group ) {
6767 if ( $group->coversPage( $title ) ) {
6868 $matchingGroups[] = $group;
6969 }
@@ -72,6 +72,27 @@
7373 }
7474
7575 /**
 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+ /**
7697 * Notifies all users that are watching a group and that should be notified
7798 * of the provided changes.
7899 *
@@ -91,19 +112,6 @@
92113 }
93114
94115 /**
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 - /**
108116 * Determines and returns if a certain user should be notified of changes
109117 * or not (in case this already happened, so this extension doesn't spam).
110118 *
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
@@ -3,8 +3,11 @@
44 class SWLChangeSet {
55
66 /**
 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.
711 *
8 - *
912 * @var SMWChangeSet
1013 */
1114 protected $changeSet;
@@ -24,7 +27,7 @@
2528 protected $time;
2629
2730 /**
28 - * DB ID of the change set (swl_change_groups.cg_id).
 31+ * DB ID of the change set (swl_sets.set_id).
2932 *
3033 * @var integer
3134 */
@@ -46,7 +49,7 @@
4750 */
4851 public static function newFromDBResult( $set ) {
4952 $changeSet = new SMWChangeSet(
50 - SMWDIWikiPage::newFromTitle( Title::newFromID( $set->cg_page_id ) )
 53+ SMWDIWikiPage::newFromTitle( Title::newFromID( $set->set_page_id ) )
5154 );
5255
5356 $dbr = wfGetDb( DB_SLAVE );
@@ -60,7 +63,7 @@
6164 'change_new_value'
6265 ),
6366 array(
64 - 'change_group_id' => $set->cg_id
 67+ 'change_set_id' => $set->set_id
6568 )
6669 );
6770
@@ -68,11 +71,11 @@
6972 $changeSet->addChange( $change->change_property, SMWPropertyChange( $change->change_old_value, $change->change_new_value ) );
7073 }
7174
72 - $changeSet = new SWLChangeSet( // swl_change_groups
 75+ $changeSet = new SWLChangeSet( // swl_sets
7376 $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
7780 );
7881
7982 return $changeSet;
@@ -107,7 +110,7 @@
108111 }
109112
110113 /**
111 - * Save the
 114+ * Save the change set to the database.
112115 *
113116 * @since 0.1
114117 *
@@ -117,11 +120,11 @@
118121 $dbw = wfGetDB( DB_MASTER );
119122
120123 $dbw->insert(
121 - 'swl_change_groups',
 124+ 'swl_sets',
122125 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()
126129 )
127130 );
128131
@@ -166,10 +169,17 @@
167170 }
168171
169172 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+
170180 $dbw->insert(
171181 'swl_changes',
172182 array(
173 - 'change_group_id' => $id,
 183+ 'change_set_id' => $id,
174184 'change_property' => $change['property'],
175185 'change_old_value' => $change['old'],
176186 'change_new_value' => $change['new']
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -88,12 +88,18 @@
8989 ) );
9090 $updater->addExtensionUpdate( array(
9191 'addTable',
92 - 'swl_changes_per_group',
 92+ 'swl_sets',
9393 dirname( __FILE__ ) . '/SemanticWatchlist.sql',
9494 true
9595 ) );
9696 $updater->addExtensionUpdate( array(
9797 'addTable',
 98+ 'swl_sets_per_group',
 99+ dirname( __FILE__ ) . '/SemanticWatchlist.sql',
 100+ true
 101+ ) );
 102+ $updater->addExtensionUpdate( array(
 103+ 'addTable',
98104 'swl_users_per_group',
99105 dirname( __FILE__ ) . '/SemanticWatchlist.sql',
100106 true

Status & tagging log