http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88965

Revision: 88965
Author:   janpaul123
Date:     2011-05-27 11:15:06 +0000 (Fri, 27 May 2011)
Log Message:
-----------
Removed the old gallery function and moved some functionality to the current 
gallery function. It's now possible to show a random selection of images.

Modified Paths:
--------------
    trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
    
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js

Modified: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
===================================================================
--- trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js 
2011-05-27 10:41:59 UTC (rev 88964)
+++ trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js 
2011-05-27 11:15:06 UTC (rev 88965)
@@ -440,60 +440,80 @@
                $.wikiLove.gallery = {};
                $( '#mw-wikilove-gallery-spinner' ).fadeIn( 200 );
                
-               $.each( $.wikiLove.currentTypeOrSubtype.gallery.imageList, 
function(index, value) {
+               if( typeof $.wikiLove.currentTypeOrSubtype.gallery.number == 
'undefined'
+                   || $.wikiLove.currentTypeOrSubtype.gallery.number <= 0
+               ) {
+                       $.wikiLove.currentTypeOrSubtype.gallery.number = 
$.wikiLove.currentTypeOrSubtype.gallery.imageList.length;
+               }
                
-                       $.ajax({
-                               url: mw.config.get( 'wgServer' ) + 
mw.config.get( 'wgScriptPath' ) + '/api.php',
-                               data: {
-                                       'action'      : 'query',
-                                       'format'      : 'json',
-                                       'prop'        : 'imageinfo',
-                                       'iiprop'      : 'mime|url',
-                                       'titles'      : value,
-                                       'iiurlwidth'  : 
$.wikiLove.currentTypeOrSubtype.gallery.width
-                               },
-                               dataType: 'json',
-                               type: 'POST',
-                               success: function( data ) {
-                                       $( '#mw-wikilove-gallery-spinner' 
).fadeOut( 200 );
-                                       
-                                       if ( !data || !data.query || 
!data.query.pages ) {
-                                               return;
+               var titles = '';
+               var imageList = 
$.wikiLove.currentTypeOrSubtype.gallery.imageList;
+               for( var i=0; i<$.wikiLove.currentTypeOrSubtype.gallery.number; 
i++ ) {
+                       // get a randomimage
+                       var id = Math.floor( Math.random() * imageList.length );
+                       titles = titles + 'File:' + imageList[id] + '|';
+                       
+                       // remove the random page from the keys array
+                       imageList.splice(id, 1);
+               }
+               
+               var index = 0;
+               $.ajax({
+                       url: mw.config.get( 'wgServer' ) + mw.config.get( 
'wgScriptPath' ) + '/api.php',
+                       data: {
+                               'action'      : 'query',
+                               'format'      : 'json',
+                               'prop'        : 'imageinfo',
+                               'iiprop'      : 'mime|url',
+                               'titles'      : titles,
+                               'iiurlwidth'  : 
$.wikiLove.currentTypeOrSubtype.gallery.width
+                       },
+                       dataType: 'json',
+                       type: 'POST',
+                       success: function( data ) {
+                               $( '#mw-wikilove-gallery-spinner' ).fadeOut( 
200 );
+                               
+                               if ( !data || !data.query || !data.query.pages 
) {
+                                       return;
+                               }
+                               $.each( data.query.pages, function( id, page ) {
+                                       if ( page.imageinfo && 
page.imageinfo.length ) {
+                                               // build an image tag with the 
correct url and width
+                                               $img = $( '<img/>' )
+                                                       .attr( 'src', 
page.imageinfo[0].thumburl )
+                                                       .attr( 'width', 
$.wikiLove.currentTypeOrSubtype.gallery.width )
+                                                       .hide()
+                                                       .load( function() { $( 
this ).css( 'display', 'inline-block' ); } );
+                                               $( 
'#mw-wikilove-gallery-content' ).append( 
+                                                       $( '<a href="#"></a>' )
+                                                               .attr( 'id', 
'mw-wikilove-gallery-img-' + index )
+                                                               .append( $img )
+                                                               .click( 
function( e ) {
+                                                                       
e.preventDefault();
+                                                                       $( 
'#mw-wikilove-gallery a' ).removeClass( 'selected' );
+                                                                       $( this 
).addClass( 'selected' );
+                                                                       $( 
'#mw-wikilove-image' ).val( $.wikiLove.gallery[$( this ).attr( 'id' )] );
+                                                               }) 
+                                               );
+                                               
$.wikiLove.gallery['mw-wikilove-gallery-img-' + index] = page.title;
+                                               index++;
                                        }
-                                       $.each( data.query.pages, function( id, 
page ) {
-                                               if ( page.imageinfo && 
page.imageinfo.length ) {
-                                                       // build an image tag 
with the correct url and width
-                                                       $img = $( '<img/>' )
-                                                               .attr( 'src', 
page.imageinfo[0].thumburl )
-                                                               .attr( 'width', 
$.wikiLove.currentTypeOrSubtype.gallery.width )
-                                                               .hide()
-                                                               .load( 
function() { $( this ).css( 'display', 'inline-block' ); } );
-                                                       $( 
'#mw-wikilove-gallery-content' ).append( 
-                                                               $( '<a 
href="#"></a>' )
-                                                                       .attr( 
'id', 'mw-wikilove-gallery-img-' + index )
-                                                                       
.append( $img )
-                                                                       .click( 
function( e ) {
-                                                                               
e.preventDefault();
-                                                                               
$( '#mw-wikilove-gallery a' ).removeClass( 'selected' );
-                                                                               
$( this ).addClass( 'selected' );
-                                                                               
$( '#mw-wikilove-image' ).val( $.wikiLove.gallery[$( this ).attr( 'id' )] );
-                                                                       }) 
-                                                       );
-                                                       
$.wikiLove.gallery['mw-wikilove-gallery-img-' + index] = page.title;
-                                               }
-                                       } );
-                               }
-                       });
-               
+                               } );
+                       }
                });
-       },
+       }
        
        /*
         * This is a bit of a hack to show some random images. A predefined set 
of image infos are
         * retrieved using the API. Then we randomise this set ourselves and 
select some images to
         * show. Eventually we probably want to make a custom API call that 
does this properly and
         * also allows for using remote galleries such as Commons, which is now 
prohibited by JS.
+        *
+        * For now this function is disabled. It also shares code with the 
current gallery function,
+        * so when enabling it again it should be implemented cleaner with a 
custom API call, and
+        * without duplicate code between functions
         */
+       /*
        makeGallery: function() {
                $( '#mw-wikilove-gallery-content' ).html( '' );
                $.wikiLove.gallery = {};
@@ -575,6 +595,7 @@
                        }
                });
        },
+       */
 };
 } ) ( jQuery );
 

