Index: trunk/extensions/OnlineStatus/OnlineStatus.css |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +/** |
| 3 | + * CSS stylesheet for OnlineStatus extension |
| 4 | + */ |
| 5 | + |
| 6 | +.online-status-js { |
| 7 | + overflow: auto; |
| 8 | + overflow-x: hidden; |
| 9 | + position: absolute; |
| 10 | + top: 0px; |
| 11 | + left: 0px; |
| 12 | + background-color: white; |
| 13 | + border-style: solid; |
| 14 | + border-color: #AAAAAA; |
| 15 | + border-width: 1px; |
| 16 | + z-index: 99; |
| 17 | + font-size: 120%; |
| 18 | +} |
Property changes on: trunk/extensions/OnlineStatus/OnlineStatus.css |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 19 | + native |
Index: trunk/extensions/OnlineStatus/OnlineStatus.js |
— | — | @@ -0,0 +1,83 @@ |
| 2 | +var OnlineStatusCreated = false; |
| 3 | + |
| 4 | +function OnlineStatus(){ |
| 5 | + var status = document.getElementById( 'pt-status' ); |
| 6 | + if( typeof status == 'object' ){ |
| 7 | + var link = status.firstChild; |
| 8 | + link.onmousedown = status.onkeypress = ShowOnlineToggle; |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +function ShowOnlineToggle(){ |
| 13 | + if( !OnlineStatusCreated ){ |
| 14 | + var div = document.createElement( 'div' ); |
| 15 | + div.id = 'online-status-js'; |
| 16 | + div.className = 'online-status-js'; |
| 17 | + |
| 18 | + // Taken from skins/mwsuggest.js of core |
| 19 | + // Credit: Robert Stojnić |
| 20 | + var left = 0; |
| 21 | + var top = this.offsetHeight; |
| 22 | + var elem = this; |
| 23 | + while( elem ){ |
| 24 | + left += elem.offsetLeft; |
| 25 | + top += elem.offsetTop; |
| 26 | + elem = elem.offsetParent; |
| 27 | + } |
| 28 | + if( navigator.userAgent.indexOf( 'Mac' ) != -1 && typeof document.body.leftMargin != 'undefined' ){ |
| 29 | + left += document.body.leftMargin; |
| 30 | + top += document.body.topMargin; |
| 31 | + } |
| 32 | + |
| 33 | + div.style.left = left + "px"; |
| 34 | + div.style.top = top + "px"; |
| 35 | + var table = document.createElement( 'table' ); |
| 36 | + sajax_do_call( 'efOnlineStatusAjax', ['get'], function( x ){ |
| 37 | + if( x.status == 200 ){ |
| 38 | + var resp = x.responseText; |
| 39 | + // A bit unsafe, but... |
| 40 | + var json = eval( resp ); |
| 41 | + for( i = 0; i < json.length; i++ ){ |
| 42 | + var status = json[i]; |
| 43 | + var tr = document.createElement( 'tr' ); |
| 44 | + var td = document.createElement( 'td' ); |
| 45 | + if( status[2] ){ |
| 46 | + td.appendChild( document.createTextNode( status[1] ) ); |
| 47 | + } else { |
| 48 | + var a = document.createElement( 'a' ); |
| 49 | + a.status = status[0]; |
| 50 | + a.onmousedown = a.onkeypress = ChangeOnlineStatus; |
| 51 | + a.appendChild( document.createTextNode( status[1] ) ); |
| 52 | + td.appendChild( a ); |
| 53 | + } |
| 54 | + tr.appendChild( td ); |
| 55 | + table.appendChild( tr ); |
| 56 | + } |
| 57 | + } |
| 58 | + } ); |
| 59 | + div.appendChild( table ); |
| 60 | + div.visible = true; |
| 61 | + document.body.appendChild( div ); |
| 62 | + OnlineStatusCreated = true; |
| 63 | + } else { |
| 64 | + var div = document.getElementById( 'online-status-js' ); |
| 65 | + div.parentNode.removeChild( div ); |
| 66 | + OnlineStatusCreated = false; |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +function ChangeOnlineStatus(){ |
| 71 | + var status = this.status; |
| 72 | + sajax_do_call( 'efOnlineStatusAjax', ['set', status], function( x ){ |
| 73 | + if( x.status == 200 ){ |
| 74 | + var resp = x.responseText; |
| 75 | + jsMsg( resp, 'watch' ); |
| 76 | + // Force update |
| 77 | + var div = document.getElementById( 'online-status-js' ); |
| 78 | + div.parentNode.removeChild( div ); |
| 79 | + OnlineStatusCreated = false; |
| 80 | + } |
| 81 | + } ); |
| 82 | +} |
| 83 | + |
| 84 | +hookEvent( 'load', OnlineStatus ); |
\ No newline at end of file |
Property changes on: trunk/extensions/OnlineStatus/OnlineStatus.js |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 85 | + native |
Index: trunk/extensions/OnlineStatus/OnlineStatus.i18n.php |
— | — | @@ -9,10 +9,14 @@ |
10 | 10 | |
11 | 11 | $messages['en'] = array( |
12 | 12 | 'onlinestatus-desc' => 'Add a preference to show if the user is currently present or not on the wiki', |
| 13 | + 'onlinestatus-js-anon' => 'Error: you must be logged in to use this feature', |
| 14 | + 'onlinestatus-js-changed' => 'Your status has been changed to "$1"', |
| 15 | + 'onlinestatus-js-error' => 'Impossible to change status, value "$1" is invalid', |
13 | 16 | 'onlinestatus-levels' => '* online |
14 | 17 | * offline', // Do not translate this message |
15 | 18 | 'onlinestatus-subtitle-offline' => 'This user is currently offline', |
16 | 19 | 'onlinestatus-subtitle-online' => 'This user is currently online', |
| 20 | + 'onlinestatus-tab' => 'Status', |
17 | 21 | 'onlinestatus-toggles-desc' => 'Your status:', |
18 | 22 | 'onlinestatus-toggles-explain' => 'This allows you to show to other users if you are actually online or not by viewing your user page.', |
19 | 23 | 'onlinestatus-toggles-show' => 'Show online status on my user page', |
— | — | @@ -156,8 +160,12 @@ |
157 | 161 | */ |
158 | 162 | $messages['fr'] = array( |
159 | 163 | 'onlinestatus-desc' => "Ajoute une préférence pour montrer si l'utilisateur est présent ou non", |
| 164 | + 'onlinestatus-js-anon' => 'Erreur : vous devez être connecté pour utiliser cette fonctionnalité', |
| 165 | + 'onlinestatus-js-changed' => 'Votre status a été changé à « $1 »', |
| 166 | + 'onlinestatus-js-error' => 'Impossible de changer le statut, la valeur « $1 » est invalide', |
160 | 167 | 'onlinestatus-subtitle-offline' => 'Cet utilisateur est actuellement hors ligne', |
161 | 168 | 'onlinestatus-subtitle-online' => 'Cet utilisateur est actuellement en ligne', |
| 169 | + 'onlinestatus-tab' => 'Statut', |
162 | 170 | 'onlinestatus-toggles-desc' => 'Votre statut :', |
163 | 171 | 'onlinestatus-toggles-explain' => 'Ceci permet aux autres utilisateur de savoir si vous êtes actuellement présent en regardant votre page utilisateur.', |
164 | 172 | 'onlinestatus-toggles-show' => 'Montrer mon statut sur ma page utilisateur', |
Index: trunk/extensions/OnlineStatus/OnlineStatus.php |
— | — | @@ -13,8 +13,8 @@ |
14 | 14 | |
15 | 15 | // Add credit :) |
16 | 16 | $wgExtensionCredits['other'][] = array( |
17 | | - 'svn-date' => '$LastChangedDate$', |
18 | | - 'svn-revision' => '$LastChangedRevision$', |
| 17 | + 'svn-date' => '$LastChangedDate$', |
| 18 | + 'svn-revision' => '$LastChangedRevision$', |
19 | 19 | 'name' => 'OnlineStatus', |
20 | 20 | 'author' => 'Alexandre Emsenhuber', |
21 | 21 | 'url' => 'http://www.mediawiki.org/wiki/Extension:OnlineStatus', |
— | — | @@ -29,10 +29,55 @@ |
30 | 30 | */ |
31 | 31 | $wgAllowAnyUserOnlineStatusFunction = true; |
32 | 32 | |
| 33 | +function efOnlineStatusAjax( $action, $stat = false ){ |
| 34 | + global $wgUser; |
| 35 | + wfLoadExtensionMessages( 'OnlineStatus' ); |
| 36 | + |
| 37 | + if( $wgUser->isAnon() ) |
| 38 | + return wfMsgHtml( 'onlinestatus-js-anon' ); |
| 39 | + |
| 40 | + switch( $action ){ |
| 41 | + case 'get': |
| 42 | + $def = $wgUser->getOption( 'online' ); |
| 43 | + $msg = wfMsgForContentNoTrans( 'onlinestatus-levels' ); |
| 44 | + $lines = explode( "\n", $msg ); |
| 45 | + $radios = array(); |
| 46 | + foreach( $lines as $line ){ |
| 47 | + if( substr( $line, 0, 1 ) != '*' ) |
| 48 | + continue; |
| 49 | + $lev = trim( $line, '* ' ); |
| 50 | + $radios[] = array( |
| 51 | + $lev, |
| 52 | + wfMsg( 'onlinestatus-toggle-' . $lev ), |
| 53 | + $lev == $def |
| 54 | + ); |
| 55 | + } |
| 56 | + return json_encode( $radios ); |
| 57 | + case 'set': |
| 58 | + if( $stat ){ |
| 59 | + $dbw = wfGetDB(DB_MASTER); |
| 60 | + $dbw->begin(); |
| 61 | + $actual = $wgUser->getOption( 'online' ); |
| 62 | + $wgUser->setOption( 'online', $stat ); |
| 63 | + if( $actual != $stat ){ |
| 64 | + $wgUser->getUserPage()->invalidateCache(); |
| 65 | + $wgUser->getTalkPage()->invalidateCache(); |
| 66 | + } |
| 67 | + $wgUser->saveSettings(); |
| 68 | + $wgUser->invalidateCache(); |
| 69 | + $dbw->commit(); |
| 70 | + return wfMsgHtml( 'onlinestatus-js-changed', wfMsgHtml( 'onlinestatus-toggle-'.$stat ) ); |
| 71 | + } else { |
| 72 | + return wfMsgHtml( 'onlinestatus-js-error', $stat ); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | + |
33 | 77 | class OnlineStatus { |
34 | 78 | |
35 | 79 | static function init(){ |
36 | | - global $wgExtensionMessagesFiles, $wgExtensionFunctions, $wgHooks, $wgAllowAnyUserOnlineStatusFunction; |
| 80 | + global $wgExtensionMessagesFiles, $wgExtensionFunctions, $wgHooks, $wgAjaxExportList; |
| 81 | + global $wgAllowAnyUserOnlineStatusFunction; |
37 | 82 | // Add messages file |
38 | 83 | $wgExtensionMessagesFiles['OnlineStatus'] = dirname( __FILE__ ) . '/OnlineStatus.i18n.php'; |
39 | 84 | |
— | — | @@ -60,6 +105,10 @@ |
61 | 106 | |
62 | 107 | // User page |
63 | 108 | $wgHooks['BeforePageDisplay'][] = 'OnlineStatus::BeforePageDisplay'; |
| 109 | + $wgHooks['PersonalUrls'][] = 'OnlineStatus::PersonalUrls'; |
| 110 | + |
| 111 | + // Ajax stuff |
| 112 | + $wgAjaxExportList[] = 'efOnlineStatusAjax'; |
64 | 113 | } |
65 | 114 | |
66 | 115 | /** |
— | — | @@ -241,7 +290,19 @@ |
242 | 291 | * Hook function for BeforePageDisplay |
243 | 292 | */ |
244 | 293 | static function BeforePageDisplay( &$out ){ |
245 | | - global $wgTitle, $wgRequest; |
| 294 | + global $wgTitle, $wgRequest, $wgUser; |
| 295 | + global $wgUseAjax; |
| 296 | + |
| 297 | + if( $wgUser->isLoggedIn() && $wgUseAjax ){ |
| 298 | + global $wgScriptPath, $wgJsMimeType; |
| 299 | + $out->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}/extensions/OnlineStatus/OnlineStatus.js\"></script>" ); |
| 300 | + $out->addLink( array( |
| 301 | + 'rel' => 'stylesheet', |
| 302 | + 'type' => 'text/css', |
| 303 | + 'href' => "{$wgScriptPath}/extensions/OnlineStatus/OnlineStatus.css" |
| 304 | + ) ); |
| 305 | + } |
| 306 | + |
246 | 307 | if( !in_array( $wgRequest->getVal( 'action', 'view' ), array( 'view', 'purge' ) ) ) |
247 | 308 | return true; |
248 | 309 | $status = self::GetUserStatus( $wgTitle, true ); |
— | — | @@ -249,8 +310,32 @@ |
250 | 311 | return true; |
251 | 312 | wfLoadExtensionMessages( 'OnlineStatus' ); |
252 | 313 | $out->setSubtitle( wfMsgExt( 'onlinestatus-subtitle-' . $status, array( 'parse' ) ) ); |
| 314 | + |
253 | 315 | return true; |
254 | 316 | } |
| 317 | + |
| 318 | + /** |
| 319 | + * Hook for PersonalUrls |
| 320 | + */ |
| 321 | + static function PersonalUrls( &$urls, &$title ){ |
| 322 | + global $wgUser, $wgUseAjax; |
| 323 | + # Require ajax |
| 324 | + if( !$wgUser->isLoggedIn() || !$wgUseAjax ) |
| 325 | + return true; |
| 326 | + $arr = array(); |
| 327 | + foreach( $urls as $key => $val ){ |
| 328 | + if( $key == 'logout' ){ |
| 329 | + wfLoadExtensionMessages( 'OnlineStatus' ); |
| 330 | + $arr['status'] = array( |
| 331 | + 'text' => wfMsgHtml( 'onlinestatus-tab' ), |
| 332 | + 'href' => 'javascript:;', |
| 333 | + ); |
| 334 | + } |
| 335 | + $arr[$key] = $val; |
| 336 | + } |
| 337 | + $urls = $arr; |
| 338 | + return true; |
| 339 | + } |
255 | 340 | } |
256 | 341 | |
257 | 342 | OnlineStatus::init(); |
\ No newline at end of file |