Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -45,8 +45,7 @@ |
46 | 46 | { |
47 | 47 | $dbw = wfGetDB( DB_MASTER ); |
48 | 48 | $row = array( |
49 | | - 'userid' => $wgUser->getID(), |
50 | | - 'username' => $wgUser->getName(), |
| 49 | + 'username' => strtolower($wgUser->getName()), |
51 | 50 | 'timestamp' => $dbw->timestamp( wfTimestamp() ), |
52 | 51 | ); |
53 | 52 | $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' ); |
— | — | @@ -67,7 +66,7 @@ |
68 | 67 | $dbw->update( |
69 | 68 | 'online_status', |
70 | 69 | array( 'timestamp' => $dbw->timestamp( wfTimestamp() ) ), |
71 | | - array( 'username' => $wgUser->getID() ), |
| 70 | + array( 'username' => strtolower($wgUser->getID()) ), |
72 | 71 | __METHOD__ |
73 | 72 | ); |
74 | 73 | |
— | — | @@ -85,11 +84,33 @@ |
86 | 85 | return 0; |
87 | 86 | } |
88 | 87 | |
| 88 | + public static function IsValid($id) |
| 89 | + { |
| 90 | + global $wgOnlineStatusBarDefaultIpUsers; |
| 91 | + // checks if anon |
| 92 | + if (User::isIP($id)) |
| 93 | + { |
| 94 | + return $wgOnlineStatusBarDefaultIpUsers; |
| 95 | + } |
| 96 | + $user = User::newFromName($id); |
| 97 | + // check if exist |
| 98 | + if ($user == null) |
| 99 | + { |
| 100 | + return false; |
| 101 | + } |
| 102 | + // do we track them |
| 103 | + if ($user->getOption("OnlineStatusBar_active") == true) |
| 104 | + { |
| 105 | + return true; |
| 106 | + } |
| 107 | + return false; |
| 108 | + } |
| 109 | + |
89 | 110 | static function GetStatus( $userID ) { |
90 | 111 | global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname; |
91 | 112 | $dbw = wfGetDB( DB_MASTER ); |
92 | 113 | OnlineStatusBar::DeleteOld(); |
93 | | - $result = $dbw->selectField( 'online_status', 'username', array( 'username' => $userID ), __METHOD__, array( 'limit 1', 'order by timestamp desc' ) ); |
| 114 | + $result = $dbw->selectField( 'online_status', 'username', array( 'username' => strtolower($userID) ), __METHOD__, array( 'limit 1', 'order by timestamp desc' ) ); |
94 | 115 | if ( $result ) |
95 | 116 | { |
96 | 117 | return $wgOnlineStatusBarDefaultOnline; |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php |
— | — | @@ -15,4 +15,8 @@ |
16 | 16 | $messages['en'] = array( |
17 | 17 | 'onlinestatusbar-desc' => "Status bar which shows whether a user is online, based on preferences, on their user page", |
18 | 18 | 'onlinestatusbar-line' => "$1 is now $2 $3", |
| 19 | + 'onlinestatusbar-used' => 'Do you want to let others see if you are online?', |
| 20 | + 'onlinestatusbar-status' => 'What is the default status you wish to use:', |
| 21 | + 'prefs-gadgets' => 'Gadgets', |
| 22 | + 'prefs-onlinestatus' => 'Online Status', |
19 | 23 | ); |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php |
— | — | @@ -52,6 +52,8 @@ |
53 | 53 | 'offline' => "red", |
54 | 54 | ); |
55 | 55 | |
| 56 | +// default for anonymous and uknown users |
| 57 | +$wgOnlineStatusBarDefaultIpUsers = false; |
56 | 58 | // default for online |
57 | 59 | $wgOnlineStatusBarDefaultOnline = "online"; |
58 | 60 | // default for offline |
— | — | @@ -96,12 +98,14 @@ |
97 | 99 | { |
98 | 100 | // better way to get a username would be great :) |
99 | 101 | $user = preg_replace( '/\/.*/', '', preg_replace( '/^.*\:/', "", $article->getTitle() ) ); |
100 | | - |
101 | | - $mode = OnlineStatusBar::GetStatus( $user ); |
102 | | - $modetext = $wgOnlineStatusBarModes[$mode]; |
103 | | - $image = OnlineStatusBar::getImageHtml( $mode ); |
104 | | - $text = wfMessage( 'onlinestatusbar-line', $user )->rawParams( $image )->params( $modetext )->escaped(); |
105 | | - $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) ); |
| 102 | + if (OnlineStatusBar::IsValid($user)) |
| 103 | + { |
| 104 | + $mode = OnlineStatusBar::GetStatus( $user ); |
| 105 | + $modetext = $wgOnlineStatusBarModes[$mode]; |
| 106 | + $image = OnlineStatusBar::getImageHtml( $mode ); |
| 107 | + $text = wfMessage( 'onlinestatusbar-line', $user )->rawParams( $image )->params( $modetext )->escaped(); |
| 108 | + $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) ); |
| 109 | + } |
106 | 110 | } |
107 | 111 | return true; |
108 | 112 | } |
— | — | @@ -113,8 +117,19 @@ |
114 | 118 | return true; |
115 | 119 | } |
116 | 120 | |
117 | | -// Unused? |
118 | | -$commonModuleInfo = array( |
119 | | - 'localBasePath' => dirname( __FILE__ ) . '/modules', |
120 | | - 'remoteExtPath' => 'OnlineStatusBar/modules', |
121 | | -); |
| 121 | +$wgHooks['GetPreferences'][] = 'wfOnlineStatusBar_PreferencesHook'; |
| 122 | +function wfOnlineStatusBar_PreferencesHook($user, &$preferences) |
| 123 | +{ |
| 124 | + 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 | + ); |
| 135 | + return true; |
| 136 | +} |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.sql |
— | — | @@ -1,7 +1,6 @@ |
2 | 2 | CREATE TABLE /*$wgDBprefix*/online_status ( |
3 | | - `userid` int(5) NOT NULL default '0', |
4 | 3 | `username` varchar(255) NOT NULL default '', |
5 | 4 | `timestamp` char(14) NOT NULL default '', |
6 | | - PRIMARY KEY USING HASH (`userid`, `username`) |
| 5 | + PRIMARY KEY USING HASH (`username`) |
7 | 6 | ) ENGINE=MEMORY; |
8 | 7 | |