https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102180

Revision: 102180
Author:   ashley
Date:     2011-11-06 15:11:30 +0000 (Sun, 06 Nov 2011)
Log Message:
-----------
SocialProfile: as per Markus' in-depth review:
*remove unused class member variables
*mark Gifts' and UserGifts' constructors as public
*optimize the DB queries in Gifts::getCustomCreatedGiftCount() and 
Gifts::getGiftCount()
*use WebRequest instead of $_POST
*var -> public/private

Modified Paths:
--------------
    trunk/extensions/SocialProfile/UserGifts/GiftsClass.php
    trunk/extensions/SocialProfile/UserGifts/SpecialGiftManager.php
    trunk/extensions/SocialProfile/UserGifts/SpecialGiftManagerLogo.php
    trunk/extensions/SocialProfile/UserGifts/UserGiftsClass.php

Modified: trunk/extensions/SocialProfile/UserGifts/GiftsClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserGifts/GiftsClass.php     2011-11-06 
15:07:34 UTC (rev 102179)
+++ trunk/extensions/SocialProfile/UserGifts/GiftsClass.php     2011-11-06 
15:11:30 UTC (rev 102180)
@@ -7,24 +7,10 @@
 class Gifts {
 
        /**
-        * All member variables should be considered private
-        * Please use the accessor functions
-        */
-
-       /**#@+
-        * @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() {
+       public function __construct() {}
 
-       }
-
        /**
         * Adds a gift to the database
         * @param $gift_name Mixed: name of the gift, as supplied by the user
@@ -203,7 +189,7 @@
                $gift_count = 0;
                $s = $dbr->selectRow(
                        'gift',
-                       array( 'COUNT(*) AS count' ),
+                       array( 'COUNT(gift_id) AS count' ),
                        array( 'gift_creator_user_id' => $user_id ),
                        __METHOD__
                );
@@ -218,7 +204,7 @@
                $gift_count = 0;
                $s = $dbr->selectRow(
                        'gift',
-                       array( 'COUNT(*) AS count' ),
+                       array( 'COUNT(gift_id) AS count' ),
                        array( 'gift_given_count' => $gift_count ),
                        __METHOD__
                );

Modified: trunk/extensions/SocialProfile/UserGifts/SpecialGiftManager.php
===================================================================
--- trunk/extensions/SocialProfile/UserGifts/SpecialGiftManager.php     
2011-11-06 15:07:34 UTC (rev 102179)
+++ trunk/extensions/SocialProfile/UserGifts/SpecialGiftManager.php     
2011-11-06 15:11:30 UTC (rev 102180)
@@ -34,12 +34,12 @@
                // Add CSS
                $wgOut->addExtensionStyle( $wgUserGiftsScripts . 
'/UserGifts.css' );
 
-               if ( count( $_POST ) ) {
-                       if ( !( $_POST['id'] ) ) {
+               if ( $wgRequest->wasPosted() ) {
+                       if ( !$wgRequest->getInt( 'id' ) ) {
                                $giftId = Gifts::addGift(
-                                       $_POST['gift_name'],
-                                       $_POST['gift_description'],
-                                       intval( $_POST['access'] )
+                                       $wgRequest->getVal( 'gift_name' ),
+                                       $wgRequest->getVal( 'gift_description' 
),
+                                       $wgRequest->getInt( 'access' )
                                );
                                $wgOut->addHTML(
                                        '<span class="view-status">' .
@@ -47,12 +47,12 @@
                                        '</span><br /><br />'
                                );
                        } else {
-                               $giftId = intval( $_POST['id'] );
+                               $giftId = $wgRequest->getInt( 'id' );
                                Gifts::updateGift(
                                        $giftId,
-                                       $_POST['gift_name'],
-                                       $_POST['gift_description'],
-                                       intval( $_POST['access'] )
+                                       $wgRequest->getVal( 'gift_name' ),
+                                       $wgRequest->getVal( 'gift_description' 
),
+                                       $wgRequest->getInt( 'access' )
                                );
                                $wgOut->addHTML(
                                        '<span class="view-status">' .

Modified: trunk/extensions/SocialProfile/UserGifts/SpecialGiftManagerLogo.php
===================================================================
--- trunk/extensions/SocialProfile/UserGifts/SpecialGiftManagerLogo.php 
2011-11-06 15:07:34 UTC (rev 102179)
+++ trunk/extensions/SocialProfile/UserGifts/SpecialGiftManagerLogo.php 
2011-11-06 15:11:30 UTC (rev 102180)
@@ -9,13 +9,13 @@
  */
 class GiftManagerLogo 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

Modified: trunk/extensions/SocialProfile/UserGifts/UserGiftsClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserGifts/UserGiftsClass.php 2011-11-06 
15:07:34 UTC (rev 102179)
+++ trunk/extensions/SocialProfile/UserGifts/UserGiftsClass.php 2011-11-06 
15:11:30 UTC (rev 102180)
@@ -5,22 +5,13 @@
  */
 class UserGifts {
 
-       /**
-        * 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

Reply via email to