http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90560
Revision: 90560
Author: ashley
Date: 2011-06-21 23:56:30 +0000 (Tue, 21 Jun 2011)
Log Message:
-----------
SocialProfile: stylize UserStatus, add/tweak docs, add one to-do item
Modified Paths:
--------------
trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php
trunk/extensions/SocialProfile/UserStatus/UserStatus.js
trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php
trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php
Modified: trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php
===================================================================
--- trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php
2011-06-21 23:28:50 UTC (rev 90559)
+++ trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php
2011-06-21 23:56:30 UTC (rev 90560)
@@ -559,10 +559,13 @@
<div id="profile-title">' .
$user_name .
'</div>';
+ // Get the user's status message, if the UserStatus feature is
enabled
if ( $wgEnableUserStatus ) {
- $user_status = $this->getStatus($this->user_id);
- $output .='<div
id="user-status-block">'.$user_status.'</div>';
- }
+ $userStatus = $this->getStatus( $this->user_id );
+ $output .= '<div id="user-status-block">' . $userStatus
. '</div>';
+ }
+ // Show the user's level and the amount of points they have if
+ // UserLevels has been configured
if ( $wgUserLevels ) {
$output .= '<div id="points-level">
<a href="' .
$level_link->escapeFullURL() . '">' .
Modified: trunk/extensions/SocialProfile/UserStatus/UserStatus.js
===================================================================
--- trunk/extensions/SocialProfile/UserStatus/UserStatus.js 2011-06-21
23:28:50 UTC (rev 90559)
+++ trunk/extensions/SocialProfile/UserStatus/UserStatus.js 2011-06-21
23:56:30 UTC (rev 90560)
@@ -1,22 +1,22 @@
-function toShowMode(status,id) {
- document.getElementById('user-status-block').innerHTML = status;
- document.getElementById('user-status-block').innerHTML+= ' <a
href="javascript:toEditMode(\''+status+'\','+id+');">Edit</a>';
+function toShowMode( status, id ) {
+ document.getElementById( 'user-status-block' ).innerHTML = status;
+ document.getElementById( 'user-status-block' ).innerHTML += ' <a
href="javascript:toEditMode(\'' + status + '\',' + id + ');">Edit</a>';
}
-function toEditMode(status,id) {
- var editbar = '<input id="user-status-input" type="text"
value="'+status+'">';
- editbar += ' <a href="javascript:saveStatus('+id+');">Save</a>';
- editbar += ' <a
href="javascript:toShowMode(\''+status+'\','+id+');">Cancel</a>';
- editbar += ' <a href="javascript:showStatusHistory;">History</a>';
- document.getElementById('user-status-block').innerHTML = editbar;
-}
+function toEditMode( status, id ) {
+ var editbar = '<input id="user-status-input" type="text" value="' +
status + '">';
+ editbar += ' <a href="javascript:saveStatus(' + id + ');">Save</a>';
+ editbar += ' <a href="javascript:toShowMode(\'' + status + '\',' + id +
');">Cancel</a>';
+ editbar += ' <a href="javascript:showStatusHistory;">History</a>';
+ document.getElementById( 'user-status-block' ).innerHTML = editbar;
+}
-function saveStatus(id) {
- var div = document.getElementById('user-status-block');
- var ustext = document.getElementById('user-status-input').value;
- sajax_do_call( 'wfSaveStatus', [id,ustext], div );
+function saveStatus( id ) {
+ var div = document.getElementById( 'user-status-block' );
+ var ustext = document.getElementById( 'user-status-input' ).value;
+ sajax_do_call( 'wfSaveStatus', [id, ustext], div );
}
-
-function showStatusHistory(){
- //A history script
+
+function showStatusHistory() {
+ // A history script
}
\ No newline at end of file
Modified: trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php
2011-06-21 23:28:50 UTC (rev 90559)
+++ trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php
2011-06-21 23:56:30 UTC (rev 90560)
@@ -1,102 +1,151 @@
<?php
+/**
+ * Class to manipulate user-specific status messages.
+ *
+ * @file
+ */
+class UserStatusClass {
-class UserStatusClass {
-
- /* private */ function __construct($u_id) {
- global $wgOut, $wgScriptPath;
-
$wgOut->addScriptFile($wgScriptPath.'/extensions/SocialProfile/UserStatus/UserStatus.js'
);
+ /* private */ function __construct( $u_id ) {
+ global $wgOut, $wgScriptPath;
+ $wgOut->addScriptFile( $wgScriptPath .
'/extensions/SocialProfile/UserStatus/UserStatus.js' );
}
-
- public function getStatus($u_id) {
- $dbr = wfGetDB(DB_SLAVE);
- $res = $dbr->select('user_status', '*', array('us_user_id' => $u_id),
__METHOD__);
- $message = array();
- if (empty($res)) {
- $message = '';
- } else {
- foreach ($res as $row) {
- $message = array(
- 'us_user_id' => $row->us_user_id,
- 'us_status' => htmlspecialchars($row->us_status),
- );
- }
- }
- return $message;
- }
- /*
- *
- */
+ public function getStatus( $u_id ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select(
+ 'user_status',
+ '*',
+ array( 'us_user_id' => $u_id ),
+ __METHOD__
+ );
- public function setStatus($u_id, $message) {
- if (mb_strlen($message) > 140) { // change
- //ERROR. Message lenth is too long
- return;
- }
- $dbw = wfGetDB(DB_MASTER);
- $res = $dbw->select('user_status', '*', array('us_user_id' => $u_id),
__METHOD__);
- $i = 0;
- foreach ($res as $row)
- $i++;
- if ($i == 0) {
- $dbw->insert(
- 'user_status',
- /* SET */ array(
- 'us_user_id' => $u_id,
- 'us_status' => $message,), __METHOD__
- );
- } else {
- $dbw->update(
- 'user_status',
- /* SET */ array('us_status' => $message),
- /* WHERE */ array('us_user_id' => $u_id), __METHOD__
- );
- }
- $this->useStatusHistory('insert',$u_id);
- return;
- }
+ $message = array();
- /*
- * Method that manipulates the user_status_history table
- * $mode - varieble for realization of two methods.
- * Variants:
- * 'insert'
- * 'select'
- */
- public function useStatusHistory($mode,$u_id) {
- $dbw = wfGetDB(DB_MASTER);
- $userHistory = $dbw->select('user_status_history', '*',
array('ush_user_id' => $u_id), __METHOD__, array('ORDER BY' => 'ush_timestamp
ASC'));
- $i = 0;
- $history = array();
- foreach ($userHistory as $row) {
- $i++;
- $history[] = array(
- 'ush_id' => $row->ush_id,
- 'ush_user_id' => $row->ush_user_id,
- 'ush_timestamp' => $row->ush_timestamp,
- 'ush_status' => $row->ush_status,
- );
- }
- if ($mode=='select') return $history;
- if ($mode=='insert'){
- $currentStatus = $this->getStatus($u_id);
+ if ( empty( $res ) ) {
+ $message = '';
+ } else {
+ foreach ( $res as $row ) {
+ $message = array(
+ 'us_user_id' => $row->us_user_id,
+ 'us_status' => htmlspecialchars(
$row->us_status ),
+ );
+ }
+ }
- if ($i < 4) {
- $dbw->insert(
- 'user_status_history',
- /* SET */ array(
- 'ush_user_id' => $u_id,
- 'ush_status' => $currentStatus['us_status']),
__METHOD__
- );
- } else {
- $dbw->update(
- 'user_status_history',
- /* SET */ array('ush_status' =>
$currentStatus['us_status']),
- /*WHERE*/ array('ush_user_id' => $u_id,
- 'ush_timestamp' =>
$history[0]['ush_timestamp']),
- __METHOD__);
- }
- return;
- }
- }
+ return $message;
+ }
+
+ /**
+ * Add a status message to the database.
+ *
+ * @param $u_id Integer: user ID number
+ * @param $message String: user-supplied status message
+ */
+ public function setStatus( $u_id, $message ) {
+ if ( mb_strlen( $message ) > 140 ) { // change
+ // ERROR. Message length is too long
+ // @todo Communicate failure to the end-user somehow...
+ return;
+ }
+
+ $dbw = wfGetDB( DB_MASTER );
+ $res = $dbw->select(
+ 'user_status',
+ '*',
+ array( 'us_user_id' => $u_id ),
+ __METHOD__
+ );
+
+ $i = 0;
+
+ foreach ( $res as $row ) {
+ $i++;
+ }
+
+ if ( $i == 0 ) {
+ $dbw->insert(
+ 'user_status',
+ /* SET */ array(
+ 'us_user_id' => $u_id,
+ 'us_status' => $message,
+ ),
+ __METHOD__
+ );
+ } else {
+ $dbw->update(
+ 'user_status',
+ /* SET */ array( 'us_status' => $message ),
+ /* WHERE */ array( 'us_user_id' => $u_id ),
+ __METHOD__
+ );
+ }
+
+ $this->useStatusHistory( 'insert', $u_id );
+ return;
+ }
+
+ /**
+ * Method that manipulates the user_status_history table.
+ *
+ * @param $mode String: variable for realization of two methods.
+ * Variants: 'insert' and 'select'
+ * @param $u_id Integer: user ID number
+ * @return Array: array when $mode == 'select', else void
+ */
+ public function useStatusHistory( $mode, $u_id ) {
+ $dbw = wfGetDB( DB_MASTER );
+ $userHistory = $dbw->select(
+ 'user_status_history',
+ '*',
+ array( 'ush_user_id' => $u_id ),
+ __METHOD__,
+ array( 'ORDER BY' => 'ush_timestamp ASC' )
+ );
+
+ $i = 0;
+ $history = array();
+
+ foreach ( $userHistory as $row ) {
+ $i++;
+ $history[] = array(
+ 'ush_id' => $row->ush_id,
+ 'ush_user_id' => $row->ush_user_id,
+ 'ush_timestamp' => $row->ush_timestamp,
+ 'ush_status' => $row->ush_status,
+ );
+ }
+
+ if ( $mode == 'select' ) {
+ return $history;
+ }
+
+ if ( $mode == 'insert' ) {
+ $currentStatus = $this->getStatus( $u_id );
+
+ if ( $i < 4 ) {
+ $dbw->insert(
+ 'user_status_history',
+ /* SET */ array(
+ 'ush_user_id' => $u_id,
+ 'ush_status' =>
$currentStatus['us_status']
+ ),
+ __METHOD__
+ );
+ } else {
+ $dbw->update(
+ 'user_status_history',
+ /* SET */ array(
+ 'ush_status' =>
$currentStatus['us_status']
+ ),
+ /*WHERE*/ array(
+ 'ush_user_id' => $u_id,
+ 'ush_timestamp' =>
$history[0]['ush_timestamp']
+ ),
+ __METHOD__
+ );
+ }
+ return;
+ }
+ }
}
\ No newline at end of file
Modified: trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php
===================================================================
--- trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php
2011-06-21 23:28:50 UTC (rev 90559)
+++ trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php
2011-06-21 23:56:30 UTC (rev 90560)
@@ -1,11 +1,14 @@
<?php
+
$wgAjaxExportList[] = 'wfSaveStatus';
-function wfSaveStatus( $u_id, $status) {
- $us_class = new UserStatusClass($u_id);
- $us_class->setStatus($u_id, $status);
- $user_status_array = $us_class->getStatus($u_id);
- $buf=$user_status_array['us_status'];
- $us =$buf;
- $us.=" <a
href=\"javascript:toEditMode('$buf','$u_id');\">Edit</a>";
+
+function wfSaveStatus( $u_id, $status ) {
+ $us_class = new UserStatusClass( $u_id );
+ $us_class->setStatus( $u_id, $status );
+ $user_status_array = $us_class->getStatus( $u_id );
+ $buf = $user_status_array['us_status'];
+ $us = $buf;
+ // @todo FIXME: i18n
+ $us .= " <a href=\"javascript:toEditMode('$buf','$u_id');\">Edit</a>";
return $us;
}
\ No newline at end of file
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs