# -*- coding: utf-8 -*-
"""
    MoinMoin - PDFIcon macro display a PDF icon which generate a PDF document

    This macro is display a picture which is a link to ?action=CreatePdfDocument to create
    a PDF document at once. The idear is to show a PDF ready page.

    @copyright: 2006  Raphael Bossek <raphael.bossek@solutions4linux.de>
    @license: GNU GPL, see COPYING for details.

    2007-08-15
    * Release v1.0.5
    * Support for DOCBOOK (do not create any HTML content)

    2006-11-16  RaphaelBossek
    * Release v1.0.4
    * Fixed URL for sub-pages.

    2006-11-14  RaphaelBossek
    * Release v1.0.3
    * Moin 1.6 support added.

    2006-09-12  RaphaelBossek
    * Release v1.0.2
    * Use the same workding for link description as the action macro. The same translation
      for both can be used.

    2006-09-06  RaphaelBossek
    * Release v1.0.1
    * Update to new action name, CreatePdfDocument

    2006-08-31  RaphaelBossek
    * Initial release v1.0.0
"""

from MoinMoin import wikiutil

def execute(macro, args):
	if not getattr(macro.request.cfg, u'pdficon_imageurl', None):
		macro.request.cfg.pdficon_imageurl = u'/icons/pdf.png'

	if macro.request.form.get(u'action', [u''])[0] != u'print':
		query_string = u'action=CreatePdfDocument&generate=1'
		if macro.request.query_string:
			url = macro.request.url.replace(macro.request.query_string, query_string)
		else:
			url = macro.request.url + u'?' + query_string
		url = macro.request.getQualifiedURL(url.replace(macro.request.http_host, u''))
		return macro.formatter.rawHTML(u'<div style="float:right;"><a href="%s"><img src="%s" style="margin:.3em 0;" title="%s" border="0" /></a></div>\n' % (url, macro.request.cfg.pdficon_imageurl, macro.request.getText(u'Create Pdf Document'),))
	return u''
