mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-16 20:35:09 +00:00
Catch exceptions thrown by localStorage.getItem
Bug: T94695 Change-Id: I7fd7c4776a55de24d702babb291faf3208c8d0af
This commit is contained in:
parent
f7ee2790ca
commit
5bd02e8cc1
|
@ -65,7 +65,11 @@
|
||||||
CP.getFromLocalStorage = function ( key, fallback ) {
|
CP.getFromLocalStorage = function ( key, fallback ) {
|
||||||
var value = null;
|
var value = null;
|
||||||
if ( this.localStorage ) {
|
if ( this.localStorage ) {
|
||||||
value = this.localStorage.getItem( key );
|
try {
|
||||||
|
value = this.localStorage.getItem( key );
|
||||||
|
} catch ( e ) {
|
||||||
|
mw.log( 'Failed to fetch item ' + key + ' from localStorage', e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( value === null && fallback !== undefined ) {
|
if ( value === null && fallback !== undefined ) {
|
||||||
value = fallback;
|
value = fallback;
|
||||||
|
|
|
@ -25,11 +25,15 @@
|
||||||
|
|
||||||
// If the user disabled MediaViewer in his preferences, we do not set up click handling.
|
// If the user disabled MediaViewer in his preferences, we do not set up click handling.
|
||||||
// This is loaded before user JS so we cannot check wgMediaViewer.
|
// This is loaded before user JS so we cannot check wgMediaViewer.
|
||||||
if (
|
try {
|
||||||
mw.config.get( 'wgMediaViewerOnClick' ) !== true
|
if (
|
||||||
|| mw.user.isAnon() && window.localStorage && localStorage.getItem( 'wgMediaViewerOnClick' ) === false
|
mw.config.get( 'wgMediaViewerOnClick' ) !== true
|
||||||
) {
|
|| mw.user.isAnon() && window.localStorage && localStorage.getItem( 'wgMediaViewerOnClick' ) === false
|
||||||
return;
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch ( e ) { // localStorage.getItem can throw exceptions
|
||||||
|
mw.log( 'Could not check value of wgMediaViewerOnClick in localStorage' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$document.on( 'click.mmv-head', 'a.image', function ( e ) {
|
$document.on( 'click.mmv-head', 'a.image', function ( e ) {
|
||||||
|
|
|
@ -138,7 +138,11 @@
|
||||||
|
|
||||||
|
|
||||||
MPSP.initialize = function () {
|
MPSP.initialize = function () {
|
||||||
this.hasOpenedMetadata = !this.localStorage || this.localStorage.getItem( 'mmv.hasOpenedMetadata' );
|
try {
|
||||||
|
this.hasOpenedMetadata = !this.localStorage || this.localStorage.getItem( 'mmv.hasOpenedMetadata' );
|
||||||
|
} catch ( e ) { // localStorage.getItem can throw exceptions
|
||||||
|
this.hasOpenedMetadata = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue