Attachment 'ChangeLink.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     ChangeLink
   4     renames virtual [[attachment:file.ext||&do=get]] to [[attachment:file.ext||&do=view]]
   5 
   6     @copyright: 2008 MoinMoin:ReimarBauer
   7     @license: GNU GPL, see COPYING for details.
   8 """
   9 from MoinMoin import config, wikiutil
  10 from MoinMoin.Page import Page
  11 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
  12 
  13 def execute(pagename, request):
  14     _ = request.getText
  15     msg = None
  16 
  17     if not request.user.may.read(pagename):
  18         msg = _("You are not allowed to view this page!")
  19 
  20     if msg:
  21         request.theme.add_msg(msg, state)
  22         Page(request, pagename).send_page()
  23         return
  24 
  25     request.formatter.page = Page(request, pagename)
  26     raw = Page(request, pagename).get_raw_body()
  27     # of course we need some regex from the parser here to handle attachment markup
  28     # that is just to show the idea
  29     raw = raw.replace('&do=get', '&do=view')
  30 
  31     html = wikiutil.renderText(request, WikiParser, raw)
  32 
  33     mimetype = "text/html"
  34     request.emit_http_headers(["Content-Type: %s; charset=%s" % (mimetype, config.charset)])
  35 
  36     request.theme.send_title(pagename,
  37                              pagename=pagename,
  38                              )
  39 
  40     request.write(request.formatter.startContent("content"))
  41 
  42     request.write(request.formatter.rawHTML(html))
  43     request.write(request.formatter.endContent())
  44     request.write(request.theme.send_footer(pagename))
  45     request.theme.send_closing_html()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-10-02 10:21:39, 1.4 KB) [[attachment:ChangeLink.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.