PK΄¦8“Χ2EGG-INFO/dependency_links.txt PK΄¦8Aι"Τ::EGG-INFO/entry_points.txt[trac.plugins] includemacro.macros = includemacro.macros PK΄¦8zΑγXEGG-INFO/PKG-INFOMetadata-Version: 1.0 Name: TracIncludeMacro Version: 2.1 Summary: Include the contents of external URLs and other Trac objects in a wiki page. Home-page: http://trac-hacks.org/wiki/IncludeMacro Author: Noah Kantrowitz Author-email: noah@coderanger.net License: BSD Description: Notes ===== This macro lets you include various things. Currently supported sources: * HTTP - ``http:`` and ``https:`` * FTP - ``ftp:`` * Wiki pages - ``wiki:`` * Repository files - ``source:`` The default source is ``wiki`` if only a source path is given. An optional second argument sets the output MIME type, though in most cases the default will be correct. Permissions =========== The three remote sources (``http``, ``https``, and ``ftp``) require ``INCLUDE_URL`` to be rendered. Anyone can add a call to these, however they will not be shown. This is **not** a replacement for ``render_unsafe_content``, see below. Configuration ============= If ``[wiki] render_unsafe_content`` is off (the default), any produced HTML will be sanitized. :warn: This is a potential security risk! Please review the implications ``render_unsafe_content`` before using this feature. To enable the plugin:: [components] includemacro.* = enabled Example ======= Include another wiki page:: [[Include(PageName)]] Include a reStructuredText__ file from the repository:: [[Include(source:trunk/docs/README, text/x-rst)]] __ http://docutils.sf.net/rst.htm :tip: If you set the ``svn:mime-type`` property on the file, you can leave off the explicit MIME type. Keywords: trac 0.11 plugin wiki include macro Platform: UNKNOWN Classifier: Framework :: Trac PK΄¦8Σ‘šEGG-INFO/requires.txtTracPK΄¦8§Y/22EGG-INFO/SOURCES.txtREADME setup.py TracIncludeMacro.egg-info/PKG-INFO TracIncludeMacro.egg-info/SOURCES.txt TracIncludeMacro.egg-info/dependency_links.txt TracIncludeMacro.egg-info/entry_points.txt TracIncludeMacro.egg-info/requires.txt TracIncludeMacro.egg-info/top_level.txt includemacro/__init__.py includemacro/macros.py PK΄¦8 Nι EGG-INFO/top_level.txtincludemacro PK΄¦8“Χ2EGG-INFO/zip-safe PKk)6includemacro/__init__.pyPK΄¦8*+쉋‹includemacro/__init__.pyc;ς *N£Ec@sdS(N((((s;build/bdist.darwin-8.11.1-i386/egg/includemacro/__init__.pys?sPKλ¦8~:ŒW††includemacro/macros.py# TracIncludeMacro macros import urllib2 from StringIO import StringIO from trac.core import * from trac.wiki.macros import WikiMacroBase from trac.wiki.formatter import system_message from trac.wiki.model import WikiPage from trac.mimeview.api import Mimeview, get_mimetype, Context from trac.perm import IPermissionRequestor from genshi.core import escape from genshi.input import HTMLParser, ParseError from genshi.filters.html import HTMLSanitizer __all__ = ['IncludeMacro'] class IncludeMacro(WikiMacroBase): """A macro to include other resources in wiki pages. More documentation to follow. """ implements(IPermissionRequestor) # Default output formats for sources that need them default_formats = { 'wiki': 'text/x-trac-wiki', } # IWikiMacroProvider methods def render_macro(self, req, name, content): args = [x.strip() for x in content.split(',')] if len(args) == 1: args.append(None) elif len(args) != 2: return system_message('Invalid arguments "%s"'%content) # Pull out the arguments source, dest_format = args try: source_format, source_obj = source.split(':', 1) except ValueError: # If no : is present, assume its a wiki page source_format, source_obj = 'wiki', source # Apply a default format if needed if dest_format is None: try: dest_format = self.default_formats[source_format] except KeyError: pass if source_format in ('http', 'https', 'ftp'): # Since I can't really do recursion checking, and because this # could be a source of abuse allow selectively blocking it. # RFE: Allow blacklist/whitelist patterns for URLS. # RFE: Track page edits and prevent unauthorized users from ever entering a URL include. if not req.perm.has_permission('INCLUDE_URL'): self.log.info('IncludeMacro: Blocking attempt by %s to include URL %s on page %s', req.authname, source, req.path_info) return '' try: urlf = urllib2.urlopen(source) out = urlf.read() except urllib2.URLError, e: return system_message('Error while retrieving file', str(e)) except TracError, e: return system_message('Error while previewing', str(e)) ctxt = Context.from_request(req) elif source_format == 'wiki': # XXX: Check for recursion in page includes. if not req.perm.has_permission('WIKI_VIEW'): return '' page = WikiPage(self.env, source_obj) if not page.exists: return system_message('Wiki page %s does not exist'%source_obj) out = page.text ctxt = Context.from_request(req, 'wiki', source_obj) elif source_format == 'source': if not req.perm.has_permission('FILE_VIEW'): return '' repo = self.env.get_repository(req.authname) node = repo.get_node(source_obj) out = node.get_content().read() if dest_format is None: dest_format = node.content_type or get_mimetype(source_obj, out) ctxt = Context.from_request(req, 'source', source_obj) # RFE: Add ticket: and comment: sources. # RFE: Add attachment: source. else: return system_message('Unsupported include source %s'%source) # If we have a preview format, use it if dest_format: out = Mimeview(self.env).render(ctxt, dest_format, out) # Escape if needed if not self.config.getbool('wiki', 'render_unsafe_content', False): try: out = HTMLParser(StringIO(out)).parse() | HTMLSanitizer() except ParseError: out = escape(out) return out # IPermissionRequestor methods def get_permission_actions(self): yield 'INCLUDE_URL' PK΄¦8YbI“ίίincludemacro/macros.pyc;ς « Hc@sΊdkZdklZdkTdklZdklZdklZdk l Z l Z l Z dk lZdklZd klZlZd klZd gZd efd „ƒYZdS( N(sStringIO(s*(s WikiMacroBase(ssystem_message(sWikiPage(sMimeviews get_mimetypesContext(sIPermissionRequestor(sescape(s HTMLParsers ParseError(s HTMLSanitizers IncludeMacrocBs9tZdZeeƒhdd