Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -16,8 +16,7 @@ |
17 | 17 | |
18 | 18 | class OnlineStatusBar { |
19 | 19 | |
20 | | - public static function Get_Html( $text, $mode ) |
21 | | - { |
| 20 | + public static function Get_Html( $text, $mode ) { |
22 | 21 | global $wgOnlineStatusBarColor, $wgOnlineStatusBarY; |
23 | 22 | $color = $wgOnlineStatusBarColor[$mode]; |
24 | 23 | return <<<HTML |
— | — | @@ -26,26 +25,24 @@ |
27 | 26 | $text</div></div> |
28 | 27 | HTML; |
29 | 28 | } |
| 29 | + |
30 | 30 | public static function GetImageHtml( $mode ) { |
31 | 31 | global $wgExtensionAssetsPath, $wgOnlineStatusBarIcon, $wgOnlineStatusBarModes; |
32 | 32 | $icon = "$wgExtensionAssetsPath/OnlineStatusBar/{$wgOnlineStatusBarIcon[$mode]}"; |
33 | 33 | $modeText = $wgOnlineStatusBarModes[$mode]; |
34 | 34 | return Html::element( 'img', array( 'src' => $icon ) ); |
35 | 35 | } |
36 | | - |
37 | | - static function GetNow() |
38 | | - { |
| 36 | + |
| 37 | + static function GetNow() { |
39 | 38 | return gmdate( 'Ymdhis', time() ); |
40 | 39 | } |
41 | 40 | |
42 | | - static function UpdateDb() |
43 | | - { |
| 41 | + static function UpdateDb() { |
44 | 42 | global $wgUser, $wgOnlineStatusBarDefaultOnline; |
45 | | - if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) != $wgOnlineStatusBarDefaultOnline ) |
46 | | - { |
| 43 | + if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) != $wgOnlineStatusBarDefaultOnline ) { |
47 | 44 | $dbw = wfGetDB( DB_MASTER ); |
48 | 45 | $row = array( |
49 | | - 'username' => strtolower($wgUser->getName()), |
| 46 | + 'username' => strtolower( $wgUser->getName() ), |
50 | 47 | 'timestamp' => $dbw->timestamp( wfTimestamp() ), |
51 | 48 | ); |
52 | 49 | $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' ); |
— | — | @@ -54,11 +51,9 @@ |
55 | 52 | return false; |
56 | 53 | } |
57 | 54 | |
58 | | - static function UpdateStatus() |
59 | | - { |
| 55 | + static function UpdateStatus() { |
60 | 56 | global $wgUser, $wgOnlineStatusBarDefaultOffline; |
61 | | - if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) |
62 | | - { |
| 57 | + if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) { |
63 | 58 | OnlineStatusBar::UpdateDb(); |
64 | 59 | return true; |
65 | 60 | } |
— | — | @@ -66,7 +61,7 @@ |
67 | 62 | $dbw->update( |
68 | 63 | 'online_status', |
69 | 64 | array( 'timestamp' => $dbw->timestamp( wfTimestamp() ) ), |
70 | | - array( 'username' => strtolower($wgUser->getID()) ), |
| 65 | + array( 'username' => strtolower( $wgUser->getID() ) ), |
71 | 66 | __METHOD__ |
72 | 67 | ); |
73 | 68 | |
— | — | @@ -74,34 +69,29 @@ |
75 | 70 | |
76 | 71 | } |
77 | 72 | |
78 | | - public static function DeleteOld() |
79 | | - { |
| 73 | + public static function DeleteOld() { |
80 | 74 | global $wgOnlineStatusBar_LogoutTime, $wgDBname; |
81 | 75 | $dbw = wfGetDB( DB_MASTER ); |
82 | 76 | $time = wfTimestamp( TS_UNIX ) - $wgOnlineStatusBar_LogoutTime; |
83 | 77 | $time = $dbw->addQuotes( $dbw->timestamp( $time ) - $wgOnlineStatusBar_LogoutTime ); |
84 | | - $dbw->delete( 'online_status', array( "timestamp < $time" ) , __METHOD__ ); |
| 78 | + $dbw->delete( 'online_status', array( "timestamp < $time" ), __METHOD__ ); |
85 | 79 | return 0; |
86 | 80 | } |
87 | 81 | |
88 | | - public static function IsValid($id) |
89 | | - { |
| 82 | + public static function IsValid( $id ) { |
90 | 83 | global $wgOnlineStatusBarDefaultIpUsers; |
91 | 84 | // checks if anon |
92 | | - if (User::isIP($id)) |
93 | | - { |
| 85 | + if ( User::isIP( $id ) ) { |
94 | 86 | return $wgOnlineStatusBarDefaultIpUsers; |
95 | 87 | } |
96 | | - $user = User::newFromName($id); |
| 88 | + $user = User::newFromName( $id ); |
97 | 89 | // check if exist |
98 | | - if ($user == null) |
99 | | - { |
| 90 | + if ( $user == null ) { |
100 | 91 | return false; |
101 | | - } |
| 92 | + } |
102 | 93 | // do we track them |
103 | | - if ($user->getOption("OnlineStatusBar_active") == true) |
104 | | - { |
105 | | - return true; |
| 94 | + if ( $user->getOption( "OnlineStatusBar_active" ) == true ) { |
| 95 | + return true; |
106 | 96 | } |
107 | 97 | return false; |
108 | 98 | } |
— | — | @@ -110,21 +100,18 @@ |
111 | 101 | global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname; |
112 | 102 | $dbw = wfGetDB( DB_MASTER ); |
113 | 103 | OnlineStatusBar::DeleteOld(); |
114 | | - $user = User::newFromName($userID); |
115 | | - if ($user == null) |
116 | | - { |
117 | | - //something is wrong |
| 104 | + $user = User::newFromName( $userID ); |
| 105 | + if ( $user == null ) { |
| 106 | + // something is wrong |
118 | 107 | return $wgOnlineStatusBarDefaultOffline; |
119 | 108 | } |
120 | | - $result = $dbw->selectField( 'online_status', 'username', array( 'username' => strtolower($userID) ), __METHOD__, array( 'limit 1', 'order by timestamp desc' ) ); |
121 | | - if ( $result ) |
122 | | - { |
123 | | - $status = $user->getOption("OnlineStatusBar_status"); |
124 | | - if ($status == null || $status == "") |
125 | | - { |
| 109 | + $result = $dbw->selectField( 'online_status', 'username', array( 'username' => strtolower( $userID ) ), |
| 110 | + __METHOD__, array( 'limit 1', 'order by timestamp desc' ) ); |
| 111 | + if ( $result ) { |
| 112 | + $status = $user->getOption( "OnlineStatusBar_status" ); |
| 113 | + if ( $status == null || $status == "" ) { |
126 | 114 | return $wgOnlineStatusBarDefaultOnline; |
127 | | - } else |
128 | | - { |
| 115 | + } else { |
129 | 116 | return $status; |
130 | 117 | } |
131 | 118 | } |
— | — | @@ -132,9 +119,8 @@ |
133 | 120 | return $wgOnlineStatusBarDefaultOffline; |
134 | 121 | } |
135 | 122 | |
136 | | - static function DeleteStatus( $userId ) |
137 | | - { |
138 | | - $dbw = wfGetDB ( DB_MASTER ); |
| 123 | + static function DeleteStatus( $userId ) { |
| 124 | + $dbw = wfGetDB( DB_MASTER ); |
139 | 125 | $dbw->delete( 'online_status', array( 'username' => $userId ), __METHOD__ ); // delete user |
140 | 126 | return true; |
141 | 127 | } |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php |
— | — | @@ -24,27 +24,27 @@ |
25 | 25 | ); |
26 | 26 | |
27 | 27 | $dir = dirname( __FILE__ ); |
28 | | -$wgExtensionMessagesFiles['OnlineStatusBar'] = "$dir/OnlineStatusBar.i18n.php"; |
| 28 | +$wgExtensionMessagesFiles['OnlineStatusBar'] = "$dir/OnlineStatusBar.i18n.php"; |
29 | 29 | |
30 | 30 | $wgAutoloadClasses['OnlineStatusBar'] = "$dir/OnlineStatusBar.body.php"; |
31 | 31 | |
32 | 32 | // Configuration |
33 | 33 | // Those values can be overriden in LocalSettings, do not change it here |
34 | | -$wgOnlineStatusBarModes = array ( |
| 34 | +$wgOnlineStatusBarModes = array( |
35 | 35 | 'online' => "On-line", |
36 | 36 | 'busy' => "Busy", |
37 | 37 | 'away' => "Away", |
38 | 38 | 'hidden' => "Offline", |
39 | 39 | 'offline' => "Offline", |
40 | 40 | ); |
41 | | -$wgOnlineStatusBarIcon = array ( |
| 41 | +$wgOnlineStatusBarIcon = array( |
42 | 42 | 'online' => "20px-Ledgreen.svg.png", |
43 | 43 | 'busy' => "20px-Ledorange.svg.png", |
44 | 44 | 'away' => "20px-Ledorange.svg.png", |
45 | 45 | 'hidden' => "20px-Nuvola_apps_krec.svg.png", |
46 | 46 | 'offline' => "20px-Nuvola_apps_krec.svg.png", |
47 | 47 | ); |
48 | | -$wgOnlineStatusBarColor = array ( |
| 48 | +$wgOnlineStatusBarColor = array( |
49 | 49 | 'online' => "green", |
50 | 50 | 'busy' => "orange", |
51 | 51 | 'away' => "orange", |
— | — | @@ -66,40 +66,32 @@ |
67 | 67 | $wgOnlineStatusBarY = "-35"; |
68 | 68 | |
69 | 69 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'wfOnlineStatusBar_CkSchema'; |
70 | | -function wfOnlineStatusBar_CkSchema( $updater = null ) |
71 | | -{ |
72 | | - if ( $updater != null ) |
73 | | - { |
74 | | - $updater->addExtensionUpdate( array ( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) ); |
75 | | - } |
76 | | - else |
77 | | - { |
| 70 | +function wfOnlineStatusBar_CkSchema( $updater = null ) { |
| 71 | + if ( $updater != null ) { |
| 72 | + $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) ); |
| 73 | + } else { |
78 | 74 | global $wgExtNewTables; |
79 | 75 | $wgExtNewTables[] = array( |
80 | | - 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' ); |
| 76 | + 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' ); |
81 | 77 | } |
82 | 78 | return true; |
83 | 79 | } |
84 | 80 | |
85 | 81 | $wgHooks['UserLogoutComplete'][] = 'wfOnlineStatusBar_Logout'; |
86 | | -function wfOnlineStatusBar_Logout( &$user, &$inject_html, $old_name ) |
87 | | -{ |
| 82 | +function wfOnlineStatusBar_Logout( &$user, &$inject_html, $old_name ) { |
88 | 83 | OnlineStatusBar::DeleteStatus( $old_name ); |
89 | 84 | return true; |
90 | 85 | } |
91 | 86 | |
92 | 87 | $wgHooks['ArticleViewHeader'][] = 'wfOnlineStatusBar_RenderBar'; |
93 | | -function wfOnlineStatusBar_RenderBar( &$article, &$outputDone, &$pcache ) |
94 | | -{ |
| 88 | +function wfOnlineStatusBar_RenderBar( &$article, &$outputDone, &$pcache ) { |
95 | 89 | global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarModes, $wgOut; |
96 | 90 | OnlineStatusBar::UpdateStatus(); |
97 | 91 | $ns = $article->getTitle()->getNamespace(); |
98 | | - if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) |
99 | | - { |
| 92 | + if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) { |
100 | 93 | // better way to get a username would be great :) |
101 | 94 | $user = preg_replace( '/\/.*/', '', preg_replace( '/^.*\:/', "", $article->getTitle() ) ); |
102 | | - if (OnlineStatusBar::IsValid($user)) |
103 | | - { |
| 95 | + if ( OnlineStatusBar::IsValid( $user ) ) { |
104 | 96 | $mode = OnlineStatusBar::GetStatus( $user ); |
105 | 97 | $modetext = $wgOnlineStatusBarModes[$mode]; |
106 | 98 | $image = OnlineStatusBar::getImageHtml( $mode ); |
— | — | @@ -111,25 +103,23 @@ |
112 | 104 | } |
113 | 105 | |
114 | 106 | $wgHooks['UserLoginComplete'][] = 'wfOnlineStatusBar_UpdateStatus'; |
115 | | -function wfOnlineStatusBar_UpdateStatus() |
116 | | -{ |
| 107 | +function wfOnlineStatusBar_UpdateStatus() { |
117 | 108 | OnlineStatusBar::UpdateDb(); |
118 | 109 | return true; |
119 | 110 | } |
120 | 111 | |
121 | 112 | $wgHooks['GetPreferences'][] = 'wfOnlineStatusBar_PreferencesHook'; |
122 | | -function wfOnlineStatusBar_PreferencesHook($user, &$preferences) |
123 | | -{ |
| 113 | +function wfOnlineStatusBar_PreferencesHook( $user, &$preferences ) { |
124 | 114 | global $wgOnlineStatusBarModes; |
125 | | - $preferences['OnlineStatusBar_active'] = array ('type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'gadgets/onlinestatus' ); |
126 | | - $preferences['OnlineStatusBar_status'] = array ('type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'gadgets/onlinestatus', |
127 | | - 'options' => array( |
128 | | - $wgOnlineStatusBarModes['online'] => 'online', |
129 | | - $wgOnlineStatusBarModes['busy'] => 'busy', |
130 | | - $wgOnlineStatusBarModes['away'] => 'away', |
131 | | - $wgOnlineStatusBarModes['hidden'] => 'hidden' |
132 | | - ), |
133 | | - 'default' => 'online', |
134 | | - ); |
| 115 | + $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'gadgets/onlinestatus' ); |
| 116 | + $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'gadgets/onlinestatus', |
| 117 | + 'options' => array( |
| 118 | + $wgOnlineStatusBarModes['online'] => 'online', |
| 119 | + $wgOnlineStatusBarModes['busy'] => 'busy', |
| 120 | + $wgOnlineStatusBarModes['away'] => 'away', |
| 121 | + $wgOnlineStatusBarModes['hidden'] => 'hidden' |
| 122 | + ), |
| 123 | + 'default' => 'online', |
| 124 | + ); |
135 | 125 | return true; |
136 | 126 | } |