Remove cols and rows preferences
[lhc/web/wiklou.git] / includes / Preferences.php
index d40e0c1..89982a6 100644 (file)
@@ -55,8 +55,6 @@ class Preferences {
        /** @var array */
        protected static $saveFilters = [
                'timecorrection' => [ 'Preferences', 'filterTimezoneInput' ],
-               'cols' => [ 'Preferences', 'filterIntval' ],
-               'rows' => [ 'Preferences', 'filterIntval' ],
                'rclimit' => [ 'Preferences', 'filterIntval' ],
                'wllimit' => [ 'Preferences', 'filterIntval' ],
                'searchlimit' => [ 'Preferences', 'filterIntval' ],
@@ -696,19 +694,23 @@ class Preferences {
                $tzOptions = self::getTimezoneOptions( $context );
 
                $tzSetting = $tzOffset;
-               if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
-                       $minDiff = $tz[1];
-                       $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
-               } elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
+               if ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
                        !in_array( $tzOffset, HTMLFormField::flattenOptions( $tzOptions ) )
                ) {
-                       # Timezone offset can vary with DST
-                       $userTZ = timezone_open( $tz[2] );
-                       if ( $userTZ !== false ) {
-                               $minDiff = floor( timezone_offset_get( $userTZ, date_create( 'now' ) ) / 60 );
+                       // Timezone offset can vary with DST
+                       try {
+                               $userTZ = new DateTimeZone( $tz[2] );
+                               $minDiff = floor( $userTZ->getOffset( new DateTime( 'now' ) ) / 60 );
                                $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
+                       } catch ( Exception $e ) {
+                               // User has an invalid time zone set. Fall back to just using the offset
+                               $tz[0] = 'Offset';
                        }
                }
+               if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
+                       $minDiff = $tz[1];
+                       $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
+               }
 
                $defaultPreferences['timecorrection'] = [
                        'class' => 'HTMLSelectOrOtherField',
@@ -813,20 +815,7 @@ class Preferences {
                                ]
                        ];
                }
-               $defaultPreferences['cols'] = [
-                       'type' => 'int',
-                       'label-message' => 'columns',
-                       'section' => 'editing/editor',
-                       'min' => 4,
-                       'max' => 1000,
-               ];
-               $defaultPreferences['rows'] = [
-                       'type' => 'int',
-                       'label-message' => 'rows',
-                       'section' => 'editing/editor',
-                       'min' => 4,
-                       'max' => 1000,
-               ];
+
                if ( $user->isAllowed( 'minoredit' ) ) {
                        $defaultPreferences['minordefault'] = [
                                'type' => 'toggle',
@@ -834,6 +823,7 @@ class Preferences {
                                'label-message' => 'tog-minordefault',
                        ];
                }
+
                $defaultPreferences['forceeditsummary'] = [
                        'type' => 'toggle',
                        'section' => 'editing/editor',
@@ -1218,7 +1208,8 @@ class Preferences {
                $pixels = $context->msg( 'unit-pixel' )->text();
 
                foreach ( $context->getConfig()->get( 'ImageLimits' ) as $index => $limits ) {
-                       $display = "{$limits[0]}×{$limits[1]}" . $pixels;
+                       // Note: A left-to-right marker (\u200e) is inserted, see T144386
+                       $display = "{$limits[0]}" . json_decode( '"\u200e"' ) . "×{$limits[1]}" . $pixels;
                        $ret[$display] = $index;
                }
 
@@ -1390,6 +1381,24 @@ class Preferences {
                $data = explode( '|', $tz, 3 );
                switch ( $data[0] ) {
                        case 'ZoneInfo':
+                               $valid = false;
+
+                               if ( count( $data ) === 3 ) {
+                                       // Make sure this timezone exists
+                                       try {
+                                               new DateTimeZone( $data[2] );
+                                               // If the constructor didn't throw, we know it's valid
+                                               $valid = true;
+                                       } catch ( Exception $e ) {
+                                               // Not a valid timezone
+                                       }
+                               }
+
+                               if ( !$valid ) {
+                                       // If the supplied timezone doesn't exist, fall back to the encoded offset
+                                       return 'Offset|' . intval( $tz[1] );
+                               }
+                               return $tz;
                        case 'System':
                                return $tz;
                        default:
@@ -1408,7 +1417,7 @@ class Preferences {
                                # Max is +14:00 and min is -12:00, see:
                                # https://en.wikipedia.org/wiki/Timezone
                                $minDiff = min( $minDiff, 840 );  # 14:00
-                               $minDiff = max( $minDiff, - 720 ); # -12:00
+                               $minDiff = max( $minDiff, -720 ); # -12:00
                                return 'Offset|' . $minDiff;
                }
        }