Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -19,25 +19,29 @@ |
20 | 20 | emailable = $( '#t-emailuser' ).length ? true : false; |
21 | 21 | |
22 | 22 | // Build a type list like this: |
23 | | - var $typeList = $( '<ul id="mw-wikilove-types"></ul>' ); |
24 | | - for( var typeId in options.types ) { |
25 | | - var $button = $( '<a href="#"></a>' ); |
26 | | - var $buttonInside = $( '<div class="mw-wikilove-inside"></div>' ); |
| 23 | + var $typeList = $( '<ul id="mw-wikilove-types"></ul>' ), |
| 24 | + type; |
| 25 | + for ( var typeId in options.types ) { |
| 26 | + type = options.types[typeId]; |
| 27 | + if ( !$.isPlainObject( type ) ) { |
| 28 | + continue; |
| 29 | + } |
| 30 | + var $button = $( '<a href="#"></a>' ), |
| 31 | + $buttonInside = $( '<div class="mw-wikilove-inside"></div>' ); |
27 | 32 | |
28 | | - if( typeof options.types[typeId].icon == 'string' ) { |
| 33 | + if ( typeof type.icon == 'string' ) { |
29 | 34 | $buttonInside.append( '<div class="mw-wikilove-icon-box"><img src="' |
30 | | - + mw.html.escape( options.types[typeId].icon ) + '"/></div>' ); |
31 | | - } |
32 | | - else { |
| 35 | + + mw.html.escape( type.icon ) + '"/></div>' ); |
| 36 | + } else { |
33 | 37 | $buttonInside.addClass( 'mw-wikilove-no-icon' ); |
34 | 38 | } |
35 | 39 | |
36 | | - $buttonInside.append( '<div class="mw-wikilove-link-text">' + options.types[typeId].name + '</div>' ); |
| 40 | + $buttonInside.append( '<div class="mw-wikilove-link-text">' + mw.html.escape( type.name ) + '</div>' ); |
37 | 41 | |
| 42 | + $button.data( 'typeId', typeId ); |
38 | 43 | $button.append( '<div class="mw-wikilove-left-cap"></div>'); |
39 | 44 | $button.append( $buttonInside ); |
40 | 45 | $button.append( '<div class="mw-wikilove-right-cap"></div>'); |
41 | | - $button.data( 'typeId', typeId ); |
42 | 46 | $typeList.append( $( '<li tabindex="0"></li>' ).append( $button ) ); |
43 | 47 | } |
44 | 48 | |
— | — | @@ -514,7 +518,9 @@ |
515 | 519 | */ |
516 | 520 | addFilePrefix: function( filename ) { |
517 | 521 | // Can't use mw.Title in 1.17 |
518 | | - var prefix = filename.split( ':' )[0] || '', |
| 522 | + var prefixSplit = filename.split( ':' ), |
| 523 | + // Make sure the we don't fail in case input is like "File.jpg" |
| 524 | + prefix = prefixSplit[1] ? prefixSplit[0] : '', |
519 | 525 | normalized = $.trim( prefix ).toLowerCase().replace( /\s/g, '_' ); |
520 | 526 | // wgNamespaceIds is missing 'file' in 1.17 on non-English wikis |
521 | 527 | if ( mw.config.get( 'wgNamespaceIds' )[normalized] !== 6 && normalized !== 'file' ) { |
— | — | @@ -769,12 +775,13 @@ |
770 | 776 | * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog. |
771 | 777 | */ |
772 | 778 | init: function() { |
| 779 | + var $wikiLoveLink = $( [] ); |
773 | 780 | options = $.wikiLoveOptions; |
774 | 781 | |
775 | 782 | if ( $( '#ca-wikilove' ).length ) { |
776 | | - var $wikiLoveLink = $( '#ca-wikilove' ).find( 'a' ); |
| 783 | + $wikiLoveLink = $( '#ca-wikilove' ).find( 'a' ); |
777 | 784 | } else { // legacy skins |
778 | | - var $wikiLoveLink = $( '#topbar a:contains(' + mw.msg( 'wikilove-tab-text' ) + ')' ); |
| 785 | + $wikiLoveLink = $( '#topbar a:contains(' + mw.msg( 'wikilove-tab-text' ) + ')' ); |
779 | 786 | } |
780 | 787 | $wikiLoveLink.unbind( 'click' ); |
781 | 788 | $wikiLoveLink.click( function( e ) { |