DocBook XML export - broken imagelinks

9 views
Skip to first unread message

MichaelS_UL

unread,
Feb 17, 2011, 3:02:42 AM2/17/11
to mwlib
Hi,

I am using MediaWiki 1.15 with mwlib 0.12.12.

When I export Wikipages with images (png, jpg) as DocBook XML I get
broken image links. The links in the exported XML file look like
this:

http://hostname/index.php?oldid=40

When I change the dbwriteImageLink method in the docbookwriter.py file
from:

imgsrc = self.environment.images.getURL(obj.target, obj.width or
None)

To:

imgsrc = self.environment.images.getURL(obj.target)

I get at least the wiki-page which describes the image:

http://hostname/index.php?title=File:image.jpg

But this is still not valid in DocBook XML, I need the direct link to
the image on the server, for example:

http://hostname/images/0/05/imagename.jpg

Does anyone of you have an idea how I can get the complete path to the
image on the server? The getURL method is in the nuwiki.py file. There
the imagelinks are built.

I tried and googled a lot ... without success. I really appreciate
every tip!

Thanks in advance,
Michael

MichaelS_UL

unread,
Feb 18, 2011, 9:52:37 AM2/18/11
to mwlib

I found the solution myself.

In case someone else faces this problem:

change the else-clause in the getURL method in nuwiki.py to the
following:

fqtitle = self.nshandler.get_fqname(name,
defaultns=defaultns)

import hashlib
import os.path

part = fqtitle.partition(":")

md5hash = hashlib.md5(part[2].replace(' ',
'_')).hexdigest()
path = "%s%s%s" %(md5hash[0], os.path.sep, md5hash[0:2])

return base_url + "images/" + path + "/" +
part[2].replace(' ', '_')

best regards,
Michael
Reply all
Reply to author
Forward
0 new messages