diff options
Diffstat (limited to 'resources/src')
-rw-r--r-- | resources/src/mediawiki.DateFormatter/DateFormatter.js | 33 | ||||
-rw-r--r-- | resources/src/mediawiki.api/AbortController.js | 7 |
2 files changed, 35 insertions, 5 deletions
diff --git a/resources/src/mediawiki.DateFormatter/DateFormatter.js b/resources/src/mediawiki.DateFormatter/DateFormatter.js index 4281a1e0163c..f67ba0cca381 100644 --- a/resources/src/mediawiki.DateFormatter/DateFormatter.js +++ b/resources/src/mediawiki.DateFormatter/DateFormatter.js @@ -595,7 +595,7 @@ class DateFormatter { * @return {string} */ formatInternal( style, type, date ) { - const formatName = style ? `${ style } ${ type }` : type; + const formatName = this.makeValidFormatName( style, type ); const formatter = this.getIntlFormatInternal( formatName ); const pattern = this.formats[ formatName ].pattern; if ( pattern ) { @@ -614,6 +614,35 @@ class DateFormatter { } /** + * Validate a style/type and combine them into a single string, falling + * back to the default style if the user style is not available with the + * specified type. + * + * @internal + * @ignore + * + * @param {string|null} style + * @param {string} type + * @return {string} + */ + makeValidFormatName( style, type ) { + if ( !style ) { + return type; + } + // Try the specified style, then the site default style, then "dmy", a + // final fallback which should always exist, because localised date + // format arrays are merged with English, which has "dmy". + for ( const tryStyle of [ style, config.defaultStyle, 'dmy' ] ) { + const name = `${ tryStyle } ${ type }`; + if ( name in this.formats ) { + return name; + } + } + // Perhaps an invalid type, or bad config? + throw new Error( `Unable to find a valid date format for "${ style } ${ type }"` ); + } + + /** * Format a time/date range with a specified style * * @internal @@ -626,7 +655,7 @@ class DateFormatter { * @return {string} */ formatRangeInternal( style, type, date1, date2 ) { - const formatName = style ? `${ style } ${ type }` : type; + const formatName = this.makeValidFormatName( style, type ); const formatter = this.getIntlFormatInternal( formatName ); const pattern = this.formats[ formatName ].rangePattern; if ( pattern ) { diff --git a/resources/src/mediawiki.api/AbortController.js b/resources/src/mediawiki.api/AbortController.js index 90059a793ef1..cb874e19ee24 100644 --- a/resources/src/mediawiki.api/AbortController.js +++ b/resources/src/mediawiki.api/AbortController.js @@ -1,6 +1,7 @@ -// Support: Safari < 11.1, probably? There's conflicting information about it on the internet. -// eslint-plugin-compat says "AbortController is not supported in Safari 11, iOS Safari 11.0-11.2", -// but the documentation on MDN and caniuse.com disagrees. If you find out who's right, update this. +// Support: Firefox < 97, Chrome < 98, Safari < 15.4. +// mw.Api's use of AbortController requires the AbortSignal 'reason' property, +// which was not supported in earlier versions. +// https://caniuse.com/mdn-api_abortsignal_reason /** * @classdesc |