Opened 14 years ago
Last modified 6 years ago
#9854 new enhancement
Download the images and fonts locally, instead of using the web browser
| Reported by: | ajo | Owned by: | |
|---|---|---|---|
| Priority: | high | Component: | TracWikiPrintPlugin |
| Severity: | normal | Keywords: | |
| Cc: | Trac Release: | 0.12 |
Description
I've changed some code in the wikiprint.py in order to enable the local access to the images, fonts and other ressources instead of downloading them via webserver. This can be usefull if you are using IIS on Windows, or you have SSON authentication enabled...
It's a draft, I don't have the time to submit it to SVN, but I hope, someone will take care of it :)
Code
def getFileName(self, name, relative=''):
try:
self.env.log.debug('WikiPrint.linkLoader => Orignal name: %s' % name)
if name.startswith('http://') or name.startswith('https://'):
self.env.log.debug('WikiPrint.linkLoader => Resolving URL: %s' % name)
url = urlparse.urljoin(relative, name)
rawpost = url.find('/raw-attachment/')
if rawpost > -1:
if self.env.config.get('wikiprint', 'raw_attachment_path'):
raw_attachment_path = self.env.config.get('wikiprint', 'raw_attachment_path')
self.env.log.debug('WikiPrint.linkLoader => raw_attachment_path will be applied')
name = url[rawpost+16:]
self.env.log.debug('WikiPrint.linkLoader => Stripped name: %s' % name)
name1=os.path.join(raw_attachment_path, name)
self.env.log.debug('WikiPrint.linkLoader => Changed name: %s' % name1)
inj_control=name1.find(raw_attachment_path)
if inj_control == 0:
return name1
else:
self.env.log.error('WikiPrint.linkLoader => Injection found!' % name1)
return ''
self.env.log.debug('WikiPrint.linkLoader => urljoined URL: %s' % url)
elif self.allow_local:
self.req.perm.assert_permission('WIKIPRINT_FILESYSTEM')
self.env.log.debug("WikiPrint.linkLoader => Resolve local filesystem %s", name)
return name
else:
#Relative path
if self.env.config.get('wikiprint', 'relative_path'):
self.env.log.debug("WikiPrint.linkLoader => Using path %s ",self.env.config.get('wikiprint', 'relative_path'))
url = os.path.join(self.env.config.get('wikiprint', 'relative_path'), name)
self.env.log.debug("WikiPrint.linkLoader => Substituing relative path %s to %s", name, url)
return url
else:
self.env.log.debug("WikiPrint.linkLoader => Relative path %s to %s", name, urlparse.urljoin(self.req.abs_href(), name))
url = urlparse.urljoin(self.req.abs_href(), name)
path = urlparse.urlsplit(url)[2]
Usage
Add following rows in to [wikiprint] section of trac.ini :
raw_attachment_path = D:\Support\Projects\ABC\attachments\ relative_path = D:\FontStorage\
The raw_attachment_path is the path to wiki and ticket attachments in the trac project directory
relative_path is the path to ressource storage... (like fonts used in css etc..)
Attachments (1)
Change History (7)
comment:1 Changed 14 years ago by
comment:3 Changed 13 years ago by
Here are the files. Please keep in mind, that this is just a hotfix and it should be revised/tested prior to submission to SVN.
comment:4 Changed 13 years ago by
comment:5 Changed 13 years ago by
A patch file, generated using e.g. svn diff > <patchfilename> or git diff > <pathfilename> is preferred. You shouldn't ever have to upload a pyc file. Thanks!
comment:6 Changed 6 years ago by
| Owner: | Álvaro Iradier deleted |
|---|



Tested on Windows 7 python 2.7 TracWikiPrint 1.9.2 modified with the code and it works!