# HG changeset patch # User Paul Boddie # Date 1374256599 -7200 # Node ID 465cae9a8a2b83cc0eba40e250ce923b2fcf0ae3 # Parent bd751ca0e7f8170014c39e6397ff6c965f5c3444 Added a macro that shows comment subpages and an action for posting new comments. diff -r bd751ca0e7f8 -r 465cae9a8a2b README.txt --- a/README.txt Fri Jul 19 16:25:35 2013 +0200 +++ b/README.txt Fri Jul 19 19:56:39 2013 +0200 @@ -57,6 +57,16 @@ http://hgweb.boddie.org.uk/MoinSupport http://moinmo.in/MacroMarket/Color2 +In addition, extensions are provided in this distribution to support various +Confluence features, notably comments on pages. These extensions are installed +as follows: + +python moinsetup.py -m install_actions $CCDIR/actions +python moinsetup.py -m install_macros $CCDIR/macros +python moinsetup.py -m install_theme_resources $CCDIR +python moinsetup.py -m edit_theme_stylesheet screen.css includecomments.css +python moinsetup.py -m edit_theme_stylesheet print.css includecomments.css + Quick Start ----------- diff -r bd751ca0e7f8 -r 465cae9a8a2b actions/PostComment.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/actions/PostComment.py Fri Jul 19 19:56:39 2013 +0200 @@ -0,0 +1,95 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - IncludeComments Macro + + @copyright: 2013 by Paul Boddie + @license: GNU GPL (v2 or later), see COPYING.txt for details. +""" + +from MoinMoin.action import ActionBase +from MoinMoin.PageEditor import PageEditor +from MoinMoin.wikiutil import escape +from MoinSupport import getPagesForSearch, getPagesFromResults, ActionSupport + +Dependencies = ['pages'] + +class PostComment(ActionBase, ActionSupport): + + "Post a comment to the wiki." + + def get_form_html(self, buttons_html): + + "Return the action's form incorporating the 'buttons_html'." + + _ = self._ + request = self.request + form = self.get_form() + + comment = form.get("comment", [""])[0] + + d = { + "comment_label" : escape(_("Write a comment in the box.")), + "comment_default" : escape(comment), + "buttons_html" : buttons_html, + } + + return u"""\ +

%(comment_label)s

+ +

%(buttons_html)s

+""" % d + + def do_action(self): + + "Attempt to post a comment." + + _ = self._ + request = self.request + form = self.get_form() + + comment = form.get("comment", [""])[0] + + if not comment.strip(): + return 0, _("A comment should have some content.") + + if not request.user.valid or not request.user.may.write(self.pagename): + return 0, _("You are not allowed to comment on this page.") + + # Determine the last comment. + + comments = get_comment_numbers(self.pagename, request) + last_comment_pagename = comments and comments[-1] or -1 + + # Write the new page. + + new_page = PageEditor(request, "%s/%04d" % (self.pagename, last_comment_pagename + 1)) + + try: + new_page.saveText(comment, 0) + return 1, _("Comment added.") + except new_page.SaveError, exc: + return 0, unicode(exc) + +def get_comment_numbers(pagename, request): + + """ + Return a list of comment numbers associated with the given 'pagename', using + the 'request' provided. + """ + + pagenames = [] + + for page in getPagesForSearch("title:regex:^%s/" % pagename, request): + basename, number = page.page_name.rsplit("/", 1) + if basename == pagename and number.isdigit(): + pagenames.append(int(number)) + + pagenames.sort() + return pagenames + +# Action invocation function. + +def execute(pagename, request): + PostComment(pagename, request).render() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r bd751ca0e7f8 -r 465cae9a8a2b convert.py --- a/convert.py Fri Jul 19 16:25:35 2013 +0200 +++ b/convert.py Fri Jul 19 19:56:39 2013 +0200 @@ -520,7 +520,7 @@ comment_section = """ ---- -<> +<> """ # Main program. diff -r bd751ca0e7f8 -r 465cae9a8a2b css/includecomments.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/css/includecomments.css Fri Jul 19 19:56:39 2013 +0200 @@ -0,0 +1,32 @@ +/* includecomments.css - some additional styles for the IncludeComments macro + which can be included in screen.css and print.css + using... + + @import "includecomments.css"; + + ...before any rules. + +Copyright (c) 2013 by Paul Boddie +Licensed under the GNU GPL (v2 or later), see COPYING.txt for details. +*/ + +.included-comment { + margin: 1em; + border: 2px solid #ddd; + padding: 1em; +} + +/* Hide the link to the comment form when showing the form. */ + +#includecomments-anchor:target > a { + display: none; +} + +/* Hide the comment form unless the link has been followed. */ + +#includecomments-anchor:not(:target) .includecomments-form { + display: none; +} + +/* vim: tabstop=4 expandtab shiftwidth=4 + */ diff -r bd751ca0e7f8 -r 465cae9a8a2b macros/IncludeComments.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/macros/IncludeComments.py Fri Jul 19 19:56:39 2013 +0200 @@ -0,0 +1,55 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - IncludeComments Macro + + @copyright: 2013 by Paul Boddie + @license: GNU GPL (v2 or later), see COPYING.txt for details. +""" + +from MoinMoin.macro import Include +from MoinMoin.wikiutil import escape + +Dependencies = ['pages'] + +# Macro functions. + +def execute(macro, text): + request = macro.request + fmt = request.formatter + pagename = request.page.page_name + _ = request.getText + + included_content = Include.execute(macro, text or "^%s/" % pagename, included_page_css_class="included-comment") + + output = [] + append = output.append + + # Provide a form for adding new comments. + + if request.user.valid and request.user.may.write(pagename): + + d = { + "show_form" : escape(_("Add a comment to this page.")), + "comment_label" : escape(_("Write a comment in the box.")), + "comment_default" : "", + "submit" : escape(_("Submit this comment")), + } + + append("""\ +
+%(show_form)s +
+

%(comment_label)s

+ +

+
+
+""" % d) + + # Add included comments. + + append(included_content) + + return u"".join(output) + +# vim: tabstop=4 expandtab shiftwidth=4