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