r107522 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107521‎ | r107522 | r107523 >
Date:20:37, 28 December 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Cleanup onLoadExtensionSchemaUpdates to use utility functions rather than array wrappers

Create all indexes at point of creating table
Modified paths:
  • /trunk/extensions/MoodBar/MoodBar.hooks.php (modified) (history)
  • /trunk/extensions/MoodBar/sql/MoodBar.sql (modified) (history)
  • /trunk/extensions/MoodBar/sql/moodbar_feedback_response.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/MoodBar.hooks.php
@@ -15,52 +15,52 @@
1616
1717 return true;
1818 }
19 -
 19+
2020 /**
2121 * Determines if this user has right to mark an feedback response as helpful, only the user who wrote the
2222 * feedback can mark the response as helpful
2323 * @param $mahaction string - mark/unmark
2424 * @param $type string - the object type to be marked
25 - * @param $item int - an item of $type to be marked
 25+ * @param $item int - an item of $type to be marked
2626 * @param $User User Object - the User in current session
2727 * @param $isAbleToMark bool - determine whether the user is able to mark the item
2828 * @return bool
2929 */
3030 public static function onMarkItemAsHelpful( $mahaction, $type, $item, $User, &$isAbleToMark ) {
31 -
 31+
3232 if ( $User->isAnon() ) {
3333 $isAbleToMark = false;
3434 return true;
3535 }
36 -
 36+
3737 if ( $type == 'mbresponse' ) {
38 -
 38+
3939 switch ( $mahaction ) {
40 -
 40+
4141 case 'mark':
4242 $dbr = wfGetDB( DB_SLAVE );
43 -
44 - $res = $dbr->selectRow( array( 'moodbar_feedback', 'moodbar_feedback_response' ),
 43+
 44+ $res = $dbr->selectRow( array( 'moodbar_feedback', 'moodbar_feedback_response' ),
4545 array( 'mbf_id' ),
46 - array( 'mbf_id = mbfr_mbf_id',
47 - 'mbfr_id' => intval( $item ),
48 - 'mbf_user_id' => $User->getId() ),
49 - __METHOD__ );
50 -
 46+ array( 'mbf_id = mbfr_mbf_id',
 47+ 'mbfr_id' => intval( $item ),
 48+ 'mbf_user_id' => $User->getId() ),
 49+ __METHOD__ );
 50+
5151 if ( $res === false ) {
5252 $isAbleToMark = false;
5353 }
54 - break;
55 -
 54+ break;
 55+
5656 case 'unmark':
5757 default:
5858 //We will leve the MarkAsHelpFul extension to check if the user has unmark right
59 - break;
 59+ break;
6060 }
6161 }
62 -
 62+
6363 return true;
64 -
 64+
6565 }
6666
6767 /**
@@ -127,45 +127,31 @@
128128 * @param $updater DatabasEUpdater
129129 */
130130 public static function onLoadExtensionSchemaUpdates( $updater = null ) {
131 - $updater->addExtensionUpdate( array( 'addTable', 'moodbar_feedback',
132 - dirname(__FILE__).'/sql/MoodBar.sql', true ) );
 131+ $dir = dirname(__FILE__) . '/sql/';
 132+ $updater->addExtensionTable( 'moodbar_feedback', $dir . 'MoodBar.sql' );
133133
134 - $updater->addExtensionUpdate( array( 'addField', 'moodbar_feedback',
135 - 'mbf_user_editcount', dirname(__FILE__).'/sql/mbf_user_editcount.sql', true )
136 - );
 134+ $updater->addExtensionField( 'moodbar_feedback', 'mbf_user_editcount', $dir . 'mbf_user_editcount.sql' );
137135
138 - $db = $updater->getDB();
139 - if ( $db->tableExists( 'moodbar_feedback' ) &&
140 - $db->indexExists( 'moodbar_feedback', 'type_timestamp', __METHOD__ ) )
141 - {
142 - $updater->addExtensionUpdate( array( 'addIndex', 'moodbar_feedback',
143 - 'mbf_type_timestamp_id', dirname( __FILE__ ) . '/sql/AddIDToIndexes.sql', true )
144 - );
145 - }
 136+ $updater->addExtensionIndex( 'moodbar_feedback', 'mbf_type_timestamp_id', $dir . 'AddIDToIndexes.sql' );
 137+
146138 $updater->addExtensionUpdate( array( 'dropIndex', 'moodbar_feedback',
147 - 'mbf_timestamp', dirname( __FILE__ ) . '/sql/AddIDToIndexes2.sql', true )
 139+ 'mbf_userid_ip_timestamp', $dir . 'AddIDToIndexes2.sql', true )
148140 );
149141
150 - $updater->addExtensionUpdate( array( 'addIndex', 'moodbar_feedback',
151 - 'mbf_timestamp_id', dirname( __FILE__ ) . '/sql/mbf_timestamp_id.sql', true )
152 - );
 142+ $updater->addExtensionIndex( 'moodbar_feedback', 'mbfr_timestamp_id', $dir . 'mbf_timestamp_id.sql' );