Modified: 
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js
===================================================================
--- 
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js   
    2011-05-27 10:41:59 UTC (rev 88964)
+++ 
trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js   
    2011-05-27 11:15:06 UTC (rev 88965)
@@ -271,11 +271,9 @@
                        header: 'A beer for you!',
                        text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: 
both"/>', // custom text
                        gallery: {
-                               // right now we can only query the local wiki 
(not e.g. commons)
-                               category: 'Category:Beer',
-                               total: 100, // total number of pictures to 
retrieve, and to randomise
-                               num: 3, // number of pictures to show from the 
randomised set
-                               width: 145 // width of each picture in pixels 
in the interface (not in the template)
+                               imageList: [ 'Cruzcampo.jpg', 
'Glass_of_la_trappe_quadrupel.jpg', 'Hefeweizen.jpg', 
'Krušovice_Mušketýr_in_glass.JPG', 'NCI_Visuals_Food_Beer.jpg', 'PintJug.jpg' ],
+                               width: 145,
+                               number: 3
                        },
                        icon: mw.config.get( 'wgServer' ) + mw.config.get( 
'wgScriptPath' ) + 
'/extensions/WikiLove/modules/ext.wikiLove/images/icons/wikilove-icon-beer.png' 
// icon for left-side menu
                },
@@ -285,8 +283,9 @@
                        header: 'A kitten for you!',
                        text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: 
both"/>', // $3 is the image filename
                        gallery: {
-                               imageList: ['File:Cucciolo gatto 
Bibo.jpg','File:Kitten (06) by Ron.jpg','File:Kitten-stare.jpg'],
-                               width: 145
+                               imageList: [ 'Cucciolo gatto Bibo.jpg','Kitten 
(06) by Ron.jpg','Kitten-stare.jpg', 'Cat03.jpg', 'Kot_Leon.JPG', 'Greycat.jpg' 
],
+                               width: 145,
+                               number: 3
                        },
                        icon: mw.config.get( 'wgServer' ) + mw.config.get( 
'wgScriptPath' ) + 
'/extensions/WikiLove/modules/ext.wikiLove/images/icons/wikilove-icon-kitten.png'
 // icon for left-side menu
                },


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to