r85903 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85902‎ | r85903 | r85904 >
Date:18:28, 12 April 2011
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: add some new hooks for Semantic SocialProfile extension (yes, I said Semantic!). Patch by Dmitry Pokoptsev and Yury Katkov.
Modified paths:
  • /trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserProfile/SpecialUploadAvatar.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php
@@ -284,28 +284,34 @@
285285
286286 $this->initProfile( $user );
287287 $dbw = wfGetDB( DB_MASTER );
 288+ $basicProfileData = array(
 289+ 'up_location_city' => $wgRequest->getVal( 'location_city' ),
 290+ 'up_location_state' => $wgRequest->getVal( 'location_state' ),
 291+ 'up_location_country' => $wgRequest->getVal( 'location_country' ),
 292+
 293+ 'up_hometown_city' => $wgRequest->getVal( 'hometown_city' ),
 294+ 'up_hometown_state' => $wgRequest->getVal( 'hometown_state' ),
 295+ 'up_hometown_country' => $wgRequest->getVal( 'hometown_country' ),
 296+
 297+ 'up_birthday' => $this->formatBirthdayDB( $wgRequest->getVal( 'birthday' ) ),
 298+ 'up_about' => $wgRequest->getVal( 'about' ),
 299+ 'up_occupation' => $wgRequest->getVal( 'occupation' ),
 300+ 'up_schools' => $wgRequest->getVal( 'schools' ),
 301+ 'up_places_lived' => $wgRequest->getVal( 'places' ),
 302+ 'up_websites' => $wgRequest->getVal( 'websites' ),
 303+ 'up_relationship' => $wgRequest->getVal( 'relationship' )
 304+ );
288305 $dbw->update(
289306 'user_profile',
290 - /* SET */array(
291 - 'up_location_city' => $wgRequest->getVal( 'location_city' ),
292 - 'up_location_state' => $wgRequest->getVal( 'location_state' ),
293 - 'up_location_country' => $wgRequest->getVal( 'location_country' ),
294 -
295 - 'up_hometown_city' => $wgRequest->getVal( 'hometown_city' ),
296 - 'up_hometown_state' => $wgRequest->getVal( 'hometown_state' ),
297 - 'up_hometown_country' => $wgRequest->getVal( 'hometown_country' ),
298 -
299 - 'up_birthday' => $this->formatBirthdayDB( $wgRequest->getVal( 'birthday' ) ),
300 - 'up_about' => $wgRequest->getVal( 'about' ),
301 - 'up_occupation' => $wgRequest->getVal( 'occupation' ),
302 - 'up_schools' => $wgRequest->getVal( 'schools' ),
303 - 'up_places_lived' => $wgRequest->getVal( 'places' ),
304 - 'up_websites' => $wgRequest->getVal( 'websites' ),
305 - 'up_relationship' => $wgRequest->getVal( 'relationship' )
306 - ),
 307+ /* SET */$basicProfileData,
307308 /* WHERE */array( 'up_user_id' => $user->getID() ),
308309 __METHOD__
309310 );
 311+ // BasicProfileChanged hook
 312+ $basicProfileData['up_name'] = $wgRequest->getVal( 'real_name' );
 313+ $basicProfileData['up_email'] = $wgRequest->getVal( 'email' );
 314+ wfRunHooks( 'BasicProfileChanged', array( $user, $basicProfileData ) );
 315+ // end of the hook
310316 $wgMemc->delete( wfMemcKey( 'user', 'profile', 'info', $user->getID() ) );
311317 }
312318
@@ -355,22 +361,26 @@
356362
357363 $this->initProfile( $user );
358364 $dbw = wfGetDB( DB_MASTER );
 365+ $interestsData = array(
 366+ 'up_companies' => $wgRequest->getVal( 'companies' ),
 367+ 'up_movies' => $wgRequest->getVal( 'movies' ),
 368+ 'up_music' => $wgRequest->getVal( 'music' ),
 369+ 'up_tv' => $wgRequest->getVal( 'tv' ),
 370+ 'up_books' => $wgRequest->getVal( 'books' ),
 371+ 'up_magazines' => $wgRequest->getVal( 'magazines' ),
 372+ 'up_video_games' => $wgRequest->getVal( 'videogames' ),
 373+ 'up_snacks' => $wgRequest->getVal( 'snacks' ),
 374+ 'up_drinks' => $wgRequest->getVal( 'drinks' )
 375+ );
