1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - IncludeComments Macro 4 5 @copyright: 2013 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 from MoinMoin.macro import Include 10 from MoinMoin.wikiutil import escape 11 12 Dependencies = ['pages'] 13 14 # Macro functions. 15 16 def execute(macro, text): 17 request = macro.request 18 fmt = request.formatter 19 pagename = request.page.page_name 20 _ = request.getText 21 22 included_content = Include.execute(macro, text or "^%s/" % pagename, included_page_css_class="included-comment") 23 24 output = [] 25 append = output.append 26 27 # Provide a form for adding new comments. 28 29 if request.user.valid and request.user.may.write(pagename): 30 31 d = { 32 "show_form" : escape(_("Add a comment to this page.")), 33 "comment_label" : escape(_("Write a comment in the box.")), 34 "comment_default" : "", 35 "submit" : escape(_("Submit this comment")), 36 } 37 38 append("""\ 39 <div id="includecomments-anchor"> 40 <a href="#includecomments-anchor">%(show_form)s</a> 41 <form action="?action=PostComment" method="post" class="includecomments-form"> 42 <p>%(comment_label)s</p> 43 <textarea name="comment" cols="60" rows="10">%(comment_default)s</textarea> 44 <p><input name="submit" type="submit" value="%(submit)s" /></p> 45 </form> 46 </div> 47 """ % d) 48 49 # Add included comments. 50 51 append(included_content) 52 53 return u"".join(output) 54 55 # vim: tabstop=4 expandtab shiftwidth=4