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