Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -321,11 +321,7 @@ |
322 | 322 | |
323 | 323 | msg = msg.replace( '$1', $( '#mw-wikilove-message' ).val() ); // replace the raw message |
324 | 324 | msg = msg.replace( '$2', $( '#mw-wikilove-title' ).val() ); // replace the title |
325 | | - var imageName = $( '#mw-wikilove-image' ).val(); |
326 | | - // if the image name doesn't start with a prefix, add one |
327 | | - if ( imageName.indexOf( 'File:' ) !== 0 && imageName.indexOf( 'Image:' ) !== 0 && imageName.indexOf( wgFormattedNamespaces[6] !== 0 ) ) { |
328 | | - imageName = 'File:' + imageName; |
329 | | - } |
| 325 | + var imageName = $.wikiLove.addFilePrefix( $( '#mw-wikilove-image' ).val() ); |
330 | 326 | msg = msg.replace( '$3', imageName ); // replace the image |
331 | 327 | msg = msg.replace( '$4', currentTypeOrSubtype.imageSize || options.defaultImageSize ); // replace the image size |
332 | 328 | msg = msg.replace( '$5', currentTypeOrSubtype.backgroundColor || options.defaultBackgroundColor ); // replace the background color |
— | — | @@ -336,6 +332,16 @@ |
337 | 333 | }, |
338 | 334 | |
339 | 335 | /* |
| 336 | + * Adds a "File:" prefix if there isn't already a media namespace prefix. |
| 337 | + */ |
| 338 | + addFilePrefix: function( filename ) { |
| 339 | + if ( filename.indexOf( 'File:' ) !== 0 && filename.indexOf( 'Image:' ) !== 0 && filename.indexOf( wgFormattedNamespaces[6] + ':' ) !== 0 ) { |
| 340 | + filename = 'File:' + filename; |
| 341 | + } |
| 342 | + return filename; |
| 343 | + }, |
| 344 | + |
| 345 | + /* |
340 | 346 | * Fires AJAX request for previewing wikitext. |
341 | 347 | */ |
342 | 348 | doPreview: function( wikitext ) { |
— | — | @@ -447,12 +453,7 @@ |
448 | 454 | for( var i=0; i<currentTypeOrSubtype.gallery.number; i++ ) { |
449 | 455 | // get a random image from imageList and add it to the list of titles to be retrieved |
450 | 456 | var id = Math.floor( Math.random() * imageList.length ); |
451 | | - // make sure the image name has a prefix |
452 | | - if ( imageList[id].indexOf( 'File:' ) === 0 || imageList[id].indexOf( 'Image:' ) === 0 || imageList[id].indexOf( wgFormattedNamespaces[6] ) === 0) { |
453 | | - titles = titles + imageList[id] + '|'; |
454 | | - } else { |
455 | | - titles = titles + 'File:' + imageList[id] + '|'; |
456 | | - } |
| 457 | + titles = titles + $.wikiLove.addFilePrefix( imageList[id] ) + '|'; |
457 | 458 | |
458 | 459 | // remove the randomly selected image from imageList so that it can't be added twice |
459 | 460 | imageList.splice(id, 1); |