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