Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php |
— | — | @@ -1,211 +0,0 @@ |
2 | | -<?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
4 | | - echo "This is a part of mediawiki and can't be started separately"; |
5 | | - die(); |
6 | | -} |
7 | | - |
8 | | -/** |
9 | | - * Hooks for OnlineStatusBar |
10 | | - * |
11 | | - * @group Extensions |
12 | | - */ |
13 | | -class OnlineStatusBarHooks { |
14 | | - /** |
15 | | - * @param DatabaseUpdater|null $updater |
16 | | - * @return bool |
17 | | - */ |
18 | | - public static function ckSchema( $updater = null ) { |
19 | | - if ( $updater !== null ) { |
20 | | - $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) ); |
21 | | - } else { |
22 | | - global $wgExtNewTables; |
23 | | - $wgExtNewTables[] = array( |
24 | | - 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' ); |
25 | | - } |
26 | | - return true; |
27 | | - } |
28 | | - |
29 | | - /** |
30 | | - * Called everytime when user logout |
31 | | - * @param $user User |
32 | | - * @return true |
33 | | - */ |
34 | | - public static function logout( &$user ) { |
35 | | - global $wgOnlineStatusBarDefaultEnabled; |
36 | | - // check if user had enabled this feature before we write to db |
37 | | - if ( $user->getOption( 'OnlineStatusBar_active', $wgOnlineStatusBarDefaultEnabled ) ) { |
38 | | - $userName = $user->getName(); |
39 | | - OnlineStatusBar_StatusCheck::deleteStatus( $userName ); |
40 | | - OnlineStatusBar::purge( $userName ); |
41 | | - } |
42 | | - return true; |
43 | | - } |
44 | | - |
45 | | - /** |
46 | | - * Called everytime on login |
47 | | - * @return bool |
48 | | - */ |
49 | | - public static function updateStatus() { |
50 | | - global $wgUser; |
51 | | - if (OnlineStatusBar::isValid( $wgUser )) { |
52 | | - // Update status |
53 | | - OnlineStatusBar_StatusCheck::updateStatus(); |
54 | | - // Purge user page (optional) |
55 | | - OnlineStatusBar::purge( $wgUser ); |
56 | | - } |
57 | | - return true; |
58 | | - } |
59 | | - |
60 | | - /** |
61 | | - * Creates a bar |
62 | | - * @param $article Article |
63 | | - * @param $outputDone bool |
64 | | - * @param $pcache string |
65 | | - * @return bool |
66 | | - */ |
67 | | - public static function renderBar( &$article, &$outputDone, &$pcache ) { |
68 | | - global $wgOnlineStatusBarCacheTime; |
69 | | - // Update status of all users who wants to be tracked |
70 | | - OnlineStatusBar_StatusCheck::updateStatus(); |
71 | | - |
72 | | - // Performace fix |
73 | | - $title = $article->getTitle(); |
74 | | - if ( $title->getNamespace() != NS_USER && $title->getNamespace() != NS_USER_TALK ) { |
75 | | - return true; |
76 | | - } |
77 | | - |
78 | | - // Retrieve status of user parsed from title |
79 | | - $result = OnlineStatusBar::getUserInfoFromTitle( $title ); |
80 | | - // In case that status can't be parsed we check if it isn't anon |
81 | | - if ( $result === false && User::isIP ( $title->getBaseText() ) ) { |
82 | | - $result = OnlineStatusBar::getAnonFromTitle( $title ); |
83 | | - } |
84 | | - |
85 | | - // In case we were unable to get a status let's quit |
86 | | - if ( $result === false ) { |
87 | | - return true; |
88 | | - } |
89 | | - |
90 | | - /** @var $user User */ |
91 | | - list( $status, $user ) = $result; |
92 | | - |
93 | | - // Don't display status of those who don't want to show bar but only use magic |
94 | | - if ( $user->getOption( 'OnlineStatusBar_hide' ) == true ) { |
95 | | - return true; |
96 | | - } |
97 | | - |
98 | | - $modetext = wfMessage( 'onlinestatusbar-status-' . $status )->toString(); |
99 | | - $image = OnlineStatusBar::getImageHtml( $status, $modetext ); |
100 | | - $text = wfMessage( 'onlinestatusbar-line', $user->getName() ) |
101 | | - ->rawParams( $image )->params( $modetext )->escaped(); |
102 | | - $context = $article->getContext(); |
103 | | - $article->getParserOutput()->updateCacheExpiry($wgOnlineStatusBarCacheTime[$status] * 60); |
104 | | - $context->getOutput()->addHtml( OnlineStatusBar::getStatusBarHtml( $text ) ); |
105 | | - |
106 | | - return true; |
107 | | - } |
108 | | - |
109 | | - /** |
110 | | - * Insert user options |
111 | | - * @param $user User |
112 | | - * @param $preferences array |
113 | | - * @return bool |
114 | | - */ |
115 | | - public static function preferencesHook( User $user, array &$preferences ) { |
116 | | - global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBar_AwayTime, $wgOnlineStatusBar_LogoutTime, $wgOnlineStatusBarModes; |
117 | | - $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' ); |
118 | | - $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' ); |
119 | | - $preferences['OnlineStatusBar_away'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-away', 'section' => 'misc/onlinestatus' ); |
120 | | - $preferences['OnlineStatusBar_autoupdate'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-purge', 'section' => 'misc/onlinestatus' ); |
121 | | - $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus', |
122 | | - 'options' => array( |
123 | | - wfMessage( 'onlinestatusbar-status-online' )->escaped() => 'online', |
124 | | - wfMessage( 'onlinestatusbar-status-busy' )->escaped() => 'busy', |
125 | | - wfMessage( 'onlinestatusbar-status-away' )->escaped() => 'away', |
126 | | - wfMessage( 'onlinestatusbar-status-hidden' )->escaped() => 'hidden' |
127 | | - ), |
128 | | - ); |
129 | | - $preferences['OnlineStatusBar_awaytime'] = array( 'min' => 2, 'max' => $wgOnlineStatusBar_LogoutTime, 'type' => 'int', 'label-message' => 'onlinestatusbar-away-time', 'section' => 'misc/onlinestatus' ); |
130 | | - return true; |
131 | | - } |
132 | | - |
133 | | - /** |
134 | | - * @param $defaultOptions array |
135 | | - * @return bool |
136 | | - */ |
137 | | - public static function setDefaultOptions( &$defaultOptions ) { |
138 | | - global $wgOnlineStatusBar_AwayTime, $wgOnlineStatusBarDefaultOnline ,$wgOnlineStatusBarDefaultEnabled; |
139 | | - // set defaults |
140 | | - $defaultOptions['OnlineStatusBar_autoupdate'] = false; |
141 | | - $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline; |
142 | | - $defaultOptions['OnlineStatusBar_away'] = true; |
143 | | - $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled; |
144 | | - $defaultOptions['OnlineStatusBar_hide'] = false; |
145 | | - $defaultOptions['OnlineStatusBar_awaytime'] = $wgOnlineStatusBar_AwayTime; |
146 | | - // quit |
147 | | - return true; |
148 | | - } |
149 | | - |
150 | | - /** |
151 | | - * @param $magicWords array |
152 | | - * @param $ln string (language) |
153 | | - * @return bool |
154 | | - */ |
155 | | - public static function magicWordVar( array &$magicWords, $ln ) { |
156 | | - $magicWords['ISONLINE'] = array( 1, 'ISONLINE' ); |
157 | | - return true; |
158 | | - } |
159 | | - |
160 | | - /** |
161 | | - * @param $out OutputPage |
162 | | - * @param $skin Skin |
163 | | - * @return bool |
164 | | - */ |
165 | | - public static function stylePage( &$out, &$skin ) { |
166 | | - $out->addModuleStyles( 'ext.OnlineStatusBar' ); |
167 | | - return true; |
168 | | - } |
169 | | - |
170 | | - /** |
171 | | - * @param $vars array |
172 | | - * @return bool |
173 | | - */ |
174 | | - public static function magicWordSet( &$vars ) { |
175 | | - $vars[] = 'ISONLINE'; |
176 | | - return true; |
177 | | - } |
178 | | - |
179 | | - /** |
180 | | - * @param $parser Parser |
181 | | - * @param $varCache ?? |
182 | | - * @param $index ?? |
183 | | - * @param $ret string? |
184 | | - * @return bool |
185 | | - */ |
186 | | - public static function parserGetVariable( &$parser, &$varCache, &$index, &$ret ) { |
187 | | - global $wgOnlineStatusBarCacheTime; |
188 | | - if ( $index != 'ISONLINE' ) { |
189 | | - return true; |
190 | | - } |
191 | | - |
192 | | - // get a status of user parsed from title |
193 | | - $result = OnlineStatusBar::getUserInfoFromTitle( $parser->getTitle() ); |
194 | | - // if user is IP and we track them |
195 | | - if ( User::isIP( $parser->getTitle()->getBaseText() ) && $result === false ) { |
196 | | - $result = OnlineStatusBar::getAnonFromTitle( $parser->getTitle() ); |
197 | | - } |
198 | | - |
199 | | - if ( $result === false ) { |
200 | | - $ret = 'unknown'; |
201 | | - return true; |
202 | | - } |
203 | | - |
204 | | - // if user is tracked we need to remove parser cache so that page update when status change |
205 | | - if ( $result !== false ) { |
206 | | - $parser->getOutput()->updateCacheExpiry($wgOnlineStatusBarCacheTime[$result[0]] * 60); |
207 | | - } |
208 | | - |
209 | | - $ret = $result[0]; |
210 | | - return true; |
211 | | - } |
212 | | -} |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.hooks.php |
— | — | @@ -0,0 +1,211 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 4 | + echo "This is a part of mediawiki and can't be started separately"; |
| 5 | + die(); |
| 6 | +} |
| 7 | + |
| 8 | +/** |
| 9 | + * Hooks for OnlineStatusBar |
| 10 | + * |
| 11 | + * @group Extensions |
| 12 | + */ |
| 13 | +class OnlineStatusBarHooks { |
| 14 | + /** |
| 15 | + * @param DatabaseUpdater|null $updater |
| 16 | + * @return bool |
| 17 | + */ |
| 18 | + public static function ckSchema( $updater = null ) { |
| 19 | + if ( $updater !== null ) { |
| 20 | + $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) ); |
| 21 | + } else { |
| 22 | + global $wgExtNewTables; |
| 23 | + $wgExtNewTables[] = array( |
| 24 | + 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' ); |
| 25 | + } |
| 26 | + return true; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Called everytime when user logout |
| 31 | + * @param $user User |
| 32 | + * @return true |
| 33 | + */ |
| 34 | + public static function logout( &$user ) { |
| 35 | + global $wgOnlineStatusBarDefaultEnabled; |
| 36 | + // check if user had enabled this feature before we write to db |
| 37 | + if ( $user->getOption( 'OnlineStatusBar_active', $wgOnlineStatusBarDefaultEnabled ) ) { |
| 38 | + $userName = $user->getName(); |
| 39 | + OnlineStatusBar_StatusCheck::deleteStatus( $userName ); |
| 40 | + OnlineStatusBar::purge( $userName ); |
| 41 | + } |
| 42 | + return true; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Called everytime on login |
| 47 | + * @return bool |
| 48 | + */ |
| 49 | + public static function updateStatus() { |
| 50 | + global $wgUser; |
| 51 | + if (OnlineStatusBar::isValid( $wgUser )) { |
| 52 | + // Update status |
| 53 | + OnlineStatusBar_StatusCheck::updateStatus(); |
| 54 | + // Purge user page (optional) |
| 55 | + OnlineStatusBar::purge( $wgUser ); |
| 56 | + } |
| 57 | + return true; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Creates a bar |
| 62 | + * @param $article Article |
| 63 | + * @param $outputDone bool |
| 64 | + * @param $pcache string |
| 65 | + * @return bool |
| 66 | + */ |
| 67 | + public static function renderBar( &$article, &$outputDone, &$pcache ) { |
| 68 | + global $wgOnlineStatusBarCacheTime; |
| 69 | + // Update status of all users who wants to be tracked |
| 70 | + OnlineStatusBar_StatusCheck::updateStatus(); |
| 71 | + |
| 72 | + // Performace fix |
| 73 | + $title = $article->getTitle(); |
| 74 | + if ( $title->getNamespace() != NS_USER && $title->getNamespace() != NS_USER_TALK ) { |
| 75 | + return true; |
| 76 | + } |
| 77 | + |
| 78 | + // Retrieve status of user parsed from title |
| 79 | + $result = OnlineStatusBar::getUserInfoFromTitle( $title ); |
| 80 | + // In case that status can't be parsed we check if it isn't anon |
| 81 | + if ( $result === false && User::isIP ( $title->getBaseText() ) ) { |
| 82 | + $result = OnlineStatusBar::getAnonFromTitle( $title ); |
| 83 | + } |
| 84 | + |
| 85 | + // In case we were unable to get a status let's quit |
| 86 | + if ( $result === false ) { |
| 87 | + return true; |
| 88 | + } |
| 89 | + |
| 90 | + /** @var $user User */ |
| 91 | + list( $status, $user ) = $result; |
| 92 | + |
| 93 | + // Don't display status of those who don't want to show bar but only use magic |
| 94 | + if ( $user->getOption( 'OnlineStatusBar_hide' ) == true ) { |
| 95 | + return true; |
| 96 | + } |
| 97 | + |
| 98 | + $modetext = wfMessage( 'onlinestatusbar-status-' . $status )->toString(); |
| 99 | + $image = OnlineStatusBar::getImageHtml( $status, $modetext ); |
| 100 | + $text = wfMessage( 'onlinestatusbar-line', $user->getName() ) |
| 101 | + ->rawParams( $image )->params( $modetext )->escaped(); |
| 102 | + $context = $article->getContext(); |
| 103 | + $article->getParserOutput()->updateCacheExpiry($wgOnlineStatusBarCacheTime[$status] * 60); |
| 104 | + $context->getOutput()->addHtml( OnlineStatusBar::getStatusBarHtml( $text ) ); |
| 105 | + |
| 106 | + return true; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Insert user options |
| 111 | + * @param $user User |
| 112 | + * @param $preferences array |
| 113 | + * @return bool |
| 114 | + */ |
| 115 | + public static function preferencesHook( User $user, array &$preferences ) { |
| 116 | + global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBar_AwayTime, $wgOnlineStatusBar_LogoutTime, $wgOnlineStatusBarModes; |
| 117 | + $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' ); |
| 118 | + $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' ); |
| 119 | + $preferences['OnlineStatusBar_away'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-away', 'section' => 'misc/onlinestatus' ); |
| 120 | + $preferences['OnlineStatusBar_autoupdate'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-purge', 'section' => 'misc/onlinestatus' ); |
| 121 | + $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus', |
| 122 | + 'options' => array( |
| 123 | + wfMessage( 'onlinestatusbar-status-online' )->escaped() => 'online', |
| 124 | + wfMessage( 'onlinestatusbar-status-busy' )->escaped() => 'busy', |
| 125 | + wfMessage( 'onlinestatusbar-status-away' )->escaped() => 'away', |
| 126 | + wfMessage( 'onlinestatusbar-status-hidden' )->escaped() => 'hidden' |
| 127 | + ), |
| 128 | + ); |
| 129 | + $preferences['OnlineStatusBar_awaytime'] = array( 'min' => 2, 'max' => $wgOnlineStatusBar_LogoutTime, 'type' => 'int', 'label-message' => 'onlinestatusbar-away-time', 'section' => 'misc/onlinestatus' ); |
| 130 | + return true; |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * @param $defaultOptions array |
| 135 | + * @return bool |
| 136 | + */ |
| 137 | + public static function setDefaultOptions( &$defaultOptions ) { |
| 138 | + global $wgOnlineStatusBar_AwayTime, $wgOnlineStatusBarDefaultOnline ,$wgOnlineStatusBarDefaultEnabled; |
| 139 | + // set defaults |
| 140 | + $defaultOptions['OnlineStatusBar_autoupdate'] = false; |
| 141 | + $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline; |
| 142 | + $defaultOptions['OnlineStatusBar_away'] = true; |
| 143 | + $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled; |
| 144 | + $defaultOptions['OnlineStatusBar_hide'] = false; |
| 145 | + $defaultOptions['OnlineStatusBar_awaytime'] = $wgOnlineStatusBar_AwayTime; |
| 146 | + // quit |
| 147 | + return true; |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * @param $magicWords array |
| 152 | + * @param $ln string (language) |
| 153 | + * @return bool |
| 154 | + */ |
| 155 | + public static function magicWordVar( array &$magicWords, $ln ) { |
| 156 | + $magicWords['ISONLINE'] = array( 1, 'ISONLINE' ); |
| 157 | + return true; |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * @param $out OutputPage |
| 162 | + * @param $skin Skin |
| 163 | + * @return bool |
| 164 | + */ |
| 165 | + public static function stylePage( &$out, &$skin ) { |
| 166 | + $out->addModuleStyles( 'ext.OnlineStatusBar' ); |
| 167 | + return true; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * @param $vars array |
| 172 | + * @return bool |
| 173 | + */ |
| 174 | + public static function magicWordSet( &$vars ) { |
| 175 | + $vars[] = 'ISONLINE'; |
| 176 | + return true; |
| 177 | + } |
| 178 | + |
| 179 | + /** |
| 180 | + * @param $parser Parser |
| 181 | + * @param $varCache ?? |
| 182 | + * @param $index ?? |
| 183 | + * @param $ret string? |
| 184 | + * @return bool |
| 185 | + */ |
| 186 | + public static function parserGetVariable( &$parser, &$varCache, &$index, &$ret ) { |
| 187 | + global $wgOnlineStatusBarCacheTime; |
| 188 | + if ( $index != 'ISONLINE' ) { |
| 189 | + return true; |
| 190 | + } |
| 191 | + |
| 192 | + // get a status of user parsed from title |
| 193 | + $result = OnlineStatusBar::getUserInfoFromTitle( $parser->getTitle() ); |
| 194 | + // if user is IP and we track them |
| 195 | + if ( User::isIP( $parser->getTitle()->getBaseText() ) && $result === false ) { |
| 196 | + $result = OnlineStatusBar::getAnonFromTitle( $parser->getTitle() ); |
| 197 | + } |
| 198 | + |
| 199 | + if ( $result === false ) { |
| 200 | + $ret = 'unknown'; |
| 201 | + return true; |
| 202 | + } |
| 203 | + |
| 204 | + // if user is tracked we need to remove parser cache so that page update when status change |
| 205 | + if ( $result !== false ) { |
| 206 | + $parser->getOutput()->updateCacheExpiry($wgOnlineStatusBarCacheTime[$result[0]] * 60); |
| 207 | + } |
| 208 | + |
| 209 | + $ret = $result[0]; |
| 210 | + return true; |
| 211 | + } |
| 212 | +} |
Property changes on: trunk/extensions/OnlineStatusBar/OnlineStatusBar.hooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 213 | + native |
Index: trunk/extensions/OnlineStatusBar/svn-commit.tmp |
— | — | @@ -0,0 +1,7 @@ |
| 2 | +Performance tweaks |
| 3 | +--This line, and those below, will be ignored-- |
| 4 | + |
| 5 | +M OnlineStatusBar.body.php |
| 6 | +M OnlineStatusBar.php |
| 7 | +A OnlineStatusBar.status.php |
| 8 | +M OnlineStatusBarHooks.php |
Index: trunk/extensions/OnlineStatusBar/svn-commit.2.tmp |
— | — | @@ -0,0 +1,5 @@ |
| 2 | +Fixed undefined v., and reworded option |
| 3 | +--This line, and those below, will be ignored-- |
| 4 | + |
| 5 | +M OnlineStatusBar.i18n.php |
| 6 | +M OnlineStatusBar.status.php |
Index: trunk/extensions/OnlineStatusBar/svn-commit.3.tmp |
— | — | @@ -0,0 +1,4 @@ |
| 2 | +Reworded en option |
| 3 | +--This line, and those below, will be ignored-- |
| 4 | + |
| 5 | +M OnlineStatusBar.i18n.php |
Index: trunk/extensions/OnlineStatusBar/README |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +OnlineStatus Bar extension for MediaWiki |
| 3 | + |
| 4 | +This extensions adds a small bar showing user status on userspace of each user who enabled it in preferences. |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -42,6 +42,9 @@ |
43 | 43 | return Html::element( 'img', array( 'src' => $icon, 'alt' => $mode_text ) ); |
44 | 44 | } |
45 | 45 | |
| 46 | + public static function getAnonFromTitle( Title $title ) { |
| 47 | + return self::getAnonFromString( $title->getBaseText() ); |
| 48 | + } |
46 | 49 | |
47 | 50 | /** |
48 | 51 | * Returns the status and User element |
— | — | @@ -49,7 +52,7 @@ |
50 | 53 | * @param Title $title a title of page |
51 | 54 | * @return array|bool Array containing the status and User object |
52 | 55 | */ |
53 | | - public static function getAnonFromTitle( Title $title ) { |
| 56 | + public static function getAnonFromString( $username ) { |
54 | 57 | global $wgOnlineStatusBarTrackIpUsers; |
55 | 58 | // if user is anon and we don't track them stop |
56 | 59 | if ( $wgOnlineStatusBarTrackIpUsers == false ) { |
— | — | @@ -58,7 +61,7 @@ |
59 | 62 | |
60 | 63 | // we need to create temporary user object |
61 | 64 | $user = User::newFromId( 0 ); |
62 | | - $user->setName( $title->getBaseText() ); |
| 65 | + $user->setName( $username ); |
63 | 66 | |
64 | 67 | // Check if something wrong didn't happen |
65 | 68 | if ( !($user instanceof User) ) { |
— | — | @@ -74,6 +77,9 @@ |
75 | 78 | return array( $status, $user ); |
76 | 79 | } |
77 | 80 | |
| 81 | + public static function getUserInfoFromTitle( Title $title ) { |
| 82 | + return self::getUserInfoFromString( $title->getBaseText() ); |
| 83 | + } |
78 | 84 | |
79 | 85 | /** |
80 | 86 | * Returns the status and User element |
— | — | @@ -81,9 +87,9 @@ |
82 | 88 | * @param Title $title a title of page |
83 | 89 | * @return array|bool Array containing the status and User object |
84 | 90 | */ |
85 | | - public static function getUserInfoFromTitle( Title $title ) { |
| 91 | + public static function getUserInfoFromString( $username ) { |
86 | 92 | // We create an user object using name of user parsed from title |
87 | | - $user = User::newFromName( $title->getBaseText() ); |
| 93 | + $user = User::newFromName( $username ); |
88 | 94 | // Invalid user |
89 | 95 | if ( !($user instanceof User) ) { |
90 | 96 | return false; |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php |
— | — | @@ -45,7 +45,9 @@ |
46 | 46 | // Load other files of extension |
47 | 47 | $wgAutoloadClasses['OnlineStatusBar'] = "$dir/OnlineStatusBar.body.php"; |
48 | 48 | $wgAutoloadClasses['OnlineStatusBar_StatusCheck'] = "$dir/OnlineStatusBar.status.php"; |
49 | | -$wgAutoloadClasses['OnlineStatusBarHooks'] = "$dir/OnlineStatusBarHooks.php"; |
| 49 | +$wgAutoloadClasses['OnlineStatusBarHooks'] = "$dir/OnlineStatusBar.hooks.php"; |
| 50 | +$wgAutoloadClasses['ApiOnlineStatus'] = "$dir/OnlineStatusBar.api.php"; |
| 51 | +$wgAPIPropModules['onlinestatus'] = 'ApiOnlineStatus'; |
50 | 52 | |
51 | 53 | // For memcached |
52 | 54 | define( 'ONLINESTATUSBAR_DELAYED_CACHE', 'd' ); |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.api.php |
— | — | @@ -0,0 +1,71 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 4 | + echo "This is a part of mediawiki and can't be started separately"; |
| 5 | + die(); |
| 6 | +} |
| 7 | + |
| 8 | +/** |
| 9 | + * Hooks for OnlineStatusBar api's |
| 10 | + * |
| 11 | + * @group Extensions |
| 12 | + */ |
| 13 | + |
| 14 | +class ApiOnlineStatus extends ApiQueryBase { |
| 15 | + public function __construct( $query, $moduleName ) { |
| 16 | + parent::__construct( $query, $moduleName, 'onlinestatus' ); |
| 17 | + } |
| 18 | + |
| 19 | + public function execute() { |
| 20 | + $params = $this->extractRequestParams(); |
| 21 | + if (is_string ( $params['user'] )) { |
| 22 | + $result = OnlineStatusBar::getUserInfoFromString( $params['user'] ); |
| 23 | + // if user is IP and we track them |
| 24 | + if ( User::isIP( $params['user'] ) && $result === false ) { |
| 25 | + $result = OnlineStatusBar::getAnonFromString( $params['user'] ); |
| 26 | + } |
| 27 | + if ( $result === false ) { |
| 28 | + $ret = 'unknown'; |
| 29 | + } else { |
| 30 | + $ret = $result[0]; |
| 31 | + } |
| 32 | + |
| 33 | + $this->getResult()->addValue( |
| 34 | + null, $this->getModuleName(), array( 'result' => $ret ) ); |
| 35 | + } else |
| 36 | + { |
| 37 | + $this->dieUsage( "You provided invalid user." ); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + public function getAllowedParams() { |
| 42 | + return array( |
| 43 | + 'user' => null, |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + public function getParamDescription() { |
| 48 | + return array( |
| 49 | + 'user' => 'Username of user you want to get status of', |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + public function getDescription() { |
| 54 | + return 'Returns online status of user.'; |
| 55 | + } |
| 56 | + |
| 57 | + public function getPossibleErrors() { |
| 58 | + return array_merge( parent::getPossibleErrors(), array( |
| 59 | + array( 'code' => 'unknown', 'info' => "User doesn't allow to display user status"), |
| 60 | + )); |
| 61 | + } |
| 62 | + |
| 63 | + public function getExamples() { |
| 64 | + return array( |
| 65 | + 'api.php?action=query&list=onlinestatus&onlinestatususer=Petrb', |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + public function getVersion() { |
| 70 | + return __CLASS__ . ': $Id: OnlineStatusBar.api.php 90814 2011-12-01 15:00:00Z petrb $'; |
| 71 | + } |
| 72 | +} |
Property changes on: trunk/extensions/OnlineStatusBar/OnlineStatusBar.api.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 73 | + native |