Jack Phoenix has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/331962 )

Change subject: Add isDefault() method for checking if a user hasn't uploaded a 
custom avatar yet
......................................................................

Add isDefault() method for checking if a user hasn't uploaded a custom avatar 
yet

Because nobody likes ugly strpos() magic.

Change-Id: I6ef106650897959236a13f3b7cf25c1b825c39ce
---
M UserProfile/AvatarClass.php
M UserProfile/SpecialUploadAvatar.php
M UserProfile/UserProfileClass.php
M UserProfile/UserProfilePage.php
M UserWelcome/UserWelcomeClass.php
5 files changed, 14 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SocialProfile 
refs/changes/62/331962/1

diff --git a/UserProfile/AvatarClass.php b/UserProfile/AvatarClass.php
index eda5add..1acec04 100644
--- a/UserProfile/AvatarClass.php
+++ b/UserProfile/AvatarClass.php
@@ -57,7 +57,7 @@
        /**
         * @param Array $extraParams: array of extra parameters to give to the 
image
         * @return String: <img> HTML tag with full path to the avatar image
-        * */
+        */
        function getAvatarURL( $extraParams = array() ) {
                global $wgUploadPath, $wgUserProfileDisplay;
 
@@ -82,6 +82,15 @@
        }
 
        /**
+        * Is the user's avatar a default one?
+        *
+        * @return bool True if they have a default avatar, false if they've 
uploaded their own
+        */
+       function isDefault() {
+               return (bool)strpos( $this->getAvatarImage(), 'default_' ) !== 
false;
+       }
+
+       /**
         * Return a string representation of this avatar object
         *
         * @return string Representation of this avatar object
diff --git a/UserProfile/SpecialUploadAvatar.php 
b/UserProfile/SpecialUploadAvatar.php
index c2136ce..fa0f9ad 100644
--- a/UserProfile/SpecialUploadAvatar.php
+++ b/UserProfile/SpecialUploadAvatar.php
@@ -387,7 +387,7 @@
                // If this is the user's first custom avatar, update statistics 
(in
                // case if we want to give out some points to the user for 
uploading
                // their first avatar)
-               if ( strpos( $avatar->getAvatarImage(), 'default_' ) !== false 
) {
+               if ( $avatar->isDefault() ) {
                        $stats = new UserStatsTrack( $uid, $user->getName() );
                        $stats->incStatField( 'user_image' );
                }
diff --git a/UserProfile/UserProfileClass.php b/UserProfile/UserProfileClass.php
index f1ab2c8..b4e4e9f 100644
--- a/UserProfile/UserProfileClass.php
+++ b/UserProfile/UserProfileClass.php
@@ -219,7 +219,7 @@
                // Check if the user has a non-default avatar
                $this->profile_fields_count++;
                $avatar = new wAvatar( $wgUser->getID(), 'l' );
-               if ( strpos( $avatar->getAvatarImage(), 'default_' ) === false 
) {
+               if ( !$avatar->isDefault() ) {
                        $complete_count++;
                }
 
diff --git a/UserProfile/UserProfilePage.php b/UserProfile/UserProfilePage.php
index 2027e25..d553e2e 100644
--- a/UserProfile/UserProfilePage.php
+++ b/UserProfile/UserProfilePage.php
@@ -1075,7 +1075,7 @@
 
                $output = '<div class="profile-image">';
                if ( $wgUser->getName() == $this->user_name ) {
-                       if ( strpos( $avatar->getAvatarImage(), 'default_' ) != 
false ) {
+                       if ( $avatar->isDefault() ) {
                                $caption = 'upload image';
                        } else {
                                $caption = 'new image';
diff --git a/UserWelcome/UserWelcomeClass.php b/UserWelcome/UserWelcomeClass.php
index ede4bc6..2c88ae3 100644
--- a/UserWelcome/UserWelcomeClass.php
+++ b/UserWelcome/UserWelcomeClass.php
@@ -51,7 +51,7 @@
                <div class="mp-welcome-image">
                <a href="' . htmlspecialchars( 
$wgUser->getUserPage()->getFullURL() ) . '" rel="nofollow">' .
                        $avatar->getAvatarURL() . '</a>';
-               if ( strpos( $avatar->getAvatarImage(), 'default_' ) !== false 
) {
+               if ( $avatar->isDefault() ) {
                        $uploadOrEditMsg = 'mp-welcome-upload';
                } else {
                        $uploadOrEditMsg = 'mp-welcome-edit';

-- 
To view, visit https://gerrit.wikimedia.org/r/331962
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ef106650897959236a13f3b7cf25c1b825c39ce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SocialProfile
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <j...@countervandalism.net>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to