Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -26,7 +26,12 @@ |
27 | 27 | $text</div></div> |
28 | 28 | HTML; |
29 | 29 | } |
30 | | - |
| 30 | + |
| 31 | + /** |
| 32 | + * Returns image |
| 33 | + * @param $mode User |
| 34 | + * @return string |
| 35 | + */ |
31 | 36 | public static function GetImageHtml( $mode ) { |
32 | 37 | global $wgExtensionAssetsPath, $wgOnlineStatusBarIcon, $wgOnlineStatusBarModes; |
33 | 38 | $icon = "$wgExtensionAssetsPath/OnlineStatusBar/{$wgOnlineStatusBarIcon[$mode]}"; |
— | — | @@ -34,34 +39,39 @@ |
35 | 40 | return Html::element( 'img', array( 'src' => $icon ) ); |
36 | 41 | } |
37 | 42 | |
38 | | - public static function GetNow() { |
39 | | - return gmdate( 'Ymdhis', time() ); |
40 | | - } |
41 | | - |
| 43 | + /** |
| 44 | + * @param $title Title |
| 45 | + * @return user |
| 46 | + */ |
42 | 47 | public static function GetOwnerFromTitle ( $title ) |
43 | 48 | { |
44 | 49 | if ( $title === null ) { |
45 | 50 | return null; |
46 | 51 | } |
47 | | - $username = preg_replace( '/\/.*/', '', $title->getText() ); |
| 52 | + $username = $title->getBaseText(); |
48 | 53 | $user_object = User::newFromName ( $username ); |
49 | 54 | return $user_object; |
50 | 55 | } |
51 | 56 | |
| 57 | + /** |
| 58 | + * @return bool |
| 59 | + */ |
52 | 60 | public static function UpdateDb() { |
53 | 61 | global $wgUser, $wgOnlineStatusBarDefaultOnline; |
54 | 62 | if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) != $wgOnlineStatusBarDefaultOnline ) { |
55 | 63 | $dbw = wfGetDB( DB_MASTER ); |
56 | 64 | $row = array( |
57 | 65 | 'username' => $wgUser->getName(), |
58 | | - 'timestamp' => $dbw->timestamp( wfTimestamp() ), /// fixme |
| 66 | + 'timestamp' => $dbw->timestamp(), |
59 | 67 | ); |
60 | 68 | $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' ); |
61 | 69 | } |
62 | | - |
63 | 70 | return false; |
64 | 71 | } |
65 | 72 | |
| 73 | + /** |
| 74 | + * @return bool |
| 75 | + */ |
66 | 76 | public static function UpdateStatus() { |
67 | 77 | global $wgUser, $wgOnlineStatusBarDefaultOffline; |
68 | 78 | if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) { |
— | — | @@ -77,9 +87,11 @@ |
78 | 88 | ); |
79 | 89 | |
80 | 90 | return false; |
81 | | - |
82 | 91 | } |
83 | 92 | |
| 93 | + /** |
| 94 | + * @return int |
| 95 | + */ |
84 | 96 | public static function DeleteOld() { |
85 | 97 | global $wgOnlineStatusBar_LogoutTime, $wgDBname; |
86 | 98 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -89,54 +101,54 @@ |
90 | 102 | return 0; |
91 | 103 | } |
92 | 104 | |
93 | | - public static function IsValid( $id ) { |
| 105 | + |
| 106 | + /** |
| 107 | + * @param $userName string |
| 108 | + * @return bool |
| 109 | + */ |
| 110 | + public static function IsValid( $userName ) { |
94 | 111 | global $wgOnlineStatusBarDefaultIpUsers, $wgOnlineStatusBarDefaultEnabled; |
95 | 112 | // checks if anon |
96 | | - if ( User::isIP( $id ) ) { |
| 113 | + if ( User::isIP( $userName ) ) { |
97 | 114 | return $wgOnlineStatusBarDefaultIpUsers; |
98 | 115 | } |
99 | | - $user = User::newFromName( $id ); |
| 116 | + $user = User::newFromName( $userName ); |
100 | 117 | // check if exist |
101 | 118 | if ( $user == null ) { |
102 | 119 | return false; |
103 | 120 | } |
104 | 121 | // do we track them |
105 | | - $value = $user->getOption( "OnlineStatusBar_active" ); |
106 | | - if ( $value === null ) { |
107 | | - return $wgOnlineStatusBarDefaultEnabled; |
108 | | - } |
109 | | - if ( $value == true ) { |
110 | | - return true; |
111 | | - } |
112 | | - return false; |
| 122 | + return $user->getOption( "OnlineStatusBar_active", $wgOnlineStatusBarDefaultEnabled ); |
113 | 123 | } |
114 | 124 | |
115 | | - static function GetStatus( $userID ) { |
| 125 | + /** |
| 126 | + * @param $userName string |
| 127 | + * @return string |
| 128 | + */ |
| 129 | + static function GetStatus( $userName ) { |
116 | 130 | global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname; |
117 | 131 | $dbw = wfGetDB( DB_MASTER ); |
118 | 132 | OnlineStatusBar::DeleteOld(); |
119 | | - $user = User::newFromName( $userID ); |
| 133 | + $user = User::newFromName( $userName ); |
120 | 134 | if ( $user == null ) { |
121 | 135 | // something is wrong |
122 | 136 | return $wgOnlineStatusBarDefaultOffline; |
123 | 137 | } |
124 | | - $result = $dbw->selectField( 'online_status', 'username', array( 'username' => $userID ), |
| 138 | + $result = $dbw->selectField( 'online_status', 'username', array( 'username' => $userName ), |
125 | 139 | __METHOD__, array( 'limit 1', 'order by timestamp desc' ) ); |
126 | 140 | if ( $result ) { |
127 | | - $status = $user->getOption( "OnlineStatusBar_status" ); |
128 | | - if ( $status === null || $status == "" ) { |
129 | | - return $wgOnlineStatusBarDefaultOnline; |
130 | | - } else { |
131 | | - return $status; |
132 | | - } |
| 141 | + return $user->getOption( "OnlineStatusBar_status", $wgOnlineStatusDefaultOnline ); |
133 | 142 | } |
134 | | - |
135 | 143 | return $wgOnlineStatusBarDefaultOffline; |
136 | 144 | } |
137 | 145 | |
138 | | - static function DeleteStatus( $userId ) { |
| 146 | + /** |
| 147 | + * @param $userName string |
| 148 | + * @return bool |
| 149 | + */ |
| 150 | + static function DeleteStatus( $userName ) { |
139 | 151 | $dbw = wfGetDB( DB_MASTER ); |
140 | | - $dbw->delete( 'online_status', array( 'username' => $userId ), __METHOD__ ); // delete user |
| 152 | + $dbw->delete( 'online_status', array( 'username' => $userName ), __METHOD__ ); // delete user |
141 | 153 | return true; |
142 | 154 | } |
143 | 155 | } |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @return bool
|
13 | 13 | */
|
14 | 14 | public static function ckSchema( $updater = null ) {
|
15 | | - if ( ( $updater === null ) != true ){
|
| 15 | + if ( $updater !== null ){
|
16 | 16 | $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) );
|
17 | 17 | } else {
|
18 | 18 | global $wgExtNewTables;
|
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | $ns = $article->getTitle()->getNamespace();
|
54 | 54 | if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
|
55 | 55 | $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() );
|
56 | | - if ( $user === null ) {
|
| 56 | + if ( $user == null ) {
|
57 | 57 | return true;
|
58 | 58 | }
|
59 | 59 | $username = $user->getName();
|
— | — | @@ -111,7 +111,6 @@ |
112 | 112 | */
|
113 | 113 | public static function magicWordVar ( array &$magicWords, $ln ) {
|
114 | 114 | $magicWords['isonline'] = array ( 0, 'isonline' );
|
115 | | -
|
116 | 115 | return true;
|
117 | 116 | }
|
118 | 117 |
|
— | — | @@ -142,7 +141,7 @@ |
143 | 142 | * @return bool
|
144 | 143 | */
|
145 | 144 | public static function parserGetVariable ( &$parser, &$varCache, &$index, &$ret ){
|
146 | | - global $wgOnlineStatusBarModes;
|
| 145 | + global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline;
|
147 | 146 | if( $index == 'isonline' ){
|
148 | 147 | $name = OnlineStatusBar::GetOwnerFromTitle ( $parser->getTitle() )->getName();
|
149 | 148 |
|
— | — | @@ -150,7 +149,10 @@ |
151 | 150 | $ret = "unknown";
|
152 | 151 | return true;
|
153 | 152 | }
|
154 | | - $ret = $wgOnlineStatusBarModes[OnlineStatusBar::GetStatus( $name )];
|
| 153 | + $ret = OnlineStatusBar::GetStatus( $name );
|
| 154 | + if ( $ret == "hidden" ) {
|
| 155 | + $ret = $wgOnlineStatusBarDefaultOffline;
|
| 156 | + }
|
155 | 157 | }
|
156 | 158 | return true;
|
157 | 159 | }
|