r92620 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92619‎ | r92620 | r92621 >
Date:10:45, 20 July 2011
Author:ashley
Status:ok
Tags:
Comment:
SocialProfile: use a temporary variable in SpecialUploadAvatar.php instead of calling User::getId() multiple times or accessing the member variable mId directly
Modified paths:
  • /trunk/extensions/SocialProfile/UserProfile/SpecialUploadAvatar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserProfile/SpecialUploadAvatar.php
@@ -78,6 +78,8 @@
7979 wfMsgForContent( 'user-profile-picture-log-entry' )
8080 );
8181
 82+ $uid = $wgUser->getId();
 83+
8284 $output = '<h1>' . wfMsg( 'uploadavatar' ) . '</h1>';
8385 $output .= UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-picture' ) );
8486 $output .= '<div class="profile-info">';
@@ -91,7 +93,7 @@
9294 wfMsg( 'user-profile-picture-large' ) .
9395 '</td>
9496 <td style="padding-bottom:20px;">
95 - <img src="' . $wgUploadPath . '/avatars/' . $wgDBname . '_' . $wgUser->mId . '_l.' . $ext . '?ts=' . rand() . '" alt="" border="0" />
 97+ <img src="' . $wgUploadPath . '/avatars/' . $wgDBname . '_' . $uid . '_l.' . $ext . '?ts=' . rand() . '" alt="" border="0" />
9698 </td>
9799 </tr>';
98100 $output .= '<tr>
@@ -99,7 +101,7 @@
100102 wfMsg( 'user-profile-picture-medlarge' ) .
101103 '</td>
102104 <td style="padding-bottom:20px;">
103 - <img src="' . $wgUploadPath . '/avatars/' . $wgDBname . '_' . $wgUser->mId . '_ml.' . $ext . '?ts=' . rand() . '" alt="" border="0" />
 105+ <img src="' . $wgUploadPath . '/avatars/' . $wgDBname . '_' . $uid . '_ml.' . $ext . '?ts=' . rand() . '" alt="" border="0" />
104106 </td>
105107 </tr>';
106108 $output .= '<tr>
@@ -107,7 +109,7 @@
108110 wfMsg( 'user-profile-picture-medium' ) .
109111 '</td>
110112 <td style="padding-bottom:20px;">
111 - <img src="' . $wgUploadPath . '/avatars/' . $wgDBname . '_' . $wgUser->mId . '_m.' . $ext . '?ts=' . rand() . '" alt="" border="0" />
 113+ <img src="' . $wgUploadPath . '/avatars/' . $wgDBname . '_' . $uid . '_m.' . $ext . '?ts=' . rand() . '" alt="" border="0" />
112114 </td>
113115 </tr>';
114116 $output .= '<tr>
@@ -115,7 +117,7 @@
116118 wfMsg( 'user-profile-picture-small' ) .
117119 '</td>
118120 <td style="padding-bottom:20px;">
119 - <img src="' . $wgUploadPath . '/avatars/' . $wgDBname . '_' . $wgUser->mId . '_s.' . $ext . '?ts' . rand() . '" alt="" border="0" />
 121+ <img src="' . $wgUploadPath . '/avatars/' . $wgDBname . '_' . $uid . '_s.' . $ext . '?ts=' . rand() . '" alt="" border="0" />
