From 72e90545454c0e014318fa3c81658e035aac58c1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 10 Jun 2009 13:00:47 +0200 Subject: applying patch to version 1.15.0 --- includes/specials/SpecialPreferences.php | 183 ++++++++++++++++++++++++------- 1 file changed, 141 insertions(+), 42 deletions(-) (limited to 'includes/specials/SpecialPreferences.php') diff --git a/includes/specials/SpecialPreferences.php b/includes/specials/SpecialPreferences.php index ca2236ee..f4a42ef4 100644 --- a/includes/specials/SpecialPreferences.php +++ b/includes/specials/SpecialPreferences.php @@ -26,13 +26,13 @@ class PreferencesForm { var $mUserLanguage, $mUserVariant; var $mSearch, $mRecent, $mRecentDays, $mTimeZone, $mHourDiff, $mSearchLines, $mSearchChars, $mAction; var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize; - var $mUnderline, $mWatchlistEdits; + var $mUnderline, $mWatchlistEdits, $mGender; /** * Constructor * Load some values */ - function PreferencesForm( &$request ) { + function __construct( &$request ) { global $wgContLang, $wgUser, $wgAllowRealName; $this->mQuickbar = $request->getVal( 'wpQuickbar' ); @@ -60,11 +60,13 @@ class PreferencesForm { $this->mUnderline = $request->getInt( 'wpOpunderline' ); $this->mAction = $request->getVal( 'action' ); $this->mReset = $request->getCheck( 'wpReset' ); + $this->mRestoreprefs = $request->getCheck( 'wpRestore' ); $this->mPosted = $request->wasPosted(); $this->mSuccess = $request->getCheck( 'success' ); $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' ); $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' ); $this->mDisableMWSuggest = $request->getCheck( 'wpDisableMWSuggest' ); + $this->mGender = $request->getVal( 'wpGender' ); $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) && $this->mPosted && @@ -117,6 +119,8 @@ class PreferencesForm { $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) ); } else if ( $this->mSaveprefs ) { $this->savePreferences(); + } else if ( $this->mRestoreprefs ) { + $this->restorePreferences(); } else { $this->resetPrefs(); $this->mainPrefsForm( '' ); @@ -204,6 +208,15 @@ class PreferencesForm { } } + function validateGender( $val ) { + $valid = array( 'male', 'female', 'unknown' ); + if ( in_array($val, $valid) ) { + return $val; + } else { + return User::getDefaultOption( 'gender' ); + } + } + /** * @access private */ @@ -269,6 +282,7 @@ class PreferencesForm { $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) ); $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) ); $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest ); + $wgUser->setOption( 'gender', $this->validateGender( $this->mGender ) ); # Set search namespace options foreach( $this->mSearchNs as $i => $value ) { @@ -420,6 +434,7 @@ class PreferencesForm { $this->mUnderline = $wgUser->getOption( 'underline' ); $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' ); $this->mDisableMWSuggest = $wgUser->getBoolOption( 'disablesuggest' ); + $this->mGender = $wgUser->getOption( 'gender' ); $togs = User::getToggles(); foreach ( $togs as $tname ) { @@ -435,6 +450,18 @@ class PreferencesForm { wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) ); } + + /** + * @access private + */ + function restorePreferences() { + global $wgUser, $wgOut; + $wgUser->restoreOptions(); + $wgUser->setCookies(); + $wgUser->saveSettings(); + $title = SpecialPage::getTitleFor( 'Preferences' ); + $wgOut->redirect( $title->getFullURL( 'success' ) ); + } /** * @access private @@ -647,12 +674,12 @@ class PreferencesForm { $userInformationHtml = $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) . - $this->tableRow( wfMsgHtml( 'uid' ), $wgLang->formatNum( htmlspecialchars( $wgUser->getId() ) ) ). + $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getId() ) ) . $this->tableRow( wfMsgExt( 'prefs-memberingroups', array( 'parseinline' ), count( $userEffectiveGroupsArray ) ), $wgLang->commaList( $userEffectiveGroupsArray ) . - '
(' . implode( ' | ', $toolLinks ) . ')' + '
(' . $wgLang->pipeList( $toolLinks ) . ')' ) . $this->tableRow( @@ -720,7 +747,22 @@ class PreferencesForm { $this->tableRow( ' ', $this->getToggle( 'fancysig' ) ) ); - list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage ); + $gender = new XMLSelect( 'wpGender', 'wpGender', $this->mGender ); + $gender->addOption( wfMsg( 'gender-unknown' ), 'unknown' ); + $gender->addOption( wfMsg( 'gender-male' ), 'male' ); + $gender->addOption( wfMsg( 'gender-female' ), 'female' ); + + $wgOut->addHTML( + $this->tableRow( + Xml::label( wfMsg( 'yourgender' ), 'wpGender' ), + $gender->getHTML(), + Xml::tags( 'div', array( 'class' => 'prefsectiontip' ), + wfMsgExt( 'prefs-help-gender', 'parseinline' ) + ) + ) + ); + + list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage, false ); $wgOut->addHTML( $this->tableRow( $lsLabel, $lsSelect ) ); @@ -849,13 +891,26 @@ class PreferencesForm { } } asort($validSkinNames); - foreach ($validSkinNames as $skinkey => $sn ) { + foreach( $validSkinNames as $skinkey => $sn ) { $checked = $skinkey == $this->mSkin ? ' checked="checked"' : ''; $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) ); $previewlink = "($previewtext)"; + $extraLinks = ''; + global $wgAllowUserCss, $wgAllowUserJs; + if( $wgAllowUserCss ) { + $cssPage = Title::makeTitleSafe( NS_USER, $wgUser->getName().'/'.$skinkey.'.css' ); + $customCSS = $sk->makeLinkObj( $cssPage, wfMsgExt('prefs-custom-css', array() ) ); + $extraLinks .= " ($customCSS)"; + } + if( $wgAllowUserJs ) { + $jsPage = Title::makeTitleSafe( NS_USER, $wgUser->getName().'/'.$skinkey.'.js' ); + $customJS = $sk->makeLinkObj( $jsPage, wfMsgHtml('prefs-custom-js') ); + $extraLinks .= " ($customJS)"; + } if( $skinkey == $wgDefaultSkin ) $sn .= ' (' . wfMsg( 'default' ) . ')'; - $wgOut->addHTML( " $previewlink
\n" ); + $wgOut->addHTML( " + $previewlink{$extraLinks}
\n" ); } $wgOut->addHTML( "\n\n" ); } @@ -972,26 +1027,54 @@ class PreferencesForm { 'onchange' => 'javascript:updateTimezoneSelection(false)' ) ); $opt .= Xml::option( wfMsg( 'timezoneuseserverdefault' ), "System|$wgLocalTZoffset", $this->mTimeZone === "System|$wgLocalTZoffset" ); $opt .= Xml::option( wfMsg( 'timezoneuseoffset' ), 'Offset', $this->mTimeZone === 'Offset' ); + if ( function_exists( 'timezone_identifiers_list' ) ) { - $optgroup = ''; + # Read timezone list $tzs = timezone_identifiers_list(); sort( $tzs ); - $selZone = explode( '|', $this->mTimeZone, 3); + + # Precache localized region names + $tzRegions = array(); + $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' ); + $tzRegions['America'] = wfMsg( 'timezoneregion-america' ); + $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' ); + $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' ); + $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' ); + $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' ); + $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' ); + $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' ); + $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' ); + $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' ); + asort( $tzRegions ); + + $selZone = explode( '|', $this->mTimeZone, 3 ); $selZone = ( $selZone[0] == 'ZoneInfo' ) ? $selZone[2] : null; $now = date_create( 'now' ); + $optgroup = ''; + foreach ( $tzs as $tz ) { $z = explode( '/', $tz, 2 ); + # timezone_identifiers_list() returns a number of # backwards-compatibility entries. This filters them out of the # list presented to the user. - if ( count( $z ) != 2 || !in_array( $z[0], array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' ) ) ) continue; + if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) ) + continue; + + # Localize region + $z[0] = $tzRegions[$z[0]]; + + # Create region groups if ( $optgroup != $z[0] ) { - if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' ); + if ( $optgroup !== '' ) { + $opt .= Xml::closeElement( 'optgroup' ); + } $optgroup = $z[0]; - $opt .= Xml::openElement( 'optgroup', array( 'label' => $z[0] ) ); + $opt .= Xml::openElement( 'optgroup', array( 'label' => $z[0] ) ) . "\n"; } + $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 ); - $opt .= Xml::option( str_replace( '_', ' ', $tz ), "ZoneInfo|$minDiff|$tz", $selZone === $tz, array( 'label' => $z[1] ) ); + $opt .= Xml::option( str_replace( '_', ' ', $z[0] . '/' . $z[1] ), "ZoneInfo|$minDiff|$tz", $selZone === $tz, array( 'label' => $z[1] ) ) . "\n"; } if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' ); } @@ -1052,7 +1135,7 @@ class PreferencesForm { $wgOut->addHTML( Xml::closeElement( 'fieldset' ) ); # Recent changes - global $wgRCMaxAge; + global $wgRCMaxAge, $wgUseRCPatrol; $wgOut->addHTML( Xml::fieldset( wfMsg( 'prefs-rc' ) ) . Xml::openElement( 'table' ) . @@ -1078,8 +1161,11 @@ class PreferencesForm { ); $toggles[] = 'hideminor'; - if( $wgRCShowWatchingUsers ) - $toggles[] = 'shownumberswatching'; + if( $wgUseRCPatrol ) { + $toggles[] = 'hidepatrolled'; + $toggles[] = 'newpageshidepatrolled'; + } + if( $wgRCShowWatchingUsers ) $toggles[] = 'shownumberswatching'; $toggles[] = 'usenewrc'; $wgOut->addHTML( @@ -1088,6 +1174,10 @@ class PreferencesForm { ); # Watchlist + $watchlistToggles = array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown', + 'watchlisthideanons', 'watchlisthideliu' ); + if( $wgUseRCPatrol ) $watchlistToggles[] = 'watchlisthidepatrolled'; + $wgOut->addHTML( Xml::fieldset( wfMsg( 'prefs-watchlist' ) ) . Xml::inputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) . ' ' . @@ -1097,7 +1187,7 @@ class PreferencesForm { Xml::inputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) . ' ' . wfMsgHTML( 'prefs-watchlist-edits-max' ) . '

