Edgewall Software

Ticket #5241 (new defect)

Opened 21 months ago

Last modified 6 months ago

Conversion of MediaWiki database to Trac Wiki database.

Reported by: Koen Werdler <werdlerk@…> Owned by: jonas
Priority: normal Milestone: not applicable
Component: general Version:
Severity: normal Keywords: trac faq wiki mediawiki
Cc: rganz@…

Description

The script provided on the wiki:TracFaq page doesn't work for MediaWiki 1.5 since the database structure has been changed.

Attached is the script I used to export the pages from Mediawiki and then import them into Trac.

Maybe someone can put this at the FAQ for me since I don't know how I should do this?

Thanks

Attachments

mediawiki2trac.ph (2.1 KB) - added by Koen Werdler <werdlerk@…> 21 months ago.
Modified MediaWiki 1.5 to Trac script (original from wiki:TracFaq)
mediawiki2trac.py (4.9 KB) - added by jason.dusek@… 6 months ago.
This script handles revisions, User: pages and Talk: pages. It exports to SQL.
mediawiki2trac.2.py (5.3 KB) - added by jason.dusek@… 6 months ago.
This version translates links correctly.
mediawiki2trac.3.py (5.2 KB) - added by jason.dusek@… 6 months ago.
This one does links even a little more nicely.
mw2tw.py (6.3 KB) - added by jason.dusek@… 6 months ago.
Grabs image data and puts it into the Trac tables. Links are more nicely formatted.

Change History

Changed 21 months ago by Koen Werdler <werdlerk@…>

Modified MediaWiki 1.5 to Trac script (original from wiki:TracFaq)

Changed 21 months ago by Koen Werdler <werdlerk@…>

mediawiki2trac.ph should've been named mediawiki2trac.py :/

Changed 18 months ago by cobwebsmasher@…

Thanks for this script. This is actually useful to me as I have an existing Mediawiki installation that folks want as part of Trac now.

Question: This code doesn't appear to address attachments. Is this a known issue or does trac-admin import mystically take care of this somehow?

Changed 18 months ago by anonymous

  • cc werdlerk@… added

Changed 17 months ago by cobwebsmasher@…

  • owner changed from jonas to anonymous
  • status changed from new to assigned

OK. Well I've done some research about attachments.

MediaWiki handles attached files in a completely different way than Trac does. In Trac, you have attached files that are associated with a given page. Whereas in MediaWiki you have files that are uploaded and it's up to the wiki-editors to create links to the uploaded documents.

So, the process for dealing with "attachments" depends on a couple of factors.

If you want your downloaded documents to be unique in Trac like they are in mediawiki, then that's a problem. AFAIK, uniqueness in mediawiki is based on the filename whereas in Trac it's a combination of filename and what Wiki page the attachment is associated with.

So if you have an attachment that is linked in multiple places from on your MediaWiki page, then to have the same effect you'd either have to set up an independent web for these attachments (so all things would link to the same file) or you need to give up on the notion that the file is unique and that you have attachments that represent copies of the file in question.

Another interesting bit is the hash encoding that can occur with how Mediawiki stores the actual files.

I haven't looked into this supremely closely, but it appears that storing the files can be toggled between two methods. The method that is enabled on our MediaWiki instance is based on the following:

Attached files are stored in an images/ folder (and possibly a media/ folder. We don't have one, but our version is 1.6 and we only have the images/ folder to store uploads).

The subfolders that the actual attachment is stored in is based on the first 2 characters of the md5 hash of the filename. You can derive the file path using the following SQL query:

select 
img_name, 
concat(left(md5(img_name),1), '/', left(md5(img_name),2), '/', img_name) as path 
from image;

So at this point, I'm going to modify the script you have here to include the possibility of bringing attachments along, moving the downloaded files to the appropriate trac directory and updating the trac database accordingly.

See you back here in a few minutes.

Changed 17 months ago by eblot

  • owner changed from anonymous to jonas
  • status changed from assigned to new

Changed 16 months ago by anonymous

  • cc rganz@… added

Changed 6 months ago by jason.dusek@…

This script handles revisions, User: pages and Talk: pages. It exports to SQL.

Changed 6 months ago by jason.dusek@…

This version translates links correctly.

Changed 6 months ago by jason.dusek@…

This one does links even a little more nicely.

Changed 6 months ago by jason.dusek@…

  • summary changed from Modified mediawiki 2 trac script to Image grabbing `sh` code.

I found out how to get the images and put them in an "Image page" that is kind of like the MediaWiki image page. I'll post the Python for generating the database part of that in a minute. In the meantime, I'll post the sh I used to gather and organize the images:

 :; find <your mediawiki installation>/images -type f > image-like-files 
 :; egrep -v 'archive|README' image-like-files > f
 :; cat f | sed -r "s|^.+/([^/]+)$|mkdir 'Image/\1' \&\& cp '&' 'Image/\1/\1'|" | sh

Changed 6 months ago by jason.dusek@…

Grabs image data and puts it into the Trac tables. Links are more nicely formatted.

Changed 6 months ago by werdlerk@…

  • cc werdlerk@… removed

Changed 6 months ago by jason.dusek@…

  • summary changed from Image grabbing `sh` code. to Conversion of MediaWiki database to Trac Wiki database.

Still not really done, alas. The data store in MediaWiki is designed to be used, not transformed. What I've worked out so far:

  • Recovery of User:, Talk: and Image: pages.
  • Recovery of image metadata.
  • Recovery of revision history.
  • Reformatting of links, so they are both functional and attractive.

What I have not done:

  • The User_talk: pages are omitted.
  • Any HTML code in the MediaWiki documents is simply ignored.
  • Page moves and archived images are ignored.
  • Anonymous users, with just an IP address, are ignored.

If you ever find yourself afflicted with this task, you have my blessing.

Add/Change #5241 (Conversion of MediaWiki database to Trac Wiki database.)

Author



Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from jonas. Next status will be 'new'
The owner will change from jonas to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.