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