def noscript_fallback_tag(self): return tag.noscript( tag.iframe(src=self.noscript_url(), height=300, width=500, frameborder=0), tag.br(), tag.textarea(name='recaptcha_challenge_field', rows=3, cols=40), tag.input(type='hidden', name='recaptcha_response_field', value='manual_challenge'), )
def render(self, hookname, req): filename = self.filename(hookname) try: contents = file(filename).read() # check for CRLF here too? return tag.textarea(contents, rows='25', cols='80', name='hook-file-contents', disabled=not self.can_enable(hookname) or None) except IOError: if self.can_enable(filename): text = "No %s hook file yet exists; enable this hook to create one" % hookname else: text = "The file, %s, is unwritable; enabling this hook will have no effect" % filename return text
def _review_attrs(self, req, changeset): review = Review.get(self.env.get_db_cnx(),changeset.rev, self.author(changeset)) if req.perm.has_permission('CODE_REVIEW'): comment = tag.textarea(review.comment, name="review_comment", rows=6, cols=100 ) if review.status=="ACCEPTED": checkbox = tag.input(type="checkbox", name="review_passed", checked="true") else: checkbox = tag.input(type="checkbox", name="review_passed") submit = tag.input(type="hidden", name="review_rev", value=changeset.rev)+ \ tag.input(type="hidden", name="review_author", value=self.author(changeset))+ \ tag.input(type="submit", name="review", value="Review") else: comment = tag.span(review.comment) checkbox = tag.span(review.status) submit = ""; return tag.form( tag.dt("Reviewer:",class_="property author"), tag.dd( req.authname,class_="author"), tag.dt("Comment:",class_="property author"), tag.dd( comment ), tag.dt("Passed:",class_="property author"), tag.dd(checkbox+submit) )
def AddComment(macro, environ, data, *args, **kwargs): """Display an add comment form allowing users to post comments. This macro allows you to display an add comment form on the current page allowing users to post comments. The comments are added to the page's content itself. **Arguments:** //No Arguments// **Example(s):** {{{ <<AddComment>> }}} <<AddComment>> """ # Setup info and defaults parser = environ.parser request = environ.request page = data["page"] page_name = page["name"] page_text = page["text"] # Get the data from the POST comment = request.kwargs.get("comment", "") action = request.kwargs.get("action", "") author = request.kwargs.get("author", environ._user()) # Ensure <<AddComment>> is not present in comment, so that infinite # recursion does not occur. comment = re.sub("(^|[^!])(\<\<AddComment)", "\\1!\\2", comment) the_preview = None the_comment = None # If we are submitting or previewing, inject comment as it should look if action == "preview": the_preview = tag.div(tag.h1("Preview"), id="preview") the_preview += tag.div(parser.generate(comment, environ=(environ, data)), class_="article") # When submitting, inject comment before macro if comment and action == "save": new_text = "" comment_text = "\n==== Comment by %s on %s ====\n\n%s\n\n" % ( author, time.strftime('%c', time.localtime()), comment) for line in page_text.split("\n"): if line.find("<<AddComment") == 0: new_text += comment_text new_text += line + "\n" search = environ.search storage = environ.storage storage.reopen() search.update(environ) storage.save_text(page_name, new_text, author, "Comment added by %s" % author) search.update_page(environ.get_page(page_name), page_name, text=new_text) the_comment = tag.div(parser.generate(comment_text, environ=(environ, data)), class_="article") the_form = tag.form( tag.input(type="hidden", name="parent", value=page["node"]), tag.fieldset( tag.legend("Add Comment"), tag.p(tag.textarea( (not action in ("cancel", "save") and comment or ""), id="comment", name="comment", cols=80, rows=5), class_="text"), tag.h4(tag.label("Your email or username:"******"author")), tag.p(tag.input(id="author", name="author", type="text", value=(not action in ("cancel", "save")) and author or ""), class_="input"), tag.p(tag.button("Preview", type="submit", name="action", value="preview"), tag.button("Save", type="submit", name="action", value="save"), tag.button("Cancel", type="submit", name="action", value="cancel"), class_="button"), ), method="post", action="") return tag(the_preview, the_comment, the_form)
class AddCommentMacro(WikiMacroBase): """A macro to add comments to a page. Usage: {{{ [[AddComment]] }}} The macro accepts one optional argument that allows appending to the wiki page even though user may not have modify permission: {{{ [[AddComment(appendonly)]] }}} """ implements(IWikiMacroProvider, IRequestFilter, IMacroPoster) def expand_macro(self, formatter, name, content): args, kw = parse_args(content) req = formatter.req context = formatter.context # Prevent multiple inclusions - store a temp in req if hasattr(req, 'addcommentmacro'): raise TracError('\'AddComment\' macro cannot be included twice.') req.addcommentmacro = True # Prevent it being used outside of wiki page context resource = context.resource if not resource.realm == 'wiki': raise TracError( '\'AddComment\' macro can only be used in Wiki pages.') # Setup info and defaults authname = req.authname page = WikiPage(self.env, resource) page_url = req.href.wiki(resource.id) wikipreview = req.args.get("preview", "") # Can this user add a comment to this page? appendonly = ('appendonly' in args) cancomment = False if page.readonly: if 'WIKI_ADMIN' in req.perm(resource): cancomment = True elif 'WIKI_MODIFY' in req.perm(resource): cancomment = True elif appendonly and 'WIKI_VIEW' in req.perm(resource): cancomment = True else: self.log.debug( 'Insufficient privileges for %s to AddComment to %s', req.authname, resource.id) # Get the data from the POST comment = req.args.get("addcomment", "") preview = req.args.get("previewaddcomment", "") cancel = req.args.get("canceladdcomment", "") submit = req.args.get("submitaddcomment", "") if not cancel and req.authname == 'anonymous': authname = req.args.get("authoraddcomment", authname) # Ensure [[AddComment]] is not present in comment, so that infinite # recursion does not occur. comment = to_unicode( re.sub('(^|[^!])(\[\[AddComment)', '\\1!\\2', comment)) the_preview = the_message = the_form = tag() # If we are submitting or previewing, inject comment as it should look if cancomment and comment and (preview or submit): heading = tag.h4("Comment by ", authname, " on ", to_unicode(time.strftime('%c', time.localtime())), id="commentpreview") if preview: the_preview = tag.div(heading, format_to_html(self.env, context, comment), class_="wikipage", id="preview") # Check the form_token form_ok = True if submit and req.args.get('__FORM_TOKEN', '') != req.form_token: form_ok = False the_message = tag.div(tag.strong("ERROR: "), "AddComment received incorrect form token. " "Do you have cookies enabled?", class_="system-message") # When submitting, inject comment before macro if comment and submit and cancomment and form_ok: submitted = False newtext = "" for line in page.text.splitlines(): if line.find('[[AddComment') == 0: newtext += "==== Comment by %s on %s ====\n%s\n\n" % ( authname, to_unicode(time.strftime('%c', time.localtime())), comment) submitted = True newtext += line + "\n" if submitted: page.text = newtext # Let the wiki page manipulators have a look at the # submission. valid = True req.args.setdefault('comment', 'Comment added.') try: for manipulator in WikiModule(self.env).page_manipulators: for field, message in manipulator.validate_wiki_page( req, page): valid = False if field: the_message += tag.div(tag.strong( "invalid field '%s': " % field), message, class_="system-message") else: the_message += tag.div(tag.strong("invalid: "), message, class_="system-message") # The TracSpamfilterPlugin does not generate messages, # but throws RejectContent. except TracError, s: valid = False the_message += tag.div(tag.strong("ERROR: "), s, class_="system-message") if valid: page.save(authname, req.args['comment'], req.environ['REMOTE_ADDR']) # We can't redirect from macro as it will raise RequestDone # which like other macro errors gets swallowed in the Formatter. # We need to re-raise it in a post_process_request instead. try: self.env.log.debug( "AddComment saved - redirecting to: %s" % page_url) req._outheaders = [] req.redirect(page_url) except RequestDone: req.addcomment_raise = True else: the_message = tag.div( tag.strong("ERROR: "), "[[AddComment]] " "macro call must be the only content on its line. " "Could not add comment.", class_="system-message") the_form = tag.form( tag.fieldset( tag.legend("Add comment"), tag.div((wikipreview and "Page preview..." or None), tag.textarea((not cancel and comment or ""), class_="wikitext", id="addcomment", name="addcomment", cols=80, rows=5, disabled=(not cancomment and "disabled" or None)), class_="field"), (req.authname == 'anonymous' and tag.div( tag.label("Your email or username:"******"authoraddcomment"), tag.input(id="authoraddcomment", type="text", size=30, value=authname, name="authoraddcomment", disabled=(not cancomment and "disabled" or None))) or None), tag.input(type="hidden", name="__FORM_TOKEN", value=req.form_token), tag.div(tag.input(value="Add comment", type="submit", name="submitaddcomment", size=30, disabled=(not cancomment and "disabled" or None)), tag.input(value="Preview comment", type="submit", name="previewaddcomment", disabled=(not cancomment and "disabled" or None)), tag.input(value="Cancel", type="submit", name="canceladdcomment", disabled=(not cancomment and "disabled" or None)), class_="buttons"), ), method="post", action=page_url + "#commenting", ) if not wikipreview: # Wiki edit preview already adds this javascript file add_script(req, 'common/js/wikitoolbar.js') return tag.div(the_preview, the_message, the_form, id="commenting")
def AddComment(macro, environ, data, *args, **kwargs): """Display an add comment form allowing users to post comments. This macro allows you to display an add comment form on the current page allowing users to post comments. The comments are added to the page's content itself. **Arguments:** //No Arguments// **Example(s):** {{{ <<AddComment>> }}} <<AddComment>> """ # Setup info and defaults parser = environ.parser request = environ.request page = data["page"] page_name = page["name"] page_text = page["text"] # Get the data from the POST comment = request.kwargs.get("comment", "") action = request.kwargs.get("action", "") author = request.kwargs.get("author", environ._user()) # Ensure <<AddComment>> is not present in comment, so that infinite # recursion does not occur. comment = re.sub("(^|[^!])(\<\<AddComment)", "\\1!\\2", comment) the_preview = None the_comment = None # If we are submitting or previewing, inject comment as it should look if action == "preview": the_preview = tag.div(tag.h1("Preview"), id="preview") the_preview += tag.div(parser.generate(comment, environ=(environ, data)), class_="article") # When submitting, inject comment before macro if comment and action == "save": new_text = "" comment_text = "\n==== Comment by %s on %s ====\n\n%s\n\n" % ( author, time.strftime('%c', time.localtime()), comment) for line in page_text.split("\n"): if line.find("<<AddComment") == 0: new_text += comment_text new_text += line + "\n" search = environ.search storage = environ.storage storage.reopen() search.update(environ) storage.save_text(page_name, new_text, author, "Comment added by %s" % author) search.update_page(environ.get_page(page_name), page_name, text=new_text) the_comment = tag.div(parser.generate(comment_text, environ=(environ, data)), class_="article") the_form = tag.form( tag.input(type="hidden", name="parent", value=page["node"]), tag.fieldset( tag.legend("Add Comment"), tag.p( tag.textarea( (not action in ("cancel", "save") and comment or ""), id="comment", name="comment", cols=80, rows=5 ), class_="text" ), tag.h4(tag.label("Your email or username:"******"author")), tag.p( tag.input(id="author", name="author", type="text", value=(not action in ("cancel", "save")) and author or "" ), class_="input" ), tag.p( tag.button("Preview", type="submit", name="action", value="preview"), tag.button("Save", type="submit", name="action", value="save"), tag.button("Cancel", type="submit", name="action", value="cancel"), class_="button" ), ), method="post", action="" ) return tag(the_preview, the_comment, the_form)