' . - $this->getToggles( array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown', 'watchlisthideanons', 'watchlisthideliu' ) ) + $this->getToggles( $watchlistToggles ) ); if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) ) { @@ -1156,25 +1246,34 @@ class PreferencesForm { # Misc # - $wgOut->addHTML('
' . wfMsg('prefs-misc') . ''); - $wgOut->addHTML( ' ' ); - $wgOut->addHTML( Xml::input( 'wpStubs', 6, $this->mStubs, array( 'id' => 'wpStubs' ) ) ); - $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) ); - $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) ); - $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) ); - $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) ); - $uopt = $wgUser->getOption("underline"); - $s0 = $uopt == 0 ? ' selected="selected"' : ''; - $s1 = $uopt == 1 ? ' selected="selected"' : ''; - $s2 = $uopt == 2 ? ' selected="selected"' : ''; - $wgOut->addHTML(" -

-

"); + $uopt = $wgUser->getOption( 'underline' ); + $wgOut->addHTML( + Xml::fieldset( wfMsg( 'prefs-misc' ) ) . + Xml::openElement( 'table' ) . + ' + ' . + // Xml::label() cannot be used because 'stub-threshold' contains plain HTML + Xml::tags( 'label', array( 'for' => 'wpStubs' ), wfMsg( 'stub-threshold' ) ) . + ' + ' . + Xml::input( 'wpStubs', 6, $this->mStubs, array( 'id' => 'wpStubs' ) ) . + ' + + ' . + Xml::label( wfMsg( 'tog-underline' ), 'wpOpunderline' ) . + ' + ' . + Xml::openElement( 'select', array( 'id' => 'wpOpunderline', 'name' => 'wpOpunderline' ) ) . + Xml::option( wfMsg ( 'underline-never' ), '0', $uopt == 0 ) . + Xml::option( wfMsg ( 'underline-always' ), '1', $uopt == 1 ) . + Xml::option( wfMsg ( 'underline-default' ), '2', $uopt == 2 ) . + Xml::closeElement( 'select' ) . + ' + ' . + Xml::closeElement( 'table' ) + ); + # And now the rest = Misc. foreach ( $togs as $tname ) { if( !array_key_exists( $tname, $this->mUsedToggles ) ) { if( $tname == 'norollbackdiff' && $wgUser->isAllowed( 'rollback' ) ) @@ -1190,14 +1289,14 @@ class PreferencesForm { $token = htmlspecialchars( $wgUser->editToken() ); $skin = $wgUser->getSkin(); + $rtl = $wgContLang->isRTL() ? 'left' : 'right'; $wgOut->addHTML( " -
-
- tooltipAndAccesskey('save')." /> - -
- -
+ + + +
tooltipAndAccesskey('save')." /> +
\n" ); -- cgit v1.2.3-54-g00ecf