120122 </td>
121123 </tr>';
122124 $output .= '<tr>
@@ -235,7 +237,7 @@
236238 function createThumbnail( $imageSrc, $imageInfo, $imgDest, $thumbWidth ) {
237239 global $wgImageMagickConvertCommand;
238240
239 - list( $origWidth, $origHeight, $typeCode ) = $imageInfo;
 241+ list( $origWidth, $origHeight, $typeCode ) = $imageInfo;
240242
241243 if ( $origWidth < $thumbWidth ) {
242244 $thumbWidth = $origWidth;
@@ -296,70 +298,74 @@
297299
298300 $dest = $this->avatarUploadDirectory;
299301
300 - $avatar = new wAvatar( $wgUser->getID(), 'l' );
 302+ $uid = $wgUser->getId();
 303+ $avatar = new wAvatar( $uid, 'l' );
 304+ // If this is the user's first custom avatar, update statistics (in
 305+ // case if we want to give out some points to the user for uploading
 306+ // their first avatar)
301307 if ( strpos( $avatar->getAvatarImage(), 'default_' ) !== false ) {
302 - $stats = new UserStatsTrack( $wgUser->getID(), $wgUser->getName() );
 308+ $stats = new UserStatsTrack( $uid, $wgUser->getName() );
303309 $stats->incStatField( 'user_image' );
304310 }
305311
306 - $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $wgUser->mId . '_l', 75 );
307 - $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $wgUser->mId . '_ml', 50 );
308 - $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $wgUser->mId . '_m', 30 );
309 - $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $wgUser->mId . '_s', 16 );
 312+ $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $uid . '_l', 75 );
 313+ $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $uid . '_ml', 50 );
 314+ $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $uid . '_m', 30 );
 315+ $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $uid . '_s', 16 );
310316
311317 if ( $ext != 'jpg' ) {
312 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.jpg' ) ) {
313 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.jpg' );
 318+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.jpg' ) ) {
 319+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.jpg' );
314320 }
315 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.jpg' ) ) {
316 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.jpg' );
 321+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.jpg' ) ) {
 322+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.jpg' );
317323 }
318 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.jpg' ) ) {
319 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.jpg' );
 324+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.jpg' ) ) {
 325+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.jpg' );
320326 }
321 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.jpg' ) ) {
322 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.jpg' );
 327+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.jpg' ) ) {
 328+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.jpg' );
323329 }
324330 }
325331 if ( $ext != 'gif' ) {
326 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.gif' ) ) {
327 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.gif' );
 332+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.gif' ) ) {
 333+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.gif' );
328334 }
329 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.gif' ) ) {
330 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.gif' );
 335+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.gif' ) ) {
 336+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.gif' );
331337 }
332 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.gif' ) ) {
333 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.gif' );
 338+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.gif' ) ) {
 339+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.gif' );
334340 }
335 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.gif' ) ) {
336 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.gif' );
 341+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.gif' ) ) {
 342+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.gif' );
337343 }
338344 }
339345 if ( $ext != 'png' ) {
340 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.png' ) ) {
341 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.png' );
 346+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.png' ) ) {
 347+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.png' );
342348 }
343 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.png' ) ) {
344 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.png' );
 349+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.png' ) ) {
 350+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.png' );
345351 }
346 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.png' ) ) {
347 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.png' );
 352+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.png' ) ) {
 353+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.png' );
348354 }
349 - if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.png' ) ) {
350 - unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.png' );
 355+ if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.png' ) ) {
 356+ unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.png' );
351357 }
352358 }
353359
354 - $key = wfMemcKey( 'user', 'profile', 'avatar', $wgUser->getID(), 's' );
 360+ $key = wfMemcKey( 'user', 'profile', 'avatar', $uid, 's' );
355361 $data = $wgMemc->delete( $key );
356362
357 - $key = wfMemcKey( 'user', 'profile', 'avatar', $wgUser->getID(), 'm' );
 363+ $key = wfMemcKey( 'user', 'profile', 'avatar', $uid, 'm' );
358364 $data = $wgMemc->delete( $key );
359365
360 - $key = wfMemcKey( 'user', 'profile', 'avatar', $wgUser->getID() , 'l' );
 366+ $key = wfMemcKey( 'user', 'profile', 'avatar', $uid , 'l' );
361367 $data = $wgMemc->delete( $key );
362368
363 - $key = wfMemcKey( 'user', 'profile', 'avatar', $wgUser->getID() , 'ml' );
 369+ $key = wfMemcKey( 'user', 'profile', 'avatar', $uid, 'ml' );
364370 $data = $wgMemc->delete( $key );
365371
366372 $this->mExtension = $ext;

Status & tagging log