Changeset 21
- Timestamp:
- 03/03/05 23:49:25 (4 years ago)
- Files:
-
- trunk/macros/AddComment.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/macros/AddComment.py
r9 r21 15 15 page = WikiPage(pagename, None, perm, db) 16 16 wikipreview = hdf.getValue("args.preview", "") 17 readonly = int(hdf.getValue("wiki.readonly", "0")) 17 appendonly = (args == 'appendonly') 18 readonlypage = int(hdf.getValue("wiki.readonly", "0")) 19 # Can this user add a comment to this page? 20 cancomment = not readonlypage 21 # Is this an "append-only" comment or are we an administrator? 22 if perm.has_permission(trac.perm.WIKI_ADMIN) or appendonly: 23 cancomment = True 18 24 19 if readonly and not perm.has_permission(trac.perm.WIKI_ADMIN):25 if not cancomment: 20 26 raise TracError('Error: Insufficient privileges to AddComment') 21 27 … … 28 34 # Ensure [[AddComment]] is not present in comment, so that infinite 29 35 # recursion does not occur. 30 comment = re.sub('(^|[^!])(\[\[AddComment \]\])', '\\1!\\2', comment)36 comment = re.sub('(^|[^!])(\[\[AddComment)', '\\1!\\2', comment) 31 37 32 38 out = StringIO() 33 39 if wikipreview or not perm.has_permission(trac.perm.WIKI_MODIFY): 34 disabled = ' disabled '40 disabled = ' disabled="disabled"' 35 41 36 42 # If we are submitting or previewing, inject comment as it should look 37 if c omment and (preview or submit):43 if cancomment and comment and (preview or submit): 38 44 if preview: 39 45 out.write("<div class='wikipage' id='preview'>\n") 40 out.write("<h4 >Comment by %s on %s</h4>\n<p>\n%s\n</p>\n" % (authname, time.strftime('%c', time.localtime()), wiki_to_html(comment, hdf, env, db)))46 out.write("<h4 id='commentpreview'>Comment by %s on %s</h4>\n<p>\n%s\n</p>\n" % (authname, time.strftime('%c', time.localtime()), wiki_to_html(comment, hdf, env, db))) 41 47 if preview: 42 48 out.write("</div>\n") … … 44 50 # When submitting, inject comment before macro 45 51 if comment and submit: 52 submitted = False 46 53 newtext = StringIO() 47 54 for line in page.text.splitlines(): 48 55 if line.find('[[AddComment') == 0: 49 56 newtext.write("==== Comment by %s on %s ====\n%s\n\n" % (authname, time.strftime('%c', time.localtime()), comment)) 57 submitted = True 50 58 newtext.write(line + "\n") 51 page.set_content(newtext.getvalue()) 52 # TODO: How do we get remote_addr from a macro? 53 page.commit(authname, 'Comment added', None) 54 comment = "" 59 if submitted: 60 # XXX Is this the dodigest hack ever? This is needed in 61 # "appendonly" mode when the page is readonly. XXX 62 if appendonly: 63 perm.expand_meta_permission('WIKI_ADMIN'); 64 page.set_content(newtext.getvalue()) 65 # TODO: How do we get remote_addr from a macro? 66 page.commit(authname, 'Comment added', None) 67 comment = "" 68 else: 69 out.write("<div class='system-message'><strong>ERROR: [[AddComment]] macro call must be the only content on its line. Could not add comment.</strong></div>\n") 55 70 56 out.write("<form name='addcomment' action='%s' method='post'>\n" % env.href.wiki(pagename))71 out.write("<form action='%s#commentpreview' method='post'>\n" % env.href.wiki(pagename)) 57 72 out.write("<fieldset>\n<legend>Add comment</legend>\n") 58 out.write("<textarea id='addcomment' name='addcomment' cols='80' rows='5' wrap='soft'%s>" % disabled)73 out.write("<textarea id='addcomment' name='addcomment' cols='80' rows='5'%s>" % disabled) 59 74 if wikipreview: 60 out.write("P review...")75 out.write("Page preview...") 61 76 elif not cancel: 62 77 out.write(comment) 63 78 out.write("</textarea>\n") 64 out.write("<br >\n")65 out.write("<input type='submit' name='submitaddcomment' value='Add comment'%s >\n" % disabled)66 out.write("<input type='submit' name='previewaddcomment' value='Preview comment'%s >\n" % disabled)67 out.write("<input type='submit' name='canceladdcomment' value='Cancel'%s >\n" % disabled)79 out.write("<br/>\n") 80 out.write("<input type='submit' name='submitaddcomment' value='Add comment'%s/>\n" % disabled) 81 out.write("<input type='submit' name='previewaddcomment' value='Preview comment'%s/>\n" % disabled) 82 out.write("<input type='submit' name='canceladdcomment' value='Cancel'%s/>\n" % disabled) 68 83 out.write("<script type='text/javascript'>\naddWikiFormattingToolbar(document.getElementById('addcomment'));\n</script>\n") 69 84 out.write("</fieldset>\n</form>\n")
