Partial revert of r32982; old Title method is fine here
[lhc/web/wiklou.git] / includes / SpecialPreferences.php
1 <?php
2 /**
3 * Hold things related to displaying and saving user preferences.
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 * Entry point that create the "Preferences" object
9 */
10 function wfSpecialPreferences() {
11 global $wgRequest;
12
13 $form = new PreferencesForm( $wgRequest );
14 $form->execute();
15 }
16
17 /**
18 * Preferences form handling
19 * This object will show the preferences form and can save it as well.
20 * @addtogroup SpecialPage
21 */
22 class PreferencesForm {
23 var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
24 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
25 var $mUserLanguage, $mUserVariant;
26 var $mSearch, $mRecent, $mRecentDays, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
27 var $mReset, $mPosted, $mToggles, $mUseAjaxSearch, $mSearchNs, $mRealName, $mImageSize;
28 var $mUnderline, $mWatchlistEdits;
29
30 /**
31 * Constructor
32 * Load some values
33 */
34 function PreferencesForm( &$request ) {
35 global $wgContLang, $wgUser, $wgAllowRealName;
36
37 $this->mQuickbar = $request->getVal( 'wpQuickbar' );
38 $this->mOldpass = $request->getVal( 'wpOldpass' );
39 $this->mNewpass = $request->getVal( 'wpNewpass' );
40 $this->mRetypePass =$request->getVal( 'wpRetypePass' );
41 $this->mStubs = $request->getVal( 'wpStubs' );
42 $this->mRows = $request->getVal( 'wpRows' );
43 $this->mCols = $request->getVal( 'wpCols' );
44 $this->mSkin = $request->getVal( 'wpSkin' );
45 $this->mMath = $request->getVal( 'wpMath' );
46 $this->mDate = $request->getVal( 'wpDate' );
47 $this->mUserEmail = $request->getVal( 'wpUserEmail' );
48 $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : '';
49 $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1;
50 $this->mNick = $request->getVal( 'wpNick' );
51 $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
52 $this->mUserVariant = $request->getVal( 'wpUserVariant' );
53 $this->mSearch = $request->getVal( 'wpSearch' );
54 $this->mRecent = $request->getVal( 'wpRecent' );
55 $this->mRecentDays = $request->getVal( 'wpRecentDays' );
56 $this->mHourDiff = $request->getVal( 'wpHourDiff' );
57 $this->mSearchLines = $request->getVal( 'wpSearchLines' );
58 $this->mSearchChars = $request->getVal( 'wpSearchChars' );
59 $this->mImageSize = $request->getVal( 'wpImageSize' );
60 $this->mThumbSize = $request->getInt( 'wpThumbSize' );
61 $this->mUnderline = $request->getInt( 'wpOpunderline' );
62 $this->mAction = $request->getVal( 'action' );
63 $this->mReset = $request->getCheck( 'wpReset' );
64 $this->mPosted = $request->wasPosted();
65 $this->mSuccess = $request->getCheck( 'success' );
66 $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
67 $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' );
68 $this->mUseAjaxSearch = $request->getCheck( 'wpUseAjaxSearch' );
69
70 $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
71 $this->mPosted &&
72 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
73
74 # User toggles (the big ugly unsorted list of checkboxes)
75 $this->mToggles = array();
76 if ( $this->mPosted ) {
77 $togs = User::getToggles();
78 foreach ( $togs as $tname ) {
79 $this->mToggles[$tname] = $request->getCheck( "wpOp$tname" ) ? 1 : 0;
80 }
81 }
82
83 $this->mUsedToggles = array();
84
85 # Search namespace options
86 # Note: namespaces don't necessarily have consecutive keys
87 $this->mSearchNs = array();
88 if ( $this->mPosted ) {
89 $namespaces = $wgContLang->getNamespaces();
90 foreach ( $namespaces as $i => $namespace ) {
91 if ( $i >= 0 ) {
92 $this->mSearchNs[$i] = $request->getCheck( "wpNs$i" ) ? 1 : 0;
93 }
94 }
95 }
96
97 # Validate language
98 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
99 $this->mUserLanguage = 'nolanguage';
100 }
101
102 wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
103 }
104
105 function execute() {
106 global $wgUser, $wgOut;
107
108 if ( $wgUser->isAnon() ) {
109 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
110 return;
111 }
112 if ( wfReadOnly() ) {
113 $wgOut->readOnlyPage();
114 return;
115 }
116 if ( $this->mReset ) {
117 $this->resetPrefs();
118 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
119 } else if ( $this->mSaveprefs ) {
120 $this->savePreferences();
121 } else {
122 $this->resetPrefs();
123 $this->mainPrefsForm( '' );
124 }
125 }
126 /**
127 * @access private
128 */
129 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
130 $val = intval($val);
131 $val = min($val, $max);
132 $val = max($val, $min);
133 return $val;
134 }
135
136 /**
137 * @access private
138 */
139 function validateFloat( &$val, $min, $max=0x7fffffff ) {
140 $val = floatval( $val );
141 $val = min( $val, $max );
142 $val = max( $val, $min );
143 return( $val );
144 }
145
146 /**
147 * @access private
148 */
149 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
150 $val = trim($val);
151 if($val === '') {
152 return $val;
153 } else {
154 return $this->validateInt( $val, $min, $max );
155 }
156 }
157
158 /**
159 * @access private
160 */
161 function validateDate( $val ) {
162 global $wgLang, $wgContLang;
163 if ( $val !== false && (
164 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
165 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
166 {
167 return $val;
168 } else {
169 return $wgLang->getDefaultDateFormat();
170 }
171 }
172
173 /**
174 * Used to validate the user inputed timezone before saving it as
175 * 'timecorrection', will return '00:00' if fed bogus data.
176 * Note: It's not a 100% correct implementation timezone-wise, it will
177 * accept stuff like '14:30',
178 * @access private
179 * @param string $s the user input
180 * @return string
181 */
182 function validateTimeZone( $s ) {
183 if ( $s !== '' ) {
184 if ( strpos( $s, ':' ) ) {
185 # HH:MM
186 $array = explode( ':' , $s );
187 $hour = intval( $array[0] );
188 $minute = intval( $array[1] );
189 } else {
190 $minute = intval( $s * 60 );
191 $hour = intval( $minute / 60 );
192 $minute = abs( $minute ) % 60;
193 }
194 # Max is +14:00 and min is -12:00, see:
195 # http://en.wikipedia.org/wiki/Timezone
196 $hour = min( $hour, 14 );
197 $hour = max( $hour, -12 );
198 $minute = min( $minute, 59 );
199 $minute = max( $minute, 0 );
200 $s = sprintf( "%02d:%02d", $hour, $minute );
201 }
202 return $s;
203 }
204
205 /**
206 * @access private
207 */
208 function savePreferences() {
209 global $wgUser, $wgOut, $wgParser;
210 global $wgEnableUserEmail, $wgEnableEmail;
211 global $wgEmailAuthentication, $wgRCMaxAge;
212 global $wgAuth, $wgEmailConfirmToEdit;
213
214
215 if ( '' != $this->mNewpass && $wgAuth->allowPasswordChange() ) {
216 if ( $this->mNewpass != $this->mRetypePass ) {
217 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass, 'badretype' ) );
218 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
219 return;
220 }
221
222 if (!$wgUser->checkPassword( $this->mOldpass )) {
223 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass, 'wrongpassword' ) );
224 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
225 return;
226 }
227
228 try {
229 $wgUser->setPassword( $this->mNewpass );
230 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass, 'success' ) );
231 $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
232 } catch( PasswordError $e ) {
233 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass, 'error' ) );
234 $this->mainPrefsForm( 'error', $e->getMessage() );
235 return;
236 }
237 }
238 $wgUser->setRealName( $this->mRealName );
239
240 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
241 $needRedirect = true;
242 } else {
243 $needRedirect = false;
244 }
245
246 # Validate the signature and clean it up as needed
247 global $wgMaxSigChars;
248 if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
249 global $wgLang;
250 $this->mainPrefsForm( 'error',
251 wfMsg( 'badsiglength', $wgLang->formatNum( $wgMaxSigChars ) ) );
252 return;
253 } elseif( $this->mToggles['fancysig'] ) {
254 if( $wgParser->validateSig( $this->mNick ) !== false ) {
255 $this->mNick = $wgParser->cleanSig( $this->mNick );
256 } else {
257 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
258 return;
259 }
260 } else {
261 // When no fancy sig used, make sure ~{3,5} get removed.
262 $this->mNick = $wgParser->cleanSigInSig( $this->mNick );
263 }
264
265 $wgUser->setOption( 'language', $this->mUserLanguage );
266 $wgUser->setOption( 'variant', $this->mUserVariant );
267 $wgUser->setOption( 'nickname', $this->mNick );
268 $wgUser->setOption( 'quickbar', $this->mQuickbar );
269 $wgUser->setOption( 'skin', $this->mSkin );
270 global $wgUseTeX;
271 if( $wgUseTeX ) {
272 $wgUser->setOption( 'math', $this->mMath );
273 }
274 $wgUser->setOption( 'date', $this->validateDate( $this->mDate ) );
275 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
276 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
277 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
278 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
279 $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays, 1, ceil($wgRCMaxAge / (3600*24))));
280 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits, 0, 1000 ) );
281 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
282 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
283 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
284 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
285 $wgUser->setOption( 'imagesize', $this->mImageSize );
286 $wgUser->setOption( 'thumbsize', $this->mThumbSize );
287 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
288 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) );
289 $wgUser->setOption( 'ajaxsearch', $this->mUseAjaxSearch );
290
291 # Set search namespace options
292 foreach( $this->mSearchNs as $i => $value ) {
293 $wgUser->setOption( "searchNs{$i}", $value );
294 }
295
296 if( $wgEnableEmail && $wgEnableUserEmail ) {
297 $wgUser->setOption( 'disablemail', $this->mEmailFlag );
298 }
299
300 # Set user toggles
301 foreach ( $this->mToggles as $tname => $tvalue ) {
302 $wgUser->setOption( $tname, $tvalue );
303 }
304
305 $error = false;
306 if( $wgEnableEmail ) {
307 $newadr = $this->mUserEmail;
308 $oldadr = $wgUser->getEmail();
309 if( ($newadr != '') && ($newadr != $oldadr) ) {
310 # the user has supplied a new email address on the login page
311 if( $wgUser->isValidEmailAddr( $newadr ) ) {
312 $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
313 $wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
314 if ($wgEmailAuthentication) {
315 # Mail a temporary password to the dirty address.
316 # User can come back through the confirmation URL to re-enable email.
317 $result = $wgUser->sendConfirmationMail();
318 if( WikiError::isError( $result ) ) {
319 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
320 } else {
321 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
322 }
323 }
324 } else {
325 $error = wfMsg( 'invalidemailaddress' );
326 }
327 } else {
328 if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
329 $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
330 return;
331 }
332 $wgUser->setEmail( $this->mUserEmail );
333 }
334 if( $oldadr != $newadr ) {
335 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
336 }
337 }
338
339 if (!$wgAuth->updateExternalDB($wgUser)) {
340 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
341 return;
342 }
343
344 $msg = '';
345 if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg ) ) ) {
346 $this->mainPrefsForm( 'error', $msg );
347 return;
348 }
349
350 $wgUser->setCookies();
351 $wgUser->saveSettings();
352
353 if( $needRedirect && $error === false ) {
354 $title = SpecialPage::getTitleFor( 'Preferences' );
355 $wgOut->redirect($title->getFullURL('success'));
356 return;
357 }
358
359 $wgOut->parserOptions( ParserOptions::newFromUser( $wgUser ) );
360 $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
361 }
362
363 /**
364 * @access private
365 */
366 function resetPrefs() {
367 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName;
368
369 $this->mOldpass = $this->mNewpass = $this->mRetypePass = '';
370 $this->mUserEmail = $wgUser->getEmail();
371 $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
372 $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
373
374 # language value might be blank, default to content language
375 $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode );
376
377 $this->mUserVariant = $wgUser->getOption( 'variant');
378 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
379 $this->mNick = $wgUser->getOption( 'nickname' );
380
381 $this->mQuickbar = $wgUser->getOption( 'quickbar' );
382 $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
383 $this->mMath = $wgUser->getOption( 'math' );
384 $this->mDate = $wgUser->getDatePreference();
385 $this->mRows = $wgUser->getOption( 'rows' );
386 $this->mCols = $wgUser->getOption( 'cols' );
387 $this->mStubs = $wgUser->getOption( 'stubthreshold' );
388 $this->mHourDiff = $wgUser->getOption( 'timecorrection' );
389 $this->mSearch = $wgUser->getOption( 'searchlimit' );
390 $this->mSearchLines = $wgUser->getOption( 'contextlines' );
391 $this->mSearchChars = $wgUser->getOption( 'contextchars' );
392 $this->mImageSize = $wgUser->getOption( 'imagesize' );
393 $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
394 $this->mRecent = $wgUser->getOption( 'rclimit' );
395 $this->mRecentDays = $wgUser->getOption( 'rcdays' );
396 $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
397 $this->mUnderline = $wgUser->getOption( 'underline' );
398 $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
399 $this->mUseAjaxSearch = $wgUser->getBoolOption( 'ajaxsearch' );
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, $wgAjaxSearch;
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->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
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 $ajaxsearch = $wgAjaxSearch ?
976 $this->addRow(
977 wfLabel( wfMsg( 'useajaxsearch' ), 'wpUseAjaxSearch' ),
978 wfCheck( 'wpUseAjaxSearch', $this->mUseAjaxSearch, array( 'id' => 'wpUseAjaxSearch' ) )
979 ) : '';
980 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
981 $ajaxsearch .
982 $this->addRow(
983 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
984 wfInput( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
985 ) .
986 $this->addRow(
987 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
988 wfInput( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
989 ) .
990 $this->addRow(
991 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
992 wfInput( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
993 ) .
994 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
995
996 # Misc
997 #
998 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
999 $wgOut->addHtml( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label>&nbsp;' );
1000 $wgOut->addHtml( Xml::input( 'wpStubs', 6, $this->mStubs, array( 'id' => 'wpStubs' ) ) );
1001 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1002 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1003 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1004 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1005 $uopt = $wgUser->getOption("underline");
1006 $s0 = $uopt == 0 ? ' selected="selected"' : '';
1007 $s1 = $uopt == 1 ? ' selected="selected"' : '';
1008 $s2 = $uopt == 2 ? ' selected="selected"' : '';
1009 $wgOut->addHTML("
1010 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1011 <select name='wpOpunderline' id='wpOpunderline'>
1012 <option value=\"0\"$s0>$msgUnderlinenever</option>
1013 <option value=\"1\"$s1>$msgUnderlinealways</option>
1014 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1015 </select></p></div>");
1016
1017 foreach ( $togs as $tname ) {
1018 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
1019 $wgOut->addHTML( $this->getToggle( $tname ) );
1020 }
1021 }
1022 $wgOut->addHTML( '</fieldset>' );
1023
1024 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1025
1026 $token = htmlspecialchars( $wgUser->editToken() );
1027 $skin = $wgUser->getSkin();
1028 $wgOut->addHTML( "
1029 <div id='prefsubmit'>
1030 <div>
1031 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
1032 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
1033 </div>
1034
1035 </div>
1036
1037 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1038 </div></form>\n" );
1039
1040 $wgOut->addHtml( Xml::tags( 'div', array( 'class' => "prefcache" ),
1041 wfMsgExt( 'clearyourcache', 'parseinline' ) )
1042 );
1043
1044 }
1045 }
1046