PhpWiki to MoinMoin Converter ideas
Ok, so I wish to go to MoinMoin, mainly because of ACLs, easier scripting and the so nicer language.
Whatever the reasons.
Basic ideas
PhpWiki can create backup dumps. Those dumps are formatted as MIME (read email). Happily, it seems Python has support for MIME, so it should be no problem to import the pages.
Then, it's only a matter of finding the proper way of creating the page in MoinMoin, and converting the content of each page to be MoinMoin compatible. So we need to document how to create those pages, and the differences between PhpWiki formatting and MoinMoin formatting.
Differences between PhpWiki and MoinMoin formatting
References: HelpOnEditing, TextFormattingRules
Listing only differences.
feature PhpWiki Implemented MoinMoin Conversion Difficulty ------------------------------------------------------------------------- linking [link] X ["link"] regexp trivial linking [text|link] X [link text] regexp trivial style *strong* '''strong''' regexp hard, watch out for lists and false positives style _emphasis_ ''emphasis'' regexp easy BR %%% X [[BR]] regexp easy tables foo ||\nbar\n foo || bar\n regexp easy headings !!! h1, !! h2, ... X = h1 = ... regexp trivial escaping <verbatim> X { { { } } } regexp easy style <pre> X missing regexp easy: treated as a <verbatim> def list foo:\nbar foo:: bar regexp should be fairly easy quoting > email text indentation regexp fairly easy anchors [#anchor] X same? regexp easy HTML <anytag> none ? impossible? code <code> { { { } } } regexp ? plugins <?Plugin foo?> some [[plugin]] mapping trivial, must have a correspondance
I'm probably missing some stuff here.
Note that in moin composite links are [link text] and not [text link]
Plugins that could be converted
A list of 25 random pages (out of [[PageCount]] total):[[RandomPage(25)]]
vs
The amount of random pages is a number from 1 to 20. ---- <?plugin RandomPage pages||||=10 info||||=''?>
A list of pages no other page links to: [[OrphanedPages]]
vs
<?plugin OrphanedPages info||||=hits,pagename,mtime?>
Here is a list of all categories known to this wiki: [[PageList(^Category.*)]]
vs
<?plugin TitleSearch s=Category noheader=1 exclude=CategoryCategory?>
Pages that are in conflict with existing MoinMoin pages
Pages that are not relevant to MoinMoin
- MagicPhpWikiURLs
- PhpWikiAdministration/Remove
I might be missing some here. In any case, phpwiki2moinmoin should make backups of the pages, so everything is available through RecentChanges.
How to create the MoinMoin pages
basically you install moin and then your script imports MoinMoin.PageEditor
you just create a page object using this class, use set_raw_body (or similar) to set the page content and then call some _write_file method (or similar) to write it to disk
make sure you add the path to moin_config.py to your python path, so it can find it and locate the right directory for the wiki pages
We have to watch out for encoding too:
that is built in into python. unicode objects have .encode, strings have .decode and there is codecs.open()
BUT: moin 1.2.x does not do unicode yet internally, it defaults to iso8859-1
strings are encoded things, in whatever you want
unicode objects behave similar to strings, but are ucs-2 or ucs-4 (16 or 32bit unicode)
real unicode support will come in moin 1.3
Starting Point
I have written such a beast in 2002. It's just a quick hack and misses some points. But it worked for me, so please feel free to take that as a starting point.
-- GuidoZockoll 2004-06-11 08:47:10
I've committed the original script to my private SVN repository. You can checkout an improved (i hope copy at https://svn.koumbit.net/svn/anarcat/trunk/bin/phpwiki2moinmoin.py. The original version is still available at revision 1498.
Things missing from this script (in order of priority)
- all the format differences non-yet implemented (see above)
- work with a dump of a DB (why not...)
- probably a bunch of other stuff
-- TheAnarcat 2004-10-14 17:02:09
A very useful script! I retrieved it from SVN, and found that it already had mysql support, pointed it to my old wiki and the convert ran fine. The main issues I had is that HomePage in phpwiki should become FrontPage in moin, and that moin doesn't support links in headings like:
== ["Introduction"] ==
-- TimotheeBesset 2004-10-01
I get an error when I try to run the script (from the link given above). The error I get is:
File "phpwiki2moinmoin.py", line 362, in ? page = PageEditor(utf8pagename, request) File "../moin//lib/python2.3/site-packages/MoinMoin/PageEditor.py", line 114, in __init__ File "../moin//lib/python2.3/site-packages/MoinMoin/Page.py", line 46, in __init__ AttributeError: 'unicode' object has no attribute 'cfg'
can someone tell me what I can do about this. I am running this on the sourceforge servers (They have Python 2.3.3).
--RishabhManocha 2005-04-08
- Delete all .pyc files.
-- NathanOsullivan 2005-10-18
The above advice ("Delete all .pyc files") seems to be wrong. I'm using moin 1.3.5 and encountered the same error above. It seems that Moin has changed the parameter order (or something) to the PageEditor init method. After fixing that, I also encountered that Moin requires the revision # to be saved (or something, I've just looked at other CLI scripts to figure out enough to make it work).
I've attached the slightly revised script - phpwiki2moinmoin135.py . I personally had phpwiki in an SQlite file, so also made modifications for that. I've left those changes in the file, but commented out.
-- ?
I've just finished importing using a modified version of this script. I couldn't get a MySql connection to my old server (host prevented it), so from the command line I ran the SQL query and dumped the result to a file. I moved the file over to my new host, then modified the script to read from the file.
-- Ian Epperson 2006-Feb-1 (http://veewiki.com)
I made some changes to the conversion script, see:
http://hg.moinmo.in/moin/1.7/file/c66e6c0a40b3/contrib/phpwiki_migration/phpwiki2moinmoin.py
If someone could test it (it converts to new moin link / macro syntax), it would be great.
-- ThomasWaldmann 2007-08-31 19:19:58
I have updated Thomas's conversion script above for phpwiki with a postgresql database - see attachment phpwiki2moinmoin171.tgz. It worked well for me with a phpwiki with several hundred pages. The mysql code is still included so this edition should be ok for both database types. Thanks Thomas for assistance. -- HarmsCon 2008-09-14 23:23:33