(bug 17190) User ID on prefs page shouldn't be delimited.
[lhc/web/wiklou.git] / includes / specials / SpecialPreferences.php
1 <?php
2 /**
3 * Hold things related to displaying and saving user preferences.
4 * @file
5 * @ingroup SpecialPage
6 */
7
8 /**
9 * Entry point that create the "Preferences" object
10 */
11 function wfSpecialPreferences() {
12 global $wgRequest;
13
14 $form = new PreferencesForm( $wgRequest );
15 $form->execute();
16 }
17
18 /**
19 * Preferences form handling
20 * This object will show the preferences form and can save it as well.
21 * @ingroup SpecialPage
22 */
23 class PreferencesForm {
24 var $mQuickbar, $mStubs;
25 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
26 var $mUserLanguage, $mUserVariant;
27 var $mSearch, $mRecent, $mRecentDays, $mTimeZone, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
28 var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
29 var $mUnderline, $mWatchlistEdits, $mGender;
30
31 /**
32 * Constructor
33 * Load some values
34 */
35 function __construct( &$request ) {
36 global $wgContLang, $wgUser, $wgAllowRealName;
37
38 $this->mQuickbar = $request->getVal( 'wpQuickbar' );
39 $this->mStubs = $request->getVal( 'wpStubs' );
40 $this->mRows = $request->getVal( 'wpRows' );
41 $this->mCols = $request->getVal( 'wpCols' );
42 $this->mSkin = Skin::normalizeKey( $request->getVal( 'wpSkin' ) );
43 $this->mMath = $request->getVal( 'wpMath' );
44 $this->mDate = $request->getVal( 'wpDate' );
45 $this->mUserEmail = $request->getVal( 'wpUserEmail' );
46 $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : '';
47 $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1;
48 $this->mNick = $request->getVal( 'wpNick' );
49 $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
50 $this->mUserVariant = $request->getVal( 'wpUserVariant' );
51 $this->mSearch = $request->getVal( 'wpSearch' );
52 $this->mRecent = $request->getVal( 'wpRecent' );
53 $this->mRecentDays = $request->getVal( 'wpRecentDays' );
54 $this->mTimeZone = $request->getVal( 'wpTimeZone' );
55 $this->mHourDiff = $request->getVal( 'wpHourDiff' );
56 $this->mSearchLines = $request->getVal( 'wpSearchLines' );
57 $this->mSearchChars = $request->getVal( 'wpSearchChars' );
58 $this->mImageSize = $request->getVal( 'wpImageSize' );
59 $this->mThumbSize = $request->getInt( 'wpThumbSize' );
60 $this->mUnderline = $request->getInt( 'wpOpunderline' );
61 $this->mAction = $request->getVal( 'action' );
62 $this->mReset = $request->getCheck( 'wpReset' );
63 $this->mRestoreprefs = $request->getCheck( 'wpRestore' );
64 $this->mPosted = $request->wasPosted();
65 $this->mSuccess = $request->getCheck( 'success' );
66 $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
67 $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' );
68 $this->mDisableMWSuggest = $request->getCheck( 'wpDisableMWSuggest' );
69 $this->mGender = $request->getVal( 'wpGender' );
70
71 $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
72 $this->mPosted &&
73 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
74
75 # User toggles (the big ugly unsorted list of checkboxes)
76 $this->mToggles = array();
77 if ( $this->mPosted ) {
78 $togs = User::getToggles();
79 foreach ( $togs as $tname ) {
80 $this->mToggles[$tname] = $request->getCheck( "wpOp$tname" ) ? 1 : 0;
81 }
82 }
83
84 $this->mUsedToggles = array();
85
86 # Search namespace options
87 # Note: namespaces don't necessarily have consecutive keys
88 $this->mSearchNs = array();
89 if ( $this->mPosted ) {
90 $namespaces = $wgContLang->getNamespaces();
91 foreach ( $namespaces as $i => $namespace ) {
92 if ( $i >= 0 ) {
93 $this->mSearchNs[$i] = $request->getCheck( "wpNs$i" ) ? 1 : 0;
94 }
95 }
96 }
97
98 # Validate language
99 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
100 $this->mUserLanguage = 'nolanguage';
101 }
102
103 wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
104 }
105
106 function execute() {
107 global $wgUser, $wgOut, $wgTitle;
108
109 if ( $wgUser->isAnon() ) {
110 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array($wgTitle->getPrefixedDBkey()) );
111 return;
112 }
113 if ( wfReadOnly() ) {
114 $wgOut->readOnlyPage();
115 return;
116 }
117 if ( $this->mReset ) {
118 $this->resetPrefs();
119 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
120 } else if ( $this->mSaveprefs ) {
121 $this->savePreferences();
122 } else if ( $this->mRestoreprefs ) {
123 $this->restorePreferences();
124 } else {
125 $this->resetPrefs();
126 $this->mainPrefsForm( '' );
127 }
128 }
129 /**
130 * @access private
131 */
132 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
133 $val = intval($val);
134 $val = min($val, $max);
135 $val = max($val, $min);
136 return $val;
137 }
138
139 /**
140 * @access private
141 */
142 function validateFloat( &$val, $min, $max=0x7fffffff ) {
143 $val = floatval( $val );
144 $val = min( $val, $max );
145 $val = max( $val, $min );
146 return( $val );
147 }
148
149 /**
150 * @access private
151 */
152 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
153 $val = trim($val);
154 if($val === '') {
155 return null;
156 } else {
157 return $this->validateInt( $val, $min, $max );
158 }
159 }
160
161 /**
162 * @access private
163 */
164 function validateDate( $val ) {
165 global $wgLang, $wgContLang;
166 if ( $val !== false && (
167 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
168 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
169 {
170 return $val;
171 } else {
172 return $wgLang->getDefaultDateFormat();
173 }
174 }
175
176 /**
177 * Used to validate the user inputed timezone before saving it as
178 * 'timecorrection', will return 'System' if fed bogus data.
179 * @access private
180 * @param string $tz the user input Zoneinfo timezone
181 * @param string $s the user input offset string
182 * @return string
183 */
184 function validateTimeZone( $tz, $s ) {
185 $data = explode( '|', $tz, 3 );
186 switch ( $data[0] ) {
187 case 'ZoneInfo':
188 case 'System':
189 return $tz;
190 case 'Offset':
191 default:
192 $data = explode( ':', $s, 2 );
193 $minDiff = 0;
194 if( count( $data ) == 2 ) {
195 $data[0] = intval( $data[0] );
196 $data[1] = intval( $data[1] );
197 $minDiff = abs( $data[0] ) * 60 + $data[1];
198 if ( $data[0] < 0 ) $minDiff = -$minDiff;
199 } else {
200 $minDiff = intval( $data[0] ) * 60;
201 }
202
203 # Max is +14:00 and min is -12:00, see:
204 # http://en.wikipedia.org/wiki/Timezone
205 $minDiff = min( $minDiff, 840 ); # 14:00
206 $minDiff = max( $minDiff, -720 ); # -12:00
207 return 'Offset|'.$minDiff;
208 }
209 }
210
211 function validateGender( $val ) {
212 $valid = array( 'male', 'female', 'unknown' );
213 if ( in_array($val, $valid) ) {
214 return $val;
215 } else {
216 return User::getDefaultOption( 'gender' );
217 }
218 }
219
220 /**
221 * @access private
222 */
223 function savePreferences() {
224 global $wgUser, $wgOut, $wgParser;
225 global $wgEnableUserEmail, $wgEnableEmail;
226 global $wgEmailAuthentication, $wgRCMaxAge;
227 global $wgAuth, $wgEmailConfirmToEdit;
228
229 $wgUser->setRealName( $this->mRealName );
230 $oldOptions = $wgUser->mOptions;
231
232 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
233 $needRedirect = true;
234 } else {
235 $needRedirect = false;
236 }
237
238 # Validate the signature and clean it up as needed
239 global $wgMaxSigChars;
240 if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
241 global $wgLang;
242 $this->mainPrefsForm( 'error',
243 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) );
244 return;
245 } elseif( $this->mToggles['fancysig'] ) {
246 if( $wgParser->validateSig( $this->mNick ) !== false ) {
247 $this->mNick = $wgParser->cleanSig( $this->mNick );
248 } else {
249 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
250 return;
251 }
252 } else {
253 // When no fancy sig used, make sure ~{3,5} get removed.
254 $this->mNick = $wgParser->cleanSigInSig( $this->mNick );
255 }
256
257 $wgUser->setOption( 'language', $this->mUserLanguage );
258 $wgUser->setOption( 'variant', $this->mUserVariant );
259 $wgUser->setOption( 'nickname', $this->mNick );
260 $wgUser->setOption( 'quickbar', $this->mQuickbar );
261 global $wgAllowUserSkin;
262 if( $wgAllowUserSkin ) {
263 $wgUser->setOption( 'skin', $this->mSkin );
264 }
265 global $wgUseTeX;
266 if( $wgUseTeX ) {
267 $wgUser->setOption( 'math', $this->mMath );
268 }
269 $wgUser->setOption( 'date', $this->validateDate( $this->mDate ) );
270 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
271 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
272 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
273 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
274 $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays, 1, ceil($wgRCMaxAge / (3600*24))));
275 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits, 0, 1000 ) );
276 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
277 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
278 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
279 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mTimeZone, $this->mHourDiff ) );
280 $wgUser->setOption( 'imagesize', $this->mImageSize );
281 $wgUser->setOption( 'thumbsize', $this->mThumbSize );
282 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
283 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) );
284 $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest );
285 $wgUser->setOption( 'gender', $this->validateGender( $this->mGender ) );
286
287 # Set search namespace options
288 foreach( $this->mSearchNs as $i => $value ) {
289 $wgUser->setOption( "searchNs{$i}", $value );
290 }
291
292 if( $wgEnableEmail && $wgEnableUserEmail ) {
293 $wgUser->setOption( 'disablemail', $this->mEmailFlag );
294 }
295
296 # Set user toggles
297 foreach ( $this->mToggles as $tname => $tvalue ) {
298 $wgUser->setOption( $tname, $tvalue );
299 }
300
301 $error = false;
302 if( $wgEnableEmail ) {
303 $newadr = $this->mUserEmail;
304 $oldadr = $wgUser->getEmail();
305 if( ($newadr != '') && ($newadr != $oldadr) ) {
306 # the user has supplied a new email address on the login page
307 if( $wgUser->isValidEmailAddr( $newadr ) ) {
308 # new behaviour: set this new emailaddr from login-page into user database record
309 $wgUser->setEmail( $newadr );
310 # but flag as "dirty" = unauthenticated
311 $wgUser->invalidateEmail();
312 if ($wgEmailAuthentication) {
313 # Mail a temporary password to the dirty address.
314 # User can come back through the confirmation URL to re-enable email.
315 $result = $wgUser->sendConfirmationMail();
316 if( WikiError::isError( $result ) ) {
317 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
318 } else {
319 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
320 }
321 }
322 } else {
323 $error = wfMsg( 'invalidemailaddress' );
324 }
325 } else {
326 if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
327 $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
328 return;
329 }
330 $wgUser->setEmail( $this->mUserEmail );
331 }
332 if( $oldadr != $newadr ) {
333 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
334 }
335 }
336
337 if( !$wgAuth->updateExternalDB( $wgUser ) ){
338 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
339 return;
340 }
341
342 $msg = '';
343 if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg, $oldOptions ) ) ) {
344 $this->mainPrefsForm( 'error', $msg );
345 return;
346 }
347
348 $wgUser->setCookies();
349 $wgUser->saveSettings();
350
351 if( $needRedirect && $error === false ) {
352 $title = SpecialPage::getTitleFor( 'Preferences' );
353 $wgOut->redirect( $title->getFullURL( 'success' ) );
354 return;
355 }
356
357 $wgOut->parserOptions( ParserOptions::newFromUser( $wgUser ) );
358 $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
359 }
360
361 /**
362 * @access private
363 */
364 function resetPrefs() {
365 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName, $wgLocalTZoffset;
366
367 $this->mUserEmail = $wgUser->getEmail();
368 $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
369 $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
370
371 # language value might be blank, default to content language
372 $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode );
373
374 $this->mUserVariant = $wgUser->getOption( 'variant');
375 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
376 $this->mNick = $wgUser->getOption( 'nickname' );
377
378 $this->mQuickbar = $wgUser->getOption( 'quickbar' );
379 $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
380 $this->mMath = $wgUser->getOption( 'math' );
381 $this->mDate = $wgUser->getDatePreference();
382 $this->mRows = $wgUser->getOption( 'rows' );
383 $this->mCols = $wgUser->getOption( 'cols' );
384 $this->mStubs = $wgUser->getOption( 'stubthreshold' );
385
386 $tz = $wgUser->getOption( 'timecorrection' );
387 $data = explode( '|', $tz, 3 );
388 $minDiff = null;
389 switch ( $data[0] ) {
390 case 'ZoneInfo':
391 $this->mTimeZone = $tz;
392 # Check if the specified TZ exists, and change to 'Offset' if
393 # not.
394 if ( !function_exists('timezone_open') || @timezone_open( $data[2] ) === false ) {
395 $this->mTimeZone = 'Offset';
396 $minDiff = intval( $data[1] );
397 }
398 break;
399 case '':
400 case 'System':
401 $this->mTimeZone = 'System|'.$wgLocalTZoffset;
402 break;
403 case 'Offset':
404 $this->mTimeZone = 'Offset';
405 $minDiff = intval( $data[1] );
406 break;
407 default:
408 $this->mTimeZone = 'Offset';
409 $data = explode( ':', $tz, 2 );
410 if( count( $data ) == 2 ) {
411 $data[0] = intval( $data[0] );
412 $data[1] = intval( $data[1] );
413 $minDiff = abs( $data[0] ) * 60 + $data[1];
414 if ( $data[0] < 0 ) $minDiff = -$minDiff;
415 } else {
416 $minDiff = intval( $data[0] ) * 60;
417 }
418 break;
419 }
420 if ( is_null( $minDiff ) ) {
421 $this->mHourDiff = '';
422 } else {
423 $this->mHourDiff = sprintf( '%+03d:%02d', floor($minDiff/60), abs($minDiff)%60 );
424 }
425
426 $this->mSearch = $wgUser->getOption( 'searchlimit' );
427 $this->mSearchLines = $wgUser->getOption( 'contextlines' );
428 $this->mSearchChars = $wgUser->getOption( 'contextchars' );
429 $this->mImageSize = $wgUser->getOption( 'imagesize' );
430 $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
431 $this->mRecent = $wgUser->getOption( 'rclimit' );
432 $this->mRecentDays = $wgUser->getOption( 'rcdays' );
433 $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
434 $this->mUnderline = $wgUser->getOption( 'underline' );
435 $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
436 $this->mDisableMWSuggest = $wgUser->getBoolOption( 'disablesuggest' );
437 $this->mGender = $wgUser->getOption( 'gender' );
438
439 $togs = User::getToggles();
440 foreach ( $togs as $tname ) {
441 $this->mToggles[$tname] = $wgUser->getOption( $tname );
442 }
443
444 $namespaces = $wgContLang->getNamespaces();
445 foreach ( $namespaces as $i => $namespace ) {
446 if ( $i >= NS_MAIN ) {
447 $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
448 }
449 }
450
451 wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
452 }
453
454 /**
455 * @access private
456 */
457 function restorePreferences() {
458 global $wgUser, $wgOut;
459 $wgUser->restoreOptions();
460 $wgUser->setCookies();
461 $wgUser->saveSettings();
462 $title = SpecialPage::getTitleFor( 'Preferences' );
463 $wgOut->redirect( $title->getFullURL( 'success' ) );
464 }
465
466 /**
467 * @access private
468 */
469 function namespacesCheckboxes() {
470 global $wgContLang;
471
472 # Determine namespace checkboxes
473 $namespaces = $wgContLang->getNamespaces();
474 $r1 = null;
475
476 foreach ( $namespaces as $i => $name ) {
477 if ($i < 0)
478 continue;
479 $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
480 $name = str_replace( '_', ' ', $namespaces[$i] );
481
482 if ( empty($name) )
483 $name = wfMsg( 'blanknamespace' );
484
485 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
486 }
487 return $r1;
488 }
489
490
491 function getToggle( $tname, $trailer = false, $disabled = false ) {
492 global $wgUser, $wgLang;
493
494 $this->mUsedToggles[$tname] = true;
495 $ttext = $wgLang->getUserToggle( $tname );
496
497 $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
498 $disabled = $disabled ? ' disabled="disabled"' : '';
499 $trailer = $trailer ? $trailer : '';
500 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
501 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
502 }
503
504 function getToggles( $items ) {
505 $out = "";
506 foreach( $items as $item ) {
507 if( $item === false )
508 continue;
509 if( is_array( $item ) ) {
510 list( $key, $trailer ) = $item;
511 } else {
512 $key = $item;
513 $trailer = false;
514 }
515 $out .= $this->getToggle( $key, $trailer );
516 }
517 return $out;
518 }
519
520 function addRow($td1, $td2) {
521 return "<tr><td class='mw-label'>$td1</td><td class='mw-input'>$td2</td></tr>";
522 }
523
524 /**
525 * Helper function for user information panel
526 * @param $td1 label for an item
527 * @param $td2 item or null
528 * @param $td3 optional help or null
529 * @return xhtml block
530 */
531 function tableRow( $td1, $td2 = null, $td3 = null ) {
532
533 if ( is_null( $td3 ) ) {
534 $td3 = '';
535 } else {
536 $td3 = Xml::tags( 'tr', null,
537 Xml::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td3 )
538 );
539 }
540
541 if ( is_null( $td2 ) ) {
542 $td1 = Xml::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td1 );
543 $td2 = '';
544 } else {
545 $td1 = Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
546 $td2 = Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
547 }
548
549 return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
550
551 }
552
553 /**
554 * @access private
555 */
556 function mainPrefsForm( $status , $message = '' ) {
557 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgAuth;
558 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
559 global $wgDisableLangConversion, $wgDisableTitleConversion;
560 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
561 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
562 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
563 global $wgContLanguageCode, $wgDefaultSkin, $wgCookieExpiration;
564 global $wgEmailConfirmToEdit, $wgEnableMWSuggest, $wgLocalTZoffset;
565
566 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
567 $wgOut->setArticleRelated( false );
568 $wgOut->setRobotPolicy( 'noindex,nofollow' );
569 $wgOut->addScriptFile( 'prefs.js' );
570
571 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
572
573 if ( $this->mSuccess || 'success' == $status ) {
574 $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
575 } else if ( 'error' == $status ) {
576 $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
577 } else if ( '' != $status ) {
578 $wgOut->addWikiText( $message . "\n----" );
579 }
580
581 $qbs = $wgLang->getQuickbarSettings();
582 $mathopts = $wgLang->getMathNames();
583 $dateopts = $wgLang->getDatePreferences();
584 $togs = User::getToggles();
585
586 $titleObj = SpecialPage::getTitleFor( 'Preferences' );
587
588 # Pre-expire some toggles so they won't show if disabled
589 $this->mUsedToggles[ 'shownumberswatching' ] = true;
590 $this->mUsedToggles[ 'showupdated' ] = true;
591 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
592 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
593 $this->mUsedToggles[ 'enotifminoredits' ] = true;
594 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
595 $this->mUsedToggles[ 'ccmeonemails' ] = true;
596 $this->mUsedToggles[ 'uselivepreview' ] = true;
597 $this->mUsedToggles[ 'noconvertlink' ] = true;
598
599
600 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
601 else { $emfc = ''; }
602
603
604 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
605 if( $wgUser->getEmailAuthenticationTimestamp() ) {
606 // date and time are separate parameters to facilitate localisation.
607 // $time is kept for backward compat reasons.
608 // 'emailauthenticated' is also used in SpecialConfirmemail.php
609 $time = $wgLang->timeAndDate( $wgUser->getEmailAuthenticationTimestamp(), true );
610 $d = $wgLang->date( $wgUser->getEmailAuthenticationTimestamp(), true );
611 $t = $wgLang->time( $wgUser->getEmailAuthenticationTimestamp(), true );
612 $emailauthenticated = wfMsg('emailauthenticated', $time, $d, $t ).'<br />';
613 $disableEmailPrefs = false;
614 } else {
615 $disableEmailPrefs = true;
616 $skin = $wgUser->getSkin();
617 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
618 $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
619 wfMsg( 'emailconfirmlink' ) ) . '<br />';
620 }
621 } else {
622 $emailauthenticated = '';
623 $disableEmailPrefs = false;
624 }
625
626 if ($this->mUserEmail == '') {
627 $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
628 }
629
630 $ps = $this->namespacesCheckboxes();
631
632 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
633 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
634 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
635 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
636
637 # </FIXME>
638
639 $wgOut->addHTML(
640 Xml::openElement( 'form', array(
641 'action' => $titleObj->getLocalUrl(),
642 'method' => 'post',
643 'id' => 'mw-preferences-form',
644 ) ) .
645 Xml::openElement( 'div', array( 'id' => 'preferences' ) )
646 );
647
648 # User data
649
650 $wgOut->addHTML(
651 Xml::fieldset( wfMsg('prefs-personal') ) .
652 Xml::openElement( 'table' ) .
653 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
654 );
655
656 # Get groups to which the user belongs
657 $userEffectiveGroups = $wgUser->getEffectiveGroups();
658 $userEffectiveGroupsArray = array();
659 foreach( $userEffectiveGroups as $ueg ) {
660 if( $ueg == '*' ) {
661 // Skip the default * group, seems useless here
662 continue;
663 }
664 $userEffectiveGroupsArray[] = User::makeGroupLinkHTML( $ueg );
665 }
666 asort( $userEffectiveGroupsArray );
667
668 $sk = $wgUser->getSkin();
669 $toolLinks = array();
670 $toolLinks[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'ListGroupRights' ), wfMsg( 'listgrouprights' ) );
671 # At the moment one tool link only but be prepared for the future...
672 # FIXME: Add a link to Special:Userrights for users who are allowed to use it.
673 # $wgUser->isAllowed( 'userrights' ) seems to strict in some cases
674
675 $userInformationHtml =
676 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
677 $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getId() ) ) .
678
679 $this->tableRow(
680 wfMsgExt( 'prefs-memberingroups', array( 'parseinline' ), count( $userEffectiveGroupsArray ) ),
681 $wgLang->commaList( $userEffectiveGroupsArray ) .
682 '<br />(' . implode( ' | ', $toolLinks ) . ')'
683 ) .
684
685 $this->tableRow(
686 wfMsgHtml( 'prefs-edits' ),
687 $wgLang->formatNum( $wgUser->getEditCount() )
688 );
689
690 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
691 $wgOut->addHTML( $userInformationHtml );
692 }
693
694 if ( $wgAllowRealName ) {
695 $wgOut->addHTML(
696 $this->tableRow(
697 Xml::label( wfMsg('yourrealname'), 'wpRealName' ),
698 Xml::input( 'wpRealName', 25, $this->mRealName, array( 'id' => 'wpRealName' ) ),
699 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
700 wfMsgExt( 'prefs-help-realname', 'parseinline' )
701 )
702 )
703 );
704 }
705 if ( $wgEnableEmail ) {
706 $wgOut->addHTML(
707 $this->tableRow(
708 Xml::label( wfMsg('youremail'), 'wpUserEmail' ),
709 Xml::input( 'wpUserEmail', 25, $this->mUserEmail, array( 'id' => 'wpUserEmail' ) ),
710 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
711 wfMsgExt( $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
712 )
713 )
714 );
715 }
716
717 global $wgParser, $wgMaxSigChars;
718 if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
719 $invalidSig = $this->tableRow(
720 '&nbsp;',
721 Xml::element( 'span', array( 'class' => 'error' ),
722 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) )
723 );
724 } elseif( !empty( $this->mToggles['fancysig'] ) &&
725 false === $wgParser->validateSig( $this->mNick ) ) {
726 $invalidSig = $this->tableRow(
727 '&nbsp;',
728 Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
729 );
730 } else {
731 $invalidSig = '';
732 }
733
734 $wgOut->addHTML(
735 $this->tableRow(
736 Xml::label( wfMsg( 'yournick' ), 'wpNick' ),
737 Xml::input( 'wpNick', 25, $this->mNick,
738 array(
739 'id' => 'wpNick',
740 // Note: $wgMaxSigChars is enforced in Unicode characters,
741 // both on the backend and now in the browser.
742 // Badly-behaved requests may still try to submit
743 // an overlong string, however.
744 'maxlength' => $wgMaxSigChars ) )
745 ) .
746 $invalidSig .
747 $this->tableRow( '&nbsp;', $this->getToggle( 'fancysig' ) )
748 );
749
750 $gender = new XMLSelect( 'wpGender', 'wpGender', $this->mGender );
751 $gender->addOption( wfMsg( 'gender-unknown' ), 'unknown' );
752 $gender->addOption( wfMsg( 'gender-male' ), 'male' );
753 $gender->addOption( wfMsg( 'gender-female' ), 'female' );
754
755 $wgOut->addHTML(
756 $this->tableRow(
757 Xml::label( wfMsg( 'yourgender' ), 'wpGender' ),
758 $gender->getHTML()
759 )
760 );
761
762 list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage, false );
763 $wgOut->addHTML(
764 $this->tableRow( $lsLabel, $lsSelect )
765 );
766
767 /* see if there are multiple language variants to choose from*/
768 if(!$wgDisableLangConversion) {
769 $variants = $wgContLang->getVariants();
770 $variantArray = array();
771
772 $languages = Language::getLanguageNames( true );
773 foreach($variants as $v) {
774 $v = str_replace( '_', '-', strtolower($v));
775 if( array_key_exists( $v, $languages ) ) {
776 // If it doesn't have a name, we'll pretend it doesn't exist
777 $variantArray[$v] = $languages[$v];
778 }
779 }
780
781 $options = "\n";
782 foreach( $variantArray as $code => $name ) {
783 $selected = ($code == $this->mUserVariant);
784 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
785 }
786
787 if(count($variantArray) > 1) {
788 $wgOut->addHTML(
789 $this->tableRow(
790 Xml::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
791 Xml::tags( 'select',
792 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
793 $options
794 )
795 )
796 );
797 }
798
799 if(count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) {
800 $wgOut->addHTML(
801 Xml::tags( 'tr', null,
802 Xml::tags( 'td', array( 'colspan' => '2' ),
803 $this->getToggle( "noconvertlink" )
804 )
805 )
806 );
807 }
808 }
809
810 # Password
811 if( $wgAuth->allowPasswordChange() ) {
812 $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ResetPass' ), wfMsgHtml( 'prefs-resetpass' ),
813 array() , array('returnto' => SpecialPage::getTitleFor( 'Preferences') ) );
814 $wgOut->addHTML(
815 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
816 $this->tableRow( '<ul><li>' . $link . '</li></ul>' ) );
817 }
818
819 # <FIXME>
820 # Enotif
821 if ( $wgEnableEmail ) {
822
823 $moreEmail = '';
824 if ($wgEnableUserEmail) {
825 // fixme -- the "allowemail" pseudotoggle is a hacked-together
826 // inversion for the "disableemail" preference.
827 $emf = wfMsg( 'allowemail' );
828 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
829 $moreEmail =
830 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>" .
831 $this->getToggle( 'ccmeonemails', '', $disableEmailPrefs );
832 }
833
834
835 $wgOut->addHTML(
836 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'email' ) ) ) .
837 $this->tableRow(
838 $emailauthenticated.
839 $enotifrevealaddr.
840 $enotifwatchlistpages.
841 $enotifusertalkpages.
842 $enotifminoredits.
843 $moreEmail
844 )
845 );
846 }
847 # </FIXME>
848
849 $wgOut->addHTML(
850 Xml::closeElement( 'table' ) .
851 Xml::closeElement( 'fieldset' )
852 );
853
854
855 # Quickbar
856 #
857 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
858 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
859 for ( $i = 0; $i < count( $qbs ); ++$i ) {
860 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
861 else { $checked = ""; }
862 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
863 }
864 $wgOut->addHTML( "</fieldset>\n\n" );
865 } else {
866 # Need to output a hidden option even if the relevant skin is not in use,
867 # otherwise the preference will get reset to 0 on submit
868 $wgOut->addHTML( Xml::hidden( 'wpQuickbar', $this->mQuickbar ) );
869 }
870
871 # Skin
872 #
873 global $wgAllowUserSkin;
874 if( $wgAllowUserSkin ) {
875 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg( 'skin' ) . "</legend>\n" );
876 $mptitle = Title::newMainPage();
877 $previewtext = wfMsg( 'skin-preview' );
878 # Only show members of Skin::getSkinNames() rather than
879 # $skinNames (skins is all skin names from Language.php)
880 $validSkinNames = Skin::getUsableSkins();
881 # Sort by UI skin name. First though need to update validSkinNames as sometimes
882 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
883 foreach ( $validSkinNames as $skinkey => &$skinname ) {
884 $msgName = "skinname-{$skinkey}";
885 $localisedSkinName = wfMsg( $msgName );
886 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
887 $skinname = $localisedSkinName;
888 }
889 }
890 asort($validSkinNames);
891 foreach( $validSkinNames as $skinkey => $sn ) {
892 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
893 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
894 $previewlink = "(<a target='_blank' href=\"$mplink\">$previewtext</a>)";
895 $extraLinks = '';
896 global $wgAllowUserCss, $wgAllowUserJs;
897 if( $wgAllowUserCss ) {
898 $cssPage = Title::makeTitleSafe( NS_USER, $wgUser->getName().'/'.$skinkey.'.css' );
899 $customCSS = $sk->makeLinkObj( $cssPage, wfMsgExt('prefs-custom-css', array() ) );
900 $extraLinks .= " ($customCSS)";
901 }
902 if( $wgAllowUserJs ) {
903 $jsPage = Title::makeTitleSafe( NS_USER, $wgUser->getName().'/'.$skinkey.'.js' );
904 $customJS = $sk->makeLinkObj( $jsPage, wfMsgHtml('prefs-custom-js') );
905 $extraLinks .= " ($customJS)";
906 }
907 if( $skinkey == $wgDefaultSkin )
908 $sn .= ' (' . wfMsg( 'default' ) . ')';
909 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked />
910 <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink{$extraLinks}<br />\n" );
911 }
912 $wgOut->addHTML( "</fieldset>\n\n" );
913 }
914
915 # Math
916 #
917 global $wgUseTeX;
918 if( $wgUseTeX ) {
919 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
920 foreach ( $mathopts as $k => $v ) {
921 $checked = ($k == $this->mMath);
922 $wgOut->addHTML(
923 Xml::openElement( 'div' ) .
924 Xml::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
925 Xml::closeElement( 'div' ) . "\n"
926 );
927 }
928 $wgOut->addHTML( "</fieldset>\n\n" );
929 }
930
931 # Files
932 #
933 $imageLimitOptions = null;
934 foreach ( $wgImageLimits as $index => $limits ) {
935 $selected = ($index == $this->mImageSize);
936 $imageLimitOptions .= Xml::option( "{$limits[0]}×{$limits[1]}" .
937 wfMsg('unit-pixel'), $index, $selected );
938 }
939
940 $imageThumbOptions = null;
941 foreach ( $wgThumbLimits as $index => $size ) {
942 $selected = ($index == $this->mThumbSize);
943 $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
944 $selected);
945 }
946
947 $imageSizeId = 'wpImageSize';
948 $thumbSizeId = 'wpThumbSize';
949 $wgOut->addHTML(
950 Xml::fieldset( wfMsg( 'files' ) ) . "\n" .
951 Xml::openElement( 'table' ) .
952 '<tr>
953 <td class="mw-label">' .
954 Xml::label( wfMsg( 'imagemaxsize' ), $imageSizeId ) .
955 '</td>
956 <td class="mw-input">' .
957 Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
958 $imageLimitOptions .
959 Xml::closeElement( 'select' ) .
960 '</td>
961 </tr><tr>
962 <td class="mw-label">' .
963 Xml::label( wfMsg( 'thumbsize' ), $thumbSizeId ) .
964 '</td>
965 <td class="mw-input">' .
966 Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
967 $imageThumbOptions .
968 Xml::closeElement( 'select' ) .
969 '</td>
970 </tr>' .
971 Xml::closeElement( 'table' ) .
972 Xml::closeElement( 'fieldset' )
973 );
974
975 # Date format
976 #
977 # Date/Time
978 #
979
980 $wgOut->addHTML(
981 Xml::openElement( 'fieldset' ) .
982 Xml::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
983 );
984
985 if ($dateopts) {
986 $wgOut->addHTML(
987 Xml::openElement( 'fieldset' ) .
988 Xml::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
989 );
990 $idCnt = 0;
991 $epoch = '20010115161234'; # Wikipedia day
992 foreach( $dateopts as $key ) {
993 if( $key == 'default' ) {
994 $formatted = wfMsg( 'datedefault' );
995 } else {
996 $formatted = $wgLang->timeanddate( $epoch, false, $key );
997 }
998 $wgOut->addHTML(
999 Xml::tags( 'div', null,
1000 Xml::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate )
1001 ) . "\n"
1002 );
1003 $idCnt++;
1004 }
1005 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) . "\n" );
1006 }
1007
1008 $nowlocal = Xml::openElement( 'span', array( 'id' => 'wpLocalTime' ) ) .
1009 $wgLang->time( $now = wfTimestampNow(), true ) .
1010 Xml::closeElement( 'span' );
1011 $nowserver = $wgLang->time( $now, false ) .
1012 Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
1013
1014 $wgOut->addHTML(
1015 Xml::openElement( 'fieldset' ) .
1016 Xml::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
1017 Xml::openElement( 'table' ) .
1018 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
1019 $this->addRow( wfMsg( 'localtime' ), $nowlocal )
1020 );
1021 $opt = Xml::openElement( 'select', array(
1022 'name' => 'wpTimeZone',
1023 'id' => 'wpTimeZone',
1024 'onchange' => 'javascript:updateTimezoneSelection(false)' ) );
1025 $opt .= Xml::option( wfMsg( 'timezoneuseserverdefault' ), "System|$wgLocalTZoffset", $this->mTimeZone === "System|$wgLocalTZoffset" );
1026 $opt .= Xml::option( wfMsg( 'timezoneuseoffset' ), 'Offset', $this->mTimeZone === 'Offset' );
1027 if ( function_exists( 'timezone_identifiers_list' ) ) {
1028 $optgroup = '';
1029 $tzs = timezone_identifiers_list();
1030 sort( $tzs );
1031 $selZone = explode( '|', $this->mTimeZone, 3);
1032 $selZone = ( $selZone[0] == 'ZoneInfo' ) ? $selZone[2] : null;
1033 $now = date_create( 'now' );
1034 foreach ( $tzs as $tz ) {
1035 $z = explode( '/', $tz, 2 );
1036 # timezone_identifiers_list() returns a number of
1037 # backwards-compatibility entries. This filters them out of the
1038 # list presented to the user.
1039 if ( count( $z ) != 2 || !in_array( $z[0], array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' ) ) ) continue;
1040 if ( $optgroup != $z[0] ) {
1041 if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
1042 $optgroup = $z[0];
1043 $opt .= Xml::openElement( 'optgroup', array( 'label' => $z[0] ) );
1044 }
1045 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1046 $opt .= Xml::option( str_replace( '_', ' ', $tz ), "ZoneInfo|$minDiff|$tz", $selZone === $tz, array( 'label' => $z[1] ) );
1047 }
1048 if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
1049 }
1050 $opt .= Xml::closeElement( 'select' );
1051 $wgOut->addHTML(
1052 $this->addRow(
1053 Xml::label( wfMsg( 'timezoneselect' ), 'wpTimeZone' ),
1054 $opt )
1055 );
1056 $wgOut->addHTML(
1057 $this->addRow(
1058 Xml::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff' ),
1059 Xml::input( 'wpHourDiff', 6, $this->mHourDiff, array(
1060 'id' => 'wpHourDiff',
1061 'onfocus' => 'javascript:updateTimezoneSelection(true)',
1062 'onblur' => 'javascript:updateTimezoneSelection(false)' ) ) ) .
1063 "<tr>
1064 <td></td>
1065 <td class='mw-submit'>" .
1066 Xml::element( 'input',
1067 array( 'type' => 'button',
1068 'value' => wfMsg( 'guesstimezone' ),
1069 'onclick' => 'javascript:guessTimezone()',
1070 'id' => 'guesstimezonebutton',
1071 'style' => 'display:none;' ) ) .
1072 "</td>
1073 </tr>" .
1074 Xml::closeElement( 'table' ) .
1075 Xml::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
1076 Xml::closeElement( 'fieldset' ) .
1077 Xml::closeElement( 'fieldset' ) . "\n\n"
1078 );
1079
1080 # Editing
1081 #
1082 global $wgLivePreview;
1083 $wgOut->addHTML(
1084 Xml::fieldset( wfMsg( 'textboxsize' ) ) .
1085 wfMsgHTML( 'prefs-edit-boxsize' ) . ' ' .
1086 Xml::inputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) . ' ' .
1087 Xml::inputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
1088 $this->getToggles( array(
1089 'editsection',
1090 'editsectiononrightclick',
1091 'editondblclick',
1092 'editwidth',
1093 'showtoolbar',
1094 'previewonfirst',
1095 'previewontop',
1096 'minordefault',
1097 'externaleditor',
1098 'externaldiff',
1099 $wgLivePreview ? 'uselivepreview' : false,
1100 'forceeditsummary',
1101 ) )
1102 );
1103
1104 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
1105
1106 # Recent changes
1107 global $wgRCMaxAge, $wgUseRCPatrol;
1108 $wgOut->addHTML(
1109 Xml::fieldset( wfMsg( 'prefs-rc' ) ) .
1110 Xml::openElement( 'table' ) .
1111 '<tr>
1112 <td class="mw-label">' .
1113 Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) .
1114 '</td>
1115 <td class="mw-input">' .
1116 Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . ' ' .
1117 wfMsgExt( 'recentchangesdays-max', 'parsemag',
1118 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) ) .
1119 '</td>
1120 </tr><tr>
1121 <td class="mw-label">' .
1122 Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) .
1123 '</td>
1124 <td class="mw-input">' .
1125 Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) .
1126 '</td>
1127 </tr>' .
1128 Xml::closeElement( 'table' ) .
1129 '<br />'
1130 );
1131
1132 $toggles[] = 'hideminor';
1133 if( $wgUseRCPatrol ) {
1134 $toggles[] = 'hidepatrolled';
1135 $toggles[] = 'newpageshidepatrolled';
1136 }
1137 if( $wgRCShowWatchingUsers ) $toggles[] = 'shownumberswatching';
1138 $toggles[] = 'usenewrc';
1139
1140 $wgOut->addHTML(
1141 $this->getToggles( $toggles ) .
1142 Xml::closeElement( 'fieldset' )
1143 );
1144
1145 # Watchlist
1146 $watchlistToggles = array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown',
1147 'watchlisthideanons', 'watchlisthideliu' );
1148 if( $wgUseRCPatrol ) $watchlistToggles[] = 'watchlisthidepatrolled';
1149
1150 $wgOut->addHTML(
1151 Xml::fieldset( wfMsg( 'prefs-watchlist' ) ) .
1152 Xml::inputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) . ' ' .
1153 wfMsgHTML( 'prefs-watchlist-days-max' ) .
1154 '<br /><br />' .
1155 $this->getToggle( 'extendwatchlist' ) .
1156 Xml::inputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) . ' ' .
1157 wfMsgHTML( 'prefs-watchlist-edits-max' ) .
1158 '<br /><br />' .
1159 $this->getToggles( $watchlistToggles )
1160 );
1161
1162 if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) ) {
1163 $wgOut->addHTML( $this->getToggle( 'watchcreations' ) );
1164 }
1165
1166 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
1167 if( $wgUser->isAllowed( $action ) )
1168 $wgOut->addHTML( $this->getToggle( $toggle ) );
1169 }
1170 $this->mUsedToggles['watchcreations'] = true;
1171 $this->mUsedToggles['watchdefault'] = true;
1172 $this->mUsedToggles['watchmoves'] = true;
1173 $this->mUsedToggles['watchdeletion'] = true;
1174
1175 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
1176
1177 # Search
1178 $mwsuggest = $wgEnableMWSuggest ?
1179 $this->addRow(
1180 Xml::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
1181 Xml::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest, array( 'id' => 'wpDisableMWSuggest' ) )
1182 ) : '';
1183 $wgOut->addHTML(
1184 // Elements for the search tab itself
1185 Xml::openElement( 'fieldset' ) .
1186 Xml::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
1187 // Elements for the search options in the search tab
1188 Xml::openElement( 'fieldset' ) .
1189 Xml::element( 'legend', null, wfMsg( 'prefs-searchoptions' ) ) .
1190 Xml::openElement( 'table' ) .
1191 $this->addRow(
1192 Xml::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
1193 Xml::input( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
1194 ) .
1195 $this->addRow(
1196 Xml::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
1197 Xml::input( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
1198 ) .
1199 $this->addRow(
1200 Xml::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
1201 Xml::input( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
1202 ) .
1203 $mwsuggest .
1204 Xml::closeElement( 'table' ) .
1205 Xml::closeElement( 'fieldset' ) .
1206 // Elements for the namespace options in the search tab
1207 Xml::openElement( 'fieldset' ) .
1208 Xml::element( 'legend', null, wfMsg( 'prefs-namespaces' ) ) .
1209 wfMsgExt( 'defaultns', array( 'parse' ) ) .
1210 $ps .
1211 Xml::closeElement( 'fieldset' ) .
1212 // End of the search tab
1213 Xml::closeElement( 'fieldset' )
1214 );
1215
1216 # Misc
1217 #
1218 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
1219 $wgOut->addHTML( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label>&nbsp;' );
1220 $wgOut->addHTML( Xml::input( 'wpStubs', 6, $this->mStubs, array( 'id' => 'wpStubs' ) ) );
1221 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1222 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1223 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1224 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1225 $uopt = $wgUser->getOption("underline");
1226 $s0 = $uopt == 0 ? ' selected="selected"' : '';
1227 $s1 = $uopt == 1 ? ' selected="selected"' : '';
1228 $s2 = $uopt == 2 ? ' selected="selected"' : '';
1229 $wgOut->addHTML("
1230 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1231 <select name='wpOpunderline' id='wpOpunderline'>
1232 <option value=\"0\"$s0>$msgUnderlinenever</option>
1233 <option value=\"1\"$s1>$msgUnderlinealways</option>
1234 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1235 </select></p></div>");
1236
1237 foreach ( $togs as $tname ) {
1238 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
1239 if( $tname == 'norollbackdiff' && $wgUser->isAllowed( 'rollback' ) )
1240 $wgOut->addHTML( $this->getToggle( $tname ) );
1241 else
1242 $wgOut->addHTML( $this->getToggle( $tname ) );
1243 }
1244 }
1245
1246 $wgOut->addHTML( '</fieldset>' );
1247
1248 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1249
1250 $token = htmlspecialchars( $wgUser->editToken() );
1251 $skin = $wgUser->getSkin();
1252 $rtl = $wgContLang->isRTL() ? 'left' : 'right';
1253 $wgOut->addHTML( "
1254 <table id='prefsubmit' cellpadding='0' width='100%' style='background:none;'><tr>
1255 <td><input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) .
1256 '"'.$skin->tooltipAndAccesskey('save')." />
1257 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" /></td>
1258 <td align='$rtl'><input type='submit' name='wpRestore' value=\"" . wfMsgHtml( 'restoreprefs' ) . "\" /></td>
1259 </tr></table>
1260
1261 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1262 </div></form>\n" );
1263
1264 $wgOut->addHTML( Xml::tags( 'div', array( 'class' => "prefcache" ),
1265 wfMsgExt( 'clearyourcache', 'parseinline' ) )
1266 );
1267 }
1268 }