Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -285,7 +285,7 @@ |
286 | 286 | $( '#mw-wikilove-image-preview' ).show(); |
287 | 287 | $( '#mw-wikilove-image-preview-content' ).html( '' ); |
288 | 288 | $( '#mw-wikilove-image-preview-spinner' ).fadeIn( 200 ); |
289 | | - var title = $.wikiLove.addFilePrefix( currentTypeOrSubtype.image ); |
| 289 | + var title = $.wikiLove.normalizeFilename( currentTypeOrSubtype.image ); |
290 | 290 | var loadingType = currentTypeOrSubtype; |
291 | 291 | $.ajax({ |
292 | 292 | url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php?', |
— | — | @@ -433,7 +433,7 @@ |
434 | 434 | $.wikiLove.submitPreview(); |
435 | 435 | } else { // image was entered by user |
436 | 436 | // Make sure the image exists |
437 | | - var imageTitle = $.wikiLove.addFilePrefix( $( '#mw-wikilove-image' ).val() ); |
| 437 | + var imageTitle = $.wikiLove.normalizeFilename( $( '#mw-wikilove-image' ).val() ); |
438 | 438 | $( '#mw-wikilove-preview-spinner' ).fadeIn( 200 ); |
439 | 439 | |
440 | 440 | $.ajax( { |
— | — | @@ -507,7 +507,7 @@ |
508 | 508 | |
509 | 509 | msg = msg.replace( '$1', $( '#mw-wikilove-message' ).val() ); // replace the raw message |
510 | 510 | msg = msg.replace( '$2', $( '#mw-wikilove-title' ).val() ); // replace the title |
511 | | - var imageName = $.wikiLove.addFilePrefix( $( '#mw-wikilove-image' ).val() ); |
| 511 | + var imageName = $.wikiLove.normalizeFilename( $( '#mw-wikilove-image' ).val() ); |
512 | 512 | msg = msg.replace( '$3', imageName ); // replace the image |
513 | 513 | msg = msg.replace( '$4', currentTypeOrSubtype.imageSize || options.defaultImageSize ); // replace the image size |
514 | 514 | msg = msg.replace( '$5', currentTypeOrSubtype.backgroundColor || options.defaultBackgroundColor ); // replace the background color |
— | — | @@ -518,9 +518,15 @@ |
519 | 519 | }, |
520 | 520 | |
521 | 521 | /* |
522 | | - * Adds a "File:" prefix if there isn't already a media namespace prefix. |
| 522 | + * Normalize a filename. |
| 523 | + * This function will extract a filename from a URL or add a "File:" prefix if there isn't |
| 524 | + * already a media namespace prefix. |
523 | 525 | */ |
524 | | - addFilePrefix: function( filename ) { |
| 526 | + normalizeFilename: function( filename ) { |
| 527 | + // If a URL is given, extract and decode the filename |
| 528 | + var index = filename.lastIndexOf( "/" ) + 1; |
| 529 | + filename = filename.substr( index ); |
| 530 | + if ( index > 0 ) filename = decodeURI( filename ); |
525 | 531 | // Can't use mw.Title in 1.17 |
526 | 532 | var prefixSplit = filename.split( ':' ), |
527 | 533 | // Make sure the we don't fail in case input is like "File.jpg" |
— | — | @@ -718,7 +724,7 @@ |
719 | 725 | for ( var i=0; i<currentTypeOrSubtype.gallery.number; i++ ) { |
720 | 726 | // get a random image from imageList and add it to the list of titles to be retrieved |
721 | 727 | var id = Math.floor( Math.random() * imageList.length ); |
722 | | - titles = titles + $.wikiLove.addFilePrefix( imageList[id] ) + '|'; |
| 728 | + titles = titles + $.wikiLove.normalizeFilename( imageList[id] ) + '|'; |
723 | 729 | |
724 | 730 | // remove the randomly selected image from imageList so that it can't be added twice |
725 | 731 | imageList.splice(id, 1); |