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