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