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