transfer moinmoin wiki to mediawiki

I switched from Moin Moin wiki to Mediawiki for system admin notes. Moin Moin is file-based and the search function failed to return results after I got up into the thousands of entries. Originally in the long ago dark ages this was an Access database, then for a while it was mysql and then postgres with a home-made front end. Then a wiki.

The advantages of Mediawiki are broad development and support (Moin Moin seemed to have stopped development for awhile, then resumed)and it is the backend for Wikipedia. It is mysql database storage – the search function is very fast.

I could not find a straight path to bring all of the Moin Moin content I had directly into Mediawiki. What I ended up doing was a hybrid – I had already put together a script to pull text files out of the Moin Moin file structure, as a backup and storage mechanism.

Here’s the script…

[dmunsinger@schultz wiki_convert] $ cat wiki_to_text.pl
#! /usr/bin/perl

 use strict;
 use Carp;
 use File::Copy;

 ## script to parse moinmoin wiki 1.3 file structure into a flat text file set.  For readability and  backup
 ## Structure:
 ## /space/Wikis/dsm/data/pages is the root directory
 ## each page is a named directory
 ## within that directory there is:
 ## lensman pages # ls -la RmanErrors/
 ## total 104
 ## drwxrwx---     4 dsm dsm  4096 Mar  8 17:09 .
 ## drwxr-x---  2348 dsm dsm 81920 Jul 24 14:18 ..
 ## drwxrwx---     2 dsm dsm  4096 Mar  8 16:58 cache
 ## -rw-rw----     1 dsm dsm     9 Mar  8 17:09 current
 ## -rw-rw----     1 dsm dsm   201 Mar  8 17:09 edit-log
 ## drwxrwx---     2 dsm dsm  4096 Mar  8 17:09 revisions
 ## cache is ignorable - that is for speedy display...
 ## what you need is to cat current into a variable
 ## chomp iot...
 ## then cat $ROOT//revisions/$variable into a text file...
 ## go into attachments file and copy those to - $RESULT_DIR/$copyname.txt`;
    # attachments if any
    if ( -d "$DIR/$file/attachments" ) {
        print ("Found ATTACHMENTS directory\n");
        opendir(ATT, "$DIR/$file/attachments") || croak "Failed to open $DIR/$file/attachments";
        my @files = grep { /^.*$/ } readdir(ATT);
        closedir(ATT);
        foreach my $attach (@files) {
            print ("attachment: $attach\n");
            unless (($attach eq ".") || ($attach eq "..")) {
                my $attach_start = "$DIR/$file/attachments/$attach";
                my $attach_endpoint = "$RESULT_DIR/$copyname-$attach";
                copy($attach_start, $attach_endpoint);
            }
        }
    }
 }
 closedir(DIR);

 `chown -R dsm.dsm $RESULT_DIR`;
 exit;

[dmunsinger@schultz wiki_convert] $

I then moved the files into subdirectories, e.g., text, images, office, programmes, pdf, etc.
moved the text subdir to damgoodespressowiki.com/_dsmwiki/maintenance/text cd into text and run

for i in *
do
    echo $i
    /usr/local/php5/bin/php ../importTest.php $i
done

and watch them march into the wiki.

I ran against a test wiki first, then started into the actual data.

The next step is to do the same with images. With the wiki_to_text.pl script these are separated out from the file structure, but they remain .png or .jpg.
You can import them in the same manner as above, using importImages.php – syntax:

 /usr/local/php5/bin/php  ./importImages.php image

These scripts, the import ones, are in the maintenance directory under your Mediawiki install:

[dmunsinger@schult _sysadminwiki] $ cd maintenance
[dmunsinger@schult maintenance] $ ls | grep import
importDump.php
importImages.inc.php
importImages.php
importLogs.inc
importLogs.php
importTextFile.php
importUseModWiki.php
[dmunsinger@schultz maintenance] $

This resulted in a usable mediawiki with all of the old content – the images are a bit orphaned, but available.

–doug