r40597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40596‎ | r40597 | r40598 >
Date:19:48, 7 September 2008
Author:ialex
Status:old
Tags:
Comment:
Added options to automatically switch status to online or offline while logging-in or -out. The latter requires MW 1.13 or higher
Modified paths:
  • /trunk/extensions/OnlineStatus/OnlineStatus.i18n.php (modified) (history)
  • /trunk/extensions/OnlineStatus/OnlineStatus.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatus/OnlineStatus.i18n.php
@@ -22,6 +22,8 @@
2323 'onlinestatus-toggles-show' => 'Show online status on my user page',
2424 'onlinestatus-toggle-offline' => 'Offline',
2525 'onlinestatus-toggle-online' => 'Online',
 26+ 'tog-onlineOnLogin' => 'Change my status to online when logging-in',
 27+ 'tog-offlineOnLogout' => 'Change my status to offline when logging-out',
2628 );
2729
2830 /** Afrikaans (Afrikaans)
@@ -201,6 +203,8 @@
202204 'onlinestatus-toggles-show' => 'Montrer mon statut sur ma page utilisateur',
203205 'onlinestatus-toggle-offline' => 'Absent',
204206 'onlinestatus-toggle-online' => 'Présent',
 207+ 'tog-onlineOnLogin' => 'Changer mon statut à en ligne quand je me connecte',
 208+ 'tog-offlineOnLogout' => 'Changer mon statut à hors ligne quand je me déconnecte',
205209 );
206210
207211 /** Galician (Galego)
Index: trunk/extensions/OnlineStatus/OnlineStatus.php
@@ -55,9 +55,12 @@
5656 $wgHooks['InitPreferencesForm'][] = 'OnlineStatus::InitPreferencesForm';
5757 $wgHooks['PreferencesUserInformationPanel'][] = 'OnlineStatus::PreferencesUserInformationPanel';
5858 $wgHooks['ResetPreferences'][] = 'OnlineStatus::ResetPreferences';
 59+ $wgHooks['SavePreferences'][] = 'OnlineStatus::SavePreferences';
5960
6061 // User hook
61 - $wgHooks['SavePreferences'][] = 'OnlineStatus::SavePreferences';
 62+ $wgHooks['UserToggles'][] = 'OnlineStatus::UserToggles';
 63+ $wgHooks['UserLoginComplete'][] = 'OnlineStatus::UserLoginComplete';
 64+ $wgHooks['UserLogoutComplete'][] = 'OnlineStatus::UserLogoutComplete';
6265
6366 // User page
6467 $wgHooks['BeforePageDisplay'][] = 'OnlineStatus::BeforePageDisplay';
@@ -290,6 +293,42 @@
291294 }
292295
293296 /**
 297+ * Hook for UserToggles
 298+ */
 299+ static function UserToggles( &$toggles ){
 300+ $toggles[] = 'onlineOnLogin';
 301+ $toggles[] = 'offlineOnLogout';
 302+ return true;
 303+ }
 304+
 305+ /**
 306+ * Hook for UserLoginComplete
 307+ */
 308+ static function UserLoginComplete( $user ){
 309+ if( $user->getOption( 'offlineOnLogout' ) ){
 310+ $user->setOption( 'online', 'online' );
 311+ $user->saveSettings();
 312+ }
 313+ return true;
 314+ }
 315+
 316+ /**
 317+ * Hook for UserLoginComplete
 318+ */
 319+ static function UserLogoutComplete( &$newUser, &$injected_html, $oldName = null ){
 320+ if( $oldName === null )
 321+ return true;
 322+ $oldUser = User::newFromName( $oldName );
 323+ if( !$oldUser instanceof User )
 324+ return true;
 325+ if( $oldUser->getOption( 'offlineOnLogout' ) ){
 326+ $oldUser->setOption( 'online', 'offline' );
 327+ $oldUser->saveSettings();
 328+ }
 329+ return true;
 330+ }
 331+
 332+ /**
294333 * Hook function for BeforePageDisplay
295334 */
296335 static function BeforePageDisplay( &$out ){