http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94906

Revision: 94906
Author:   ashley
Date:     2011-08-18 16:35:31 +0000 (Thu, 18 Aug 2011)
Log Message:
-----------
SocialProfile: in UserStatus, moved the public history button from JS to PHP, 
added some <tr> and <td> tags around the "no status history" message in 
wfGetHistory, made it so that the owner of a status update and anons can't 
"like" the status update, removed unused JS globals and renamed the method 
which outputs the new JS global and added some wfReadOnly() checks

Modified Paths:
--------------
    trunk/extensions/SocialProfile/UserStatus/UserStatus.js
    trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php

Modified: trunk/extensions/SocialProfile/UserStatus/UserStatus.js
===================================================================
--- trunk/extensions/SocialProfile/UserStatus/UserStatus.js     2011-08-18 
16:21:54 UTC (rev 94905)
+++ trunk/extensions/SocialProfile/UserStatus/UserStatus.js     2011-08-18 
16:35:31 UTC (rev 94906)
@@ -23,11 +23,6 @@
                document.getElementById( 'status-letter-count' ).innerHTML = 
len + ' ' + _US_LETTERS;
        },
 
-       publicHistoryButton: function( id ) {
-               document.getElementById( 'user-status-block' ).innerHTML +=
-                       '<br /> <a class="us-link" 
href="javascript:UserStatus.useHistory(' + id + ');">' + _US_HISTORY + '</a>';
-       },
-
        /**
         * Enter the edit mode by hiding the current status message and 
displaying
         * the hidden input field which allows the user to enter a new status
@@ -79,14 +74,14 @@
                        historyBlock.id = 'status-history-block';
                        statusBlock.appendChild( historyBlock );
                }
-               
-               if ( historyBlock.style.display == "block" ) {
-                       historyBlock.style.display = "none";
+
+               if ( historyBlock.style.display == 'block' ) {
+                       historyBlock.style.display = 'none';
                } else {
-                       //This call should be here, as it fixes bug, 
-                       //when history does not change after first status save
+                       // This call should be here, as it fixes bug,
+                       // when history does not change after first status save
                        sajax_do_call( 'wfGetHistory', [id], historyBlock );
-                       historyBlock.style.display = "block";
+                       historyBlock.style.display = 'block';
                }
        },
 
@@ -101,7 +96,7 @@
                document.getElementById( 'user-status-input' ).value =
                        jQuery( '#status-history-entry-' + statusId ).text();
        },
-       
+
        like: function( userID, messageID ) {
                var div = document.getElementById( 'like-status-' + messageID );
                sajax_do_call( 'wfStatusLike', [userID, messageID], div );

Modified: trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php
===================================================================
--- trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php      
2011-08-18 16:21:54 UTC (rev 94905)
+++ trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php      
2011-08-18 16:35:31 UTC (rev 94906)
@@ -11,7 +11,7 @@
 
        // Would probably be best to pass an edit token here, like most other MW
        // forms do
-       if ( $u_id == $wgUser->getId() ) {
+       if ( $u_id == $wgUser->getId() && !wfReadOnly() ) {
                // Decode what we encoded in JS, UserStatus.saveStatus; this is 
safe
                // because the Database class that UserStatusClass uses for its 
DB queries
                // will do all the escaping for us.
@@ -41,7 +41,7 @@
        $output = '<table id="user-status-history">';
 
        if ( empty( $historyArray ) ) {
-               $output .= 'No status history.';
+               $output .= '<tr><td>No status history.</td></tr>';
        } else {
                foreach ( $historyArray as $row ) {
                        $us = htmlspecialchars( $row['ush_status'] );
@@ -55,19 +55,27 @@
                                $href = ' 
href="javascript:UserStatus.insertStatusFromHistory(' . $status_id .
                                        ');"';
                        }
-                       
+
+                       $likeSymbol = '&#9829;';
+                       // Don't allow 1) the owner of the status update or 2) 
anonymous
+                       // users to like the status
+                       if ( !( $wgUser->getId() == $u_id ) && 
$wgUser->isLoggedIn() ) {
+                               $likeSymbol = '<a 
href="javascript:UserStatus.like(' .
+                                       $wgUser->getId() . ',' . $status_id . 
');">&#9829;</a>';
+                       }
+
                        $output .= '<tr>
                                <td width="60" id="status-history-time">' .
                                        $wgLang->timeanddate( wfTimestamp( 
TS_MW, $row['ush_timestamp'] ), true ) .
                                '</td>
                                <td width="360">
-                                       <a id="status-history-entry-' . 
$status_id . '"' . $href . '>'. $us . '</a>
+                                       <a id="status-history-entry-' . 
$status_id . '"' . $href .
+                                               '>' . $us . '</a>
                                </td>
                                <td width="30" id="like-status">
-                               <span id="like-status-' . $status_id . '" >' . 
$status_likes . '<span>
-                                       <a href="javascript:UserStatus.like(' . 
$wgUser->getId() . ',' . $status_id .
-                                               ');">&#9829;</a>
-                               </td>
+                               <span id="like-status-' . $status_id . '" >' . 
$status_likes .
+                                       '<span>' . $likeSymbol .
+                               '</td>
                        </tr>';
                }
        }
@@ -79,10 +87,17 @@
 
 $wgAjaxExportList[] = 'wfStatusLike';
 
-function wfStatusLike ( $u_id, $status_id ) {
-       $us_class = new UserStatusClass();
-       $count = $us_class->likeStatus( $u_id, $status_id );
-       return $count;  
+function wfStatusLike( $u_id, $status_id ) {
+       global $wgUser;
+       // Only logged-in users should be able to like people's statuses
+       // @todo CHECKME: maybe we should introduce a new permission for liking
+       // status updates and then use isAllowed( 'our-new-permission' ) here
+       // instead of isLoggedIn()?
+       if ( $wgUser->isLoggedIn() && $wgUser->getId() !== $u_id && 
!wfReadOnly() ) {
+               $us_class = new UserStatusClass();
+               $count = $us_class->likeStatus( $u_id, $status_id );
+               return $count;
+       }
 }
 
 $wgAjaxExportList[] = 'SpecialGetStatusByName';
@@ -101,8 +116,8 @@
                if ( !empty( $currentStatus ) ) {
                        $output .="CURRENT STATUS:<br />
                                                <input id=\"ush_delete\" 
type=\"button\" value=\"Delete\"
-                                               
onclick=\"javascript:UserStatus.specialStatusDelete('".$currentStatus['us_id']."');\">"
-                                               .$currentStatus['us_status'] . 
'<br /><br />';
+                                               
onclick=\"javascript:UserStatus.specialStatusDelete('" . 
$currentStatus['us_id'] . "');\">"
+                                               . $currentStatus['us_status'] . 
'<br /><br />';
                }
 
                $output .= 'HISTORY:<br />';
@@ -113,8 +128,8 @@
                } else {
                        foreach ( $userHistory as $row ) {
                                $output .= "<input id=\"ush_delete\" 
type=\"button\" value=\"Delete\"
-                                                       
onclick=\"javascript:UserStatus.specialHistoryDelete('".$row['ush_id']."');\">"
-                                                       
.$row['ush_timestamp']." - ".$row['ush_status']." <br />";
+                                                       
onclick=\"javascript:UserStatus.specialHistoryDelete('" . $row['ush_id'] . 
"');\">"
+                                                       . $row['ush_timestamp'] 
. ' - ' . $row['ush_status'] . ' <br />';
                        }
                }
        }
@@ -135,18 +150,13 @@
        return '';
 }
 
-$wgHooks['MakeGlobalVariablesScript'][] = 'addJSGlobals';
+$wgHooks['MakeGlobalVariablesScript'][] = 'wfUserStatusAddJSGlobals';
 
-function addJSGlobals( $vars ) {
-       $vars['_US_EDIT'] = wfMsg( 'userstatus-edit' );
-       $vars['_US_SAVE'] = wfMsg( 'userstatus-save' );
-       $vars['_US_CANCEL'] = wfMsg( 'userstatus-cancel' );
-       $vars['_US_HISTORY'] = wfMsg( 'userstatus-history' );
+function wfUserStatusAddJSGlobals( $vars ) {
        $vars['_US_LETTERS'] = wfMsg( 'userstatus-letters-left' );
        return true;
 }
 
-
 $wgHooks['UserProfileBeginRight'][] = 'wfUserProfileStatusOutput';
 
 /**
@@ -192,11 +202,22 @@
                        }
                }
 
+               $publicHistoryLink = '';
+               // Public history link to the masses (i.e. everyone who is not 
the
+               // owner of the profile; the owner has a history link in the 
edit links
+               // below)
+               if ( !( $user_profile->user_id == $wgUser->getId() ) ) {
+                       $publicHistoryLink = '<br /> <a class="us-link" 
href="javascript:UserStatus.useHistory(' .
+                               $user_profile->user_id . ');">' .
+                               wfMsg( 'userstatus-history' ) . '</a>';
+               }
+
                $output = '<div id="status-box">
                                        <div id="status-box-top"></div>
                                                <div id="status-box-content">
                                                        <div 
id="user-status-block">' .
                                                                
htmlspecialchars( $userStatus ) . $editLink .
+                                                               
$publicHistoryLink .
                                                        '</div>';
 
                // No need to show the editing controls to anyone else except 
the owner
@@ -217,9 +238,6 @@
                                                                        <span 
id="status-letter-count"></span>
                                                                </div>
                                                        </div><!-- 
#status-edit-controls -->';
-               } else {
-                       // Public history link to the masses
-                       $output .= 
"<script>UserStatus.publicHistoryButton('{$user_profile->user_id}');</script>";
                }
 
                $output .= '</div>


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

Reply via email to