<<QR>>

Description

Genrates QR-code for the text provided. If no text is provided, generates QR-code for the current page URL (sans parameters).

Requires qrencode to be installed. (In Ubuntu/Debian this is sudo apt-get install qrencode)

Warning: This macro is provided as-is without any implied warranty! Security of this macro depends upon security of qrencode. It should be pretty secure due to its simplicity, but absense of security holes is not guaranteed.

Download & Release Notes

Download

Release Version

Moin Version

Release Notes

attachment.txt

Usage

Copy this code to QR.py in macro directory.

   1 import os
   2 from subprocess import Popen, PIPE
   3 from hashlib import sha1
   4 from MoinMoin.Page import Page
   5 
   6 qr_options = ["-s", "4"]
   7 
   8 def png_path(request, pagename, text):
   9         return "/PATH/TO/wiki-data/qr", png_filename(text)
  10 def png_url(request, pagename, text):
  11         return "/wiki-data/qr/" + png_filename(text)
  12 def png_filename(text):
  13         return sha1(text).hexdigest()[:16] + ".png"
  14 
  15 def macro_QR(macro, text=None):
  16         if text is None:
  17                 text = macro.request.getQualifiedURL(macro.request.page.url(macro.request))
  18 
  19         prefix, suffix = png_path(macro.request, macro.request.page.page_name, text)
  20         if not os.path.exists(prefix):
  21                 os.mkdir(prefix)
  22 
  23         filename = os.path.join(prefix, suffix)
  24         if not os.path.exists(filename):
  25                 p = Popen(["qrencode", "-o", filename] + qr_options, stdin=PIPE)
  26                 p.stdin.write(text)
  27                 p.stdin.close()
  28                 p.wait()
  29 
  30         img_url = png_url(macro.request, macro.request.page.page_name, text)
  31         return macro.formatter.image(img_url, alt=text, title=text)

Edit png_path and png_url to your likes & your FS layout.

Restart your web server.

Enjoy!

Example

 qr-code of link to this page:: <<QR>>
 qr-code of some funny stuff:: <<QR(some funny stuff)>>

Daniil Alexeyevsky, 2013

License

This macro is public licensed.

Bugs

Discussion

MoinMoin: MacroMarket/QR (last edited 2013-02-13 14:32:00 by dslb-092-074-138-171)