e8bfc3286a7d7a70a5a7eb80747167435e7869be
2 function wfSpecialPreferences()
6 $form = new PreferencesForm( $wgRequest );
10 class PreferencesForm
{
11 var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
12 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
13 var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
14 var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName;
16 function PreferencesForm( &$request ) {
17 global $wgLang, $wgAllowRealName;
19 $this->mQuickbar
= $request->getVal( 'wpQuickbar' );
20 $this->mOldpass
= $request->getVal( 'wpOldpass' );
21 $this->mNewpass
= $request->getVal( 'wpNewpass' );
22 $this->mRetypePass
=$request->getVal( 'wpRetypePass' );
23 $this->mStubs
= $request->getVal( 'wpStubs' );
24 $this->mRows
= $request->getVal( 'wpRows' );
25 $this->mCols
= $request->getVal( 'wpCols' );
26 $this->mSkin
= $request->getVal( 'wpSkin' );
27 $this->mMath
= $request->getVal( 'wpMath' );
28 $this->mDate
= $request->getVal( 'wpDate' );
29 $this->mUserEmail
= $request->getVal( 'wpUserEmail' );
30 $this->mRealName
= ($wgAllowRealName) ?
$request->getVal( 'wpRealName' ) : '';
31 $this->mEmailFlag
= $request->getCheck( 'wpEmailFlag' ) ?
1 : 0;
32 $this->mNick
= $request->getVal( 'wpNick' );
33 $this->mSearch
= $request->getVal( 'wpSearch' );
34 $this->mRecent
= $request->getVal( 'wpRecent' );
35 $this->mHourDiff
= $request->getVal( 'wpHourDiff' );
36 $this->mSearchLines
= $request->getVal( 'wpSearchLines' );
37 $this->mSearchChars
= $request->getVal( 'wpSearchChars' );
38 $this->mAction
= $request->getVal( 'action' );
39 $this->mReset
= $request->getCheck( 'wpReset' );
40 $this->mPosted
= $request->wasPosted();
41 $this->mSaveprefs
= $request->getCheck( 'wpSaveprefs' ) && $this->mPosted
;
43 # User toggles (the big ugly unsorted list of checkboxes)
44 $this->mToggles
= array();
45 if ( $this->mPosted
) {
46 $togs = $wgLang->getUserToggles();
47 foreach ( $togs as $tname ) {
48 $this->mToggles
[$tname] = $request->getCheck( "wpOp$tname" ) ?
1 : 0;
52 $this->mUsedToggles
= array();
54 # Search namespace options
55 # Note: namespaces don't necessarily have consecutive keys
56 $this->mSearchNs
= array();
57 if ( $this->mPosted
) {
58 $namespaces = $wgLang->getNamespaces();
59 foreach ( $namespaces as $i => $namespace ) {
61 $this->mSearchNs
[$i] = $request->getCheck( "wpNs$i" ) ?
1 : 0;
68 global $wgUser, $wgOut, $wgUseDynamicDates;
70 if ( 0 == $wgUser->getID() ) {
71 $wgOut->errorpage( "prefsnologin", "prefsnologintext" );
75 $wgOut->readOnlyPage();
78 if ( $this->mReset
) {
80 $this->mainPrefsForm( wfMsg( "prefsreset" ) );
81 } else if ( $this->mSaveprefs
) {
82 $this->savePreferences();
85 $this->mainPrefsForm( "" );
89 /* private */ function validateInt( &$val, $min=0, $max=0x7fffffff ) {
91 $val = min($val, $max);
92 $val = max($val, $min);
96 /* private */ function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
101 return $this->validateInt( $val, $min, $max );
105 /* private */ function validateTimeZone( $s )
109 if ( strpos( $s, ":" ) ) {
111 $array = explode( ":" , $s );
112 $hour = intval( $array[0] );
113 $minute = intval( $array[1] );
115 $minute = intval( $s * 60 );
116 $hour = intval( $minute / 60 );
117 $minute = abs( $minute ) %
60;
119 $hour = min( $hour, 15 );
120 $hour = max( $hour, -15 );
121 $minute = min( $minute, 59 );
122 $minute = max( $minute, 0 );
123 $s = sprintf( "%02d:%02d", $hour, $minute );
128 /* private */ function savePreferences()
130 global $wgUser, $wgLang, $wgDeferredUpdateList, $wgOut;
132 if ( "" != $this->mNewpass
) {
133 if ( $this->mNewpass
!= $this->mRetypePass
) {
134 $this->mainPrefsForm( wfMsg( "badretype" ) );
138 if (!$wgUser->checkPassword( $this->mOldpass
)) {
139 $this->mainPrefsForm( wfMsg( "wrongpassword" ) );
142 $wgUser->setPassword( $this->mNewpass
);
144 $wgUser->setEmail( $this->mUserEmail
);
145 $wgUser->setRealName( $this->mRealName
);
146 $wgUser->setOption( "nickname", $this->mNick
);
147 $wgUser->setOption( "quickbar", $this->mQuickbar
);
148 $wgUser->setOption( "skin", $this->mSkin
);
149 $wgUser->setOption( "math", $this->mMath
);
150 $wgUser->setOption( "date", $this->mDate
);
151 $wgUser->setOption( "searchlimit", $this->validateIntOrNull( $this->mSearch
) );
152 $wgUser->setOption( "contextlines", $this->validateIntOrNull( $this->mSearchLines
) );
153 $wgUser->setOption( "contextchars", $this->validateIntOrNull( $this->mSearchChars
) );
154 $wgUser->setOption( "rclimit", $this->validateIntOrNull( $this->mRecent
) );
155 $wgUser->setOption( "rows", $this->validateInt( $this->mRows
, 4, 1000 ) );
156 $wgUser->setOption( "cols", $this->validateInt( $this->mCols
, 4, 1000 ) );
157 $wgUser->setOption( "stubthreshold", $this->validateIntOrNull( $this->mStubs
) );
158 $wgUser->setOption( "timecorrection", $this->validateTimeZone( $this->mHourDiff
, -12, 14 ) );
160 # Set search namespace options
161 foreach( $this->mSearchNs
as $i => $value ) {
162 $wgUser->setOption( "searchNs{$i}", $value );
165 $wgUser->setOption( "disablemail", $this->mEmailFlag
);
168 foreach ( $this->mToggles
as $tname => $tvalue ) {
169 $wgUser->setOption( $tname, $tvalue );
171 $wgUser->setCookies();
172 $up = new UserUpdate();
173 array_push( $wgDeferredUpdateList, $up );
174 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
175 $po = ParserOptions
::newFromUser( $wgUser );
176 $this->mainPrefsForm( wfMsg( "savedprefs" ) );
179 /* private */ function resetPrefs()
181 global $wgUser, $wgLang, $wgAllowRealName;
183 $this->mOldpass
= $this->mNewpass
= $this->mRetypePass
= "";
184 $this->mUserEmail
= $wgUser->getEmail();
185 $this->mRealName
= ($wgAllowRealName) ?
$wgUser->getRealName() : '';
186 if ( 1 == $wgUser->getOption( "disablemail" ) ) { $this->mEmailFlag
= 1; }
187 else { $this->mEmailFlag
= 0; }
188 $this->mNick
= $wgUser->getOption( "nickname" );
190 $this->mQuickbar
= $wgUser->getOption( "quickbar" );
191 $this->mSkin
= $wgUser->getOption( "skin" );
192 $this->mMath
= $wgUser->getOption( "math" );
193 $this->mDate
= $wgUser->getOption( "date" );
194 $this->mRows
= $wgUser->getOption( "rows" );
195 $this->mCols
= $wgUser->getOption( "cols" );
196 $this->mStubs
= $wgUser->getOption( "stubthreshold" );
197 $this->mHourDiff
= $wgUser->getOption( "timecorrection" );
198 $this->mSearch
= $wgUser->getOption( "searchlimit" );
199 $this->mSearchLines
= $wgUser->getOption( "contextlines" );
200 $this->mSearchChars
= $wgUser->getOption( "contextchars" );
201 $this->mRecent
= $wgUser->getOption( "rclimit" );
203 $togs = $wgLang->getUserToggles();
204 foreach ( $togs as $tname ) {
205 $ttext = wfMsg("tog-".$tname);
206 $this->mToggles
[$tname] = $wgUser->getOption( $tname );
209 $namespaces = $wgLang->getNamespaces();
210 foreach ( $namespaces as $i => $namespace ) {
212 $this->mSearchNs
[$i] = $wgUser->getOption( "searchNs$i" );
217 /* private */ function namespacesCheckboxes()
219 global $wgLang, $wgUser;
221 # Determine namespace checkboxes
222 $namespaces = $wgLang->getNamespaces();
225 foreach ( $namespaces as $i => $name ) {
226 # Skip special or anything similar
229 if ( $this->mSearchNs
[$i] ) {
230 $checked = ' checked="checked"';
232 $name = str_replace( "_", " ", $namespaces[$i] );
234 $name = wfMsg( "blanknamespace" );
240 $r1 .= "<label><input type='checkbox' value=\"1\" name=\"" .
241 "wpNs$i\"{$checked} />{$name}</label>\n";
249 function getToggle( $tname ) {
250 global $wgUser, $wgLang;
252 $this->mUsedToggles
[$tname] = true;
253 $ttext = $wgLang->getUserToggle( $tname );
255 if ( 1 == $wgUser->getOption( $tname ) ) {
256 $checked = ' checked="checked"';
260 return "<div><input type='checkbox' value=\"1\" "
261 . "id=\"$tname\" name=\"wpOp$tname\"$checked /><label for=\"$tname\">$ttext</label></div>\n";
264 /* private */ function mainPrefsForm( $err )
266 global $wgUser, $wgOut, $wgLang, $wgUseDynamicDates, $wgValidSkinNames;
267 global $wgAllowRealName;
269 $wgOut->setPageTitle( wfMsg( "preferences" ) );
270 $wgOut->setArticleRelated( false );
271 $wgOut->setRobotpolicy( "noindex,nofollow" );
274 $wgOut->addHTML( "<p class='error'>" . htmlspecialchars( $err ) . "</p>\n" );
276 $uname = $wgUser->getName();
277 $uid = $wgUser->getID();
279 $wgOut->addWikiText( wfMsg( "prefslogintext", $uname, $uid ) );
280 $wgOut->addWikiText( wfMsg('clearyourcache'));
282 $qbs = $wgLang->getQuickbarSettings();
283 $skinNames = $wgLang->getSkinNames();
284 $mathopts = $wgLang->getMathNames();
285 $dateopts = $wgLang->getDateFormats();
286 $togs = $wgLang->getUserToggles();
288 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Preferences" );
289 $action = $titleObj->escapeLocalURL();
291 $qb = wfMsg( "qbsettings" );
292 $cp = wfMsg( "changepassword" );
293 $sk = wfMsg( "skin" );
294 $math = wfMsg( "math" );
295 $dateFormat = wfMsg("dateformat");
296 $opw = wfMsg( "oldpassword" );
297 $npw = wfMsg( "newpassword" );
298 $rpw = wfMsg( "retypenew" );
299 $svp = wfMsg( "saveprefs" );
300 $rsp = wfMsg( "resetprefs" );
301 $tbs = wfMsg( "textboxsize" );
302 $tbr = wfMsg( "rows" );
303 $tbc = wfMsg( "columns" );
304 $ltz = wfMsg( "localtime" );
305 $timezone = wfMsg( "timezonelegend" );
306 $tzt = wfMsg( "timezonetext" );
307 $tzo = wfMsg( "timezoneoffset" );
308 $tzGuess = wfMsg( "guesstimezone" );
309 $tzServerTime = wfMsg( "servertime" );
310 $yem = wfMsg( "youremail" );
311 $yrn = ($wgAllowRealName) ?
wfMsg( "yourrealname" ) : '';
312 $emf = wfMsg( "emailflag" );
313 $ynn = wfMsg( "yournick" );
314 $stt = wfMsg ( "stubthreshold" ) ;
315 $srh = wfMsg( "searchresultshead" );
316 $rpp = wfMsg( "resultsperpage" );
317 $scl = wfMsg( "contextlines" );
318 $scc = wfMsg( "contextchars" );
319 $rcc = wfMsg( "recentchangescount" );
320 $dsn = wfMsg( "defaultns" );
322 $wgOut->addHTML( "<form id=\"preferences\" name=\"preferences\" action=\"$action\"
325 # First section: identity
328 $this->mUserEmail
= htmlspecialchars( $this->mUserEmail
);
329 $this->mRealName
= htmlspecialchars( $this->mRealName
);
330 $this->mNick
= htmlspecialchars( $this->mNick
);
331 if ( $this->mEmailFlag
) { $emfc = 'checked="checked"'; }
334 $ps = $this->namespacesCheckboxes();
336 $wgOut->addHTML( "<fieldset>
337 <legend>".wfMsg('prefs-personal')."</legend>");
338 if ($wgAllowRealName) {
339 $wgOut->addHTML("<div><label>$yrn: <input type='text' name=\"wpRealName\" value=\"{$this->mRealName}\" size='20' /></label></div>");
342 <div><label>$yem: <input type='text' name=\"wpUserEmail\" value=\"{$this->mUserEmail}\" size='20' /></label></div>
343 <div><label><input type='checkbox' $emfc value=\"1\" name=\"wpEmailFlag\" /> $emf</label></div>
344 <div><label>$ynn: <input type='text' name=\"wpNick\" value=\"{$this->mNick}\" size='12' /></label></div>\n" );
346 # Fields for changing password
348 $this->mOldpass
= htmlspecialchars( $this->mOldpass
);
349 $this->mNewpass
= htmlspecialchars( $this->mNewpass
);
350 $this->mRetypePass
= htmlspecialchars( $this->mRetypePass
);
352 $wgOut->addHTML( "<fieldset>
354 <div><label>$opw: <input type='password' name=\"wpOldpass\" value=\"{$this->mOldpass}\" size='20' /></label></div>
355 <div><label>$npw: <input type='password' name=\"wpNewpass\" value=\"{$this->mNewpass}\" size='20' /></label></div>
356 <div><label>$rpw: <input type='password' name=\"wpRetypePass\" value=\"{$this->mRetypePass}\" size='20' /></label></div>
357 " . $this->getToggle( "rememberpassword" ) . "
359 <div class='prefsectiontip'>".wfMsg('prefs-help-userdata')."</div>\n</fieldset>\n" );
364 $wgOut->addHtml( "<fieldset>\n<legend>$qb</legend>\n" );
365 for ( $i = 0; $i < count( $qbs ); ++
$i ) {
366 if ( $i == $this->mQuickbar
) { $checked = ' checked="checked"'; }
367 else { $checked = ""; }
368 $wgOut->addHTML( "<div><label><input type='radio' name=\"wpQuickbar\"
369 value=\"$i\"$checked /> {$qbs[$i]}</label></div>\n" );
371 $wgOut->addHtml('<div class="prefsectiontip">'.wfMsg('qbsettingsnote').'</div>');
372 $wgOut->addHtml( "</fieldset>\n\n" );
376 $wgOut->addHTML( "<fieldset>\n<legend>$sk</legend>\n" );
377 # Only show members of $wgValidSkinNames rather than
378 # $skinNames (skins is all skin names from Language.php)
379 foreach ($wgValidSkinNames as $skinkey => $skinname ) {
380 if ( $skinkey == $this->mSkin
) {
381 $checked = ' checked="checked"';
385 if ( isset( $skinNames[$skinkey] ) ) {
386 $sn = $skinNames[$skinkey];
390 $wgOut->addHTML( "<div><label><input type='radio' name=\"wpSkin\"
391 value=\"$skinkey\"$checked /> {$sn}</label></div>\n" );
393 $wgOut->addHTML( "</fieldset>\n\n" );
397 $wgOut->addHTML( "<fieldset>\n<legend>$math</legend>\n" );
398 for ( $i = 0; $i < count( $mathopts ); ++
$i ) {
399 if ( $i == $this->mMath
) { $checked = ' checked="checked"'; }
400 else { $checked = ""; }
401 $wgOut->addHTML( "<div><label><input type='radio' name=\"wpMath\"
402 value=\"$i\"$checked /> ".wfMsg($mathopts[$i])."</label></div>\n" );
404 $wgOut->addHTML( "</fieldset>\n\n" );
408 if ( $wgUseDynamicDates ) {
409 $wgOut->addHTML( "<fieldset>\n<legend>$dateFormat</legend>\n" );
410 for ( $i = 0; $i < count( $dateopts ); ++
$i) {
411 if ( $i == $this->mDate
) {
412 $checked = ' checked="checked"';
416 $wgOut->addHTML( "<div><label><input type='radio' name=\"wpDate\" ".
417 "value=\"$i\"$checked /> {$dateopts[$i]}</label></div>\n" );
419 $wgOut->addHTML( "</fieldset>\n\n");
424 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
425 $nowserver = $wgLang->time( $now, false );
426 $wgOut->addHTML( "<fieldset>
427 <legend>$tbs</legend>\n
429 <label>$tbr: <input type='text' name=\"wpRows\" value=\"{$this->mRows}\" size='6' /></label>
430 <label>$tbc: <input type='text' name=\"wpCols\" value=\"{$this->mCols}\" size='6' /></label>
432 $this->getToggle( "editwidth" ) .
433 $this->getToggle( "showtoolbar" ) .
434 $this->getToggle( "previewontop" ) .
435 $this->getToggle( "watchdefault" ) .
436 $this->getToggle( "minordefault" ) . "
440 <legend>$timezone</legend>
441 <div><b>$tzServerTime:</b> $nowserver</div>
442 <div><b>$ltz:</b> $nowlocal</div>
443 <div><label>$tzo*: <input type='text' name=\"wpHourDiff\" value=\"{$this->mHourDiff}\" size='6' /></label></div>
444 <div><input type=\"button\" value=\"$tzGuess\" onClick=\"javascript:guessTimezone()\" id=\"guesstimezonebutton\" style=\"display:none\" /></div>
445 <div class='prefsectiontip'>* {$tzt}</div>
449 <fieldset><legend>".wfMsg('prefs-rc')."</legend>
450 <div><label>$rcc: <input type='text' name=\"wpRecent\" value=\"$this->mRecent\" size='6' /></label></div>
451 " . $this->getToggle( "hideminor" ) .
452 $this->getToggle( "usenewrc" ) . "
453 <div><label>$stt: <input type='text' name=\"wpStubs\" value=\"$this->mStubs\" size='6' /></label></div>
457 <legend>$srh</legend>
458 <div><label>$rpp: <input type='text' name=\"wpSearch\" value=\"$this->mSearch\" size='6' /></label></div>
459 <div><label>$scl: <input type='text' name=\"wpSearchLines\" value=\"$this->mSearchLines\" size='6' /></label></div>
460 <div><label>$scc: <input type='text' name=\"wpSearchChars\" value=\"$this->mSearchChars\" size='6' /></label></div>
463 <legend>$dsn</legend>
469 # Various checkbox options
471 $wgOut->addHTML("<fieldset><legend>".wfMsg('prefs-misc')."</legend>");
472 foreach ( $togs as $tname ) {
473 if( !array_key_exists( $tname, $this->mUsedToggles
) ) {
474 $wgOut->addHTML( $this->getToggle( $tname ) );
477 $wgOut->addHTML( "</fieldset>\n\n" );
480 <div id='prefsubmit'>
482 <input type='submit' name=\"wpSaveprefs\" value=\"$svp\" accesskey=\"".
483 wfMsg('accesskey-save')."\" title=\"[alt-".wfMsg('accesskey-save')."]\" />
484 <input type='submit' name=\"wpReset\" value=\"$rsp\" />