1.1 --- a/README.txt Fri Jul 19 16:25:35 2013 +0200
1.2 +++ b/README.txt Fri Jul 19 19:56:39 2013 +0200
1.3 @@ -57,6 +57,16 @@
1.4 http://hgweb.boddie.org.uk/MoinSupport
1.5 http://moinmo.in/MacroMarket/Color2
1.6
1.7 +In addition, extensions are provided in this distribution to support various
1.8 +Confluence features, notably comments on pages. These extensions are installed
1.9 +as follows:
1.10 +
1.11 +python moinsetup.py -m install_actions $CCDIR/actions
1.12 +python moinsetup.py -m install_macros $CCDIR/macros
1.13 +python moinsetup.py -m install_theme_resources $CCDIR
1.14 +python moinsetup.py -m edit_theme_stylesheet screen.css includecomments.css
1.15 +python moinsetup.py -m edit_theme_stylesheet print.css includecomments.css
1.16 +
1.17 Quick Start
1.18 -----------
1.19
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/actions/PostComment.py Fri Jul 19 19:56:39 2013 +0200
2.3 @@ -0,0 +1,95 @@
2.4 +# -*- coding: iso-8859-1 -*-
2.5 +"""
2.6 + MoinMoin - IncludeComments Macro
2.7 +
2.8 + @copyright: 2013 by Paul Boddie <paul@boddie.org.uk>
2.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
2.10 +"""
2.11 +
2.12 +from MoinMoin.action import ActionBase
2.13 +from MoinMoin.PageEditor import PageEditor
2.14 +from MoinMoin.wikiutil import escape
2.15 +from MoinSupport import getPagesForSearch, getPagesFromResults, ActionSupport
2.16 +
2.17 +Dependencies = ['pages']
2.18 +
2.19 +class PostComment(ActionBase, ActionSupport):
2.20 +
2.21 + "Post a comment to the wiki."
2.22 +
2.23 + def get_form_html(self, buttons_html):
2.24 +
2.25 + "Return the action's form incorporating the 'buttons_html'."
2.26 +
2.27 + _ = self._
2.28 + request = self.request
2.29 + form = self.get_form()
2.30 +
2.31 + comment = form.get("comment", [""])[0]
2.32 +
2.33 + d = {
2.34 + "comment_label" : escape(_("Write a comment in the box.")),
2.35 + "comment_default" : escape(comment),
2.36 + "buttons_html" : buttons_html,
2.37 + }
2.38 +
2.39 + return u"""\
2.40 +<p>%(comment_label)s</p>
2.41 +<textarea name="comment" cols="60" rows="10">%(comment_default)s</textarea>
2.42 +<p>%(buttons_html)s</p>
2.43 +""" % d
2.44 +
2.45 + def do_action(self):
2.46 +
2.47 + "Attempt to post a comment."
2.48 +
2.49 + _ = self._
2.50 + request = self.request
2.51 + form = self.get_form()
2.52 +
2.53 + comment = form.get("comment", [""])[0]
2.54 +
2.55 + if not comment.strip():
2.56 + return 0, _("A comment should have some content.")
2.57 +
2.58 + if not request.user.valid or not request.user.may.write(self.pagename):
2.59 + return 0, _("You are not allowed to comment on this page.")
2.60 +
2.61 + # Determine the last comment.
2.62 +
2.63 + comments = get_comment_numbers(self.pagename, request)
2.64 + last_comment_pagename = comments and comments[-1] or -1
2.65 +
2.66 + # Write the new page.
2.67 +
2.68 + new_page = PageEditor(request, "%s/%04d" % (self.pagename, last_comment_pagename + 1))
2.69 +
2.70 + try:
2.71 + new_page.saveText(comment, 0)
2.72 + return 1, _("Comment added.")
2.73 + except new_page.SaveError, exc:
2.74 + return 0, unicode(exc)
2.75 +
2.76 +def get_comment_numbers(pagename, request):
2.77 +
2.78 + """
2.79 + Return a list of comment numbers associated with the given 'pagename', using
2.80 + the 'request' provided.
2.81 + """
2.82 +
2.83 + pagenames = []
2.84 +
2.85 + for page in getPagesForSearch("title:regex:^%s/" % pagename, request):
2.86 + basename, number = page.page_name.rsplit("/", 1)
2.87 + if basename == pagename and number.isdigit():
2.88 + pagenames.append(int(number))
2.89 +
2.90 + pagenames.sort()
2.91 + return pagenames
2.92 +
2.93 +# Action invocation function.
2.94 +
2.95 +def execute(pagename, request):
2.96 + PostComment(pagename, request).render()
2.97 +
2.98 +# vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/convert.py Fri Jul 19 16:25:35 2013 +0200
3.2 +++ b/convert.py Fri Jul 19 19:56:39 2013 +0200
3.3 @@ -520,7 +520,7 @@
3.4 comment_section = """
3.5 ----
3.6
3.7 -<<Include("^%s/")>>
3.8 +<<ShowComments>>
3.9 """
3.10
3.11 # Main program.
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/css/includecomments.css Fri Jul 19 19:56:39 2013 +0200
4.3 @@ -0,0 +1,32 @@
4.4 +/* includecomments.css - some additional styles for the IncludeComments macro
4.5 + which can be included in screen.css and print.css
4.6 + using...
4.7 +
4.8 + @import "includecomments.css";
4.9 +
4.10 + ...before any rules.
4.11 +
4.12 +Copyright (c) 2013 by Paul Boddie
4.13 +Licensed under the GNU GPL (v2 or later), see COPYING.txt for details.
4.14 +*/
4.15 +
4.16 +.included-comment {
4.17 + margin: 1em;
4.18 + border: 2px solid #ddd;
4.19 + padding: 1em;
4.20 +}
4.21 +
4.22 +/* Hide the link to the comment form when showing the form. */
4.23 +
4.24 +#includecomments-anchor:target > a {
4.25 + display: none;
4.26 +}
4.27 +
4.28 +/* Hide the comment form unless the link has been followed. */
4.29 +
4.30 +#includecomments-anchor:not(:target) .includecomments-form {
4.31 + display: none;
4.32 +}
4.33 +
4.34 +/* vim: tabstop=4 expandtab shiftwidth=4
4.35 + */
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/macros/IncludeComments.py Fri Jul 19 19:56:39 2013 +0200
5.3 @@ -0,0 +1,55 @@
5.4 +# -*- coding: iso-8859-1 -*-
5.5 +"""
5.6 + MoinMoin - IncludeComments Macro
5.7 +
5.8 + @copyright: 2013 by Paul Boddie <paul@boddie.org.uk>
5.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
5.10 +"""
5.11 +
5.12 +from MoinMoin.macro import Include
5.13 +from MoinMoin.wikiutil import escape
5.14 +
5.15 +Dependencies = ['pages']
5.16 +
5.17 +# Macro functions.
5.18 +
5.19 +def execute(macro, text):
5.20 + request = macro.request
5.21 + fmt = request.formatter
5.22 + pagename = request.page.page_name
5.23 + _ = request.getText
5.24 +
5.25 + included_content = Include.execute(macro, text or "^%s/" % pagename, included_page_css_class="included-comment")
5.26 +
5.27 + output = []
5.28 + append = output.append
5.29 +
5.30 + # Provide a form for adding new comments.
5.31 +
5.32 + if request.user.valid and request.user.may.write(pagename):
5.33 +
5.34 + d = {
5.35 + "show_form" : escape(_("Add a comment to this page.")),
5.36 + "comment_label" : escape(_("Write a comment in the box.")),
5.37 + "comment_default" : "",
5.38 + "submit" : escape(_("Submit this comment")),
5.39 + }
5.40 +
5.41 + append("""\
5.42 +<div id="includecomments-anchor">
5.43 +<a href="#includecomments-anchor">%(show_form)s</a>
5.44 +<form action="?action=PostComment" method="post" class="includecomments-form">
5.45 +<p>%(comment_label)s</p>
5.46 +<textarea name="comment" cols="60" rows="10">%(comment_default)s</textarea>
5.47 +<p><input name="submit" type="submit" value="%(submit)s" /></p>
5.48 +</form>
5.49 +</div>
5.50 +""" % d)
5.51 +
5.52 + # Add included comments.
5.53 +
5.54 + append(included_content)
5.55 +
5.56 + return u"".join(output)
5.57 +
5.58 +# vim: tabstop=4 expandtab shiftwidth=4