SpecialMergeHistory: add redirect=no on target parameter on success message
[lhc/web/wiklou.git] / includes / Preferences.php
index 9b0ada8..b3ee207 100644 (file)
@@ -112,26 +112,26 @@ class Preferences {
         * @return array|null
         */
        static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
-               ## Remove preferences that wikis don't want to use
+               # # Remove preferences that wikis don't want to use
                foreach ( $context->getConfig()->get( 'HiddenPrefs' ) as $pref ) {
                        if ( isset( $defaultPreferences[$pref] ) ) {
                                unset( $defaultPreferences[$pref] );
                        }
                }
 
-               ## Make sure that form fields have their parent set. See bug 41337.
+               # # Make sure that form fields have their parent set. See bug 41337.
                $dummyForm = new HTMLForm( array(), $context );
 
                $disable = !$user->isAllowed( 'editmyoptions' );
 
-               ## Prod in defaults from the user
+               $defaultOptions = User::getDefaultOptions();
+               # # Prod in defaults from the user
                foreach ( $defaultPreferences as $name => &$info ) {
                        $prefFromUser = self::getOptionFromUser( $name, $info, $user );
                        if ( $disable && !in_array( $name, self::$saveBlacklist ) ) {
                                $info['disabled'] = 'disabled';
                        }
                        $field = HTMLForm::loadInputFromParameters( $name, $info, $dummyForm ); // For validation
-                       $defaultOptions = User::getDefaultOptions();
                        $globalDefault = isset( $defaultOptions[$name] )
                                ? $defaultOptions[$name]
                                : null;
@@ -211,7 +211,7 @@ class Preferences {
                // retrieving user name for GENDER and misc.
                $userName = $user->getName();
 
-               ## User info #####################################
+               # # User info #####################################
                // Information panel
                $defaultPreferences['username'] = array(
                        'type' => 'info',
@@ -427,7 +427,7 @@ class Preferences {
                        'section' => 'personal/signature'
                );
 
-               ## Email stuff
+               # # Email stuff
 
                if ( $config->get( 'EnableEmail' ) ) {
                        if ( $canViewPrivateInfo ) {
@@ -571,7 +571,7 @@ class Preferences {
         * @return void
         */
        static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Skin #####################################
+               # # Skin #####################################
 
                // Skin selector, if there is at least one valid skin
                $skinOptions = self::generateSkinOptions( $user, $context );
@@ -620,7 +620,7 @@ class Preferences {
         * @param array $defaultPreferences
         */
        static function filesPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Files #####################################
+               # # Files #####################################
                $defaultPreferences['imagesize'] = array(
                        'type' => 'select',
                        'options' => self::getImageSizes( $context ),
@@ -642,7 +642,7 @@ class Preferences {
         * @return void
         */
        static function datetimePreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Date and time #####################################
+               # # Date and time #####################################
                $dateOptions = self::getDateOptions( $context );
                if ( $dateOptions ) {
                        $defaultPreferences['date'] = array(
@@ -715,7 +715,7 @@ class Preferences {
         * @param array $defaultPreferences
         */
        static function renderingPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Diffs ####################################
+               # # Diffs ####################################
                $defaultPreferences['diffonly'] = array(
                        'type' => 'toggle',
                        'section' => 'rendering/diffs',
@@ -727,7 +727,7 @@ class Preferences {
                        'label-message' => 'tog-norollbackdiff',
                );
 
-               ## Page Rendering ##############################
+               # # Page Rendering ##############################
                if ( $context->getConfig()->get( 'AllowUserCssPrefs' ) ) {
                        $defaultPreferences['underline'] = array(
                                'type' => 'select',
@@ -751,7 +751,11 @@ class Preferences {
                        'type' => 'select',
                        'section' => 'rendering/advancedrendering',
                        'options' => $stubThresholdOptions,
-                       'label-raw' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
+                       // This is not a raw HTML message; label-raw is needed for the manual <a></a>
+                       'label-raw' => $context->msg( 'stub-threshold' )->rawParams(
+                               '<a href="#" class="stub">' .
+                               $context->msg( 'stub-threshold-sample-link' )->parse() .
+                               '</a>' )->parse(),
                );
 
                $defaultPreferences['showhiddencats'] = array(
@@ -773,7 +777,7 @@ class Preferences {
         * @param array $defaultPreferences
         */
        static function editingPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               ## Editing #####################################
+               # # Editing #####################################
                $defaultPreferences['editsectiononrightclick'] = array(
                        'type' => 'toggle',
                        'section' => 'editing/advancedediting',
@@ -861,7 +865,7 @@ class Preferences {
        static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) {
                $config = $context->getConfig();
                $rcMaxAge = $config->get( 'RCMaxAge' );
-               ## RecentChanges #####################################
+               # # RecentChanges #####################################
                $defaultPreferences['rcdays'] = array(
                        'type' => 'float',
                        'label-message' => 'recentchangesdays',
@@ -922,7 +926,7 @@ class Preferences {
                $config = $context->getConfig();
                $watchlistdaysMax = ceil( $config->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
 
-               ## Watchlist #####################################
+               # # Watchlist #####################################
                if ( $user->isAllowed( 'editmywatchlist' ) ) {
                        $editWatchlistLinks = array();
                        $editWatchlistModes = array(
@@ -1294,12 +1298,19 @@ class Preferences {
                $opt = array();
 
                $localTZoffset = $context->getConfig()->get( 'LocalTZoffset' );
+               $timeZoneList = self::getTimeZoneList( $context->getLanguage() );
+
                $timestamp = MWTimestamp::getLocalInstance();
                // Check that the LocalTZoffset is the same as the local time zone offset
                if ( $localTZoffset == $timestamp->format( 'Z' ) / 60 ) {
+                       $timezoneName = $timestamp->getTimezone()->getName();
+                       // Localize timezone
+                       if ( isset( $timeZoneList[$timezoneName] ) ) {
+                               $timezoneName = $timeZoneList[$timezoneName]['name'];
+                       }
                        $server_tz_msg = $context->msg(
                                'timezoneuseserverdefault',
-                               $timestamp->getTimezone()->getName()
+                               $timezoneName
                        )->text();
                } else {
                        $tzstring = sprintf(
@@ -1313,49 +1324,12 @@ class Preferences {
                $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
                $opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
 
-               if ( function_exists( 'timezone_identifiers_list' ) ) {
-                       # Read timezone list
-                       $tzs = timezone_identifiers_list();
-                       sort( $tzs );
-
-                       $tzRegions = array();
-                       $tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
-                       $tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
-                       $tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
-                       $tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
-                       $tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
-                       $tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
-                       $tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
-                       $tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
-                       $tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
-                       $tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
-                       asort( $tzRegions );
-
-                       $prefill = array_fill_keys( array_values( $tzRegions ), array() );
-                       $opt = array_merge( $opt, $prefill );
-
-                       $now = date_create( 'now' );
-
-                       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 || !array_key_exists( $z[0], $tzRegions ) ) {
-                                       continue;
-                               }
-
-                               # Localize region
-                               $z[0] = $tzRegions[$z[0]];
-
-                               $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
-
-                               $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
-                               $value = "ZoneInfo|$minDiff|$tz";
-
-                               $opt[$z[0]][$display] = $value;
+               foreach ( $timeZoneList as $timeZoneInfo ) {
+                       $region = $timeZoneInfo['region'];
+                       if ( !isset( $opt[$region] ) ) {
+                               $opt[$region] = array();
                        }
+                       $opt[$region][$timeZoneInfo['name']] = $timeZoneInfo['timecorrection'];
                }
                return $opt;
        }
@@ -1394,7 +1368,7 @@ class Preferences {
                                }
 
                                # Max is +14:00 and min is -12:00, see:
-                               # http://en.wikipedia.org/wiki/Timezone
+                               # https://en.wikipedia.org/wiki/Timezone
                                $minDiff = min( $minDiff, 840 );  # 14:00
                                $minDiff = max( $minDiff, - 720 ); # -12:00
                                return 'Offset|' . $minDiff;
@@ -1459,10 +1433,10 @@ class Preferences {
                        }
 
                        Hooks::run( 'PreferencesFormPreSave', array( $formData, $form, $user, &$result ) );
-                       $user->saveSettings();
                }
 
                $wgAuth->updateExternalDB( $user );
+               $user->saveSettings();
 
                return $result;
        }
@@ -1491,6 +1465,68 @@ class Preferences {
 
                return Status::newGood();
        }
+
+       /**
+        * Get a list of all time zones
+        * @param Language $language Language used for the localized names
+        * @return array A list of all time zones. The system name of the time zone is used as key and
+        *  the value is an array which contains localized name, the timecorrection value used for
+        *  preferences and the region
+        * @since 1.26
+        */
+       public static function getTimeZoneList( Language $language ) {
+               $identifiers = DateTimeZone::listIdentifiers();
+               if ( $identifiers === false ) {
+                       return array();
+               }
+               sort( $identifiers );
+
+               $tzRegions = array(
+                       'Africa' => wfMessage( 'timezoneregion-africa' )->inLanguage( $language )->text(),
+                       'America' => wfMessage( 'timezoneregion-america' )->inLanguage( $language )->text(),
+                       'Antarctica' => wfMessage( 'timezoneregion-antarctica' )->inLanguage( $language )->text(),
+                       'Arctic' => wfMessage( 'timezoneregion-arctic' )->inLanguage( $language )->text(),
+                       'Asia' => wfMessage( 'timezoneregion-asia' )->inLanguage( $language )->text(),
+                       'Atlantic' => wfMessage( 'timezoneregion-atlantic' )->inLanguage( $language )->text(),
+                       'Australia' => wfMessage( 'timezoneregion-australia' )->inLanguage( $language )->text(),
+                       'Europe' => wfMessage( 'timezoneregion-europe' )->inLanguage( $language )->text(),
+                       'Indian' => wfMessage( 'timezoneregion-indian' )->inLanguage( $language )->text(),
+                       'Pacific' => wfMessage( 'timezoneregion-pacific' )->inLanguage( $language )->text(),
+               );
+               asort( $tzRegions );
+
+               $timeZoneList = array();
+
+               $now = new DateTime();
+
+               foreach ( $identifiers as $identifier ) {
+                       $parts = explode( '/', $identifier, 2 );
+
+                       // DateTimeZone::listIdentifiers() returns a number of
+                       // backwards-compatibility entries. This filters them out of the
+                       // list presented to the user.
+                       if ( count( $parts ) !== 2 || !array_key_exists( $parts[0], $tzRegions ) ) {
+                               continue;
+                       }
+
+                       // Localize region
+                       $parts[0] = $tzRegions[$parts[0]];
+
+                       $dateTimeZone = new DateTimeZone( $identifier );
+                       $minDiff = floor( $dateTimeZone->getOffset( $now ) / 60 );
+
+                       $display = str_replace( '_', ' ', $parts[0] . '/' . $parts[1] );
+                       $value = "ZoneInfo|$minDiff|$identifier";
+
+                       $timeZoneList[$identifier] = array(
+                               'name' => $display,
+                               'timecorrection' => $value,
+                               'region' => $parts[0],
+                       );
+               }
+
+               return $timeZoneList;
+       }
 }
 
 /** Some tweaks to allow js prefs to work */