r102176 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102175‎ | r102176 | r102177 >
Date:14:55, 6 November 2011
Author:ashley
Status:deferred
Tags:socialprofile 
Comment:
SocialProfile: as per Markus' in-depth review:
*use WebRequest instead of $_POST
*var -> public/private
*define (well, kinda) a previously undefined variable
*use DB_SLAVE for reads instead of DB_MASTER (I don't think we need to have 100% up-to-date data in Special:ViewSystemGift)
*add a few missing i18n messages
*use isset() to check if the index is set instead of wfSuppressWarnings() and wfRestoreWarnings()
*mark constructors as public
Modified paths:
  • /trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
@@ -50,7 +50,7 @@
5151 if ( $wgRequest->wasPosted() ) {
5252 $g = new SystemGifts();
5353
54 - if ( !( $_POST['id'] ) ) { // @todo FIXME/CHECKME: why $_POST? Why not $wgRequest?
 54+ if ( !$wgRequest->getInt( 'id' ) ) {
5555 // Add the new system gift to the database
5656 $gift_id = $g->addGift(
5757 $wgRequest->getVal( 'gift_name' ),
@@ -101,10 +101,12 @@
102102 */
103103 function displayGiftList() {
104104 global $wgUser;
 105+
105106 $output = ''; // Prevent E_NOTICE
106107 $page = 0;
107108 $per_page = 50;
108109 $gifts = SystemGifts::getGiftList( $per_page, $page );
 110+
109111 if ( $gifts ) {
110112 foreach ( $gifts as $gift ) {
111113 $deleteLink = '';
@@ -122,6 +124,7 @@
123125 $deleteLink . '</div>' . "\n";
124126 }
125127 }
 128+
126129 return '<div id="views">' . $output . '</div>';
127130 }
128131
Index: trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php
@@ -47,7 +47,7 @@
4848 }
4949 }
5050 // DB stuff
51 - $dbr = wfGetDB( DB_MASTER );
 51+ $dbr = wfGetDB( DB_SLAVE );
5252 $res = $dbr->select(
5353 'user_system_gift',
5454 array(
Index: trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php
@@ -10,13 +10,13 @@
1111
1212 class SystemGiftManagerLogo extends UnlistedSpecialPage {
1313
14 - var $mUploadFile, $mUploadDescription, $mIgnoreWarning;
15 - var $mUploadSaveName, $mUploadTempName, $mUploadSize, $mUploadOldVersion;
16 - var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload;
17 - var $mOname, $mSessionKey, $mStashed, $mDestFile;
18 - var $avatarUploadDirectory;
19 - var $fileExtensions;
20 - var $gift_id;
 14+ public $mUploadFile, $mUploadDescription, $mIgnoreWarning;
 15+ public $mUploadSaveName, $mUploadTempName, $mUploadSize, $mUploadOldVersion;
 16+ public $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload;
 17+ public $mOname, $mSessionKey, $mStashed, $mDestFile;
 18+ public $avatarUploadDirectory;
 19+ public $fileExtensions;
 20+ public $gift_id;
2121
2222 /**
2323 * Constructor -- set up the new special page
@@ -412,9 +412,9 @@
413413 }
414414
415415 if ( $type < 0 ) {
416 - # FIXME: undefined variable $stash
417 - throw new FatalError( wfMsg( 'filecopyerror', $tempName, $stash ) );
 416+ throw new FatalError( wfMsg( 'filecopyerror', $tempName, /*$stash*/'' ) );
418417 }
 418+
419419 return $type;
420420 }
421421
Index: trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
@@ -57,6 +57,8 @@
5858 This will also delete it from users who may have received it.',
5959 'ga-remove-success-title' => 'You have successfully removed the gift "$1"',
6060 'ga-remove-success-message' => 'The gift "$1" has been removed.',
 61+ 'ga-user-got-awards' => '$1 got $2',
 62+ 'ga-awards-given-out' => '{{PLURAL:$1|One award|$1 awards}} were given out',
6163 'topawards' => 'Top Awards',
6264 'topawards-edit-title' => 'Top Awards - Edit Milestones',
6365 'topawards-vote-title' => 'Top Awards - Vote Milestones',
@@ -1146,6 +1148,8 @@
11471149 Tämä poistaa sen myös käyttäjiltä, jotka ovat saattaneet saada sen.',
11481150 'ga-remove-success-title' => 'Olet onnistuneesti poistanut lahjan "$1"',
11491151 'ga-remove-success-message' => 'Lahja "$1" on poistettu.',
 1152+ 'ga-user-got-awards' => '$1 sai palkinnon $2',
 1153+ 'ga-awards-given-out' => '{{PLURAL:$1|Yksi palkinto|$1 palkintoa}} jaettiin',
11501154 'system_gift_received_subject' => 'Olet saanut palkinnon $1 {{GRAMMAR:inessive|{{SITENAME}}}}!',
11511155 'system_gift_received_body' => 'Hei $1:
11521156
Index: trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php
@@ -4,22 +4,13 @@
55 */
66 class UserSystemGifts {
77
8 - /**
9 - * All member variables should be considered private
10 - * Please use the accessor functions
11 - */
 8+ private $user_id; # Text form (spaces not underscores) of the main part
 9+ private $user_name; # Text form (spaces not underscores) of the main part
1210
13 - /**#@+
14 - * @private
15 - */
16 - var $user_id; # Text form (spaces not underscores) of the main part
17 - var $user_name; # Text form (spaces not underscores) of the main part
18 -
1911 /**
2012 * Constructor
21 - * @private
2213 */
23 - /* private */ function __construct( $username ) {
 14+ public function __construct( $username ) {
2415 $title1 = Title::newFromDBkey( $username );
2516 $this->user_name = $title1->getText();
2617 $this->user_id = User::idFromName( $this->user_name );
Index: trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php
@@ -8,7 +8,7 @@
99 * All member variables should be considered private
1010 * Please use the accessor functions
1111 */
12 - var $categories = array(
 12+ private $categories = array(
1313 'edit' => 1,
1414 'vote' => 2,
1515 'comment' => 3,
@@ -26,13 +26,6 @@
2727 );
2828
2929 /**
30 - * Constructor
31 - * @private
32 - */
33 - /* private */ function __construct() {
34 - }
35 -
36 - /**
3730 * Adds awards for all registered users, updates statistics and purges
3831 * caches.
3932 * Special:PopulateAwards calls this function
@@ -86,13 +79,17 @@
8780 // Update counters (bug #27981)
8881 UserSystemGifts::incGiftGivenCount( $row->gift_id );
8982
90 - $wgOut->addHTML( $row2->stats_user_name . ' got ' . $row->gift_name . '<br />' );
 83+ $wgOut->addHTML( wfMsg(
 84+ 'ga-user-got-awards',
 85+ $row2->stats_user_name,
 86+ $row->gift_name
 87+ ) . '<br />' );
9188 $x++;
9289 }
9390 }
9491 }
9592 }
96 - $wgOut->addHTML( "{$x} awards were given out" );
 93+ $wgOut->addHTML( wfMsgExt( 'ga-awards-given-out', 'parsemag', $x ) );
9794 }
9895
9996 /**
@@ -170,11 +167,12 @@
171168
172169 public function doesGiftExistForThreshold( $category, $threshold ) {
173170 $dbr = wfGetDB( DB_SLAVE );
174 - wfSuppressWarnings();
175 - // Can cause notices like "Notice: Undefined index: user_image" after
176 - // a user has uploaded their (first) avatar
177 - $awardCategory = $this->categories[$category];
178 - wfRestoreWarnings();
 171+
 172+ $awardCategory = 0;
 173+ if ( isset( $this->categories[$category] ) ) {
 174+ $awardCategory = $this->categories[$category];
 175+ }
 176+
179177 $s = $dbr->selectRow(
180178 'system_gift',
181179 array( 'gift_id' ),
@@ -184,6 +182,7 @@
185183 ),
186184 __METHOD__
187185 );
 186+
188187 if ( $s === false ) {
189188 return false;
190189 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r104105SocialProfile: partial revert of r102176, r102180 and r102288 -- UserProfile'...ashley23:39, 23 November 2011

Status & tagging log