r85500 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85499‎ | r85500 | r85501 >
Date:01:01, 6 April 2011
Author:ashley
Status:ok
Tags:
Comment:
SocialProfile: in SpecialViewGift.php:
*removed some unused variables ($user_name, $id, $relationship)
*swapped a $wgRequest->getVal() to $wgRequest->getInt() since we always assume gift_id to be an integer and there's no reason for it to be something else than an int
*broke some way too long lines
*renamed variables from not_camel_case to upperCamelCase
Modified paths:
  • /trunk/extensions/SocialProfile/UserGifts/SpecialViewGift.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserGifts/SpecialViewGift.php
@@ -19,26 +19,15 @@
2020
2121 $wgOut->addExtensionStyle( $wgUserGiftsScripts . '/UserGifts.css' );
2222
23 - $user_name = ''; // Prevent E_NOTICE
24 -
25 - $gift_id = $wgRequest->getVal( 'gift_id' );
26 - if ( !$gift_id || !is_numeric( $gift_id ) ) {
 23+ $giftId = $wgRequest->getInt( 'gift_id' );
 24+ if ( !$giftId || !is_numeric( $giftId ) ) {
2725 $wgOut->setPageTitle( wfMsg( 'g-error-title' ) );
2826 $wgOut->addHTML( wfMsg( 'g-error-message-invalid-link' ) );
2927 return false;
3028 }
3129
32 - if ( !$user_name ) {
33 - $user_name = $wgUser->getName();
34 - }
35 - $gift = UserGifts::getUserGift( $gift_id );
36 - $user_safe = urlencode( $gift['user_name_to'] );
37 - $id = User::idFromName( $user_name );
38 - $relationship = UserRelationship::getUserRelationshipByID( $id, $wgUser->getID() );
 30+ $gift = UserGifts::getUserGift( $giftId );
3931
40 - // DB stuff
41 - $dbr = wfGetDB( DB_SLAVE );
42 -
4332 if ( $gift ) {
4433 if ( $gift['status'] == 1 ) {
4534 if ( $gift['user_name_to'] == $wgUser->getName() ) {
@@ -48,12 +37,14 @@
4938 }
5039 }
5140
 41+ // DB stuff
 42+ $dbr = wfGetDB( DB_SLAVE );
5243 $res = $dbr->select(
5344 'user_gift',
5445 array( 'DISTINCT ug_user_name_to', 'ug_user_id_to', 'ug_date' ),
5546 array(
5647 'ug_gift_id' => $gift['gift_id'],
57 - "ug_user_name_to<>'" . addslashes( $gift['user_name_to'] ) . "'"
 48+ "ug_user_name_to <> '" . addslashes( $gift['user_name_to'] ) . "'"
5849 ),
5950 __METHOD__,
6051 array(
@@ -63,58 +54,73 @@
6455 )
6556 );
6657
67 - $output = $wgOut->setPageTitle( wfMsgExt( 'g-description-title', 'parsemag', $gift['user_name_to'], $gift['name'] ) );
 58+ $wgOut->setPageTitle( wfMsgExt(
 59+ 'g-description-title',
 60+ 'parsemag',
 61+ $gift['user_name_to'],
 62+ $gift['name']
 63+ ) );
6864
69 - $output .= '<div class="back-links">
 65+ $output = '<div class="back-links">
7066 <a href="' . Title::makeTitle( NS_USER, $gift['user_name_to'] )->escapeFullURL() . '">'
7167 . wfMsg( 'g-back-link', $gift['user_name_to'] ) . '</a>
7268 </div>';
7369
7470 $user = Title::makeTitle( NS_USER, $gift['user_name_from'] );
75 - $remove_gift_link = SpecialPage::getTitleFor( 'RemoveGift' );
76 - $give_gift_link = SpecialPage::getTitleFor( 'GiveGift' );
 71+ $removeGiftLink = SpecialPage::getTitleFor( 'RemoveGift' );
 72+ $giveGiftLink = SpecialPage::getTitleFor( 'GiveGift' );
7773
7874 $avatar = new wAvatar( $gift['user_id_from'], 's' );
79 - $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />';
80 - $gift_image = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage( $gift['gift_id'], 'l' ) . '" border="0" alt="" />';
 75+ $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' .
 76+ $avatar->getAvatarImage() . '" alt="" border="0" />';
 77+ $giftImage = '<img src="' . $wgUploadPath . '/awards/' .
 78+ Gifts::getGiftImage( $gift['gift_id'], 'l' ) .
 79+ '" border="0" alt="" />';
8180
8281 $message = $wgOut->parse( trim( $gift['message'] ), false );
8382
8483 $output .= '<div class="g-description-container">';
85 -
86 - $gift_image = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage( $gift['gift_id'], 'l' ) . '" border="0" alt="" />';
87 -
8884 $output .= '<div class="g-description">'
89 - . $gift_image .
 85+ . $giftImage .
9086 '<div class="g-name">' . $gift['name'] . '</div>
9187 <div class="g-timestamp">(' . $gift['timestamp'] . ')</div>
92 - <div class="g-from">' . wfMsg( 'g-from', $user->escapeFullURL(), $gift['user_name_from'] ) . '</div>';
 88+ <div class="g-from">' . wfMsg(
 89+ 'g-from',
 90+ $user->escapeFullURL(),
 91+ $gift['user_name_from']
 92+ ) . '</div>';
9393 if ( $message ) {
9494 $output .= '<div class="g-user-message">' . $message . '</div>';
9595 }
9696 $output .= '<div class="cleared"></div>
9797 <div class="g-describe">' . $gift['description'] . '</div>
9898 <div class="g-actions">
99 - <a href="' . $give_gift_link->escapeFullURL( 'gift_id=' . $gift['gift_id'] ) . '">' . wfMsg( 'g-to-another' ) . '</a>';
 99+ <a href="' . $giveGiftLink->escapeFullURL( 'gift_id=' . $gift['gift_id'] ) . '">' .
 100+ wfMsg( 'g-to-another' ) . '</a>';
100101 if ( $gift['user_name_to'] == $wgUser->getName() ) {
101 - $output .= '&nbsp';
102 - $output .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
103 - $output .= '&#160;';
104 - $output .= '<a href="' . $remove_gift_link->escapeFullURL( 'gift_id=' . $gift['id'] ) . '">' . wfMsg( 'g-remove-gift' ) . '</a>';
 102+ $output .= '&nbsp';
 103+ $output .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
 104+ $output .= '&#160;';
 105+ $output .= '<a href="' . $removeGiftLink->escapeFullURL( 'gift_id=' . $gift['id'] ) . '">' .
 106+ wfMsg( 'g-remove-gift' ) . '</a>';
105107 }
106108 $output .= '</div>
107109 </div>';
108110
109111 $output .= '<div class="g-recent">
110 - <div class="g-recent-title">' . wfMsg( 'g-recent-recipients' ) . '</div>
111 - <div class="g-gift-count">' . wfMsgExt( 'g-given', 'parsemag', $gift['gift_count'] ) . '</div>';
 112+ <div class="g-recent-title">' .
 113+ wfMsg( 'g-recent-recipients' ) .
 114+ '</div>
 115+ <div class="g-gift-count">' .
 116+ wfMsgExt( 'g-given', 'parsemag', $gift['gift_count'] ) .
 117+ '</div>';
112118
113119 foreach ( $res as $row ) {
114 - $user_to_id = $row->ug_user_id_to;
115 - $avatar = new wAvatar( $user_to_id, 'ml' );
116 - $user_name_link = Title::makeTitle( NS_USER, $row->ug_user_name_to );
 120+ $userToId = $row->ug_user_id_to;
 121+ $avatar = new wAvatar( $userToId, 'ml' );
 122+ $userNameLink = Title::makeTitle( NS_USER, $row->ug_user_name_to );
117123
118 - $output .= '<a href="' . $user_name_link->escapeFullURL() . "\">
 124+ $output .= '<a href="' . $userNameLink->escapeFullURL() . "\">
119125 {$avatar->getAvatarURL()}
120126 </a>";
121127 }

Status & tagging log