153143
154 - $updater->addExtensionUpdate( array( 'addField', 'moodbar_feedback',
155 - 'mbf_hidden_state', dirname(__FILE__).'/sql/mbf_hidden_state.sql', true ) );
156 -
157 - $updater->addExtensionUpdate( array( 'addTable', 'moodbar_feedback_response',
158 - dirname(__FILE__).'/sql/moodbar_feedback_response.sql', true ) );
 144+ $updater->addExtensionField( 'moodbar_feedback', 'mbf_hidden_state', $dir . 'mbf_hidden_state.sql' );
159145
160 - $updater->addExtensionUpdate( array( 'addIndex', 'moodbar_feedback_response',
161 - 'mbfr_timestamp_id', dirname( __FILE__ ) . '/sql/mbfr_timestamp_id_index.sql', true )
162 - );
163 -
 146+ $updater->addExtensionTable( 'moodbar_feedback_response', $dir . 'moodbar_feedback_response.sql' );
 147+
 148+ $updater->addExtensionIndex( 'moodbar_feedback_response', 'mbfr_timestamp_id', $dir . 'mbfr_timestamp_id_index.sql' );
 149+
164150 return true;
165151 }
166152
167153 /**
168154 * Gets the MoodBar testing bucket that a user is in.
169 - * @param $user The user to check
 155+ * @param $user User The user to check
170156 * @return array of bucket names
171157 */
172158 public static function getUserBuckets( $user ) {
Index: trunk/extensions/MoodBar/sql/MoodBar.sql
@@ -1,20 +1,20 @@
22 CREATE TABLE /*_*/moodbar_feedback (
33 mbf_id int unsigned NOT NULL PRIMARY KEY auto_increment, -- Primary key
44 mbf_type varchar(32) binary NOT NULL, -- Type of feedback
5 -
 5+
66 -- User who provided the feedback
77 mbf_user_id int unsigned NOT NULL, -- User ID, or zero
88 mbf_user_ip varchar(255) binary NULL, -- If anonymous, user's IP address
99 mbf_user_editcount int unsigned NOT NULL, -- Edit count of the user
10 -
 10+
1111 -- Page where the feedback was received
1212 -- Nullable.
1313 mbf_namespace int,
1414 mbf_title varchar(255) binary,
15 -
 15+
1616 -- The feedback itself
1717 mbf_comment varchar(255) binary,
18 -
 18+
1919 -- Options and context
2020 -- Whether or not the feedback item is hidden
2121 -- 0 = No; 255 = Yes (other values reserved for partial hiding)
Index: trunk/extensions/MoodBar/sql/moodbar_feedback_response.sql
@@ -1,18 +1,18 @@
22 CREATE TABLE /*_*/moodbar_feedback_response (
33 mbfr_id int unsigned NOT NULL PRIMARY KEY auto_increment, -- Primary key
4 -
 4+
55 mbfr_mbf_id int unsigned NOT NULL, -- Primary key of moodbar_feedback table
6 -
 6+
77 -- User who provided the response
88 mbfr_user_id int unsigned NOT NULL, -- User ID, or zero
99 mbfr_user_ip varbinary(40) NULL, -- If anonymous, user's IP address
10 -
 10+
1111 mbfr_commenter_editcount int unsigned NOT NULL, -- number of edit for the user who writes the feedback
1212 mbfr_user_editcount int unsigned NOT NULL, -- number of edit for the responder
13 -
 13+
1414 -- The response itself
1515 mbfr_response_text text NOT NULL,
16 -
 16+
1717 -- Options and context
1818 mbfr_timestamp varchar(14) binary NOT NULL, -- When response was received
1919 mbfr_anonymous tinyint unsigned NOT NULL DEFAULT 0, -- Anonymity
@@ -23,3 +23,4 @@
2424 ) /*$wgDBTableOptions*/;
2525
2626 CREATE INDEX /*i*/mbfr_mbf_id ON /*_*/moodbar_feedback_response (mbfr_mbf_id);
 27+CREATE INDEX /*i*/mbfr_timestamp_id ON /*_*/moodbar_feedback_response (mbfr_mbf_id, mbfr_timestamp, mbfr_id);

Follow-up revisions

RevisionCommit summaryAuthorDate
r107566Follow-up r107522: Moar whitespace and indentation updates.siebrand12:59, 29 December 2011
r107611Fix for r107522: incorrect index name in update hooktstarling01:10, 30 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   06:27, 29 December 2011
+								array( 'mbf_id = mbfr_mbf_id',
+										'mbfr_id' => intval( $item ),
+										'mbf_user_id' => $User->getId() ),

The previous indentation was better.

"$dir/Fooname.sql" is shorter and maybe easier to read.

#Comment by Reedy (talk | contribs)   11:43, 29 December 2011

It'd be more consistent with other extensions too

Status & tagging log