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