r91389 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91388‎ | r91389 | r91390 >
Date:23:50, 3 July 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
WikiLove fixes:
* Follow-up r91083 CR: Make sure input like "image.jpg" or "File.jpg" will get a "File:" prefix as well.
* Adding some caching in openDialog() for the current type (to avoid re-accessing a 3-levels-down object member)
* Adding a check to make sure the "type" property is not "null" or "undefined" but actually a plain object. This allows hooks and/or local configurations to not only modify and add wikilove-types but also to allow renaming, moving and removing object types by setting a property to null or undefined.
** Previously this kind of modification:
< [[MediaWiki:WikiLove.js]]:
> $.wikiLoveOptions.types.food = null;

.. triggered an exception (as well as the dialog not actually being opened.)
< [[User_talk:Foo]] Click WikiLove icon:
> Uncaught TypeError: Cannot read property 'icon' of null

* Setting $wikiLoveLink in the scope of wikiLove.init scope directly

* Passing JSHint now (when ignoring escapement of HTML-snippet)
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
@@ -19,25 +19,29 @@
2020 emailable = $( '#t-emailuser' ).length ? true : false;
2121
2222 // 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>' );
2732
28 - if( typeof options.types[typeId].icon == 'string' ) {
 33+ if ( typeof type.icon == 'string' ) {
2934 $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 {
3337 $buttonInside.addClass( 'mw-wikilove-no-icon' );
3438 }
3539
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>' );
3741
 42+ $button.data( 'typeId', typeId );
3843 $button.append( '<div class="mw-wikilove-left-cap"></div>');
3944 $button.append( $buttonInside );
4045 $button.append( '<div class="mw-wikilove-right-cap"></div>');
41 - $button.data( 'typeId', typeId );
4246 $typeList.append( $( '<li tabindex="0"></li>' ).append( $button ) );
4347 }
4448
@@ -514,7 +518,9 @@
515519 */
516520 addFilePrefix: function( filename ) {
517521 // 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] : '',
519525 normalized = $.trim( prefix ).toLowerCase().replace( /\s/g, '_' );
520526 // wgNamespaceIds is missing 'file' in 1.17 on non-English wikis
521527 if ( mw.config.get( 'wgNamespaceIds' )[normalized] !== 6 && normalized !== 'file' ) {
@@ -769,12 +775,13 @@
770776 * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog.
771777 */
772778 init: function() {
 779+ var $wikiLoveLink = $( [] );
773780 options = $.wikiLoveOptions;
774781
775782 if ( $( '#ca-wikilove' ).length ) {
776 - var $wikiLoveLink = $( '#ca-wikilove' ).find( 'a' );
 783+ $wikiLoveLink = $( '#ca-wikilove' ).find( 'a' );
777784 } else { // legacy skins
778 - var $wikiLoveLink = $( '#topbar a:contains(' + mw.msg( 'wikilove-tab-text' ) + ')' );
 785+ $wikiLoveLink = $( '#topbar a:contains(' + mw.msg( 'wikilove-tab-text' ) + ')' );
779786 }
780787 $wikiLoveLink.unbind( 'click' );
781788 $wikiLoveLink.click( function( e ) {

Past revisions this follows-up on

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

Comments

#Comment by Kaldari (talk | contribs)   21:16, 5 July 2011

Looks good.

Status & tagging log