* (bug 13040) Gender switch in user preferences
[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' ), $wgLang->formatNum( 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 if( $skinkey == $this->mSkin ) {
897 $cssPage = Title::makeTitleSafe( NS_USER, $wgUser->getName().'/'.$skinkey.'.css' );
898 $jsPage = Title::makeTitleSafe( NS_USER, $wgUser->getName().'/'.$skinkey.'.js' );
899 $customCSS = $sk->makeLinkObj( $cssPage, wfMsgExt('prefs-custom-css', array() ) );
900 $customJS = $sk->makeLinkObj( $jsPage, wfMsgHtml('prefs-custom-js') );
901 $extraLinks = " ($customCSS) ($customJS)";
902 }
903 if( $skinkey == $wgDefaultSkin )
904 $sn .= ' (' . wfMsg( 'default' ) . ')';
905 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked />
906 <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink{$extraLinks}<br />\n" );
907 }
908 $wgOut->addHTML( "</fieldset>\n\n" );
909 }
910
911 # Math
912 #
913 global $wgUseTeX;
914 if( $wgUseTeX ) {
915 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
916 foreach ( $mathopts as $k => $v ) {
917 $checked = ($k == $this->mMath);
918 $wgOut->addHTML(
919 Xml::openElement( 'div' ) .
920 Xml::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
921 Xml::closeElement( 'div' ) . "\n"
922 );
923 }
924 $wgOut->addHTML( "</fieldset>\n\n" );
925 }
926
927 # Files
928 #
929 $imageLimitOptions = null;
930 foreach ( $wgImageLimits as $index => $limits ) {
931 $selected = ($index == $this->mImageSize);
932 $imageLimitOptions .= Xml::option( "{$limits[0]}×{$limits[1]}" .
933 wfMsg('unit-pixel'), $index, $selected );
934 }
935
936 $imageThumbOptions = null;
937 foreach ( $wgThumbLimits as $index => $size ) {
938 $selected = ($index == $this->mThumbSize);
939 $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
940 $selected);
941 }
942
943 $imageSizeId = 'wpImageSize';
944 $thumbSizeId = 'wpThumbSize';
945 $wgOut->addHTML(
946 Xml::fieldset( wfMsg( 'files' ) ) . "\n" .
947 Xml::openElement( 'table' ) .
948 '<tr>
949 <td class="mw-label">' .
950 Xml::label( wfMsg( 'imagemaxsize' ), $imageSizeId ) .
951 '</td>
952 <td class="mw-input">' .
953 Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
954 $imageLimitOptions .
955 Xml::closeElement( 'select' ) .
956 '</td>
957 </tr><tr>
958 <td class="mw-label">' .
959 Xml::label( wfMsg( 'thumbsize' ), $thumbSizeId ) .
960 '</td>
961 <td class="mw-input">' .
962 Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
963 $imageThumbOptions .
964 Xml::closeElement( 'select' ) .
965 '</td>
966 </tr>' .
967 Xml::closeElement( 'table' ) .
968 Xml::closeElement( 'fieldset' )
969 );
970
971 # Date format
972 #
973 # Date/Time
974 #
975
976 $wgOut->addHTML(
977 Xml::openElement( 'fieldset' ) .
978 Xml::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
979 );
980
981 if ($dateopts) {
982 $wgOut->addHTML(
983 Xml::openElement( 'fieldset' ) .
984 Xml::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
985 );
986 $idCnt = 0;
987 $epoch = '20010115161234'; # Wikipedia day
988 foreach( $dateopts as $key ) {
989 if( $key == 'default' ) {
990 $formatted = wfMsg( 'datedefault' );
991 } else {
992 $formatted = $wgLang->timeanddate( $epoch, false, $key );
993 }
994 $wgOut->addHTML(
995 Xml::tags( 'div', null,
996 Xml::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate )
997 ) . "\n"
998 );
999 $idCnt++;
1000 }
1001 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) . "\n" );
1002 }
1003
1004 $nowlocal = Xml::openElement( 'span', array( 'id' => 'wpLocalTime' ) ) .
1005 $wgLang->time( $now = wfTimestampNow(), true ) .
1006 Xml::closeElement( 'span' );
1007 $nowserver = $wgLang->time( $now, false ) .
1008 Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
1009
1010 $wgOut->addHTML(
1011 Xml::openElement( 'fieldset' ) .
1012 Xml::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
1013 Xml::openElement( 'table' ) .
1014 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
1015 $this->addRow( wfMsg( 'localtime' ), $nowlocal )
1016 );
1017 $opt = Xml::openElement( 'select', array(
1018 'name' => 'wpTimeZone',
1019 'id' => 'wpTimeZone',
1020 'onchange' => 'javascript:updateTimezoneSelection(false)' ) );
1021 $opt .= Xml::option( wfMsg( 'timezoneuseserverdefault' ), "System|$wgLocalTZoffset", $this->mTimeZone === "System|$wgLocalTZoffset" );
1022 $opt .= Xml::option( wfMsg( 'timezoneuseoffset' ), 'Offset', $this->mTimeZone === 'Offset' );
1023 if ( function_exists( 'timezone_identifiers_list' ) ) {
1024 $optgroup = '';
1025 $tzs = timezone_identifiers_list();
1026 sort( $tzs );
1027 $selZone = explode( '|', $this->mTimeZone, 3);
1028 $selZone = ( $selZone[0] == 'ZoneInfo' ) ? $selZone[2] : null;
1029 $now = date_create( 'now' );
1030 foreach ( $tzs as $tz ) {
1031 $z = explode( '/', $tz, 2 );
1032 # timezone_identifiers_list() returns a number of
1033 # backwards-compatibility entries. This filters them out of the
1034 # list presented to the user.
1035 if ( count( $z ) != 2 || !in_array( $z[0], array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' ) ) ) continue;
1036 if ( $optgroup != $z[0] ) {
1037 if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
1038 $optgroup = $z[0];
1039 $opt .= Xml::openElement( 'optgroup', array( 'label' => $z[0] ) );
1040 }
1041 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1042 $opt .= Xml::option( str_replace( '_', ' ', $tz ), "ZoneInfo|$minDiff|$tz", $selZone === $tz, array( 'label' => $z[1] ) );
1043 }
1044 if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
1045 }
1046 $opt .= Xml::closeElement( 'select' );
1047 $wgOut->addHTML(
1048 $this->addRow(
1049 Xml::label( wfMsg( 'timezoneselect' ), 'wpTimeZone' ),
1050 $opt )
1051 );
1052 $wgOut->addHTML(
1053 $this->addRow(
1054 Xml::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff' ),
1055 Xml::input( 'wpHourDiff', 6, $this->mHourDiff, array(
1056 'id' => 'wpHourDiff',
1057 'onfocus' => 'javascript:updateTimezoneSelection(true)',
1058 'onblur' => 'javascript:updateTimezoneSelection(false)' ) ) ) .
1059 "<tr>
1060 <td></td>
1061 <td class='mw-submit'>" .
1062 Xml::element( 'input',
1063 array( 'type' => 'button',
1064 'value' => wfMsg( 'guesstimezone' ),
1065 'onclick' => 'javascript:guessTimezone()',
1066 'id' => 'guesstimezonebutton',
1067 'style' => 'display:none;' ) ) .
1068 "</td>
1069 </tr>" .
1070 Xml::closeElement( 'table' ) .
1071 Xml::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
1072 Xml::closeElement( 'fieldset' ) .
1073 Xml::closeElement( 'fieldset' ) . "\n\n"
1074 );
1075
1076 # Editing
1077 #
1078 global $wgLivePreview;
1079 $wgOut->addHTML(
1080 Xml::fieldset( wfMsg( 'textboxsize' ) ) .
1081 wfMsgHTML( 'prefs-edit-boxsize' ) . ' ' .
1082 Xml::inputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) . ' ' .
1083 Xml::inputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
1084 $this->getToggles( array(
1085 'editsection',
1086 'editsectiononrightclick',
1087 'editondblclick',
1088 'editwidth',
1089 'showtoolbar',
1090 'previewonfirst',
1091 'previewontop',
1092 'minordefault',
1093 'externaleditor',
1094 'externaldiff',
1095 $wgLivePreview ? 'uselivepreview' : false,
1096 'forceeditsummary',
1097 ) )
1098 );
1099
1100 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
1101
1102 # Recent changes
1103 global $wgRCMaxAge, $wgUseRCPatrol;
1104 $wgOut->addHTML(
1105 Xml::fieldset( wfMsg( 'prefs-rc' ) ) .
1106 Xml::openElement( 'table' ) .
1107 '<tr>
1108 <td class="mw-label">' .
1109 Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) .
1110 '</td>
1111 <td class="mw-input">' .
1112 Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . ' ' .
1113 wfMsgExt( 'recentchangesdays-max', 'parsemag',
1114 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) ) .
1115 '</td>
1116 </tr><tr>
1117 <td class="mw-label">' .
1118 Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) .
1119 '</td>
1120 <td class="mw-input">' .
1121 Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) .
1122 '</td>
1123 </tr>' .
1124 Xml::closeElement( 'table' ) .
1125 '<br />'
1126 );
1127
1128 $toggles[] = 'hideminor';
1129 if( $wgUseRCPatrol ) {
1130 $toggles[] = 'hidepatrolled';
1131 $toggles[] = 'newpageshidepatrolled';
1132 }
1133 if( $wgRCShowWatchingUsers ) $toggles[] = 'shownumberswatching';
1134 $toggles[] = 'usenewrc';
1135
1136 $wgOut->addHTML(
1137 $this->getToggles( $toggles ) .
1138 Xml::closeElement( 'fieldset' )
1139 );
1140
1141 # Watchlist
1142 $watchlistToggles = array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown',
1143 'watchlisthideanons', 'watchlisthideliu' );
1144 if( $wgUseRCPatrol ) $watchlistToggles[] = 'watchlisthidepatrolled';
1145
1146 $wgOut->addHTML(
1147 Xml::fieldset( wfMsg( 'prefs-watchlist' ) ) .
1148 Xml::inputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) . ' ' .
1149 wfMsgHTML( 'prefs-watchlist-days-max' ) .
1150 '<br /><br />' .
1151 $this->getToggle( 'extendwatchlist' ) .
1152 Xml::inputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) . ' ' .
1153 wfMsgHTML( 'prefs-watchlist-edits-max' ) .
1154 '<br /><br />' .
1155 $this->getToggles( $watchlistToggles )
1156 );
1157
1158 if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) ) {
1159 $wgOut->addHTML( $this->getToggle( 'watchcreations' ) );
1160 }
1161
1162 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
1163 if( $wgUser->isAllowed( $action ) )
1164 $wgOut->addHTML( $this->getToggle( $toggle ) );
1165 }
1166 $this->mUsedToggles['watchcreations'] = true;
1167 $this->mUsedToggles['watchdefault'] = true;
1168 $this->mUsedToggles['watchmoves'] = true;
1169 $this->mUsedToggles['watchdeletion'] = true;
1170
1171 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
1172
1173 # Search
1174 $mwsuggest = $wgEnableMWSuggest ?
1175 $this->addRow(
1176 Xml::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
1177 Xml::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest, array( 'id' => 'wpDisableMWSuggest' ) )
1178 ) : '';
1179 $wgOut->addHTML(
1180 // Elements for the search tab itself
1181 Xml::openElement( 'fieldset' ) .
1182 Xml::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
1183 // Elements for the search options in the search tab
1184 Xml::openElement( 'fieldset' ) .
1185 Xml::element( 'legend', null, wfMsg( 'prefs-searchoptions' ) ) .
1186 Xml::openElement( 'table' ) .
1187 $this->addRow(
1188 Xml::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
1189 Xml::input( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
1190 ) .
1191 $this->addRow(
1192 Xml::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
1193 Xml::input( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
1194 ) .
1195 $this->addRow(
1196 Xml::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
1197 Xml::input( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
1198 ) .
1199 $mwsuggest .
1200 Xml::closeElement( 'table' ) .
1201 Xml::closeElement( 'fieldset' ) .
1202 // Elements for the namespace options in the search tab
1203 Xml::openElement( 'fieldset' ) .
1204 Xml::element( 'legend', null, wfMsg( 'prefs-namespaces' ) ) .
1205 wfMsgExt( 'defaultns', array( 'parse' ) ) .
1206 $ps .
1207 Xml::closeElement( 'fieldset' ) .
1208 // End of the search tab
1209 Xml::closeElement( 'fieldset' )
1210 );
1211
1212 # Misc
1213 #
1214 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
1215 $wgOut->addHTML( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label>&nbsp;' );
1216 $wgOut->addHTML( Xml::input( 'wpStubs', 6, $this->mStubs, array( 'id' => 'wpStubs' ) ) );
1217 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1218 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1219 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1220 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1221 $uopt = $wgUser->getOption("underline");
1222 $s0 = $uopt == 0 ? ' selected="selected"' : '';
1223 $s1 = $uopt == 1 ? ' selected="selected"' : '';
1224 $s2 = $uopt == 2 ? ' selected="selected"' : '';
1225 $wgOut->addHTML("
1226 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1227 <select name='wpOpunderline' id='wpOpunderline'>
1228 <option value=\"0\"$s0>$msgUnderlinenever</option>
1229 <option value=\"1\"$s1>$msgUnderlinealways</option>
1230 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1231 </select></p></div>");
1232
1233 foreach ( $togs as $tname ) {
1234 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
1235 if( $tname == 'norollbackdiff' && $wgUser->isAllowed( 'rollback' ) )
1236 $wgOut->addHTML( $this->getToggle( $tname ) );
1237 else
1238 $wgOut->addHTML( $this->getToggle( $tname ) );
1239 }
1240 }
1241
1242 $wgOut->addHTML( '</fieldset>' );
1243
1244 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1245
1246 $token = htmlspecialchars( $wgUser->editToken() );
1247 $skin = $wgUser->getSkin();
1248 $rtl = $wgContLang->isRTL() ? 'left' : 'right';
1249 $wgOut->addHTML( "
1250 <table id='prefsubmit' cellpadding='0' width='100%' style='background:none;'><tr>
1251 <td><input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) .
1252 '"'.$skin->tooltipAndAccesskey('save')." />
1253 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" /></td>
1254 <td align='$rtl'><input type='submit' name='wpRestore' value=\"" . wfMsgHtml( 'restoreprefs' ) . "\" /></td>
1255 </tr></table>
1256
1257 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1258 </div></form>\n" );
1259
1260 $wgOut->addHTML( Xml::tags( 'div', array( 'class' => "prefcache" ),
1261 wfMsgExt( 'clearyourcache', 'parseinline' ) )
1262 );
1263 }
1264 }