https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102176
Revision: 102176
Author: ashley
Date: 2011-11-06 14:55:25 +0000 (Sun, 06 Nov 2011)
Log Message:
-----------
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
trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php
trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php
trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php
trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php
Modified:
trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
2011-11-06 13:26:46 UTC (rev 102175)
+++ trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
2011-11-06 14:55:25 UTC (rev 102176)
@@ -50,7 +50,7 @@
if ( $wgRequest->wasPosted() ) {
$g = new SystemGifts();
- if ( !( $_POST['id'] ) ) { // @todo FIXME/CHECKME: why
$_POST? Why not $wgRequest?
+ if ( !$wgRequest->getInt( 'id' ) ) {
// Add the new system gift to the database
$gift_id = $g->addGift(
$wgRequest->getVal( 'gift_name' ),
@@ -101,10 +101,12 @@
*/
function displayGiftList() {
global $wgUser;
+
$output = ''; // Prevent E_NOTICE
$page = 0;
$per_page = 50;
$gifts = SystemGifts::getGiftList( $per_page, $page );
+
if ( $gifts ) {
foreach ( $gifts as $gift ) {
$deleteLink = '';
@@ -122,6 +124,7 @@
$deleteLink . '</div>' . "\n";
}
}
+
return '<div id="views">' . $output . '</div>';
}
Modified:
trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php
2011-11-06 13:26:46 UTC (rev 102175)
+++ trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php
2011-11-06 14:55:25 UTC (rev 102176)
@@ -10,13 +10,13 @@
class SystemGiftManagerLogo extends UnlistedSpecialPage {
- var $mUploadFile, $mUploadDescription, $mIgnoreWarning;
- var $mUploadSaveName, $mUploadTempName, $mUploadSize,
$mUploadOldVersion;
- var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload;
- var $mOname, $mSessionKey, $mStashed, $mDestFile;
- var $avatarUploadDirectory;
- var $fileExtensions;
- var $gift_id;
+ public $mUploadFile, $mUploadDescription, $mIgnoreWarning;
+ public $mUploadSaveName, $mUploadTempName, $mUploadSize,
$mUploadOldVersion;
+ public $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction,
$mUpload;
+ public $mOname, $mSessionKey, $mStashed, $mDestFile;
+ public $avatarUploadDirectory;
+ public $fileExtensions;
+ public $gift_id;
/**
* Constructor -- set up the new special page
@@ -412,9 +412,9 @@
}
if ( $type < 0 ) {
- # FIXME: undefined variable $stash
- throw new FatalError( wfMsg( 'filecopyerror',
$tempName, $stash ) );
+ throw new FatalError( wfMsg( 'filecopyerror',
$tempName, /*$stash*/'' ) );
}
+
return $type;
}
Modified: trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php
2011-11-06 13:26:46 UTC (rev 102175)
+++ trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php
2011-11-06 14:55:25 UTC (rev 102176)
@@ -47,7 +47,7 @@
}
}
// DB stuff
- $dbr = wfGetDB( DB_MASTER );
+ $dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
'user_system_gift',
array(
Modified: trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
2011-11-06 13:26:46 UTC (rev 102175)
+++ trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
2011-11-06 14:55:25 UTC (rev 102176)
@@ -57,6 +57,8 @@
This will also delete it from users who may have received it.',
'ga-remove-success-title' => 'You have successfully removed the gift
"$1"',
'ga-remove-success-message' => 'The gift "$1" has been removed.',
+ 'ga-user-got-awards' => '$1 got $2',
+ 'ga-awards-given-out' => '{{PLURAL:$1|One award|$1 awards}} were given
out',
'topawards' => 'Top Awards',
'topawards-edit-title' => 'Top Awards - Edit Milestones',
'topawards-vote-title' => 'Top Awards - Vote Milestones',
@@ -1146,6 +1148,8 @@
Tämä poistaa sen myös käyttäjiltä, jotka ovat saattaneet saada sen.',
'ga-remove-success-title' => 'Olet onnistuneesti poistanut lahjan "$1"',
'ga-remove-success-message' => 'Lahja "$1" on poistettu.',
+ 'ga-user-got-awards' => '$1 sai palkinnon $2',
+ 'ga-awards-given-out' => '{{PLURAL:$1|Yksi palkinto|$1 palkintoa}}
jaettiin',
'system_gift_received_subject' => 'Olet saanut palkinnon $1
{{GRAMMAR:inessive|{{SITENAME}}}}!',
'system_gift_received_body' => 'Hei $1:
Modified: trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php
2011-11-06 13:26:46 UTC (rev 102175)
+++ trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php
2011-11-06 14:55:25 UTC (rev 102176)
@@ -8,7 +8,7 @@
* All member variables should be considered private
* Please use the accessor functions
*/
- var $categories = array(
+ private $categories = array(
'edit' => 1,
'vote' => 2,
'comment' => 3,
@@ -26,13 +26,6 @@
);
/**
- * Constructor
- * @private
- */
- /* private */ function __construct() {
- }
-
- /**
* Adds awards for all registered users, updates statistics and purges
* caches.
* Special:PopulateAwards calls this function
@@ -86,13 +79,17 @@
// Update counters (bug #27981)
UserSystemGifts::incGiftGivenCount( $row->gift_id );
- $wgOut->addHTML(
$row2->stats_user_name . ' got ' . $row->gift_name . '<br />' );
+ $wgOut->addHTML( wfMsg(
+ 'ga-user-got-awards',
+ $row2->stats_user_name,
+ $row->gift_name
+ ) . '<br />' );
$x++;
}
}
}
}
- $wgOut->addHTML( "{$x} awards were given out" );
+ $wgOut->addHTML( wfMsgExt( 'ga-awards-given-out', 'parsemag',
$x ) );
}
/**
@@ -170,11 +167,12 @@
public function doesGiftExistForThreshold( $category, $threshold ) {
$dbr = wfGetDB( DB_SLAVE );
- wfSuppressWarnings();
- // Can cause notices like "Notice: Undefined index: user_image"
after
- // a user has uploaded their (first) avatar
- $awardCategory = $this->categories[$category];
- wfRestoreWarnings();
+
+ $awardCategory = 0;
+ if ( isset( $this->categories[$category] ) ) {
+ $awardCategory = $this->categories[$category];
+ }
+
$s = $dbr->selectRow(
'system_gift',
array( 'gift_id' ),
@@ -184,6 +182,7 @@
),
__METHOD__
);
+
if ( $s === false ) {
return false;
} else {
Modified: trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php
2011-11-06 13:26:46 UTC (rev 102175)
+++ trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php
2011-11-06 14:55:25 UTC (rev 102176)
@@ -4,22 +4,13 @@
*/
class UserSystemGifts {
- /**
- * All member variables should be considered private
- * Please use the accessor functions
- */
+ private $user_id; # Text form (spaces not underscores) of
the main part
+ private $user_name; # Text form (spaces not underscores) of
the main part
- /**#@+
- * @private
- */
- var $user_id; # Text form (spaces not underscores) of
the main part
- var $user_name; # Text form (spaces not underscores) of
the main part
-
/**
* Constructor
- * @private
*/
- /* private */ function __construct( $username ) {
+ public function __construct( $username ) {
$title1 = Title::newFromDBkey( $username );
$this->user_name = $title1->getText();
$this->user_id = User::idFromName( $this->user_name );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs