r93756 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93755‎ | r93756 | r93757 >
Date:14:44, 2 August 2011
Author:kaldari
Status:ok
Tags:
Comment:
support for using URLs for images
Modified paths:
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
@@ -285,7 +285,7 @@
286286 $( '#mw-wikilove-image-preview' ).show();
287287 $( '#mw-wikilove-image-preview-content' ).html( '' );
288288 $( '#mw-wikilove-image-preview-spinner' ).fadeIn( 200 );
289 - var title = $.wikiLove.addFilePrefix( currentTypeOrSubtype.image );
 289+ var title = $.wikiLove.normalizeFilename( currentTypeOrSubtype.image );
290290 var loadingType = currentTypeOrSubtype;
291291 $.ajax({
292292 url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php?',
@@ -433,7 +433,7 @@
434434 $.wikiLove.submitPreview();
435435 } else { // image was entered by user
436436 // Make sure the image exists
437 - var imageTitle = $.wikiLove.addFilePrefix( $( '#mw-wikilove-image' ).val() );
 437+ var imageTitle = $.wikiLove.normalizeFilename( $( '#mw-wikilove-image' ).val() );
438438 $( '#mw-wikilove-preview-spinner' ).fadeIn( 200 );
439439
440440 $.ajax( {
@@ -507,7 +507,7 @@
508508
509509 msg = msg.replace( '$1', $( '#mw-wikilove-message' ).val() ); // replace the raw message
510510 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() );
512512 msg = msg.replace( '$3', imageName ); // replace the image
513513 msg = msg.replace( '$4', currentTypeOrSubtype.imageSize || options.defaultImageSize ); // replace the image size
514514 msg = msg.replace( '$5', currentTypeOrSubtype.backgroundColor || options.defaultBackgroundColor ); // replace the background color
@@ -518,9 +518,15 @@
519519 },
520520
521521 /*
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.
523525 */
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 );
525531 // Can't use mw.Title in 1.17
526532 var prefixSplit = filename.split( ':' ),
527533 // Make sure the we don't fail in case input is like "File.jpg"
@@ -718,7 +724,7 @@
719725 for ( var i=0; i<currentTypeOrSubtype.gallery.number; i++ ) {
720726 // get a random image from imageList and add it to the list of titles to be retrieved
721727 var id = Math.floor( Math.random() * imageList.length );
722 - titles = titles + $.wikiLove.addFilePrefix( imageList[id] ) + '|';
 728+ titles = titles + $.wikiLove.normalizeFilename( imageList[id] ) + '|';
723729
724730 // remove the randomly selected image from imageList so that it can't be added twice
725731 imageList.splice(id, 1);

Status & tagging log