Contents
MoinMoin Gallery Macro
Description
A photo gallery written by SimonRyan and implemented as a MoinMoin macro.
<simon AT smartblackbox DOT com>
Feature List
- All original images reside as attachments to pages
A gallery is displayed on the page at the position the Gallery macro is inserted eg: [[Gallery(key1=value1,key2=value2....)]] where the following keys are valid:
- thumbnailwidth = no of pixels wide to make the thumbnails
- webnailwidth = width of the web sized images
- numberofcolumns = no of columns used in the thumbnail table
default values are used when there are no arguments [[Gallery]]
A small file is added to the attachments directory called delete.me.to.regenerate.thumbnails.and.webnails (usefull to delete if you have changed the width definition arguments)
- Image manipulation is done by PIL (if you have it) or in a forked Image Magick process (convert and mogrify)
- Click once on a thumbnail to get the webnail, click again to get full sized image
- Simple 1 line annotation (so far, just type your annotation and press enter)
Simple temp filename convention so sysadmins can easily find and --exec rm -f {}\; them
- tmp.thumbnail.imagename.jpg
- tmp.webnail.imagename.jpg
- tmp.annotation.imagename.txt
- tmp.rotated.imagename.txt
- Navigational Bar with PREV, THUMBS and NEXT links
- Tool Bar with Rotate buttons (only visible to administrators but I may make this configurable)
Rotating originals does not actually change the original but creates a tmp.rotated.imagename file which is preferentially linked to
- All form input is reduced to alphanumeric characters for cgi security
Any forked processes running for longer than some delay (40 seconds) are detached from the moinmoin cgi process before the web browser times out (or preferably before the user falls asleep )
- Thumbnail and Webnail generation use file locks to prevent system administrator nightmares
- Authentication: If a user can delete a page, then they are considered a gallery administrator (and can rotate, annotate and trigger a rebuild of the thumbnails and webnails) (This will probably become configurable)
Support added for MoinMoin-1.3.3 and MoinMoin-1.3.4 (still experimental at this stage so YMMV)
Download & Release Notes
Download |
Release Version |
Moin Version |
Release Notes |
|
1.2, 1.3, 1.5 |
|
|
|
|
|
|
|
1.2 |
|
Installation
Download and install PIL (Python Image Library): http://www.pythonware.com/products/pil/
- Download the latest macro and place it either in your global macro directory (!MoinMoin/macro) or preferably in your local macro directory (yourwiki/data/plugins/macro)
- Ensure that the file is readable by your webserver process
chmod 444 Gallery.py
Check your SystemInfo page to ensure that you can see Gallery.py listed in either the Global or Local macros section
Usage Guide
- Place the following code on any wiki page:
[[Gallery]]
- Upload some images as attachments to that page
- You should now see those images as a table of thumbnails inserted at the position of your macro code.
Parameters
As of version 0.80 the parameters are as follows:
[[Gallery(key1=value1,key2=value2....)]]
- where the following keys are valid:
- thumbnailwidth = the width in pixels of the thumbnails generated
- webnailwidth = the width in pixels of the webnails generated
- numberofcolumns = the number of columns in the html table used to display the thumbnails (this may be deprecated in future versions if floating css thumbnails are implemented)
Advanced Options
gallerytempdir
The default behaviour is to serve the images via MoinMoin's internal attachment view facility. This has the downside that each image then causes a separate invocation of the MoinMoin application.
There are a number of ways around this such as:
Run MoinMoin using mod_python (untested)
Run MoinMoin using FastCGI (this works well)
- Using an alias in your web config file to alias the attachment requests to direct webserver requests
These methods have pros and cons, the cons including serious security implications.
The preferred method for getting around this is to insert an extra couple of parameters into your wikiconfig.py:
gallerytempdir
gallerytempurl
These point to a directory which you have created to be writable for the MoinMoin process and readable by the webserver process such that it can serve images placed there as items in it's urlspace.
gallerytempdir defines the filesystem location of the writable directory
gallerytempurl defines the web accessable url to reach the directory
The Gallery macro will create a new directory for each pagename that utilises the Gallery macro, it will then, on first view, populate it with thumbnails and webnails for the images contained in the pages attachements directory, eg:
gallerytempdir = '/var/www/html/moin/nails' gallerytempurl = url_prefix + '/nails'
in the DesktopEdition, the base url_prefix is the folder moin-desktop/wiki/htdocs
Example
FAQ
Question: I uploaded a heap of images and only some of them seem to be displayed as thumbnails.
Answer: New images are processed into thumbnails and webnails by the Gallery macro. If this process takes longer than 40 seconds, then rather than keeping you waiting, the processing moves into the background. You should see a message displayed when this occurs.
The thumbnail generation process was taking too long so it has been backgrounded. Please try again later to see the full set of thumbnails.
Question: Why didn't you implement feature X?
Answer: Probably because this macro was thrown together on the weekend If you have a feature suggestion, bug (or preferably bug-fix), please email it to me.
Question: Why is thumbnail view so slow to appear on my browser?
Answer: By default the macro delivers images using MoinMoin's internal attachment view mechanism. Read the Advanced section of the documentation and implement the moin_config gallerytempdir and gallerytempurl variables or change your configuration to use FastCGI.
Question: If I am using the wikiconfig.attachments style of attachment download speedup, will it still work?
Answer: Yes you can, as of version 0.81, but the support is currently experimental.
Change Log
22/07/06 - Version 0.87
- Added a delete button - It's just so much easier to delete from the webnail than trying to figure out which attachment to delete
- Now works with Moin version 1.5.3 (and 4?)
- Rotate now no longer rotates the original image. Only the thumbnail and webnails are rotated.
- Fixed various bugs (thanks to all those who contributed fixes - if I'm missed merging in yours, please remind me)
- PIL support seems stable now.
19/08/05 - Version 0.86
- Fixed the rotate refresh issue so that rotate refreshes correctly
- Fixed the subpages bug (I think)
- Now uses wikiconfig rather than older moin_config
- Added experimental support for PIL
12/7/04 - Version 0.82
- Bug fix for handling of spaces in filenames
10/7/04 - Version 0.81
Added support for moin_config.attachments dictionary at the request of ReimarBauer
9/7/04 - Version 0.80 - Stable release now also at MacroMarket
- Parameters are now comma delimited key value pairs
- Bug Fixes including issue with rotations surviving nail regeneration fixed
- Improvement to the way annotations work
- cleaner html generation
8/7/04 - Version 0.74
- Users with privileges to delete pages are considered Gallery administrators for those pages
- Macro error messages are more pronounced
- Double quotes in annotations are now handled correctly
- More code cleaning and fixes in preparation for version jump to 1.0
For older entries see MoinMoinGallery
Other Galleries for MoinMoin
An excellent alternative is the recent ParserMarket/Gallery2 by ReimarBauer
This implements the idea of Gallery as a combination of a MoinMoin Action and Parser as opposed to a Macro.
Bugs
If you're using the Macro on a pagename with Umlauts an error "ascii' codec can't encode character " appears.
ascii' codec can't encode character u'\xe4' in position 39: ordinal not in range(128) * args = ('ascii', u'<td><a href="http://intranet.heavy.ch/H\xe4fner, Ma...il.person.jpg" alt="" title=""></a></center></td>', 39, 40, 'ordinal not in range(128)') * encoding = 'ascii' * end = 40 * message = '' * object = u'<td><a href="http://intranet.heavy.ch/H\xe4fner, Ma...il.person.jpg" alt="" title=""></a></center></td>' * reason = 'ordinal not in range(128)' * start = 39
See Log UmlautError_Gallery.txt. Using MoinMoin 1.6.2. -- MarcelHäfner 2008-04-07 11:36:49
Discussion
I may have found an issue on line 450 when using gallerytempdir settings. Say that there are two places where Gallery is used - Example/Example1 and Example/Example2. When processing the second line 450 is trying to create the Example directory again.
os.mkdir(Globs.gallerytempdirroot+compbit)
This will raise an exception since Example exists. This might solve things:
if not os.access(Globs.gallerytempdirroot+compbit, os.F_OK):
- os.mkdir(Globs.gallerytempdirroot+compbit)
-- Magnus 2006-06-07 00:41:08
Do you have any idea for porting this to Windows version of MoinMoin? -- silee 2005-10-03 07:41:08
- It should run on Windows as well - what is your problem? It is true that there is not a package yet which enables you to easily install it.
Sorry for my stupid question , I had no idea what PIL means: From the .py code, I thought that I need Windows ImageMagick installed but it didn't work. I have added Windows PIL, it works very well. Thanks! -- silee 2005-10-03 08:19:10
This macro seems not to be compliant to none-ascii platforms (korean in my case). It throws UnicodeErrors when I insert none-ascii characters as annotation. I've tried to modify the code as follows.
(line 59) + import codecs, StringIO (line 431) - out=cStringIO.StringIO() + out=StringIO.StringIO() (line 545) - ouf=open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt','w') + ouf=codecs.open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt','w', encoding='utf-8') (line 312) - atext=open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt').readline() + atext=codecs.open(Globs.attachmentdir+'/tmp.annotation.'+target+'.txt', encoding='utf-8').readline()
It works well until now but I am not convinced. - silee 2005-10-03 11:27:49
- Thanks for that. I'll give it a try - Simon.
Since you have the capability of looking to a gallery directory outside of the wiki space, you can seperate out thumbnail and metadata creation to a seperate script. The script could be run from cron or manually. Something similar to Curator. You could then also include really advanced functions that take too much computation like wavelet similarity comparisons that could be adapted from imgSeek. -- TimCera 2005-10-27 13:09:51
When I click a thumb instead of showme the real image size it go to Edit Wiki mode, what's wrongn ? --Walter 26/03/2007
- I got same thing just now. Link for images and "?action=edit" instead of "?action=show". I deleted the del.me file and things went back to normal.
DanParslow writes: Thanks for this terrific macro. I did find that when placing galleries in a long page where they were scrolled off, it was inconvenient to have to keep scrolling down the page while navigating through the images. I modified it to automatically include and use anchor tags if you provide the argument anchor=youranchorname. A diff against .87 follows:
--- Gallery-087.py 2008-01-02 23:18:21.000000000 -0800 +++ Gallery.py 2008-01-02 23:16:49.000000000 -0800 @@ -67,2 +67,4 @@ webnailwidth='600' + anchor='' + anchortag='' numberofcolumns=4 @@ -114,3 +116,3 @@ description=query - return '<a href="'+Globs.baseurl+pagename+'?'+querystring+'='+query+Globs.bcomp+'">'+description+'</a>' + return '<a href="'+Globs.baseurl+pagename+'?'+querystring+'='+query+Globs.bcomp+Globs.anchor+'">'+description+'</a>' @@ -121,3 +123,3 @@ # Append the action to the end of the URLS. This allows us to keep modes such as action=print - thumbs='<a href="'+Globs.subname+'?'+Globs.bcomp+'">THUMBS</a>' + thumbs='<a href="'+Globs.subname+'?'+Globs.bcomp+Globs.anchor+'">THUMBS</a>' index=positions.index(target) @@ -126,7 +128,7 @@ # We are not the first so we can provide a back link - back=qlink(Globs.pagename, querystring, positions[index-1], 'PREV') + back=qlink(Globs.pagename, querystring, positions[index-1], 'PREV') if not index==len(positions)-1: # We are not the last so we can provide a forward link - forward=qlink(Globs.pagename, querystring, positions[index+1], 'NEXT') - return '<table><tr><td>'+back+'</td><td>'+thumbs+'</td><td>'+forward+'</td></tr></table>' + forward=qlink(Globs.pagename, querystring, positions[index+1], 'NEXT') + return Globs.anchortag+'<table><tr><td>'+back+'</td><td>'+thumbs+'</td><td>'+forward+'</td></tr></table>' @@ -383,2 +385,4 @@ Globs.pagename='' + Globs.anchor='' + Globs.anchortag='' @@ -396,2 +400,5 @@ Globs.webnailwidth=value + elif key=='anchor': + Globs.anchor='#'+value + Globs.anchortag='<a name="'+value+'">' elif key=='numberofcolumns': @@ -716,3 +723,3 @@ return macro.formatter.rawHTML( Globs.adminmsg ) - out.write('\n<table>') + out.write('\n'+Globs.anchortag+'<table>') cease='' @@ -733,3 +740,3 @@ # Table entry for thumbnail image - out.write('<td><a href="'+Globs.baseurl+Globs.pagename+'?webnail='+item+Globs.bcomp+'"><center><img src="'+Globs.gallerytempurl+'tmp.thumbnail.'+item+'.jpg" '+rollover+'></a></center></td>') + out.write('<td><a href="'+Globs.baseurl+Globs.pagename+'?webnail='+item+Globs.bcomp+Globs.anchor+'"><center><img src="'+Globs.gallerytempurl+'tmp.thumbnail.'+item+'.jpg" '+rollover+'></a></center></td>') out.write('</tr>\n')
There are some thumbnail generating problems with Moin 1.7 -- MelaEckenfels 2008-08-03 00:33:04