Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.hooks.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 | | -} |