r49838 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49837‎ | r49838 | r49839 >
Date:20:08, 24 April 2009
Author:ialex
Status:deferred
Tags:
Comment:
Follow-up r49825: complete compatibility with the new preferences system
Modified paths:
  • /trunk/extensions/OnlineStatus/OnlineStatus.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatus/OnlineStatus.php
@@ -49,13 +49,9 @@
5050 $wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatus::ParserGetVariable';
5151
5252 // Hooks for Special:Preferences
53 - $wgHooks['InitPreferencesForm'][] = 'OnlineStatus::InitPreferencesForm';
54 - $wgHooks['PreferencesUserInformationPanel'][] = 'OnlineStatus::PreferencesUserInformationPanel';
55 - $wgHooks['ResetPreferences'][] = 'OnlineStatus::ResetPreferences';
56 - $wgHooks['SavePreferences'][] = 'OnlineStatus::SavePreferences';
 53+ $wgHooks['GetPreferences'][] = 'OnlineStatus::GetPreferences';
5754
5855 // User hook
59 - $wgHooks['GetPreferences'][] = 'OnlineStatus::onGetPreferences';
6056 $wgHooks['UserLoginComplete'][] = 'OnlineStatus::UserLoginComplete';
6157 $wgHooks['UserLogoutComplete'][] = 'OnlineStatus::UserLogoutComplete';
6258
@@ -215,52 +211,11 @@
216212 }
217213
218214 /**
219 - * Hook function for SavePreferences
 215+ * Hook for user preferences
220216 */
221 - static function SavePreferences( $prefs, $user, &$msg, $old = array() ){
222 - # We need to invalidate caches for these pages, maybe it would be good
223 - # to be done for subpages, but it would too expensive
224 - if( !is_array( $old ) || empty( $old ) ){
225 - # MediaWiki is < 1.13, at that time, $old param wasn't present
226 - # We can't check if the user changed the online toggle as it is
227 - # already saved :(
228 - $changed = true;
229 - } elseif( !isset( $old['online'] ) || !isset( $old['showonline'] ) ) {
230 - $changed = true;
231 - } else {
232 - $changed = !( $old['online'] == $user->mOptions['online']
233 - && $old['showonline'] == $user->mOptions['showonline'] );
234 - }
235 - if( $changed ){
236 - $user->getUserPage()->invalidateCache();
237 - $user->getTalkPage()->invalidateCache();
238 - }
239 - return true;
240 - }
241 -
242 - /**
243 - * Hook function for InitPreferencesForm
244 - */
245 - static function InitPreferencesForm( $prefs, $request ) {
246 - $prefs->mToggles['online'] = $request->getVal( 'wpOnline' );
247 - $prefs->mToggles['showonline'] = $request->getCheck( 'wpOpShowOnline' ) ? 1 : 0;
248 - return true;
249 - }
250 -
251 - /**
252 - * Hook function for ResetPreferences
253 - */
254 - static function ResetPreferences( $prefs, $user ) {
255 - $prefs->mToggles['online'] = $user->getOption( 'online' );
256 - $prefs->mToggles['showonline'] = $user->getOption( 'showonline' );
257 - return true;
258 - }
259 -
260 - /**
261 - * Hook function for PreferencesUserInformationPanel
262 - */
263 - static function PreferencesUserInformationPanel( $prefsForm, &$html ) {
 217+ public static function GetPreferences( $user, &$preferences ) {
264218 wfLoadExtensionMessages( 'OnlineStatus' );
 219+
265220 $msg = wfMsgForContentNoTrans( 'onlinestatus-levels' );
266221 $lines = explode( "\n", $msg );
267222 $radios = array();
@@ -268,30 +223,9 @@
269224 if( substr( $line, 0, 1 ) != '*' )
270225 continue;
271226 $lev = trim( $line, '* ' );
272 - $radios[] = Xml::radioLabel(
273 - wfMsg( 'onlinestatus-toggle-' . $lev ),
274 - 'wpOnline',
275 - $lev,
276 - 'wpOnline-' . $lev,
277 - $lev == $prefsForm->mToggles['online']
278 - );
 227+ $radios[wfMsg( 'onlinestatus-toggle-' . $lev )] = $lev;
279228 }
280 - $out = "<ul>\n<li>";
281 - $out .= implode( "</li>\n<li>", $radios );
282 - $out .= "</li>\n</ul>";
283 - $html .= $prefsForm->tableRow(
284 - wfMsgExt( 'onlinestatus-toggles-desc', array( 'escapenoentities' ) ),
285 - $out .
286 - Xml::checkLabel( wfMsg( 'onlinestatus-toggles-show' ), 'wpOpShowOnline', 'wpOpShowOnline', (bool)$prefsForm->mToggles['showonline'] ) .
287 - wfMsgExt( 'onlinestatus-toggles-explain', array( 'parse' ) )
288 - );
289 - return true;
290 - }
291229
292 - /**
293 - * Hook for user preferences
294 - */
295 - public static function onGetPreferences( $user, &$preferences ) {
296230 $preferences['onlinestatusonlogin'] =
297231 array(
298232 'type' => 'toggle',
@@ -306,6 +240,22 @@
307241 'label-message' => 'onlinestatus-pref-offlineonlogout',
308242 );
309243
 244+ $prefs = array(
 245+ 'online' => array(
 246+ 'type' => 'radio',
 247+ 'section' => 'personal',
 248+ 'options' => $radios,
 249+ 'label-message' => 'onlinestatus-toggles-desc',
 250+ ),
 251+ 'showonline' => array(
 252+ 'type' => 'check',
 253+ 'section' => 'personal',
 254+ 'label-message' => 'onlinestatus-toggles-show',
 255+ 'help-message' => 'onlinestatus-toggles-explain',
 256+ )
 257+ );
 258+ $preferences = wfArrayInsertAfter( $preferences, $prefs, 'registrationdate' );
 259+
310260 return true;
311261 }
312262

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r49825Updates preferences handling to work with r49790 and up. Needs review, as the...siebrand18:06, 24 April 2009

Status & tagging log