Ticket #9854 (new enhancement)

Opened 1 year ago

Last modified 4 months ago

Download the images and fonts locally, instead of using the web browser

Reported by: ajo Assigned to: airadier
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

wikiprint.py (19.0 kB) - added by ajo on 01/13/13 15:57:55.
wikiprint py file

Change History

04/06/12 10:04:03 changed by Federico Belli

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

04/06/12 21:21:19 changed by rjollos

Could you provide the changes as a patch file?

01/13/13 15:57:55 changed by ajo

  • attachment wikiprint.py added.

wikiprint py file

01/13/13 16:03:27 changed by ajo

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.

01/13/13 16:29:04 changed by anonymous

And you may check the enhancement #8623 - there is cummulative .PY with both - #9854 and #8623.

01/13/13 23:17:53 changed by rjollos

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!


Add/Change #9854 (Download the images and fonts locally, instead of using the web browser)




Change Properties
Action