Had a bash at cleaning up the horrendous-looking deletion log on the edit page:
[lhc/web/wiklou.git] / includes / SpecialPreferences.php
1 <?php
2 /**
3 * Hold things related to displaying and saving user preferences.
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 * Entry point that create the "Preferences" object
9 */
10 function wfSpecialPreferences() {
11 global $wgRequest;
12
13 $form = new PreferencesForm( $wgRequest );
14 $form->execute();
15 }
16
17 /**
18 * Preferences form handling
19 * This object will show the preferences form and can save it as well.
20 * @addtogroup SpecialPage
21 */
22 class PreferencesForm {
23 var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
24 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
25 var $mUserLanguage, $mUserVariant;
26 var $mSearch, $mRecent, $mRecentDays, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
27 var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
28 var $mUnderline, $mWatchlistEdits;
29
30 /**
31 * Constructor
32 * Load some values
33 */
34 function PreferencesForm( &$request ) {
35 global $wgContLang, $wgUser, $wgAllowRealName;
36
37 $this->mQuickbar = $request->getVal( 'wpQuickbar' );
38 $this->mOldpass = $request->getVal( 'wpOldpass' );
39 $this->mNewpass = $request->getVal( 'wpNewpass' );
40 $this->mRetypePass =$request->getVal( 'wpRetypePass' );
41 $this->mStubs = $request->getVal( 'wpStubs' );
42 $this->mRows = $request->getVal( 'wpRows' );
43 $this->mCols = $request->getVal( 'wpCols' );
44 $this->mSkin = $request->getVal( 'wpSkin' );
45 $this->mMath = $request->getVal( 'wpMath' );
46 $this->mDate = $request->getVal( 'wpDate' );
47 $this->mUserEmail = $request->getVal( 'wpUserEmail' );
48 $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : '';
49 $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1;
50 $this->mNick = $request->getVal( 'wpNick' );
51 $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
52 $this->mUserVariant = $request->getVal( 'wpUserVariant' );
53 $this->mSearch = $request->getVal( 'wpSearch' );
54 $this->mRecent = $request->getVal( 'wpRecent' );
55 $this->mRecentDays = $request->getVal( 'wpRecentDays' );
56 $this->mHourDiff = $request->getVal( 'wpHourDiff' );
57 $this->mSearchLines = $request->getVal( 'wpSearchLines' );
58 $this->mSearchChars = $request->getVal( 'wpSearchChars' );
59 $this->mImageSize = $request->getVal( 'wpImageSize' );
60 $this->mThumbSize = $request->getInt( 'wpThumbSize' );
61 $this->mUnderline = $request->getInt( 'wpOpunderline' );
62 $this->mAction = $request->getVal( 'action' );
63 $this->mReset = $request->getCheck( 'wpReset' );
64 $this->mPosted = $request->wasPosted();
65 $this->mSuccess = $request->getCheck( 'success' );
66 $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
67 $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' );
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
102 function execute() {
103 global $wgUser, $wgOut;
104
105 if ( $wgUser->isAnon() ) {
106 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
107 return;
108 }
109 if ( wfReadOnly() ) {
110 $wgOut->readOnlyPage();
111 return;
112 }
113 if ( $this->mReset ) {
114 $this->resetPrefs();
115 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
116 } else if ( $this->mSaveprefs ) {
117 $this->savePreferences();
118 } else {
119 $this->resetPrefs();
120 $this->mainPrefsForm( '' );
121 }
122 }
123 /**
124 * @access private
125 */
126 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
127 $val = intval($val);
128 $val = min($val, $max);
129 $val = max($val, $min);
130 return $val;
131 }
132
133 /**
134 * @access private
135 */
136 function validateFloat( &$val, $min, $max=0x7fffffff ) {
137 $val = floatval( $val );
138 $val = min( $val, $max );
139 $val = max( $val, $min );
140 return( $val );
141 }
142
143 /**
144 * @access private
145 */
146 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
147 $val = trim($val);
148 if($val === '') {
149 return $val;
150 } else {
151 return $this->validateInt( $val, $min, $max );
152 }
153 }
154
155 /**
156 * @access private
157 */
158 function validateDate( $val ) {
159 global $wgLang, $wgContLang;
160 if ( $val !== false && (
161 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
162 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
163 {
164 return $val;
165 } else {
166 return $wgLang->getDefaultDateFormat();
167 }
168 }
169
170 /**
171 * Used to validate the user inputed timezone before saving it as
172 * 'timecorrection', will return '00:00' if fed bogus data.
173 * Note: It's not a 100% correct implementation timezone-wise, it will
174 * accept stuff like '14:30',
175 * @access private
176 * @param string $s the user input
177 * @return string
178 */
179 function validateTimeZone( $s ) {
180 if ( $s !== '' ) {
181 if ( strpos( $s, ':' ) ) {
182 # HH:MM
183 $array = explode( ':' , $s );
184 $hour = intval( $array[0] );
185 $minute = intval( $array[1] );
186 } else {
187 $minute = intval( $s * 60 );
188 $hour = intval( $minute / 60 );
189 $minute = abs( $minute ) % 60;
190 }
191 # Max is +14:00 and min is -12:00, see:
192 # http://en.wikipedia.org/wiki/Timezone
193 $hour = min( $hour, 14 );
194 $hour = max( $hour, -12 );
195 $minute = min( $minute, 59 );
196 $minute = max( $minute, 0 );
197 $s = sprintf( "%02d:%02d", $hour, $minute );
198 }
199 return $s;
200 }
201
202 /**
203 * @access private
204 */
205 function savePreferences() {
206 global $wgUser, $wgOut, $wgParser;
207 global $wgEnableUserEmail, $wgEnableEmail;
208 global $wgEmailAuthentication;
209 global $wgAuth;
210
211
212 if ( '' != $this->mNewpass && $wgAuth->allowPasswordChange() ) {
213 if ( $this->mNewpass != $this->mRetypePass ) {
214 wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'badretype' ) );
215 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
216 return;
217 }
218
219 if (!$wgUser->checkPassword( $this->mOldpass )) {
220 wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'wrongpassword' ) );
221 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
222 return;
223 }
224
225 try {
226 $wgUser->setPassword( $this->mNewpass );
227 wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'success' ) );
228 $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
229 } catch( PasswordError $e ) {
230 wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'error' ) );
231 $this->mainPrefsForm( 'error', $e->getMessage() );
232 return;
233 }
234 }
235 $wgUser->setRealName( $this->mRealName );
236
237 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
238 $needRedirect = true;
239 } else {
240 $needRedirect = false;
241 }
242
243 # Validate the signature and clean it up as needed
244 if( $this->mToggles['fancysig'] ) {
245 if( Parser::validateSig( $this->mNick ) !== false ) {
246 $this->mNick = $wgParser->cleanSig( $this->mNick );
247 } else {
248 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
249 }
250 } else {
251 // When no fancy sig used, make sure ~{3,5} get removed.
252 $this->mNick = $wgParser->cleanSigInSig( $this->mNick );
253 }
254
255 $wgUser->setOption( 'language', $this->mUserLanguage );
256 $wgUser->setOption( 'variant', $this->mUserVariant );
257 $wgUser->setOption( 'nickname', $this->mNick );
258 $wgUser->setOption( 'quickbar', $this->mQuickbar );
259 $wgUser->setOption( 'skin', $this->mSkin );
260 global $wgUseTeX;
261 if( $wgUseTeX ) {
262 $wgUser->setOption( 'math', $this->mMath );
263 }
264 $wgUser->setOption( 'date', $this->validateDate( $this->mDate ) );
265 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
266 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
267 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
268 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
269 $wgUser->setOption( 'rcdays', $this->validateInt( $this->mRecentDays, 1, 7 ) );
270 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits, 0, 1000 ) );
271 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
272 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
273 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
274 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
275 $wgUser->setOption( 'imagesize', $this->mImageSize );
276 $wgUser->setOption( 'thumbsize', $this->mThumbSize );
277 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
278 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) );
279
280 # Set search namespace options
281 foreach( $this->mSearchNs as $i => $value ) {
282 $wgUser->setOption( "searchNs{$i}", $value );
283 }
284
285 if( $wgEnableEmail && $wgEnableUserEmail ) {
286 $wgUser->setOption( 'disablemail', $this->mEmailFlag );
287 }
288
289 # Set user toggles
290 foreach ( $this->mToggles as $tname => $tvalue ) {
291 $wgUser->setOption( $tname, $tvalue );
292 }
293 if (!$wgAuth->updateExternalDB($wgUser)) {
294 $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
295 return;
296 }
297 $wgUser->setCookies();
298 $wgUser->saveSettings();
299
300 $error = false;
301 if( $wgEnableEmail ) {
302 $newadr = $this->mUserEmail;
303 $oldadr = $wgUser->getEmail();
304 if( ($newadr != '') && ($newadr != $oldadr) ) {
305 # the user has supplied a new email address on the login page
306 if( $wgUser->isValidEmailAddr( $newadr ) ) {
307 $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
308 $wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
309 $wgUser->saveSettings();
310 if ($wgEmailAuthentication) {
311 # Mail a temporary password to the dirty address.
312 # User can come back through the confirmation URL to re-enable email.
313 $result = $wgUser->sendConfirmationMail();
314 if( WikiError::isError( $result ) ) {
315 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
316 } else {
317 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
318 }
319 }
320 } else {
321 $error = wfMsg( 'invalidemailaddress' );
322 }
323 } else {
324 $wgUser->setEmail( $this->mUserEmail );
325 $wgUser->setCookies();
326 $wgUser->saveSettings();
327 }
328 if( $oldadr != $newadr ) {
329 wfRunHooks( "PrefsEmailAudit", array( $wgUser, $oldadr, $newadr ) );
330 }
331 }
332
333 if( $needRedirect && $error === false ) {
334 $title =& SpecialPage::getTitleFor( "Preferences" );
335 $wgOut->redirect($title->getFullURL('success'));
336 return;
337 }
338
339 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
340 $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
341 }
342
343 /**
344 * @access private
345 */
346 function resetPrefs() {
347 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName;
348
349 $this->mOldpass = $this->mNewpass = $this->mRetypePass = '';
350 $this->mUserEmail = $wgUser->getEmail();
351 $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
352 $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
353
354 # language value might be blank, default to content language
355 $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode );
356
357 $this->mUserVariant = $wgUser->getOption( 'variant');
358 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
359 $this->mNick = $wgUser->getOption( 'nickname' );
360
361 $this->mQuickbar = $wgUser->getOption( 'quickbar' );
362 $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
363 $this->mMath = $wgUser->getOption( 'math' );
364 $this->mDate = $wgUser->getDatePreference();
365 $this->mRows = $wgUser->getOption( 'rows' );
366 $this->mCols = $wgUser->getOption( 'cols' );
367 $this->mStubs = $wgUser->getOption( 'stubthreshold' );
368 $this->mHourDiff = $wgUser->getOption( 'timecorrection' );
369 $this->mSearch = $wgUser->getOption( 'searchlimit' );
370 $this->mSearchLines = $wgUser->getOption( 'contextlines' );
371 $this->mSearchChars = $wgUser->getOption( 'contextchars' );
372 $this->mImageSize = $wgUser->getOption( 'imagesize' );
373 $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
374 $this->mRecent = $wgUser->getOption( 'rclimit' );
375 $this->mRecentDays = $wgUser->getOption( 'rcdays' );
376 $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
377 $this->mUnderline = $wgUser->getOption( 'underline' );
378 $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
379
380 $togs = User::getToggles();
381 foreach ( $togs as $tname ) {
382 $this->mToggles[$tname] = $wgUser->getOption( $tname );
383 }
384
385 $namespaces = $wgContLang->getNamespaces();
386 foreach ( $namespaces as $i => $namespace ) {
387 if ( $i >= NS_MAIN ) {
388 $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
389 }
390 }
391 }
392
393 /**
394 * @access private
395 */
396 function namespacesCheckboxes() {
397 global $wgContLang;
398
399 # Determine namespace checkboxes
400 $namespaces = $wgContLang->getNamespaces();
401 $r1 = null;
402
403 foreach ( $namespaces as $i => $name ) {
404 if ($i < 0)
405 continue;
406 $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
407 $name = str_replace( '_', ' ', $namespaces[$i] );
408
409 if ( empty($name) )
410 $name = wfMsg( 'blanknamespace' );
411
412 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
413 }
414 return $r1;
415 }
416
417
418 function getToggle( $tname, $trailer = false, $disabled = false ) {
419 global $wgUser, $wgLang;
420
421 $this->mUsedToggles[$tname] = true;
422 $ttext = $wgLang->getUserToggle( $tname );
423
424 $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
425 $disabled = $disabled ? ' disabled="disabled"' : '';
426 $trailer = $trailer ? $trailer : '';
427 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
428 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
429 }
430
431 function getToggles( $items ) {
432 $out = "";
433 foreach( $items as $item ) {
434 if( $item === false )
435 continue;
436 if( is_array( $item ) ) {
437 list( $key, $trailer ) = $item;
438 } else {
439 $key = $item;
440 $trailer = false;
441 }
442 $out .= $this->getToggle( $key, $trailer );
443 }
444 return $out;
445 }
446
447 function addRow($td1, $td2) {
448 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
449 }
450
451 /**
452 * Helper function for user information panel
453 * @param $td1 label for an item
454 * @param $td2 item or null
455 * @param $td3 optional help or null
456 * @return xhtml block
457 */
458 function tableRow( $td1, $td2 = null, $td3 = null ) {
459 global $wgContLang;
460
461 $align['align'] = $wgContLang->isRtl() ? 'right' : 'left';
462
463 if ( is_null( $td3 ) ) {
464 $td3 = '';
465 } else {
466 $td3 = Xml::tags( 'tr', null,
467 Xml::tags( 'td', array( 'colspan' => '2' ), $td3 )
468 );
469 }
470
471 if ( is_null( $td2 ) ) {
472 $td1 = Xml::tags( 'td', $align + array( 'colspan' => '2' ), $td1 );
473 $td2 = '';
474 } else {
475 $td1 = Xml::tags( 'td', $align, $td1 );
476 $td2 = Xml::tags( 'td', $align, $td2 );
477 }
478
479 return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
480
481 }
482
483 /**
484 * @access private
485 */
486 function mainPrefsForm( $status , $message = '' ) {
487 global $wgUser, $wgOut, $wgLang, $wgContLang;
488 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
489 global $wgDisableLangConversion;
490 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
491 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
492 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
493 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins, $wgAuth;
494
495 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
496 $wgOut->setArticleRelated( false );
497 $wgOut->setRobotpolicy( 'noindex,nofollow' );
498
499 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
500
501 if ( $this->mSuccess || 'success' == $status ) {
502 $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
503 } else if ( 'error' == $status ) {
504 $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
505 } else if ( '' != $status ) {
506 $wgOut->addWikitext( $message . "\n----" );
507 }
508
509 $qbs = $wgLang->getQuickbarSettings();
510 $skinNames = $wgLang->getSkinNames();
511 $mathopts = $wgLang->getMathNames();
512 $dateopts = $wgLang->getDatePreferences();
513 $togs = User::getToggles();
514
515 $titleObj = SpecialPage::getTitleFor( 'Preferences' );
516 $action = $titleObj->escapeLocalURL();
517
518 # Pre-expire some toggles so they won't show if disabled
519 $this->mUsedToggles[ 'shownumberswatching' ] = true;
520 $this->mUsedToggles[ 'showupdated' ] = true;
521 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
522 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
523 $this->mUsedToggles[ 'enotifminoredits' ] = true;
524 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
525 $this->mUsedToggles[ 'ccmeonemails' ] = true;
526 $this->mUsedToggles[ 'uselivepreview' ] = true;
527
528
529 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
530 else { $emfc = ''; }
531
532
533 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
534 if( $wgUser->getEmailAuthenticationTimestamp() ) {
535 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
536 $disableEmailPrefs = false;
537 } else {
538 $disableEmailPrefs = true;
539 $skin = $wgUser->getSkin();
540 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
541 $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
542 wfMsg( 'emailconfirmlink' ) );
543 }
544 } else {
545 $emailauthenticated = '';
546 $disableEmailPrefs = false;
547 }
548
549 if ($this->mUserEmail == '') {
550 $emailauthenticated = wfMsg( 'noemailprefs' );
551 }
552
553 $ps = $this->namespacesCheckboxes();
554
555 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
556 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
557 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
558 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
559
560 # </FIXME>
561
562 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
563 $wgOut->addHTML( "<div id='preferences'>" );
564
565 # User data
566
567 $wgOut->addHTML(
568 Xml::openElement( 'fieldset ' ) .
569 Xml::element( 'legend', null, wfMsg('prefs-personal') ) .
570 Xml::openElement( 'table' ) .
571 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
572 );
573
574 $userInformationHtml =
575 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
576 $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getID() ) );
577
578 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
579 $wgOut->addHtml( $userInformationHtml );
580 }
581
582 if ( $wgAllowRealName ) {
583 $wgOut->addHTML(
584 $this->tableRow(
585 Xml::label( wfMsg('yourrealname'), 'wpRealName' ),
586 Xml::input( 'wpRealName', 25, $this->mRealName, array( 'id' => 'wpRealName' ) ),
587 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
588 wfMsgExt( 'prefs-help-realname', 'parseinline' )
589 )
590 )
591 );
592 }
593 if ( $wgEnableEmail ) {
594 $wgOut->addHTML(
595 $this->tableRow(
596 Xml::label( wfMsg('youremail'), 'wpUserEmail' ),
597 Xml::input( 'wpUserEmail', 25, $this->mUserEmail, array( 'id' => 'wpUserEmail' ) ),
598 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
599 wfMsgExt( 'prefs-help-email', 'parseinline' )
600 )
601 )
602 );
603 }
604
605 global $wgParser;
606 if( !empty( $this->mToggles['fancysig'] ) &&
607 false === $wgParser->validateSig( $this->mNick ) ) {
608 $invalidSig = $this->tableRow(
609 '&nbsp;',
610 Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
611 );
612 } else {
613 $invalidSig = '';
614 }
615
616 $wgOut->addHTML(
617 $this->tableRow(
618 Xml::label( wfMsg( 'yournick' ), 'wpNick' ),
619 Xml::input( 'wpNick', 25, $this->mNick, array( 'id' => 'wpNick' ) )
620 ) .
621 $invalidSig .
622 $this->tableRow( '&nbsp;', $this->getToggle( 'fancysig' ) )
623 );
624
625 list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage );
626 $wgOut->addHTML(
627 $this->tableRow( $lsLabel, $lsSelect )
628 );
629
630 /* see if there are multiple language variants to choose from*/
631 if(!$wgDisableLangConversion) {
632 $variants = $wgContLang->getVariants();
633 $variantArray = array();
634
635 $languages = Language::getLanguageNames( true );
636 foreach($variants as $v) {
637 $v = str_replace( '_', '-', strtolower($v));
638 if( array_key_exists( $v, $languages ) ) {
639 // If it doesn't have a name, we'll pretend it doesn't exist
640 $variantArray[$v] = $languages[$v];
641 }
642 }
643
644 $options = "\n";
645 foreach( $variantArray as $code => $name ) {
646 $selected = ($code == $this->mUserVariant);
647 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
648 }
649
650 if(count($variantArray) > 1) {
651 $wgOut->addHtml(
652 $this->tableRow(
653 Xml::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
654 Xml::tags( 'select',
655 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
656 $options
657 )
658 )
659 );
660 }
661 }
662
663 # Password
664 if( $wgAuth->allowPasswordChange() ) {
665 $wgOut->addHTML(
666 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
667 $this->tableRow(
668 Xml::label( wfMsg( 'oldpassword' ), 'wpOldpass' ),
669 Xml::password( 'wpOldpass', 25, $this->mOldpass, array( 'id' => 'wpOldpass' ) )
670 ) .
671 $this->tableRow(
672 Xml::label( wfMsg( 'newpassword' ), 'wpNewpass' ),
673 Xml::password( 'wpNewpass', 25, $this->mNewpass, array( 'id' => 'wpNewpass' ) )
674 ) .
675 $this->tableRow(
676 Xml::label( wfMsg( 'retypenew' ), 'wpRetypePass' ),
677 Xml::password( 'wpRetypePass', 25, $this->mRetypePass, array( 'id' => 'wpRetypePass' ) )
678 ) .
679 Xml::tags( 'tr', null,
680 Xml::tags( 'td', array( 'colspan' => '2' ),
681 $this->getToggle( "rememberpassword" )
682 )
683 )
684 );
685 }
686
687 # <FIXME>
688 # Enotif
689 if ( $wgEnableEmail ) {
690
691 $moreEmail = '';
692 if ($wgEnableUserEmail) {
693 $emf = wfMsg( 'allowemail' );
694 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
695 $moreEmail =
696 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>";
697 }
698
699
700 $wgOut->addHTML(
701 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'email' ) ) ) .
702 $this->tableRow(
703 $emailauthenticated.
704 $enotifrevealaddr.
705 $enotifwatchlistpages.
706 $enotifusertalkpages.
707 $enotifminoredits.
708 $moreEmail.
709 $this->getToggle( 'ccmeonemails' )
710 )
711 );
712 }
713 # </FIXME>
714
715 $wgOut->addHTML(
716 Xml::closeElement( 'table' ) .
717 Xml::closeElement( 'fieldset' )
718 );
719
720
721 # Quickbar
722 #
723 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
724 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
725 for ( $i = 0; $i < count( $qbs ); ++$i ) {
726 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
727 else { $checked = ""; }
728 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
729 }
730 $wgOut->addHtml( "</fieldset>\n\n" );
731 } else {
732 # Need to output a hidden option even if the relevant skin is not in use,
733 # otherwise the preference will get reset to 0 on submit
734 $wgOut->addHtml( wfHidden( 'wpQuickbar', $this->mQuickbar ) );
735 }
736
737 # Skin
738 #
739 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
740 $mptitle = Title::newMainPage();
741 $previewtext = wfMsg('skinpreview');
742 # Only show members of Skin::getSkinNames() rather than
743 # $skinNames (skins is all skin names from Language.php)
744 $validSkinNames = Skin::getSkinNames();
745 # Sort by UI skin name. First though need to update validSkinNames as sometimes
746 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
747 foreach ($validSkinNames as $skinkey => & $skinname ) {
748 if ( isset( $skinNames[$skinkey] ) ) {
749 $skinname = $skinNames[$skinkey];
750 }
751 }
752 asort($validSkinNames);
753 foreach ($validSkinNames as $skinkey => $sn ) {
754 if ( in_array( $skinkey, $wgSkipSkins ) ) {
755 continue;
756 }
757 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
758
759 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
760 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
761 if( $skinkey == $wgDefaultSkin )
762 $sn .= ' (' . wfMsg( 'default' ) . ')';
763 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
764 }
765 $wgOut->addHTML( "</fieldset>\n\n" );
766
767 # Math
768 #
769 global $wgUseTeX;
770 if( $wgUseTeX ) {
771 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
772 foreach ( $mathopts as $k => $v ) {
773 $checked = ($k == $this->mMath);
774 $wgOut->addHTML(
775 Xml::openElement( 'div' ) .
776 Xml::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
777 Xml::closeElement( 'div' ) . "\n"
778 );
779 }
780 $wgOut->addHTML( "</fieldset>\n\n" );
781 }
782
783 # Files
784 #
785 $wgOut->addHTML(
786 "<fieldset>\n" . Xml::element( 'legend', null, wfMsg( 'files' ) ) . "\n"
787 );
788
789 $imageLimitOptions = null;
790 foreach ( $wgImageLimits as $index => $limits ) {
791 $selected = ($index == $this->mImageSize);
792 $imageLimitOptions .= Xml::option( "{$limits[0]}ร—{$limits[1]}" .
793 wfMsg('unit-pixel'), $index, $selected );
794 }
795
796 $imageSizeId = 'wpImageSize';
797 $wgOut->addHTML(
798 "<div>" . Xml::label( wfMsg('imagemaxsize'), $imageSizeId ) . " " .
799 Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
800 $imageLimitOptions .
801 Xml::closeElement( 'select' ) . "</div>\n"
802 );
803
804 $imageThumbOptions = null;
805 foreach ( $wgThumbLimits as $index => $size ) {
806 $selected = ($index == $this->mThumbSize);
807 $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
808 $selected);
809 }
810
811 $thumbSizeId = 'wpThumbSize';
812 $wgOut->addHTML(
813 "<div>" . Xml::label( wfMsg('thumbsize'), $thumbSizeId ) . " " .
814 Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
815 $imageThumbOptions .
816 Xml::closeElement( 'select' ) . "</div>\n"
817 );
818
819 $wgOut->addHTML( "</fieldset>\n\n" );
820
821 # Date format
822 #
823 # Date/Time
824 #
825
826 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
827
828 if ($dateopts) {
829 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
830 $idCnt = 0;
831 $epoch = '20010115161234'; # Wikipedia day
832 foreach( $dateopts as $key ) {
833 if( $key == 'default' ) {
834 $formatted = wfMsgHtml( 'datedefault' );
835 } else {
836 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
837 }
838 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
839 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
840 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
841 $idCnt++;
842 }
843 $wgOut->addHTML( "</fieldset>\n" );
844 }
845
846 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
847 $nowserver = $wgLang->time( $now, false );
848
849 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
850 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
851 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
852 $this->addRow(
853 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
854 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
855 ) . "<tr><td colspan='2'>
856 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
857 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
858 </td></tr></table><div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div></fieldset>
859 </fieldset>\n\n" );
860
861 # Editing
862 #
863 global $wgLivePreview;
864 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
865 <div>' .
866 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) .
867 ' ' .
868 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
869 "</div>" .
870 $this->getToggles( array(
871 'editsection',
872 'editsectiononrightclick',
873 'editondblclick',
874 'editwidth',
875 'showtoolbar',
876 'previewonfirst',
877 'previewontop',
878 'minordefault',
879 'externaleditor',
880 'externaldiff',
881 $wgLivePreview ? 'uselivepreview' : false,
882 'forceeditsummary',
883 ) ) . '</fieldset>'
884 );
885
886 # Recent changes
887 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-rc' ) . '</legend>' );
888
889 $rc = '<table><tr>';
890 $rc .= '<td>' . Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) . '</td>';
891 $rc .= '<td>' . Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . '</td>';
892 $rc .= '</tr><tr>';
893 $rc .= '<td>' . Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) . '</td>';
894 $rc .= '<td>' . Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) . '</td>';
895 $rc .= '</tr></table>';
896 $wgOut->addHtml( $rc );
897
898 $wgOut->addHtml( '<br />' );
899
900 $toggles[] = 'hideminor';
901 if( $wgRCShowWatchingUsers )
902 $toggles[] = 'shownumberswatching';
903 $toggles[] = 'usenewrc';
904 $wgOut->addHtml( $this->getToggles( $toggles ) );
905
906 $wgOut->addHtml( '</fieldset>' );
907
908 # Watchlist
909 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
910
911 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) );
912 $wgOut->addHtml( '<br /><br />' );
913
914 $wgOut->addHtml( $this->getToggle( 'extendwatchlist' ) );
915 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) );
916 $wgOut->addHtml( '<br /><br />' );
917
918 $wgOut->addHtml( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'watchlisthideminor' ) ) );
919
920 if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) )
921 $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
922 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
923 if( $wgUser->isAllowed( $action ) )
924 $wgOut->addHtml( $this->getToggle( $toggle ) );
925 }
926 $this->mUsedToggles['watchcreations'] = true;
927 $this->mUsedToggles['watchdefault'] = true;
928 $this->mUsedToggles['watchmoves'] = true;
929 $this->mUsedToggles['watchdeletion'] = true;
930
931 $wgOut->addHtml( '</fieldset>' );
932
933 # Search
934 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
935 $this->addRow(
936 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
937 wfInput( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
938 ) .
939 $this->addRow(
940 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
941 wfInput( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
942 ) .
943 $this->addRow(
944 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
945 wfInput( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
946 ) .
947 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
948
949 # Misc
950 #
951 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
952 $wgOut->addHTML( wfInputLabel( wfMsg( 'stubthreshold' ),
953 'wpStubs', 'wpStubs', 6, $this->mStubs ) );
954 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
955 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
956 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
957 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
958 $uopt = $wgUser->getOption("underline");
959 $s0 = $uopt == 0 ? ' selected="selected"' : '';
960 $s1 = $uopt == 1 ? ' selected="selected"' : '';
961 $s2 = $uopt == 2 ? ' selected="selected"' : '';
962 $wgOut->addHTML("
963 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
964 <select name='wpOpunderline' id='wpOpunderline'>
965 <option value=\"0\"$s0>$msgUnderlinenever</option>
966 <option value=\"1\"$s1>$msgUnderlinealways</option>
967 <option value=\"2\"$s2>$msgUnderlinedefault</option>
968 </select></p></div>");
969
970 foreach ( $togs as $tname ) {
971 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
972 $wgOut->addHTML( $this->getToggle( $tname ) );
973 }
974 }
975 $wgOut->addHTML( '</fieldset>' );
976
977 $token = $wgUser->editToken();
978 $skin = $wgUser->getSkin();
979 $wgOut->addHTML( "
980 <div id='prefsubmit'>
981 <div>
982 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
983 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
984 </div>
985
986 </div>
987
988 <input type='hidden' name='wpEditToken' value='{$token}' />
989 </div></form>\n" );
990
991 $wgOut->addHtml( Xml::tags( 'div', array( 'class' => "prefcache" ),
992 wfMsgExt( 'clearyourcache', 'parseinline' ) )
993 );
994
995 }
996 }
997 ?>