r90880 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90879‎ | r90880 | r90881 >
Date:15:11, 27 June 2011
Author:janpaul123
Status:resolved (Comments)
Tags:
Comment:
Fixed adding file prefix as mentioned in the comments of r90220
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
@@ -321,11 +321,7 @@
322322
323323 msg = msg.replace( '$1', $( '#mw-wikilove-message' ).val() ); // replace the raw message
324324 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() );
330326 msg = msg.replace( '$3', imageName ); // replace the image
331327 msg = msg.replace( '$4', currentTypeOrSubtype.imageSize || options.defaultImageSize ); // replace the image size
332328 msg = msg.replace( '$5', currentTypeOrSubtype.backgroundColor || options.defaultBackgroundColor ); // replace the background color
@@ -336,6 +332,16 @@
337333 },
338334
339335 /*
 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+ /*
340346 * Fires AJAX request for previewing wikitext.
341347 */
342348 doPreview: function( wikitext ) {
@@ -447,12 +453,7 @@
448454 for( var i=0; i<currentTypeOrSubtype.gallery.number; i++ ) {
449455 // get a random image from imageList and add it to the list of titles to be retrieved
450456 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] ) + '|';
457458
458459 // remove the randomly selected image from imageList so that it can't be added twice
459460 imageList.splice(id, 1);

Follow-up revisions

RevisionCommit summaryAuthorDate
r91083WikiLove minor fixes:...krinkle17:29, 29 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90220include localized prefix per comments at r90191kaldari17:58, 16 June 2011

Comments

#Comment by Krinkle (talk | contribs)   18:38, 29 June 2011

NS_FILE has a primary and an legacy alias (File and Image) and both are localized (eg. nl: Bestand/Afbeelding, de: Datei/Bild). The localized alias wasn't checked for yet. Fixed in r91083

Status & tagging log