359376 $dbw->update(
360377 'user_profile',
361 - /* SET */array(
362 - 'up_companies' => $wgRequest->getVal( 'companies' ),
363 - 'up_movies' => $wgRequest->getVal( 'movies' ),
364 - 'up_music' => $wgRequest->getVal( 'music' ),
365 - 'up_tv' => $wgRequest->getVal( 'tv' ),
366 - 'up_books' => $wgRequest->getVal( 'books' ),
367 - 'up_magazines' => $wgRequest->getVal( 'magazines' ),
368 - 'up_video_games' => $wgRequest->getVal( 'videogames' ),
369 - 'up_snacks' => $wgRequest->getVal( 'snacks' ),
370 - 'up_drinks' => $wgRequest->getVal( 'drinks' )
371 - ),
 378+ /* SET */$interestsData,
372379 /* WHERE */array( 'up_user_id' => $user->getID() ),
373380 __METHOD__
374381 );
 382+ // PersonalInterestsChanged hook
 383+ wfRunHooks( 'PersonalInterestsChanged', array( $user, $interestsData ) );
 384+ // end of the hook
375385 $wgMemc->delete( wfMemcKey( 'user', 'profile', 'info', $user->getID() ) );
376386 }
377387
Index: trunk/extensions/SocialProfile/UserProfile/SpecialUploadAvatar.php
@@ -55,6 +55,8 @@
5656 $wgOut->redirect( '' );
5757
5858 $this->showSuccess( $this->mUpload->mExtension );
 59+ // Run a hook on avatar change
 60+ wfRunHooks( 'NewAvatarUploaded', array( $wgUser ) );
5961 }
6062 }
6163
@@ -229,6 +231,7 @@
230232 return "<img src=\"{$wgUploadPath}/avatars/" . basename( $files[0] ) . '" alt="" border="0" />';
231233 }
232234 }
 235+
233236 }
234237
235238 class UploadAvatar extends UploadFromFile {
Index: trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php
@@ -266,6 +266,13 @@
267267 $wgMemc->delete( wfMemcKey( 'relationship', 'profile', "{$this->user_id}-{$ur_type}" ) );
268268 $wgMemc->delete( wfMemcKey( 'relationship', 'profile', "{$ur_user_id_from}-{$ur_type}" ) );
269269
 270+ // Hooks (for Semantic SocialProfile mostly)
 271+ if ( $ur_type == 1 ) {
 272+ wfRunHooks( 'NewFriendAccepted', array( $ur_user_name_from, $this->user_name ) );
 273+ } else {
 274+ wfRunHooks( 'NewFoeAccepted', array( $ur_user_name_from, $this->user_name ) );
 275+ }
 276+
270277 return true;
271278 } else {
272279 return false;
@@ -304,6 +311,10 @@
305312 $wgMemc->delete( wfMemcKey( 'relationship', 'profile', "{$user1}-2" ) );
306313 $wgMemc->delete( wfMemcKey( 'relationship', 'profile', "{$user2}-2" ) );
307314
 315+ // RelationshipRemovedByUserID hook
 316+ wfRunHooks( 'RelationshipRemovedByUserID', array( $user1, $user2 ) );
 317+
 318+ // Update social statistics for both users
308319 $stats = new UserStatsTrack( $user1, '' );
309320 $stats->updateRelationshipCount( 1 );
310321 $stats->updateRelationshipCount( 2 );

Status & tagging log