Attachment 'extAction.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - extAction macro
4
5 Creates an action link.
6
7 Usage:
8
9 [[Action("action")]]
10 Create a link to current page with '?action=action' and the
11 translated link text 'action'.
12
13 [[Action("action", "text")]]
14 Same with custom 'text' as link text.
15
16 [[Action("action", page="pagename")]]
17 Create a link to the page 'pagename' with '?action=action' and the
18 translated link text 'pagename[action]'.
19
20 [[Action("action", "text", "pagename")]]
21 Same with custom 'text' as link text.
22
23 Please note: Except for "Edit" and "Slideshow" translations for the
24 built-in actions are missing in Moin currently.
25
26 @copyright: 2004-2007 by Johannes Berg <johannes@sipsolutions.de>
27 and Oliver Siemoneit <oliver.siemoneit@web.de>
28 @license: GNU GPL, see COPYING for details.
29 """
30
31 from MoinMoin import wikiutil
32 from MoinMoin.Page import Page
33
34 Dependencies = ["language"]
35
36 class ActionLink:
37 """ ActionLink - link to page with action """
38
39 def __init__(self, macro, args):
40 self.macro = macro
41 self.request = macro.request
42 argParser = wikiutil.ParameterParser("%(action)s%(text)s%(page)s")
43 # Prevent argParser from crashing when macro was called with '[[Action]]' only
44 if not args:
45 args='""'
46 self.arg_list, self.arg_dict = argParser.parse_parameters(args)
47
48 def renderInText(self):
49 """ Render macro in text context
50
51 The parser should decide what to do if this macro is placed in a
52 paragraph context.
53 """
54 _ = self.request.getText
55
56 # Default to 'show page' instead of an error message (too lazy to
57 # do an error message now).
58 action = self.arg_dict['action']
59 if not action:
60 action = 'show'
61 action = wikiutil.escape(action, 1)
62
63 # Basepage for action
64 page = self.arg_dict['page']
65
66 # Use text (or translated action name instead) as link text
67 text = self.arg_dict['text']
68 if not text:
69 text = _(action, formatted=False)
70 if page:
71 text = '%s [%s]' % (page, text)
72 text = wikiutil.escape(text, 1)
73
74 # Create link
75 target = self.macro.formatter.page
76 if page:
77 target = Page(self.request, wikiutil.escape(page, 1))
78 link = target.link_to(self.request, text, querystr='action=%s' % action)
79 return link
80
81
82 def execute(macro, args):
83 """ Temporary glue code to use with moin current macro system """
84 return ActionLink(macro, args).renderInText()
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.You are not allowed to attach a file to this page.