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