1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - AddLinkToPage 4 5 Add a link using a form in the page, getting details of the linked document 6 and inserting them with the link itself. 7 8 @copyright: 2010 Paul Boddie <paul@boddie.org.uk> 9 @license: GNU GPL, see COPYING for details. 10 """ 11 12 Dependencies = ["pages"] 13 14 from MoinMoin import wikiutil 15 16 # Macro functions. 17 18 def execute(macro, args): 19 20 """ 21 Execute the 'macro' with the given 'args': 22 """ 23 24 request = macro.request 25 formatter = macro.formatter 26 page = formatter.page 27 _ = macro._ 28 29 # Interpret the arguments. 30 31 try: 32 parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or [] 33 except AttributeError: 34 parsed_args = args.split(",") 35 36 parsed_args = [arg for arg in parsed_args if arg] 37 38 # The macro's identifier should always appear first. 39 40 identifier = parsed_args[0] 41 42 # Look for keywords determining the action of the macro. 43 44 insert_before = "before" in parsed_args[1:] or not ("after" in parsed_args[1:]) 45 46 # Show the fields for link submission. 47 48 d = { 49 "script_name" : request.getScriptname(), 50 "page_url" : wikiutil.quoteWikinameURL(page.page_name), 51 "identifier" : wikiutil.escape(identifier, 1), 52 "insert_before" : insert_before and "true" or "", 53 "submit_label" : wikiutil.escape(_("Add link")) 54 } 55 56 html = ''' 57 <form class="macro" method="POST" action="%(script_name)s/%(page_url)s"> 58 <input type="hidden" name="action" value="AddLinkToPage" /> 59 <input type="hidden" name="identifier" value="%(identifier)s" /> 60 <input type="hidden" name="insert_before" value="%(insert_before)s" /> 61 <div> 62 <input type="text" name="link" /> 63 <input type="submit" value="%(submit_label)s" /> 64 </div> 65 </form>''' % d 66 67 return formatter.rawHTML(html) 68 69 # vim: tabstop=4 expandtab shiftwidth=4