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