04ac7597d5e0d4252b0c2c55074f0aa8231b2c34
[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, $wgOut;
447 $wgUser->restoreOptions();
448 $wgUser->setCookies();
449 $wgUser->saveSettings();
450 $title = SpecialPage::getTitleFor( 'Preferences' );
451 $wgOut->redirect( $title->getFullURL( 'success' ) );
452 }
453
454 /**
455 * @access private
456 */
457 function namespacesCheckboxes() {
458 global $wgContLang;
459
460 # Determine namespace checkboxes
461 $namespaces = $wgContLang->getNamespaces();
462 $r1 = null;
463
464 foreach ( $namespaces as $i => $name ) {
465 if ($i < 0)
466 continue;
467 $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
468 $name = str_replace( '_', ' ', $namespaces[$i] );
469
470 if ( empty($name) )
471 $name = wfMsg( 'blanknamespace' );
472
473 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
474 }
475 return $r1;
476 }
477
478
479 function getToggle( $tname, $trailer = false, $disabled = false ) {
480 global $wgUser, $wgLang;
481
482 $this->mUsedToggles[$tname] = true;
483 $ttext = $wgLang->getUserToggle( $tname );
484
485 $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
486 $disabled = $disabled ? ' disabled="disabled"' : '';
487 $trailer = $trailer ? $trailer : '';
488 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
489 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
490 }
491
492 function getToggles( $items ) {
493 $out = "";
494 foreach( $items as $item ) {
495 if( $item === false )
496 continue;
497 if( is_array( $item ) ) {
498 list( $key, $trailer ) = $item;
499 } else {
500 $key = $item;
501 $trailer = false;
502 }
503 $out .= $this->getToggle( $key, $trailer );
504 }
505 return $out;
506 }
507
508 function addRow($td1, $td2) {
509 return "<tr><td class='mw-label'>$td1</td><td class='mw-input'>$td2</td></tr>";
510 }
511
512 /**
513 * Helper function for user information panel
514 * @param $td1 label for an item
515 * @param $td2 item or null
516 * @param $td3 optional help or null
517 * @return xhtml block
518 */
519 function tableRow( $td1, $td2 = null, $td3 = null ) {
520
521 if ( is_null( $td3 ) ) {
522 $td3 = '';
523 } else {
524 $td3 = Xml::tags( 'tr', null,
525 Xml::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td3 )
526 );
527 }
528
529 if ( is_null( $td2 ) ) {
530 $td1 = Xml::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td1 );
531 $td2 = '';
532 } else {
533 $td1 = Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
534 $td2 = Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
535 }
536
537 return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
538
539 }
540
541 /**
542 * @access private
543 */
544 function mainPrefsForm( $status , $message = '' ) {
545 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgAuth;
546 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
547 global $wgDisableLangConversion, $wgDisableTitleConversion;
548 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
549 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
550 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
551 global $wgContLanguageCode, $wgDefaultSkin, $wgCookieExpiration;
552 global $wgEmailConfirmToEdit, $wgEnableMWSuggest, $wgLocalTZoffset;
553
554 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
555 $wgOut->setArticleRelated( false );
556 $wgOut->setRobotPolicy( 'noindex,nofollow' );
557 $wgOut->addScriptFile( 'prefs.js' );
558
559 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
560
561 if ( $this->mSuccess || 'success' == $status ) {
562 $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
563 } else if ( 'error' == $status ) {
564 $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
565 } else if ( '' != $status ) {
566 $wgOut->addWikiText( $message . "\n----" );
567 }
568
569 $qbs = $wgLang->getQuickbarSettings();
570 $mathopts = $wgLang->getMathNames();
571 $dateopts = $wgLang->getDatePreferences();
572 $togs = User::getToggles();
573
574 $titleObj = SpecialPage::getTitleFor( 'Preferences' );
575
576 # Pre-expire some toggles so they won't show if disabled
577 $this->mUsedToggles[ 'shownumberswatching' ] = true;
578 $this->mUsedToggles[ 'showupdated' ] = true;
579 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
580 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
581 $this->mUsedToggles[ 'enotifminoredits' ] = true;
582 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
583 $this->mUsedToggles[ 'ccmeonemails' ] = true;
584 $this->mUsedToggles[ 'uselivepreview' ] = true;
585 $this->mUsedToggles[ 'noconvertlink' ] = true;
586
587
588 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
589 else { $emfc = ''; }
590
591
592 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
593 if( $wgUser->getEmailAuthenticationTimestamp() ) {
594 // date and time are separate parameters to facilitate localisation.
595 // $time is kept for backward compat reasons.
596 // 'emailauthenticated' is also used in SpecialConfirmemail.php
597 $time = $wgLang->timeAndDate( $wgUser->getEmailAuthenticationTimestamp(), true );
598 $d = $wgLang->date( $wgUser->getEmailAuthenticationTimestamp(), true );
599 $t = $wgLang->time( $wgUser->getEmailAuthenticationTimestamp(), true );
600 $emailauthenticated = wfMsg('emailauthenticated', $time, $d, $t ).'<br />';
601 $disableEmailPrefs = false;
602 } else {
603 $disableEmailPrefs = true;
604 $skin = $wgUser->getSkin();
605 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
606 $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
607 wfMsg( 'emailconfirmlink' ) ) . '<br />';
608 }
609 } else {
610 $emailauthenticated = '';
611 $disableEmailPrefs = false;
612 }
613
614 if ($this->mUserEmail == '') {
615 $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
616 }
617
618 $ps = $this->namespacesCheckboxes();
619
620 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
621 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
622 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
623 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
624
625 # </FIXME>
626
627 $wgOut->addHTML(
628 Xml::openElement( 'form', array(
629 'action' => $titleObj->getLocalUrl(),
630 'method' => 'post',
631 'id' => 'mw-preferences-form',
632 ) ) .
633 Xml::openElement( 'div', array( 'id' => 'preferences' ) )
634 );
635
636 # User data
637
638 $wgOut->addHTML(
639 Xml::fieldset( wfMsg('prefs-personal') ) .
640 Xml::openElement( 'table' ) .
641 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
642 );
643
644 # Get groups to which the user belongs
645 $userEffectiveGroups = $wgUser->getEffectiveGroups();
646 $userEffectiveGroupsArray = array();
647 foreach( $userEffectiveGroups as $ueg ) {
648 if( $ueg == '*' ) {
649 // Skip the default * group, seems useless here
650 continue;
651 }
652 $userEffectiveGroupsArray[] = User::makeGroupLinkHTML( $ueg );
653 }
654 asort( $userEffectiveGroupsArray );
655
656 $sk = $wgUser->getSkin();
657 $toolLinks = array();
658 $toolLinks[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'ListGroupRights' ), wfMsg( 'listgrouprights' ) );
659 # At the moment one tool link only but be prepared for the future...
660 # FIXME: Add a link to Special:Userrights for users who are allowed to use it.
661 # $wgUser->isAllowed( 'userrights' ) seems to strict in some cases
662
663 $userInformationHtml =
664 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
665 $this->tableRow( wfMsgHtml( 'uid' ), $wgLang->formatNum( htmlspecialchars( $wgUser->getId() ) ) ).
666
667 $this->tableRow(
668 wfMsgExt( 'prefs-memberingroups', array( 'parseinline' ), count( $userEffectiveGroupsArray ) ),
669 $wgLang->commaList( $userEffectiveGroupsArray ) .
670 '<br />(' . implode( ' | ', $toolLinks ) . ')'
671 ) .
672
673 $this->tableRow(
674 wfMsgHtml( 'prefs-edits' ),
675 $wgLang->formatNum( $wgUser->getEditCount() )
676 );
677
678 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
679 $wgOut->addHTML( $userInformationHtml );
680 }
681
682 if ( $wgAllowRealName ) {
683 $wgOut->addHTML(
684 $this->tableRow(
685 Xml::label( wfMsg('yourrealname'), 'wpRealName' ),
686 Xml::input( 'wpRealName', 25, $this->mRealName, array( 'id' => 'wpRealName' ) ),
687 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
688 wfMsgExt( 'prefs-help-realname', 'parseinline' )
689 )
690 )
691 );
692 }
693 if ( $wgEnableEmail ) {
694 $wgOut->addHTML(
695 $this->tableRow(
696 Xml::label( wfMsg('youremail'), 'wpUserEmail' ),
697 Xml::input( 'wpUserEmail', 25, $this->mUserEmail, array( 'id' => 'wpUserEmail' ) ),
698 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
699 wfMsgExt( $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
700 )
701 )
702 );
703 }
704
705 global $wgParser, $wgMaxSigChars;
706 if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
707 $invalidSig = $this->tableRow(
708 '&nbsp;',
709 Xml::element( 'span', array( 'class' => 'error' ),
710 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) )
711 );
712 } elseif( !empty( $this->mToggles['fancysig'] ) &&
713 false === $wgParser->validateSig( $this->mNick ) ) {
714 $invalidSig = $this->tableRow(
715 '&nbsp;',
716 Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
717 );
718 } else {
719 $invalidSig = '';
720 }
721
722 $wgOut->addHTML(
723 $this->tableRow(
724 Xml::label( wfMsg( 'yournick' ), 'wpNick' ),
725 Xml::input( 'wpNick', 25, $this->mNick,
726 array(
727 'id' => 'wpNick',
728 // Note: $wgMaxSigChars is enforced in Unicode characters,
729 // both on the backend and now in the browser.
730 // Badly-behaved requests may still try to submit
731 // an overlong string, however.
732 'maxlength' => $wgMaxSigChars ) )
733 ) .
734 $invalidSig .
735 $this->tableRow( '&nbsp;', $this->getToggle( 'fancysig' ) )
736 );
737
738 list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage );
739 $wgOut->addHTML(
740 $this->tableRow( $lsLabel, $lsSelect )
741 );
742
743 /* see if there are multiple language variants to choose from*/
744 if(!$wgDisableLangConversion) {
745 $variants = $wgContLang->getVariants();
746 $variantArray = array();
747
748 $languages = Language::getLanguageNames( true );
749 foreach($variants as $v) {
750 $v = str_replace( '_', '-', strtolower($v));
751 if( array_key_exists( $v, $languages ) ) {
752 // If it doesn't have a name, we'll pretend it doesn't exist
753 $variantArray[$v] = $languages[$v];
754 }
755 }
756
757 $options = "\n";
758 foreach( $variantArray as $code => $name ) {
759 $selected = ($code == $this->mUserVariant);
760 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
761 }
762
763 if(count($variantArray) > 1) {
764 $wgOut->addHTML(
765 $this->tableRow(
766 Xml::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
767 Xml::tags( 'select',
768 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
769 $options
770 )
771 )
772 );
773 }
774
775 if(count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) {
776 $wgOut->addHTML(
777 Xml::tags( 'tr', null,
778 Xml::tags( 'td', array( 'colspan' => '2' ),
779 $this->getToggle( "noconvertlink" )
780 )
781 )
782 );
783 }
784 }
785
786 # Password
787 if( $wgAuth->allowPasswordChange() ) {
788 $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ResetPass' ), wfMsgHtml( 'prefs-resetpass' ),
789 array() , array('returnto' => SpecialPage::getTitleFor( 'Preferences') ) );
790 $wgOut->addHTML(
791 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
792 $this->tableRow( '<ul><li>' . $link . '</li></ul>' ) );
793 }
794
795 # <FIXME>
796 # Enotif
797 if ( $wgEnableEmail ) {
798
799 $moreEmail = '';
800 if ($wgEnableUserEmail) {
801 // fixme -- the "allowemail" pseudotoggle is a hacked-together
802 // inversion for the "disableemail" preference.
803 $emf = wfMsg( 'allowemail' );
804 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
805 $moreEmail =
806 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>" .
807 $this->getToggle( 'ccmeonemails', '', $disableEmailPrefs );
808 }
809
810
811 $wgOut->addHTML(
812 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'email' ) ) ) .
813 $this->tableRow(
814 $emailauthenticated.
815 $enotifrevealaddr.
816 $enotifwatchlistpages.
817 $enotifusertalkpages.
818 $enotifminoredits.
819 $moreEmail
820 )
821 );
822 }
823 # </FIXME>
824
825 $wgOut->addHTML(
826 Xml::closeElement( 'table' ) .
827 Xml::closeElement( 'fieldset' )
828 );
829
830
831 # Quickbar
832 #
833 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
834 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
835 for ( $i = 0; $i < count( $qbs ); ++$i ) {
836 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
837 else { $checked = ""; }
838 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
839 }
840 $wgOut->addHTML( "</fieldset>\n\n" );
841 } else {
842 # Need to output a hidden option even if the relevant skin is not in use,
843 # otherwise the preference will get reset to 0 on submit
844 $wgOut->addHTML( Xml::hidden( 'wpQuickbar', $this->mQuickbar ) );
845 }
846
847 # Skin
848 #
849 global $wgAllowUserSkin;
850 if( $wgAllowUserSkin ) {
851 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg( 'skin' ) . "</legend>\n" );
852 $mptitle = Title::newMainPage();
853 $previewtext = wfMsg( 'skin-preview' );
854 # Only show members of Skin::getSkinNames() rather than
855 # $skinNames (skins is all skin names from Language.php)
856 $validSkinNames = Skin::getUsableSkins();
857 # Sort by UI skin name. First though need to update validSkinNames as sometimes
858 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
859 foreach ( $validSkinNames as $skinkey => &$skinname ) {
860 $msgName = "skinname-{$skinkey}";
861 $localisedSkinName = wfMsg( $msgName );
862 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
863 $skinname = $localisedSkinName;
864 }
865 }
866 asort($validSkinNames);
867 foreach ($validSkinNames as $skinkey => $sn ) {
868 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
869 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
870 $previewlink = "(<a target='_blank' href=\"$mplink\">$previewtext</a>)";
871 if( $skinkey == $wgDefaultSkin )
872 $sn .= ' (' . wfMsg( 'default' ) . ')';
873 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
874 }
875 $wgOut->addHTML( "</fieldset>\n\n" );
876 }
877
878 # Math
879 #
880 global $wgUseTeX;
881 if( $wgUseTeX ) {
882 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
883 foreach ( $mathopts as $k => $v ) {
884 $checked = ($k == $this->mMath);
885 $wgOut->addHTML(
886 Xml::openElement( 'div' ) .
887 Xml::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
888 Xml::closeElement( 'div' ) . "\n"
889 );
890 }
891 $wgOut->addHTML( "</fieldset>\n\n" );
892 }
893
894 # Files
895 #
896 $imageLimitOptions = null;
897 foreach ( $wgImageLimits as $index => $limits ) {
898 $selected = ($index == $this->mImageSize);
899 $imageLimitOptions .= Xml::option( "{$limits[0]}×{$limits[1]}" .
900 wfMsg('unit-pixel'), $index, $selected );
901 }
902
903 $imageThumbOptions = null;
904 foreach ( $wgThumbLimits as $index => $size ) {
905 $selected = ($index == $this->mThumbSize);
906 $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
907 $selected);
908 }
909
910 $imageSizeId = 'wpImageSize';
911 $thumbSizeId = 'wpThumbSize';
912 $wgOut->addHTML(
913 Xml::fieldset( wfMsg( 'files' ) ) . "\n" .
914 Xml::openElement( 'table' ) .
915 '<tr>
916 <td class="mw-label">' .
917 Xml::label( wfMsg( 'imagemaxsize' ), $imageSizeId ) .
918 '</td>
919 <td class="mw-input">' .
920 Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
921 $imageLimitOptions .
922 Xml::closeElement( 'select' ) .
923 '</td>
924 </tr><tr>
925 <td class="mw-label">' .
926 Xml::label( wfMsg( 'thumbsize' ), $thumbSizeId ) .
927 '</td>
928 <td class="mw-input">' .
929 Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
930 $imageThumbOptions .
931 Xml::closeElement( 'select' ) .
932 '</td>
933 </tr>' .
934 Xml::closeElement( 'table' ) .
935 Xml::closeElement( 'fieldset' )
936 );
937
938 # Date format
939 #
940 # Date/Time
941 #
942
943 $wgOut->addHTML(
944 Xml::openElement( 'fieldset' ) .
945 Xml::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
946 );
947
948 if ($dateopts) {
949 $wgOut->addHTML(
950 Xml::openElement( 'fieldset' ) .
951 Xml::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
952 );
953 $idCnt = 0;
954 $epoch = '20010115161234'; # Wikipedia day
955 foreach( $dateopts as $key ) {
956 if( $key == 'default' ) {
957 $formatted = wfMsg( 'datedefault' );
958 } else {
959 $formatted = $wgLang->timeanddate( $epoch, false, $key );
960 }
961 $wgOut->addHTML(
962 Xml::tags( 'div', null,
963 Xml::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate )
964 ) . "\n"
965 );
966 $idCnt++;
967 }
968 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) . "\n" );
969 }
970
971 $nowlocal = Xml::openElement( 'span', array( 'id' => 'wpLocalTime' ) ) .
972 $wgLang->time( $now = wfTimestampNow(), true ) .
973 Xml::closeElement( 'span' );
974 $nowserver = $wgLang->time( $now, false ) .
975 Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
976
977 $wgOut->addHTML(
978 Xml::openElement( 'fieldset' ) .
979 Xml::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
980 Xml::openElement( 'table' ) .
981 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
982 $this->addRow( wfMsg( 'localtime' ), $nowlocal )
983 );
984 $opt = Xml::openElement( 'select', array(
985 'name' => 'wpTimeZone',
986 'id' => 'wpTimeZone',
987 'onchange' => 'javascript:updateTimezoneSelection(false)' ) );
988 $opt .= Xml::option( wfMsg( 'timezoneuseserverdefault' ), "System|$wgLocalTZoffset", $this->mTimeZone === "System|$wgLocalTZoffset" );
989 $opt .= Xml::option( wfMsg( 'timezoneuseoffset' ), 'Offset', $this->mTimeZone === 'Offset' );
990 if ( function_exists( 'timezone_identifiers_list' ) ) {
991 $optgroup = '';
992 $tzs = timezone_identifiers_list();
993 sort( $tzs );
994 $selZone = explode( '|', $this->mTimeZone, 3);
995 $selZone = ( $selZone[0] == 'ZoneInfo' ) ? $selZone[2] : null;
996 $now = date_create( 'now' );
997 foreach ( $tzs as $tz ) {
998 $z = explode( '/', $tz, 2 );
999 # timezone_identifiers_list() returns a number of
1000 # backwards-compatibility entries. This filters them out of the
1001 # list presented to the user.
1002 if ( count( $z ) != 2 || !in_array( $z[0], array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' ) ) ) continue;
1003 if ( $optgroup != $z[0] ) {
1004 if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
1005 $optgroup = $z[0];
1006 $opt .= Xml::openElement( 'optgroup', array( 'label' => $z[0] ) );
1007 }
1008 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1009 $opt .= Xml::option( str_replace( '_', ' ', $tz ), "ZoneInfo|$minDiff|$tz", $selZone === $tz, array( 'label' => $z[1] ) );
1010 }
1011 if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
1012 }
1013 $opt .= Xml::closeElement( 'select' );
1014 $wgOut->addHTML(
1015 $this->addRow(
1016 Xml::label( wfMsg( 'timezoneselect' ), 'wpTimeZone' ),
1017 $opt )
1018 );
1019 $wgOut->addHTML(
1020 $this->addRow(
1021 Xml::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff' ),
1022 Xml::input( 'wpHourDiff', 6, $this->mHourDiff, array(
1023 'id' => 'wpHourDiff',
1024 'onfocus' => 'javascript:updateTimezoneSelection(true)',
1025 'onblur' => 'javascript:updateTimezoneSelection(false)' ) ) ) .
1026 "<tr>
1027 <td></td>
1028 <td class='mw-submit'>" .
1029 Xml::element( 'input',
1030 array( 'type' => 'button',
1031 'value' => wfMsg( 'guesstimezone' ),
1032 'onclick' => 'javascript:guessTimezone()',
1033 'id' => 'guesstimezonebutton',
1034 'style' => 'display:none;' ) ) .
1035 "</td>
1036 </tr>" .
1037 Xml::closeElement( 'table' ) .
1038 Xml::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
1039 Xml::closeElement( 'fieldset' ) .
1040 Xml::closeElement( 'fieldset' ) . "\n\n"
1041 );
1042
1043 # Editing
1044 #
1045 global $wgLivePreview;
1046 $wgOut->addHTML(
1047 Xml::fieldset( wfMsg( 'textboxsize' ) ) .
1048 wfMsgHTML( 'prefs-edit-boxsize' ) . ' ' .
1049 Xml::inputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) . ' ' .
1050 Xml::inputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
1051 $this->getToggles( array(
1052 'editsection',
1053 'editsectiononrightclick',
1054 'editondblclick',
1055 'editwidth',
1056 'showtoolbar',
1057 'previewonfirst',
1058 'previewontop',
1059 'minordefault',
1060 'externaleditor',
1061 'externaldiff',
1062 $wgLivePreview ? 'uselivepreview' : false,
1063 'forceeditsummary',
1064 ) )
1065 );
1066
1067 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
1068
1069 # Recent changes
1070 global $wgRCMaxAge;
1071 $wgOut->addHTML(
1072 Xml::fieldset( wfMsg( 'prefs-rc' ) ) .
1073 Xml::openElement( 'table' ) .
1074 '<tr>
1075 <td class="mw-label">' .
1076 Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) .
1077 '</td>
1078 <td class="mw-input">' .
1079 Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . ' ' .
1080 wfMsgExt( 'recentchangesdays-max', 'parsemag',
1081 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) ) .
1082 '</td>
1083 </tr><tr>
1084 <td class="mw-label">' .
1085 Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) .
1086 '</td>
1087 <td class="mw-input">' .
1088 Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) .
1089 '</td>
1090 </tr>' .
1091 Xml::closeElement( 'table' ) .
1092 '<br />'
1093 );
1094
1095 $toggles[] = 'hideminor';
1096 if( $wgRCShowWatchingUsers )
1097 $toggles[] = 'shownumberswatching';
1098 $toggles[] = 'usenewrc';
1099
1100 $wgOut->addHTML(
1101 $this->getToggles( $toggles ) .
1102 Xml::closeElement( 'fieldset' )
1103 );
1104
1105 # Watchlist
1106 $wgOut->addHTML(
1107 Xml::fieldset( wfMsg( 'prefs-watchlist' ) ) .
1108 Xml::inputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) . ' ' .
1109 wfMsgHTML( 'prefs-watchlist-days-max' ) .
1110 '<br /><br />' .
1111 $this->getToggle( 'extendwatchlist' ) .
1112 Xml::inputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) . ' ' .
1113 wfMsgHTML( 'prefs-watchlist-edits-max' ) .
1114 '<br /><br />' .
1115 $this->getToggles( array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown', 'watchlisthideanons', 'watchlisthideliu' ) )
1116 );
1117
1118 if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) ) {
1119 $wgOut->addHTML( $this->getToggle( 'watchcreations' ) );
1120 }
1121
1122 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
1123 if( $wgUser->isAllowed( $action ) )
1124 $wgOut->addHTML( $this->getToggle( $toggle ) );
1125 }
1126 $this->mUsedToggles['watchcreations'] = true;
1127 $this->mUsedToggles['watchdefault'] = true;
1128 $this->mUsedToggles['watchmoves'] = true;
1129 $this->mUsedToggles['watchdeletion'] = true;
1130
1131 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
1132
1133 # Search
1134 $mwsuggest = $wgEnableMWSuggest ?
1135 $this->addRow(
1136 Xml::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
1137 Xml::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest, array( 'id' => 'wpDisableMWSuggest' ) )
1138 ) : '';
1139 $wgOut->addHTML(
1140 // Elements for the search tab itself
1141 Xml::openElement( 'fieldset' ) .
1142 Xml::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
1143 // Elements for the search options in the search tab
1144 Xml::openElement( 'fieldset' ) .
1145 Xml::element( 'legend', null, wfMsg( 'prefs-searchoptions' ) ) .
1146 Xml::openElement( 'table' ) .
1147 $this->addRow(
1148 Xml::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
1149 Xml::input( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
1150 ) .
1151 $this->addRow(
1152 Xml::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
1153 Xml::input( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
1154 ) .
1155 $this->addRow(
1156 Xml::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
1157 Xml::input( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
1158 ) .
1159 $mwsuggest .
1160 Xml::closeElement( 'table' ) .
1161 Xml::closeElement( 'fieldset' ) .
1162 // Elements for the namespace options in the search tab
1163 Xml::openElement( 'fieldset' ) .
1164 Xml::element( 'legend', null, wfMsg( 'prefs-namespaces' ) ) .
1165 wfMsgExt( 'defaultns', array( 'parse' ) ) .
1166 $ps .
1167 Xml::closeElement( 'fieldset' ) .
1168 // End of the search tab
1169 Xml::closeElement( 'fieldset' )
1170 );
1171
1172 # Misc
1173 #
1174 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
1175 $wgOut->addHTML( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label>&nbsp;' );
1176 $wgOut->addHTML( Xml::input( 'wpStubs', 6, $this->mStubs, array( 'id' => 'wpStubs' ) ) );
1177 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1178 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1179 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1180 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1181 $uopt = $wgUser->getOption("underline");
1182 $s0 = $uopt == 0 ? ' selected="selected"' : '';
1183 $s1 = $uopt == 1 ? ' selected="selected"' : '';
1184 $s2 = $uopt == 2 ? ' selected="selected"' : '';
1185 $wgOut->addHTML("
1186 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1187 <select name='wpOpunderline' id='wpOpunderline'>
1188 <option value=\"0\"$s0>$msgUnderlinenever</option>
1189 <option value=\"1\"$s1>$msgUnderlinealways</option>
1190 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1191 </select></p></div>");
1192
1193 foreach ( $togs as $tname ) {
1194 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
1195 if( $tname == 'norollbackdiff' && $wgUser->isAllowed( 'rollback' ) )
1196 $wgOut->addHTML( $this->getToggle( $tname ) );
1197 else
1198 $wgOut->addHTML( $this->getToggle( $tname ) );
1199 }
1200 }
1201
1202 $wgOut->addHTML( '</fieldset>' );
1203
1204 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1205
1206 $token = htmlspecialchars( $wgUser->editToken() );
1207 $skin = $wgUser->getSkin();
1208 $wgOut->addHTML( "
1209 <div id='prefsubmit'>
1210 <input type='submit' name='wpRestore' class='btnSavePrefs' style='float:right;' value=\"" .
1211 wfMsgHtml( 'restoreprefs' ) . "\" />
1212 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) .
1213 '"'.$skin->tooltipAndAccesskey('save')." />
1214 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
1215 </div>
1216
1217 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1218 </div></form>\n" );
1219
1220 $wgOut->addHTML( Xml::tags( 'div', array( 'class' => "prefcache" ),
1221 wfMsgExt( 'clearyourcache', 'parseinline' ) )
1222 );
1223 }
1224 }