Changeset 3038 for trac


Ignore:
Timestamp:
10/27/05 18:50:34 (8 years ago)
Author:
moschny
Message:

Import of http://trac-hacks.swapoff.org/browser/addcommentmacro/0.9/AddComment.py?format=raw .

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trac/trunk/wiki-macros/AddComment.py

    r3000 r3038  
    77from trac.wiki.model import WikiPage 
    88from trac.util import TracError 
     9from trac.web.chrome import add_link 
    910import re 
    1011 
     
    1718    authname = hdf.getValue("trac.authname", "anonymous") 
    1819    db = env.get_db_cnx() 
    19     perm = trac.perm.PermissionCache(db, authname) 
     20    perm = trac.perm.PermissionCache(env, authname) 
    2021    pagename = hdf.getValue("wiki.page_name", "WikiStart") 
    2122    page = WikiPage(env, pagename, None, db) 
     
    2627    cancomment = not readonlypage 
    2728    # Is this an "append-only" comment or are we an administrator? 
    28     if perm.has_permission(trac.perm.WIKI_ADMIN) or appendonly: 
     29    if perm.has_permission('WIKI_ADMIN') or appendonly: 
    2930        cancomment = True 
    3031 
     
    3334 
    3435    disabled = '' 
    35     print dir(hdf) 
    3636 
    3737    comment = hdf.getValue("args.addcomment", "") 
     
    4747 
    4848    out = StringIO() 
    49     if wikipreview or not perm.has_permission(trac.perm.WIKI_MODIFY): 
     49    if wikipreview or not (perm.has_permission('WIKI_MODIFY') or appendonly): 
    5050        disabled = ' disabled="disabled"' 
    5151 
     
    5454        if preview: 
    5555            out.write("<div class='wikipage' id='preview'>\n") 
    56         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))) 
     56        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, env, None))) 
    5757        if preview: 
    5858            out.write("</div>\n") 
     
    6868            newtext.write(line + "\n") 
    6969        if submitted: 
    70             # XXX Is this the dodigest hack ever? This is needed in  
     70            # XXX Is this the dodgiest hack ever? This is needed in  
    7171            # "appendonly" mode when the page is readonly. XXX 
    72             if appendonly: 
    73                 perm.expand_meta_permission('WIKI_ADMIN'); 
     72#            if appendonly: 
     73#                perm.expand_meta_permission('WIKI_ADMIN'); 
    7474            # TODO: How do we get remote_addr from a macro? 
    7575            page.text = newtext.getvalue() 
     
    7979            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") 
    8080 
    81     out.write("<form action='%s#commentpreview' method='post'>\n" % env.href.wiki(pagename)) 
     81    out.write("<form action='%s#commentpreview' method='get'>\n" % env.href.wiki(pagename)) 
    8282    out.write("<fieldset>\n<legend>Add comment</legend>\n") 
    8383    out.write("<div class='field'>\n<textarea id='addcomment' name='addcomment' cols='80' rows='5'%s>" % disabled) 
     
    9292    out.write("<input type='submit' name='previewaddcomment' value='Preview comment'%s/>\n" % disabled) 
    9393    out.write("<input type='submit' name='canceladdcomment' value='Cancel'%s/>\n</div>\n" % disabled) 
     94    out.write('<script type="text/javascript" src="%sjs/wikitoolbar.js"></script>' % hdf['htdocs_location']) 
    9495    out.write("<script type='text/javascript'>\naddWikiFormattingToolbar(document.getElementById('addcomment'));\n</script>\n") 
    9596    out.write("</fieldset>\n</form>\n") 
Note: See TracChangeset for help on using the changeset viewer.