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