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 try: 41 identifier = parsed_args[0] 42 except IndexError, exc: 43 return macro.format_error(exc) 44 45 # Look for keywords determining the action of the macro. 46 47 insert_before = "before" in parsed_args[1:] or not ("after" in parsed_args[1:]) 48 49 # Show the fields for link submission. 50 51 d = { 52 "script_name" : request.getScriptname(), 53 "page_url" : wikiutil.quoteWikinameURL(page.page_name), 54 "identifier" : wikiutil.escape(identifier, 1), 55 "insert_before" : insert_before and "true" or "", 56 "submit_label" : wikiutil.escape(_("Add link")) 57 } 58 59 html = ''' 60 <form class="macro" method="POST" action="%(script_name)s/%(page_url)s"> 61 <input type="hidden" name="action" value="AddLinkToPage" /> 62 <input type="hidden" name="identifier" value="%(identifier)s" /> 63 <input type="hidden" name="insert_before" value="%(insert_before)s" /> 64 <div> 65 <input type="text" name="link" /> 66 <input type="submit" value="%(submit_label)s" /> 67 </div> 68 </form>''' % d 69 70 return formatter.rawHTML(html) 71 72 # vim: tabstop=4 expandtab shiftwidth=4