r106966 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106965‎ | r106966 | r106967 >
Date:19:07, 21 December 2011
Author:bsitu
Status:deferred
Tags:markashelpful 
Comment:
follow up to -r106843 - Use addExtensionTable() instead of addExtensionUpdate() for db schema set up, change mysql index for better search and corresponding code update
Modified paths:
  • /trunk/extensions/MarkAsHelpful/MarkAsHelpful.hooks.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/sql/mark_as_helpful.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/MarkAsHelpful/sql/mark_as_helpful.sql
@@ -18,4 +18,4 @@
1919 mah_locale varchar(32) binary NULL -- The locale of the user's browser
2020 ) /*$wgDBTableOptions*/;
2121
22 -CREATE INDEX /*i*/mah_type_item ON /*_*/mark_as_helpful (mah_type, mah_item);
 22+CREATE INDEX /*i*/mah_type_item_user_id_ip ON /*_*/mark_as_helpful (mah_type, mah_item, mah_user_id, mah_user_ip);
Index: trunk/extensions/MarkAsHelpful/MarkAsHelpful.hooks.php
@@ -32,8 +32,7 @@
3333 * @param $updater DatabasEUpdater
3434 */
3535 public static function onLoadExtensionSchemaUpdates( $updater = null ) {
36 - $updater->addExtensionUpdate( array( 'addTable', 'mark_as_helpful',
37 - dirname( __FILE__ ) . '/sql/mark_as_helpful.sql', true ) );
 36+ $updater->addExtensionTable( 'mark_as_helpful', dirname( __FILE__ ) . '/sql/mark_as_helpful.sql' );
3837
3938 return true;
4039 }
Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php
@@ -136,8 +136,17 @@
137137 */
138138 public function loadFromDatabase( $conds ) {
139139
140 - $searchKey = array_keys( $conds );
 140+ $searchKey = array();
141141
 142+ foreach ( $conds AS $key => $value) {
 143+ if ( $value == 'mah_user_ip IS NULL' ) {
 144+ $searchKey[] = 'mah_user_ip';
 145+ }
 146+ else {
 147+ $searchKey[] = $key;
 148+ }
 149+ }
 150+
142151 $flag = sort( $searchKey );
143152
144153 if ( !$flag ) {
@@ -146,7 +155,7 @@
147156
148157 $searchKey = implode(',', $searchKey );
149158
150 - $allowableSearchKey = array ( 'mah_id', 'mah_item,mah_type,mah_user_id', 'mah_item,mah_type,mah_user_ip' );
 159+ $allowableSearchKey = array ( 'mah_id', 'mah_item,mah_type,mah_user_id,mah_user_ip' );
151160
152161 if ( !in_array( $searchKey, $allowableSearchKey ) ) {
153162 throw new MWMarkAsHelpFulItemSearchKeyException( 'Invalid search key!' );
@@ -203,34 +212,36 @@
204213 * @param $currentUser Object - the current user who is browsing the site
205214 */
206215 public function unmark( $currentUser ) {
 216+
207217 if ( $this->getProperty( 'mah_id' ) ) {
 218+
208219 if ( !$this->getProperty( 'mah_type' ) ) {
209220 if( !$this->loadFromDatabase( array( 'mah_id' => $this->getProperty( 'mah_id' ) ) ) ) {
210221 return;
211222 }
212223 }
213224
214 - // for sure this is an invalid item
215 - if( !$this->getProperty( 'mah_item' ) ) {
216 - return;
217 - }
218 -
219225 $user = $this->getUser();
220226
221227 if ( $user ) {
222 - if (
223 - $currentUser->getId() == $user->getId() ||
224 - $currentUser->getName() == $user->getName()
225 - )
226 - {
227 - $dbw = wfGetDB( DB_MASTER );
 228+
 229+ if ( $currentUser->isAnon() == $user->isAnon() ) {
 230+
 231+ if ( $currentUser->getId() == $user->getId() ||
 232+ $currentUser->getName() == $user->getName() ) {
 233+
 234+ $dbw = wfGetDB( DB_MASTER );
228235
229 - $dbw->delete(
230 - 'mark_as_helpful',
231 - array( 'mah_id' => $this->getProperty( 'mah_id' ) ),
232 - __METHOD__
233 - );
 236+ $dbw->delete(
 237+ 'mark_as_helpful',
 238+ array( 'mah_id' => $this->getProperty( 'mah_id' ) ),
 239+ __METHOD__
 240+ );
 241+
 242+ }
 243+
234244 }
 245+
235246 }
236247 }
237248
Index: trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php
@@ -28,19 +28,19 @@
2929 case 'unmark':
3030 $item = new MarkAsHelpfulItem();
3131
 32+ $conds = array ( 'mah_type' => $params['type'],
 33+ 'mah_item' => $params['item'] );
 34+
3235 if( $wgUser->isAnon() ) {
33 - $status = $item->loadFromDatabase( array(
34 - 'mah_type' => $params['type'],
35 - 'mah_item' => $params['item'],
36 - 'mah_user_ip' => $wgUser->getName()
37 - ) );
 36+ $conds['mah_user_id'] = 0;
 37+ $conds['mah_user_ip'] = $wgUser->getName();
3838 } else {
39 - $status = $item->loadFromDatabase( array(
40 - 'mah_type' => $params['type'],
41 - 'mah_item' => $params['item'],
42 - 'mah_user_id' => $wgUser->getId()
43 - ) );
 39+ $conds['mah_user_id'] = $wgUser->getId();
 40+ $conds[] = 'mah_user_ip IS NULL';
4441 }
 42+
 43+ $status = $item->loadFromDatabase( $conds );
 44+
4545 if ( $status ) {
4646 $item->unmark( $wgUser );
4747 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r107078follow up to -r106985 - Use assignment style for NULL value in where clausebsitu17:45, 22 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106843Mark As Helpful APIs and backendbsitu19:30, 20 December 2011

Status & tagging log