Index: trunk/extensions/OnlineStatus/OnlineStatus.i18n.php |
— | — | @@ -22,6 +22,8 @@ |
23 | 23 | 'onlinestatus-toggles-show' => 'Show online status on my user page', |
24 | 24 | 'onlinestatus-toggle-offline' => 'Offline', |
25 | 25 | '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', |
26 | 28 | ); |
27 | 29 | |
28 | 30 | /** Afrikaans (Afrikaans) |
— | — | @@ -201,6 +203,8 @@ |
202 | 204 | 'onlinestatus-toggles-show' => 'Montrer mon statut sur ma page utilisateur', |
203 | 205 | 'onlinestatus-toggle-offline' => 'Absent', |
204 | 206 | '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', |
205 | 209 | ); |
206 | 210 | |
207 | 211 | /** Galician (Galego) |
Index: trunk/extensions/OnlineStatus/OnlineStatus.php |
— | — | @@ -55,9 +55,12 @@ |
56 | 56 | $wgHooks['InitPreferencesForm'][] = 'OnlineStatus::InitPreferencesForm'; |
57 | 57 | $wgHooks['PreferencesUserInformationPanel'][] = 'OnlineStatus::PreferencesUserInformationPanel'; |
58 | 58 | $wgHooks['ResetPreferences'][] = 'OnlineStatus::ResetPreferences'; |
| 59 | + $wgHooks['SavePreferences'][] = 'OnlineStatus::SavePreferences'; |
59 | 60 | |
60 | 61 | // User hook |
61 | | - $wgHooks['SavePreferences'][] = 'OnlineStatus::SavePreferences'; |
| 62 | + $wgHooks['UserToggles'][] = 'OnlineStatus::UserToggles'; |
| 63 | + $wgHooks['UserLoginComplete'][] = 'OnlineStatus::UserLoginComplete'; |
| 64 | + $wgHooks['UserLogoutComplete'][] = 'OnlineStatus::UserLogoutComplete'; |
62 | 65 | |
63 | 66 | // User page |
64 | 67 | $wgHooks['BeforePageDisplay'][] = 'OnlineStatus::BeforePageDisplay'; |
— | — | @@ -290,6 +293,42 @@ |
291 | 294 | } |
292 | 295 | |
293 | 296 | /** |
| 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 | + /** |
294 | 333 | * Hook function for BeforePageDisplay |
295 | 334 | */ |
296 | 335 | static function BeforePageDisplay( &$out ){ |