r90996 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90995‎ | r90996 | r90997 >
Date:21:06, 28 June 2011
Author:zhenya
Status:deferred (Comments)
Tags:
Comment:
Modified paths:
  • /trunk/extensions/SocialProfile/UserStatus/UserStatus.i18n.php (added) (history)
  • /trunk/extensions/SocialProfile/UserStatus/UserStatus.js (modified) (history)
  • /trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php
@@ -1,5 +1,7 @@
22 <?php
3 -
 3+/**
 4+ * AJAX functions used in UserStatus
 5+ */
46 $wgAjaxExportList[] = 'wfSaveStatus';
57
68 function wfSaveStatus( $u_id, $status ) {
@@ -11,4 +13,18 @@
1214 // @todo FIXME: i18n
1315 $us .= " <a href=\"javascript:toEditMode('$buf','$u_id');\">Edit</a>";
1416 return $us;
 17+}
 18+
 19+$wgAjaxExportList[] = 'wfGetHistory';
 20+
 21+function wfGetHistory( $u_id ) {
 22+ $us_class = new UserStatusClass( $u_id );
 23+ $historyArray = $us_class->useStatusHistory('select', $u_id);
 24+ $output='<table>';
 25+ /*Under construction*/
 26+ foreach ($historyArray as $row ) {
 27+ $output .= '<tr><td id="status-history-time">'.$row['ush_timestamp'].' </td><td> '.$row['ush_status'].'</td></tr>';
 28+ }
 29+ $output.='</table>';
 30+ return $output;
1531 }
\ No newline at end of file
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus.i18n.php
@@ -0,0 +1,30 @@
 2+<?php
 3+/**
 4+ * Internationalization file for UserStatus extension.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/** English
 13+ * @author Yevhenii Vlasenko
 14+ */
 15+$messages['en'] = array(
 16+ 'edit' => "Edit",
 17+);
 18+
 19+/** Russian (Русский)
 20+ * @author Yevhenii Vlasenko
 21+ */
 22+$messages['ru'] = array(
 23+ 'edit' => 'Изменить',
 24+);
 25+
 26+/** Ukrainian (Українська)
 27+ * @author Yevhenii Vlasenko
 28+ */
 29+$messages['uk'] = array(
 30+ 'edit' => 'Редагувати',
 31+);
\ No newline at end of file
Property changes on: trunk/extensions/SocialProfile/UserStatus/UserStatus.i18n.php
___________________________________________________________________
Added: svn:eol-style
132 + native
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus.js
@@ -1,3 +1,5 @@
 2+var historyOpened = false;
 3+
24 function toShowMode( status, id ) {
35 document.getElementById( 'user-status-block' ).innerHTML = status;
46 document.getElementById( 'user-status-block' ).innerHTML += ' <a href="javascript:toEditMode(\'' + status + '\',' + id + ');">Edit</a>';
@@ -7,7 +9,7 @@
810 var editbar = '<input id="user-status-input" type="text" value="' + status + '">';
911 editbar += ' <a href="javascript:saveStatus(' + id + ');">Save</a>';
1012 editbar += ' <a href="javascript:toShowMode(\'' + status + '\',' + id + ');">Cancel</a>';
11 - editbar += ' <a href="javascript:showStatusHistory;">History</a>';
 13+ editbar += ' <a href="javascript:useHistory(' + id + ');">History</a>';
1214 document.getElementById( 'user-status-block' ).innerHTML = editbar;
1315 }
1416
@@ -17,6 +19,28 @@
1820 sajax_do_call( 'wfSaveStatus', [id, ustext], div );
1921 }
2022
21 -function showStatusHistory() {
22 - // A history script
 23+function useHistory(id){
 24+ if (historyOpened){
 25+ //alert('closed');
 26+ closeStatusHistory();
 27+ }
 28+ else {
 29+ //alert('opened');
 30+ openStatusHistory(id);
 31+ }
 32+}
 33+
 34+function openStatusHistory(id) {
 35+ var statusBlock = document.getElementById('user-status-block');
 36+ var historyBlock = document.createElement('div');
 37+ historyBlock.id = 'status-history-block';
 38+ statusBlock.appendChild(historyBlock);
 39+ historyOpened = true;
 40+ sajax_do_call( 'wfGetHistory', [id], historyBlock );
 41+}
 42+
 43+function closeStatusHistory() {
 44+ var hBlock = document.getElementById('status-history-block');
 45+ hBlock.parentNode.removeChild(hBlock);
 46+ historyOpened = false;
2347 }
\ No newline at end of file
Index: trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php
@@ -8,7 +8,9 @@
99
1010 /* private */ function __construct( $u_id ) {
1111 global $wgOut, $wgScriptPath;
 12+ $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserStatus/UserStatus.css' );
1213 $wgOut->addScriptFile( $wgScriptPath . '/extensions/SocialProfile/UserStatus/UserStatus.js' );
 14+
1315 }
1416
1517 public function getStatus( $u_id ) {
@@ -100,7 +102,7 @@
101103 '*',
102104 array( 'ush_user_id' => $u_id ),
103105 __METHOD__,
104 - array( 'ORDER BY' => 'ush_timestamp ASC' )
 106+ array( 'ORDER BY' => 'ush_timestamp' )
105107 );
106108
107109 $i = 0;

Comments

#Comment by Nikerabbit (talk | contribs)   21:33, 28 June 2011

Please always write a commit message. Extension messages should be prefixed to avoid conflict with core messages.

#Comment by Jack Phoenix (talk | contribs)   17:52, 30 June 2011

I'd prefer if you used tabs instead of spaces consistently across the code. Right now, the first two lines and the last line of wfGetHistory use tabs, while the rest of the function uses spaces. Depending on your text editor, it should be relatively easy to set it to convert four spaces to one tab character.

The JS should be (re)written to be object-oriented, just to avoid any problems with ResourceLoader (even though SocialProfile doesn't really support RL yet). See r91173 for an example where I converted UserBoard's BoardBlast.js to be more object-oriented.

In UserStatusClass.php, you're adding a CSS file that does not (yet?) exist to the page output. I assume that you're planning to add the file eventually, so it's not such a big deal.

As Nikerabbit mentioned above, messages should be prefixed with a key (I'd suggest userstatus-) to prevent conflict with core MediaWiki message. If you later on decide to change UserStatus' edit message from "Edit" to "Edit this status" (for example), it won't change the text of the edit tab on normal wiki pages. :-)

Status & tagging log