r77272 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77271‎ | r77272 | r77273 >
Date:07:46, 25 November 2010
Author:mah
Status:deferred (Comments)
Tags:
Comment:
Simplify the SQL setup code, maka schema createion work on SQLite and, with r77271, make MW auto translate some MySQL-isms for SQLite.
Modified paths:
  • /trunk/extensions/SocialProfile/SocialProfile.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SystemGifts.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/systemgifts.sql (modified) (history)
  • /trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserBoard/user_board.sql (modified) (history)
  • /trunk/extensions/SocialProfile/UserGifts/SpecialGiveGift.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserGifts/usergifts.sql (modified) (history)
  • /trunk/extensions/SocialProfile/UserProfile/user_profile.sql (modified) (history)
  • /trunk/extensions/SocialProfile/UserRelationship/user_relationship.sql (modified) (history)
  • /trunk/extensions/SocialProfile/UserSystemMessages/user_system_messages.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserProfile/user_profile.sql
@@ -3,7 +3,7 @@
44 --
55
66 CREATE TABLE /*$wgDBprefix*/user_profile (
7 - `up_user_id` int(5) NOT NULL default '0',
 7+ `up_user_id` int(5) NOT NULL PRIMARY KEY default '0',
88 `up_location_city` varchar(255) default NULL,
99 `up_location_state` varchar(100) default NULL,
1010 `up_location_country` varchar(255) default NULL,
@@ -34,6 +34,5 @@
3535 `up_custom_4` text,
3636 `up_custom_5` text,
3737 `up_last_seen` datetime default NULL,
38 - `up_type` int(5) NOT NULL default '1',
39 - PRIMARY KEY (`up_user_id`)
 38+ `up_type` int(5) NOT NULL default '1'
4039 ) DEFAULT CHARSET=utf8;
Index: trunk/extensions/SocialProfile/UserRelationship/user_relationship.sql
@@ -3,24 +3,23 @@
44 --
55
66 CREATE TABLE /*$wgDBprefix*/user_relationship (
7 - `r_id` int(11) NOT NULL auto_increment,
 7+ `r_id` int(11) PRIMARY KEY auto_increment,
88 `r_user_id` int(5) unsigned NOT NULL default '0',
99 `r_user_name` varchar(255) NOT NULL default '',
1010 `r_user_id_relation` int(5) unsigned NOT NULL default '0',
1111 `r_user_name_relation` varchar(255) NOT NULL default '',
1212 `r_type` int(2) default NULL,
13 - `r_date` datetime default NULL,
14 - PRIMARY KEY (`r_id`),
15 - KEY `r_user_id` (`r_user_id`),
16 - KEY `r_user_id_relation` (`r_user_id_relation`)
17 -)DEFAULT CHARSET=utf8;
 13+ `r_date` datetime default NULL
 14+) DEFAULT CHARSET=utf8;
 15+CREATE INDEX /*i*/r_user_id ON /*_*/user_relationship (`r_user_id`);
 16+CREATE INDEX /*i*/r_user_id_relation ON /*_*/user_relationship (`r_user_id_relation`);
1817
1918 --
2019 -- Table structure for table `user_relationship_request`
2120 --
2221
2322 CREATE TABLE /*$wgDBprefix*/user_relationship_request (
24 - `ur_id` int(11) NOT NULL auto_increment,
 23+ `ur_id` int(11) PRIMARY KEY auto_increment,
2524 `ur_user_id_from` int(5) unsigned NOT NULL default '0',
2625 `ur_user_name_from` varchar(255) NOT NULL default '',
2726 `ur_user_id_to` int(5) unsigned NOT NULL default '0',
@@ -28,8 +27,7 @@
2928 `ur_status` int(2) default '0',
3029 `ur_type` int(2) default NULL,
3130 `ur_message` varchar(255) default NULL,
32 - `ur_date` datetime default NULL,
33 - PRIMARY KEY (`ur_id`),
34 - KEY `ur_user_id_from` (`ur_user_id_from`),
35 - KEY `ur_user_id_to` (`ur_user_id_to`)
 31+ `ur_date` datetime default NULL
3632 ) DEFAULT CHARSET=utf8;
 33+CREATE INDEX /*i*/ur_user_id_from ON /*_*/user_relationship_request (`ur_user_id_from`);
 34+CREATE INDEX /*I*/ur_user_id_to ON /*_*/user_relationship_request (`ur_user_id_to`);
