r85505 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85504‎ | r85505 | r85506 >
Date:01:36, 6 April 2011
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: cleanup in SystemGifts; removed unused variables, renamed some badly named variables, used $wgRequest->getInt() instead of $wgRequest->getVal() in some places etc.
Modified paths:
  • /trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGifts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php
@@ -26,25 +26,18 @@
2727 $wgOut->addExtensionStyle( $wgSystemGiftsScripts . '/SystemGift.css' );
2828
2929 $output = ''; // Prevent E_NOTICE
30 - $user_name = ''; // Prevent E_NOTICE
3130
3231 // If gift ID wasn't passed in the URL parameters or if it's not
3332 // numeric, display an error message
34 - $gift_id = $wgRequest->getVal( 'gift_id' );
35 - if ( !$gift_id || !is_numeric( $gift_id ) ) {
 33+ $giftId = $wgRequest->getInt( 'gift_id' );
 34+ if ( !$giftId || !is_numeric( $giftId ) ) {
3635 $wgOut->setPageTitle( wfMsg( 'ga-error-title' ) );
3736 $wgOut->addHTML( wfMsg( 'ga-error-message-invalid-link' ) );
3837 return false;
3938 }
4039
41 - // We assume the current user by default
42 - if ( !$user_name ) {
43 - $user_name = $wgUser->getName();
44 - }
 40+ $gift = UserSystemGifts::getUserGift( $giftId );
4541
46 - $gift = UserSystemGifts::getUserGift( $gift_id );
47 - $id = User::idFromName( $user_name );
48 -
4942 if ( $gift ) {
5043 if ( $gift['status'] == 1 ) {
5144 if ( $gift['user_name'] == $wgUser->getName() ) {
@@ -74,22 +67,22 @@
7568 )
7669 );
7770
78 - $output .= $wgOut->setPageTitle( wfMsg( 'ga-gift-title', $gift['user_name'], $gift['name'] ) );
 71+ $wgOut->setPageTitle( wfMsg( 'ga-gift-title', $gift['user_name'], $gift['name'] ) );
7972
8073 $profileURL = Title::makeTitle( NS_USER, $gift['user_name'] )->escapeFullURL();
81 - $output .= '<div class="back-links">'
82 - . wfMsg( 'ga-back-link', $profileURL, $gift['user_name'] ) .
 74+ $output .= '<div class="back-links">' .
 75+ wfMsg( 'ga-back-link', $profileURL, $gift['user_name'] ) .
8376 '</div>';
8477
8578 $message = $wgOut->parse( trim( $gift['description'] ), false );
8679 $output .= '<div class="ga-description-container">';
8780
88 - $gift_image = "<img src=\"{$wgUploadPath}/awards/" .
 81+ $giftImage = "<img src=\"{$wgUploadPath}/awards/" .
8982 SystemGifts::getGiftImage( $gift['gift_id'], 'l' ) .
9083 '" border="0" alt=""/>';
9184
9285 $output .= "<div class=\"ga-description\">
93 - {$gift_image}
 86+ {$giftImage}
9487 <div class=\"ga-name\">{$gift['name']}</div>
9588 <div class=\"ga-timestamp\">({$gift['timestamp']})</div>
9689 <div class=\"ga-description-message\">\"{$message}\"</div>";
@@ -97,19 +90,23 @@
9891 </div>';
9992
10093 $output .= '<div class="ga-recent">
101 - <div class="ga-recent-title">'
102 - . wfMsg( 'ga-recent-recipients-award' ) .
 94+ <div class="ga-recent-title">' .
 95+ wfMsg( 'ga-recent-recipients-award' ) .
10396 '</div>
104 - <div class="ga-gift-count">'
105 - . wfMsgExt( 'ga-gift-given-count', 'parsemag', $gift['gift_count'] ) .
 97+ <div class="ga-gift-count">' .
 98+ wfMsgExt(
 99+ 'ga-gift-given-count',
 100+ 'parsemag',
 101+ $gift['gift_count']
 102+ ) .
106103 '</div>';
107104
108105 foreach ( $res as $row ) {
109 - $user_to_id = $row->sg_user_id;
110 - $avatar = new wAvatar( $user_to_id, 'ml' );
111 - $user_name_link = Title::makeTitle( NS_USER, $row->sg_user_name );
 106+ $userToId = $row->sg_user_id;
 107+ $avatar = new wAvatar( $userToId, 'ml' );
 108+ $userNameLink = Title::makeTitle( NS_USER, $row->sg_user_name );
112109
113 - $output .= '<a href="' . $user_name_link->escapeFullURL() . "\">
 110+ $output .= '<a href="' . $userNameLink->escapeFullURL() . "\">
114111 {$avatar->getAvatarURL()}
115112 </a>";
116113 }
@@ -119,7 +116,6 @@
120117 </div>';
121118
122119 $wgOut->addHTML( $output );
123 -
124120 } else {
125121 $wgOut->setPageTitle( wfMsg( 'ga-error-title' ) );
126122 $wgOut->addHTML( wfMsg( 'ga-error-message-invalid-link' ) );
Index: trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGifts.php
@@ -21,7 +21,7 @@
2222 * @param $par Mixed: parameter passed to the page or null
2323 */
2424 public function execute( $par ) {
25 - global $wgUser, $wgOut, $wgRequest, $wgMemc, $wgUploadPath, $wgSystemGiftsScripts;
 25+ global $wgUser, $wgOut, $wgRequest, $wgUploadPath, $wgSystemGiftsScripts;
2626
2727 $wgOut->addExtensionStyle( $wgSystemGiftsScripts . '/SystemGift.css' );
2828
@@ -41,14 +41,12 @@
4242 }
4343
4444 /**
45 - * If no user is set in the URL, we assume its the current user
 45+ * If no user is set in the URL, we assume it's the current user
4646 */
4747 if ( !$user_name ) {
4848 $user_name = $wgUser->getName();
4949 }
5050 $user_id = User::idFromName( $user_name );
51 - $user = Title::makeTitle( NS_USER, $user_name );
52 - $user_safe = urlencode( $user_name );
5351
5452 /**
5553 * Error message for username that does not exist (from URL)
@@ -76,19 +74,20 @@
7775 $gifts = $rel->getUserGiftList( 0, $per_page, $page );
7876 $total = $rel->getGiftCountByUsername( $user_name );
7977
80 - $relationship = UserRelationship::getUserRelationshipByID( $user_id, $wgUser->getID() );
81 -
8278 /**
8379 * Show gift count for user
8480 */
85 - $output .= $wgOut->setPageTitle( wfMsg( 'ga-title', $rel->user_name ) );
 81+ $wgOut->setPageTitle( wfMsg( 'ga-title', $rel->user_name ) );
8682
87 - $output .= '<div class="back-links">'
88 - . wfMsg( 'ga-back-link', $wgUser->getUserPage()->escapeFullURL(), $rel->user_name ) .
89 - '</div>';
 83+ $output .= '<div class="back-links">' .
 84+ wfMsg(
 85+ 'ga-back-link',
 86+ $wgUser->getUserPage()->escapeFullURL(),
 87+ $rel->user_name
 88+ ) . '</div>';
9089
91 - $output .= '<div class="ga-count">'
92 - . wfMsgExt( 'ga-count', 'parsemag', $rel->user_name, $total ) .
 90+ $output .= '<div class="ga-count">' .
 91+ wfMsgExt( 'ga-count', 'parsemag', $rel->user_name, $total ) .
9392 '</div>';
9493
9594 // Safelinks
@@ -137,8 +136,7 @@
138137 $output .= '<div class="page-nav">';
139138 if ( $page > 1 ) {
140139 $output .= '<a href="' . $page_link->escapeFullURL(
141 - 'user=' . $user_name . '&rel_type=' . $rel_type .
142 - '&page=' . ( $page - 1 ) ) . '">' .
 140+ 'user=' . $user_name . '&page=' . ( $page - 1 ) ) . '">' .
143141 wfMsg( 'ga-previous' ) . '</a> ';
144142 }
145143
@@ -157,15 +155,14 @@
158156 $output .= ( $i . ' ' );
159157 } else {
160158 $output .= '<a href="' . $page_link->escapeFullURL(
161 - 'user=' . $user_name . '&rel_type=' . $rel_type .
162 - '&page=' . $i ) . "\">$i</a> ";
 159+ 'user=' . $user_name . '&page=' . $i ) . "\">$i</a> ";
163160 }
164161 }
165162
166163 if ( ( $total - ( $per_page * $page ) ) > 0 ) {
167164 $output .= ' <a href="' . $page_link->escapeFullURL(
168 - 'user=' . $user_name . '&rel_type=' . $rel_type .
169 - '&page=' . ( $page + 1 ) ) . '">' . wfMsg( 'ga-next' ) .
 165+ 'user=' . $user_name . '&page=' . ( $page + 1 ) ) . '">' .
 166+ wfMsg( 'ga-next' ) .
170167 '</a>';
171168 }
172169 $output .= '</div>';

Status & tagging log