r87935 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87934‎ | r87935 | r87936 >
Date:22:11, 12 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
commiting changes I made on plane - created a wrapper around SMWChangeSet to hold extra info and writeToDb method
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/includes/SWL_ChangeSet.php (added) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Group.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.sql
@@ -22,14 +22,20 @@
2323 -- List of all changes made to properties.
2424 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes (
2525 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
2927 change_property VARCHAR(255) NOT NULL, -- Name of the property of which a value was changed
3028 change_old_value BLOB NULL, -- The old value of the property (null for an adittion)
3129 change_new_value BLOB NULL -- The new value of the property (null for a deletion)
3230 ) /*$wgDBTableOptions*/;
3331
 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+
3440 -- Links changes to watchlist groups.
3541 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/swl_changes_per_group (
3642 cpg_group_id SMALLINT unsigned NOT NULL,
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
@@ -226,7 +226,7 @@
227227 * @return array of integer
228228 */
229229 public function getWatchingUsers() {
230 - $dbr = wfGetDb( DB_SLAVE );
 230+ $dbr = wfGetDB( DB_SLAVE );
231231
232232 $users = $dbr->select(
233233 'swl_users_per_group',
@@ -255,7 +255,7 @@
256256 *
257257 * @param SMWChangeSet $changes
258258 */
259 - public function notifyWatchingUsers( SMWChangeSet $changes ) {
 259+ public function notifyWatchingUsers( SWLChangeSet $changes ) {
260260 $users = $this->getWatchingUsers();
261261
262262 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
1104 + native
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
@@ -60,6 +60,7 @@
6161 $wgAutoloadClasses['ApiQuerySemanticWatchlist'] = dirname( __FILE__ ) . '/api/ApiQuerySemanticWatchlist.php';
6262 $wgAutoloadClasses['ApiSemanticWatchlist'] = dirname( __FILE__ ) . '/api/ApiSemanticWatchlist.php';
6363
 64+$wgAutoloadClasses['SWLChangeSet'] = dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php';
6465 $wgAutoloadClasses['SWLChange'] = dirname( __FILE__ ) . '/includes/SWL_Change.php';
6566 $wgAutoloadClasses['SWLChanges'] = dirname( __FILE__ ) . '/includes/SWL_Changes.php';
6667 $wgAutoloadClasses['SWLChangeSet'] = dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php';
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -25,9 +25,9 @@
2626 * @return true
2727 */
2828 public static function onDataChanged( SMWStore $store, SMWChangeSet $changes ) {
29 - $title = Title::makeTitle( $changes->getSubject()->getNamespace(), $changes->getSubject()->getDBkey() );
 29+ $changes = new SWLChangeSet( $changes );
3030
31 - foreach ( SWLGroups::getMatchingWatchGroups( $title ) as /* SWLGroup */ $group ) {
 31+ foreach ( SWLGroups::getMatchingWatchGroups( $changes->getTitle() ) as /* SWLGroup */ $group ) {
3232 $group->notifyWatchingUsers( $changes );
3333 }
3434
@@ -46,7 +46,7 @@
4747 *
4848 * @return true
4949 */
50 - public static function onGroupNotify( SWLGroup $group, array $userIDs, SMWChangeSet $changes ) {
 50+ public static function onGroupNotify( SWLGroup $group, array $userIDs, SWLChangeSet $changes ) {
5151
5252 foreach ( $userIDs as $userID ) {
5353 self::notifyUser( $group, User::newFromId( $userID ), $changes );
@@ -55,7 +55,7 @@
5656 return true;
5757 }
5858
59 - protected static function notifyUser( SWLGroup $group, User $user, SMWChangeSet $changes ) {
 59+ protected static function notifyUser( SWLGroup $group, User $user, SWLChangeSet $changes ) {
6060 // TODO
6161 //var_dump($group);var_dump($user);var_dump($changes);exit;
6262 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r87937follow up to r87935jeroendedauw22:38, 12 May 2011

Status & tagging log