Index: trunk/extensions/SocialProfile/SocialProfile.php
@@ -199,80 +199,36 @@
200200 # Schema changes
201201 $wgHooks['LoadExtensionSchemaUpdates'][] = 'efSocialProfileSchemaUpdates';
202202
203 -function efSocialProfileSchemaUpdates( $updater = null ) {
204 - $dir = dirname( __FILE__ );
 203+function efSocialProfileDBUpdate( $updater, $label, $file ) {
205204 if ( $updater === null ) {
206 - global $wgExtNewTables, $wgDBtype;
207 - if ( $wgDBtype == 'mysql' ) {
208 - // Initial install tables
209 - $wgExtNewTables[] = array( 'user_board', "$dir/UserBoard/user_board.sql" );
210 - $wgExtNewTables[] = array( 'user_profile', "$dir/UserProfile/user_profile.sql" );
211 - $wgExtNewTables[] = array( 'user_stats', "$dir/UserStats/user_stats.sql" );
212 - $wgExtNewTables[] = array( 'user_relationship', "$dir/UserRelationship/user_relationship.sql" );
213 - $wgExtNewTables[] = array( 'user_relationship_request', "$dir/UserRelationship/user_relationship.sql" );
214 - $wgExtNewTables[] = array( 'user_system_gift', "$dir/SystemGifts/systemgifts.sql" );
215 - $wgExtNewTables[] = array( 'system_gift', "$dir/SystemGifts/systemgifts.sql" );
216 - $wgExtNewTables[] = array( 'user_gift', "$dir/UserGifts/usergifts.sql" );
217 - $wgExtNewTables[] = array( 'gift', "$dir/UserGifts/usergifts.sql" );
218 - $wgExtNewTables[] = array( 'user_system_messages', "$dir/UserSystemMessages/user_system_messages.sql" );
219 - } elseif( $wgDBtype == 'postgres' ) {
220 - $wgExtNewTables[] = array( 'user_board', "$dir/UserBoard/user_board.postgres.sql" );
221 - $wgExtNewTables[] = array( 'user_profile', "$dir/UserProfile/user_profile.postgres.sql" );
222 - $wgExtNewTables[] = array( 'user_stats', "$dir/UserStats/user_stats.postgres.sql" );
223 - $wgExtNewTables[] = array( 'user_relationship', "$dir/UserRelationship/user_relationship.postgres.sql" );
224 - $wgExtNewTables[] = array( 'user_relationship_request', "$dir/UserRelationship/user_relationship.postgres.sql" );
225 - $wgExtNewTables[] = array( 'user_system_gift', "$dir/SystemGifts/systemgifts.postgres.sql" );
226 - $wgExtNewTables[] = array( 'system_gift', "$dir/SystemGifts/systemgifts.postgres.sql" );
227 - $wgExtNewTables[] = array( 'user_gift', "$dir/UserGifts/usergifts.postgres.sql" );
228 - $wgExtNewTables[] = array( 'gift', "$dir/UserGifts/usergifts.postgres.sql" );
229 - $wgExtNewTables[] = array( 'user_system_messages', "$dir/UserSystemMessages/user_system_messages.postgres.sql" );
230 - }
 205+ global $wgExtNewTables;
 206+
 207+ $wgExtNewTables[] = array( $label, $file );
231208 } else {
232 - if ( $updater->getDB()->getType() == 'mysql' ) {
233 - // Initial install tables
234 - $updater->addExtensionUpdate( array( 'addTable', 'user_board',
235 - "$dir/UserBoard/user_board.sql", true ) );
236 - $updater->addExtensionUpdate( array( 'addTable', 'user_profile',
237 - "$dir/UserProfile/user_profile.sql", true ) );
238 - $updater->addExtensionUpdate( array( 'addTable', 'user_stats',
239 - "$dir/UserStats/user_stats.sql", true ) );
240 - $updater->addExtensionUpdate( array( 'addTable', 'user_relationship',
241 - "$dir/UserRelationship/user_relationship.sql", true ) );
242 - $updater->addExtensionUpdate( array( 'addTable', 'user_relationship_request',
243 - "$dir/UserRelationship/user_relationship.sql", true ) );
244 - $updater->addExtensionUpdate( array( 'addTable', 'user_system_gift',
245 - "$dir/SystemGifts/systemgifts.sql", true ) );
246 - $updater->addExtensionUpdate( array( 'addTable', 'system_gift',
247 - "$dir/SystemGifts/systemgifts.sql", true ) );
248 - $updater->addExtensionUpdate( array( 'addTable', 'user_gift',
249 - "$dir/UserGifts/usergifts.sql", true ) );
250 - $updater->addExtensionUpdate( array( 'addTable', 'gift',
251 - "$dir/UserGifts/usergifts.sql", true ) );
252 - $updater->addExtensionUpdate( array( 'addTable', 'user_system_messages',
253 - "$dir/UserSystemMessages/user_system_messages.sql", true ) );
254 - } elseif ( $updater->getDB()->getType() == 'postgres' ) {
255 - $updater->addExtensionUpdate( array( 'addTable', 'user_board',
256 - "$dir/UserBoard/user_board.postgres.sql", true ) );
257 - $updater->addExtensionUpdate( array( 'addTable', 'user_profile',
258 - "$dir/UserProfile/user_profile.postgres.sql", true ) );
259 - $updater->addExtensionUpdate( array( 'addTable', 'user_stats',
260 - "$dir/UserStats/user_stats.postgres.sql", true ) );
261 - $updater->addExtensionUpdate( array( 'addTable', 'user_relationship',
262 - "$dir/UserRelationship/user_relationship.postgres.sql", true ) );
263 - $updater->addExtensionUpdate( array( 'addTable', 'user_relationship_request',
264 - "$dir/UserRelationship/user_relationship.postgres.sql", true ) );
265 - $updater->addExtensionUpdate( array( 'addTable', 'user_system_gift',
266 - "$dir/SystemGifts/systemgifts.postgres.sql", true ) );
267 - $updater->addExtensionUpdate( array( 'addTable', 'system_gift',
268 - "$dir/SystemGifts/systemgifts.postgres.sql", true ) );
269 - $updater->addExtensionUpdate( array( 'addTable', 'user_gift',
270 - "$dir/UserGifts/usergifts.postgres.sql", true ) );
271 - $updater->addExtensionUpdate( array( 'addTable', 'gift',
272 - "$dir/UserGifts/usergifts.postgres.sql", true ) );
273 - $updater->addExtensionUpdate( array( 'addTable', 'user_system_messages',
274 - "$dir/UserSystemMessages/user_system_messages.postgres.sql", true ) );
275 - }
 209+ $updater->addExtensionUpdate( array( 'addTable', $label, $file, true ) );
276210 }
 211+}
 212+
 213+function efSocialProfileSchemaUpdates( $updater = null ) {
 214+ $dir = dirname( __FILE__ );
 215+ $dbExt = "";
 216+ global $wgExtNewTables, $wgDBtype;
 217+
 218+ if ( $wgDBtype == 'postgres' ) {
 219+ $dbExt = '.postgres';
 220+ }
 221+
 222+ efSocialProfileDBUpdate( $updater, 'user_board', "$dir/UserBoard/user_board$dbExt.sql" );
 223+ efSocialProfileDBUpdate( $updater, 'user_profile', "$dir/UserProfile/user_profile$dbExt.sql" );
 224+ efSocialProfileDBUpdate( $updater, 'user_stats', "$dir/UserStats/user_stats$dbExt.sql" );
 225+ efSocialProfileDBUpdate( $updater, 'user_relationship', "$dir/UserRelationship/user_relationship$dbExt.sql" );
 226+ efSocialProfileDBUpdate( $updater, 'user_relationship_request', "$dir/UserRelationship/user_relationship$dbExt.sql" );
 227+ efSocialProfileDBUpdate( $updater, 'user_system_gift', "$dir/SystemGifts/systemgifts$dbExt.sql" );
 228+ efSocialProfileDBUpdate( $updater, 'system_gift', "$dir/SystemGifts/systemgifts$dbExt.sql" );
 229+ efSocialProfileDBUpdate( $updater, 'user_gift', "$dir/UserGifts/usergifts$dbExt.sql" );
 230+ efSocialProfileDBUpdate( $updater, 'gift', "$dir/UserGifts/usergifts$dbExt.sql" );
 231+ efSocialProfileDBUpdate( $updater, 'user_system_messages', "$dir/UserSystemMessages/user_system_messages$dbExt.sql" );
 232+
277233 return true;
278234 }
279235
Index: trunk/extensions/SocialProfile/SystemGifts/systemgifts.sql
@@ -1,24 +1,22 @@
22 CREATE TABLE /*$wgDBprefix*/user_system_gift (
3 - `sg_id` int(11) NOT NULL auto_increment,
 3+ `sg_id` int(11) NOT NULL PRIMARY KEY auto_increment,
44 `sg_gift_id` int(5) unsigned NOT NULL default '0',
55 `sg_user_id` int(11) unsigned NOT NULL default '0',
66 `sg_user_name` varchar(255) NOT NULL default '',
77 `sg_status` int(2) default '1',
8 - `sg_date` datetime default NULL,
9 - PRIMARY KEY (`sg_id`),
10 - KEY `sg_user_id` (`sg_user_id`),
11 - KEY `sg_gift_id` (`sg_gift_id`)
 8+ `sg_date` datetime default NULL
129 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 10+CREATE INDEX /*i*/sg_user_id ON /*_*/user_system_gift (`sg_user_id`);
 11+CREATE INDEX /*i*/sg_gift_id ON /*_*/user_system_gift (`sg_gift_id`);
1312
1413 CREATE TABLE /*$wgDBprefix*/system_gift (
15 - `gift_id` int(11) NOT NULL auto_increment,
 14+ `gift_id` int(11) NOT NULL PRIMARY KEY auto_increment,
1615 `gift_name` varchar(255) NOT NULL default '',
1716 `gift_description` text,
1817 `gift_given_count` int(11) default '0',
1918 `gift_category` int(11) default '0',
2019 `gift_threshold` int(15) default '0',
21 - `gift_createdate` datetime default NULL,
22 - PRIMARY KEY (`gift_id`),
23 - KEY `giftcategoryidx` (`gift_category`),
24 - KEY `giftthresholdidx` (`gift_threshold`)
25 -) ENGINE=InnoDB DEFAULT CHARSET=utf8;
\ No newline at end of file
 20+ `gift_createdate` datetime default NULL
 21+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 22+CREATE INDEX /*i*/giftcategoryidx ON /*_*/system_gift (`gift_category`);
 23+CREATE INDEX /*i*/giftthresholdidx ON /*_*/system_gift (`gift_threshold`);
Index: trunk/extensions/SocialProfile/SystemGifts/SystemGifts.php
@@ -1,5 +1,8 @@
22 <?php
33
 4+global $IP, $wgScriptPath, $wgAutoloadClasses, $wgAvailableRights, $wgGroupPermissions,
 5+ $wgSpecialPages, $wgExtenstionMessagesFiles;
 6+
47 $wgAvailableRights[] = 'awardsmanage';
58 $wgGroupPermissions['staff']['awardsmanage'] = true;
69 $wgGroupPermissions['sysop']['awardsmanage'] = true;
Index: trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php
@@ -287,7 +287,6 @@
288288 WHERE {$user_sql}
289289 ORDER BY ub_id DESC
290290 {$limit_sql}";
291 -
292291 $res = $dbr->query( $sql, __METHOD__ );
293292 $messages = array();
294293 foreach ( $res as $row ) {
Index: trunk/extensions/SocialProfile/UserBoard/user_board.sql
@@ -3,16 +3,15 @@
44 --
55
66 CREATE TABLE /*$wgDBprefix*/user_board (
7 - `ub_id` int(11) NOT NULL auto_increment,
 7+ `ub_id` int(11) PRIMARY KEY auto_increment,
88 `ub_user_id` int(11) NOT NULL default '0',
99 `ub_user_name` varchar(255) NOT NULL default '',
1010 `ub_user_id_from` int(11) NOT NULL default '0',
1111 `ub_user_name_from` varchar(255) NOT NULL default '',
1212 `ub_message` text NOT NULL,
1313 `ub_type` int(5) default '0',
14 - `ub_date` datetime default NULL,
15 - PRIMARY KEY (`ub_id`),
16 - KEY `ub_user_id` (`ub_user_id`),
17 - KEY `ub_user_id_from` (`ub_user_id_from`),
18 - KEY `ub_type` (`ub_type`)
 14+ `ub_date` datetime default NULL
1915 ) DEFAULT CHARSET=utf8;
 16+CREATE INDEX /*i*/ub_user_id ON /*_*/user_board (ub_user_id),
 17+CREATE INDEX /*i*/ub_user_id_from ON /*_*/user_board (ub_user_id_from),
 18+CREATE INDEX /*i*/ub_type ON /*_*/user_board (ub_type)
Index: trunk/extensions/SocialProfile/UserGifts/usergifts.sql
@@ -1,5 +1,5 @@
22 CREATE TABLE /*$wgDBprefix*/user_gift (
3 - `ug_id` int(11) NOT NULL auto_increment,
 3+ `ug_id` int(11) PRIMARY KEY auto_increment,
44 `ug_gift_id` int(5) unsigned NOT NULL default '0',
55 `ug_user_id_to` int(5) unsigned NOT NULL default '0',
66 `ug_user_name_to` varchar(255) NOT NULL default '',
@@ -8,20 +8,18 @@
99 `ug_status` int(2) default '1',
1010 `ug_type` int(2) default NULL,
1111 `ug_message` varchar(255) default NULL,
12 - `ug_date` datetime default NULL,
13 - PRIMARY KEY (`ug_id`),
14 - KEY `ug_user_id_from` (`ug_user_id_from`),
15 - KEY `ug_user_id_to` (`ug_user_id_to`)
 12+ `ug_date` datetime default NULL
1613 ) ENGINE=InnoDB;
 14+CREATE INDEX /*i*/ug_user_id_from ON /*_*/user_gift (`ug_user_id_from`);
 15+CREATE INDEX /*i*/ug_user_id_to ON /*_*/user_gift (`ug_user_id_to`);
1716
1817 CREATE TABLE /*$wgDBprefix*/gift (
19 - `gift_id` int(11) unsigned NOT NULL auto_increment,
 18+ `gift_id` int(11) UNSIGNED PRIMARY KEY auto_increment,
2019 `gift_access` int(5) NOT NULL default '0',
2120 `gift_creator_user_id` int(11) NOT NULL default '0',
2221 `gift_creator_user_name` varchar(255) NOT NULL default '',
2322 `gift_name` varchar(255) NOT NULL default '',
2423 `gift_description` text,
2524 `gift_given_count` int(5) default '0',
26 - `gift_createdate` datetime default NULL,
27 - PRIMARY KEY (`gift_id`)
 25+ `gift_createdate` datetime default NULL
2826 ) ENGINE=InnoDB;
\ No newline at end of file
Index: trunk/extensions/SocialProfile/UserGifts/SpecialGiveGift.php
@@ -9,6 +9,7 @@
1010 parent::__construct( 'GiveGift' );
1111 }
1212
 13+
1314 /**
1415 * Show the special page
1516 *
@@ -34,7 +35,10 @@
3536 $gift_id = $wgRequest->getVal( 'gift_id' );
3637 $out = '';
3738
38 - if ( $wgUser->getID() == $this->user_id_to ) {
 39+ var_dump( $wgUser->getID() );
 40+ var_dump( $this->user_id_to );
 41+
 42+ if ( $wgUser->getID() === $this->user_id_to ) {
3943 $wgOut->setPageTitle( wfMsg( 'g-error-title' ) );
4044 $out .= wfMsg( 'g-error-message-to-yourself' );
4145 $wgOut->addHTML( $out );
Index: trunk/extensions/SocialProfile/UserSystemMessages/user_system_messages.sql
@@ -1,10 +1,9 @@
22 CREATE TABLE /*$wgDBprefix*/user_system_messages (
3 - `um_id` int(11) NOT NULL auto_increment,
 3+ `um_id` int(11) NOT NULL PRIMARY KEY auto_increment,
44 `um_user_id` int(11) NOT NULL default '0',
55 `um_user_name` varchar(255) NOT NULL default '',
66 `um_message` varchar(255) NOT NULL default '',
77 `um_type` int(5) default '0',
8 - `um_date` datetime default NULL,
9 - PRIMARY KEY (`um_id`),
10 - KEY `up_user_id` (`um_user_id`)
11 -) ENGINE=InnoDB DEFAULT CHARSET=utf8;
\ No newline at end of file
 8+ `um_date` datetime default NULL
 9+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 10+CREATE INDEX /*i*/up_user_id ON /*_*/user_system_messages (`um_user_id`);

Follow-up revisions

RevisionCommit summaryAuthorDate
r77319followup r77272 remove var_dumpsmah03:16, 26 November 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77271Give SQLite a translation for MySQL's UNIX_TIMESTAMP() functions. Pg will pro...mah07:39, 25 November 2010

Comments

#Comment by MarkAHershberger (talk | contribs)   07:48, 25 November 2010

+global $IP, $wgScriptPath, $wgAutoloadClasses, $wgAvailableRights, $wgGroupPermissions,

+	$wgSpecialPages, $wgExtenstionMessagesFiles;
+

This bit was necessary to stop MW from complaining about undefined variables.

#Comment by Jack Phoenix (talk | contribs)   14:01, 25 November 2010

In SpecialGiveGift.php:

-		if ( $wgUser->getID() == $this->user_id_to ) {
+		var_dump( $wgUser->getID() );
+		var_dump( $this->user_id_to );
+
+		if ( $wgUser->getID() === $this->user_id_to ) {

Whoops... :)

Other than that, looks very nice — maybe one day we can get rid of those nasty raw SQL queries that SocialProfile uses in many places and make it support PostgreSQL and SQLite fully!

Status & tagging log