PK ΒM:5 addcomment/__init__.pyPK Νl6βχ addcomment/__init__.pyc;ς /Ec @ s d S( N( ( ( ( s8 build/bdist.darwin-8.8.1-i386/egg/addcomment/__init__.pys ? s PK Kl6mWΊ Ί addcomment/macro.py# vim: expandtab from trac.core import * from trac.wiki.macros import WikiMacroBase import trac.perm from StringIO import StringIO from trac.wiki.formatter import wiki_to_html from trac.wiki.model import WikiPage from trac.util import Markup from trac.util import TracError from trac.web.chrome import add_link from trac.util.text import to_unicode import re, time class AddCommentMacro(WikiMacroBase): """A macro to add comments to a page.""" def render_macro(self, req, name, content): return execute(req.hdf, content, self.env) def _render_macro(self, req, name, content): pass # Fill in a deuglified version here def process_macro_post(self, req): self.log.debug('AddCommentMacro: Got a POST') def execute(hdf, args, env): # prevents from multiple inclusions if hdf.has_key('addcommentmacro'): raise TracError('\'AddComment\' macro cannot be included twice') hdf['addcommentmacro'] = True authname = hdf.getValue("trac.authname", "anonymous") db = env.get_db_cnx() perm = trac.perm.PermissionCache(env, authname) pagename = hdf.getValue("wiki.page_name", "WikiStart") page = WikiPage(env, pagename, None, db) wikipreview = hdf.getValue("wiki.preview", "") appendonly = (args == 'appendonly') readonlypage = int(hdf.getValue("wiki.readonly", "0")) # Can this user add a comment to this page? cancomment = not readonlypage # Is this an "append-only" comment or are we an administrator? if perm.has_permission('WIKI_ADMIN') or appendonly: cancomment = True if not cancomment: raise TracError('Error: Insufficient privileges to AddComment') disabled = '' comment = Markup(to_unicode(hdf.getValue("args.addcomment", ""))).unescape() preview = hdf.getValue("args.previewaddcomment", "") cancel = hdf.getValue("args.canceladdcomment", "") submit = hdf.getValue("args.submitaddcomment", "") if not cancel: authname = hdf.getValue("args.authoraddcomment", authname) # Ensure [[AddComment]] is not present in comment, so that infinite # recursion does not occur. comment = re.sub('(^|[^!])(\[\[AddComment)', '\\1!\\2', comment) out = StringIO() if wikipreview or not (perm.has_permission('WIKI_MODIFY') or appendonly): disabled = ' disabled="disabled"' # If we are submitting or previewing, inject comment as it should look if cancomment and comment and (preview or submit): if preview: out.write("
\n%s\n
\n" % (authname, time.strftime('%c', time.localtime()), wiki_to_html(comment, env, None))) if preview: out.write("" + hdf.dump() + "" PK Νl6Α~΄y y addcomment/macro.pyc;ς ίότEc @ s d k Td k l Z d k Z d k l Z d k l Z d k l Z d k l Z d k l Z d k l Z d k l Z d k Z d k Z d e f d YZ d Z d S( ( s *( s WikiMacroBaseN( s StringIO( s wiki_to_html( s WikiPage( s Markup( s TracError( s add_link( s to_unicodes AddCommentMacroc B s) t Z d Z d Z d Z d Z RS( s" A macro to add comments to a page.c C s t | i | | i Sd S( N( s executes reqs hdfs contents selfs env( s selfs reqs names content( ( s5 build/bdist.darwin-8.8.1-i386/egg/addcomment/macro.pys render_macro s c C s d S( N( ( s selfs reqs names content( ( s5 build/bdist.darwin-8.8.1-i386/egg/addcomment/macro.pys _render_macro s c C s | i i d d S( Ns AddCommentMacro: Got a POST( s selfs logs debug( s selfs req( ( s5 build/bdist.darwin-8.8.1-i386/egg/addcomment/macro.pys process_macro_post s ( s __name__s __module__s __doc__s render_macros _render_macros process_macro_post( ( ( s5 build/bdist.darwin-8.8.1-i386/egg/addcomment/macro.pys AddCommentMacro s c C s | i d o t d n t | d <| i d d } | i } t i i | | } | i d d } t | | t | } | i d d } | d j } t | i d d } | } | i d p | o t } n | o t d n d } t t | i d d i } | i d d } | i d d } | i d d } | o | i d | } n t i d d | } t! } | p | i d p | o d } n | o | o | p | ol | o | i# d n | i# d | t$ i% d t$ i&