aboutsummaryrefslogtreecommitdiffstats
path: root/resources/src/mediawiki.special.upload
diff options
context:
space:
mode:
authorjdlrobson <jdlrobson@gmail.com>2020-10-16 14:13:31 -0700
committerJdlrobson <jrobson@wikimedia.org>2020-10-21 23:12:44 +0000
commitc8fd448392a1c618537fd3b3c11d3dd6bdc1cc28 (patch)
tree0966208bf7b9b2b7818b72285e49c61b706b80a6 /resources/src/mediawiki.special.upload
parent260c75ab9d8b2748142ce14a8997f8e8531217f3 (diff)
downloadmediawikicore-c8fd448392a1c618537fd3b3c11d3dd6bdc1cc28.tar.gz
mediawikicore-c8fd448392a1c618537fd3b3c11d3dd6bdc1cc28.zip
Harden code working with user input to fix JavaScript exceptions
There have been a few errors in the error logs relating to these lines of code. Let's harden it in the cases where the response is unexpected and when the user input is empty. Change-Id: Ib43d93004b3959404b01fe3e16fb0650d163decd
Diffstat (limited to 'resources/src/mediawiki.special.upload')
-rw-r--r--resources/src/mediawiki.special.upload/upload.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/resources/src/mediawiki.special.upload/upload.js b/resources/src/mediawiki.special.upload/upload.js
index 62a52f4c5417..b95a4cedaa1b 100644
--- a/resources/src/mediawiki.special.upload/upload.js
+++ b/resources/src/mediawiki.special.upload/upload.js
@@ -51,7 +51,8 @@
} ).done( function ( result ) {
var
resultOut = '',
- page = result.query.pages[ 0 ];
+ page = result && result.query && result.query.pages && result.query.pages.length ?
+ result.query.pages[ 0 ] : {};
if ( page.imageinfo ) {
resultOut = page.imageinfo[ 0 ].html;
} else if ( page.invalidreason ) {
@@ -164,8 +165,10 @@
);
}
- // fillDestFile setup
- mw.config.get( 'wgUploadSourceIds' ).forEach( function ( sourceId ) {
+ // fillDestFile setup. Note if the upload wiki does not allow uploads,
+ // e.g. Polish Wikipedia - this code still runs amnd this will be undefined,
+ // so fallback to empty array.
+ mw.config.get( 'wgUploadSourceIds', [] ).forEach( function ( sourceId ) {
$( '#' + sourceId ).on( 'change', function () {
var path, slash, backslash, fname;
if ( !mw.config.get( 'wgUploadAutoFill' ) ) {
@@ -215,8 +218,8 @@
// Replace spaces by underscores
fname = fname.replace( / /g, '_' );
- // Capitalise first letter if needed
- if ( mw.config.get( 'wgCapitalizeUploads' ) ) {
+ // Capitalise first letter if needed. Note fname may be empty string.
+ if ( fname && mw.config.get( 'wgCapitalizeUploads' ) ) {
fname = fname[ 0 ].toUpperCase() + fname.slice( 1 );
}