Phpwiki

aus www.kruedewagen.de, Homepage von Ralf und Judith Krüdewagen (Kruedewagen)
Zur Navigation springen Zur Suche springen

Konvertierung von Phpwiki nach Mediawiki

  • Phpwiki-Version: 1.2.7
  • PhpWiki DB: File
  • Mediawiki-Version: 1.11.0

Konvertierung gemäß

Vorgehen

Phpwiki Seiten exportieren

  • per ZIP-Snapshot
  • Umlaute sollten nicht in "quoted-printable" konvertiert werden und Zeilen sollten nicht abgeschnitten werden. Änderungen in ziplib.php:
function QuotedPrintableEncode ($string)
{
...
      if (!empty($match[3]))
	  //$quoted .= sprintf("=%02X", ord($match[3]));
	  $quoted .= $match[3];
...
  //return preg_replace('/(?=.{77})(.{10,74}[ \t]|.{71,73}[^=][^=])/s',
  //		      "\\1=\r\n", $quoted);
  return $quoted;
}

Dateien und Inhalte konvertieren

  • Script phpwikiconvert_wrapper.sh ausführen.

Seiten in Mediawiki importieren

  • Script phpwikiconvert_sqladd.sh ausführen
  • maintenance/rebuildall.php für Mediawiki ausführen (AdminSettings.php muss korrekt sein)

Einschränkungen

  • Ausrufezeichen werden in == konvertiert.
  • Interne Links wie InternerLink werden nicht konvertiert, wenn * davor steht.
  • Alle Wörter mit mindestens 2 Großbuchstaben werden nach [[LINK]] konvertiert.

Scripts

phpwikiconvert_wrapper.sh:

#!/bin/bash
# See http://meta.wikimedia.org/wiki/Documentation:PhpWiki_conversion
# and http://wikiworld.com/wiki/index.php/PhpWiki2MediaWiki
# dont't split lines in ziplib.php !! return $quoted;
PRECONVERT=1

if [ "$PRECONVERT" = "1" ];then
 for file in pages/*
 do
  #awk 'i==1;/^\x0d$/{i=1}' $file | sed -f phpwikiconvert > converted/$file
  # convert to UNIX format
  dos2unix $file

  # convert ISO-8859-1 to UTF-8, don't convert to quoted-printable in ziplib.php
  # $quoted .= $match[3]; in Zeile 464
  # THIS MUST ONLY BE DONE ONCE. DO NOT REPLY THIS ON ALREADY CONVERTED FILES.
  recode ISO_8859-1..UTF-8 $file

  # filename converting
  mv $file `echo $file|sed 's!%20!_!g'` 2>/dev/null     # spaces to _
  mv $file `echo $file|sed 's!%2F!_!g'` 2>/dev/null     # slashes to _
  mv $file `echo $file|sed 's!%F6!ö!g'` 2>/dev/null     # for Behörden page
 done
fi

for file in pages/*; do
  # remove all lines including the first empty one and run syntax converter
  mkdir -p converted/pages
  awk 'i==1;/^$/{i=1}' $file | sed -f phpwikiconvert > converted/$file
done

phpwikiconvert:

# Problems:
# - Ausrufezeichen werden in == konvertiert
# - interne Links InternerLink werden nicht konvertiert, wenn * davor steht
# - alle Wörter mit 2 Großbuchstaben werden nach [[LINK]] konvertiert.

# typeset markup
s/_\([^_]*\)_/''\1''/g  # italic -- OK -> Seems to be bold
#s/\*\([^\*]*\)\*/'''\1'''/g  # boldface -- OK -> problems with ** and ***
#s!=\([^=]*\)=!<code>\1</code>!g  # fixed-width -- OK -> problems with =

# header markup -- OK
s/!!!\(.*\)$/==\1==/g
s/!!\(.*\)$/===\1===/g
s/!\(.*\)$/====\1====/g

# table markup (hopefully)
s!\([^|][^|]*\)|!\1||!g
s!^|!|-\n|!g  # convert row start -- OK
s!.*plugin OldStyleTable.*!\{\|!  # convert table start -- mostly OK
s!^?>$!\|\}!  # convert table end -- mostly OK

# link markup
s!\[\(.*\)|\(http.*\)]![\2 \1]!g  # url format -- OK
s!\[\(.*\)|\(.*\)\]![\2|\1]!g  # switch display and link text -- OK
s!\[\([^]]*\)\]![[\1]]!g  # double bracketize -- OK
s!\[\[\(http.*\)\]\]![\1]!g  # undo double-bracketing urls by above -- OK

# redirects
s!<?plugin RedirectTo page=\(.*\)?>!#REDIRECT [[\1]]!

# quotes
s!"!\\"!g

# %%% newlines - jim
s/!%%%/<br>/
s/<verbatim>/<pre>/
s!</vertatim>!</ pre>! # take out space b4 running - jim
#wikiwords - jim - allowing numbers added afterwards
s/^\([A-Z][a-z0-9][a-z0-9]*[A-Z][A-Za-z0-9]*\)/[[\1]]/
s/ \([A-Z][a-z0-9][a-z0-9]*[A-Z][A-Za-z0-9]*\)/ [[\1]]/g

phpwikiconvert_sqladd.sh:

#!/bin/bash
# danach noch rebuildall.php ausführen (nach AdminSettings.php erstellen)

cd converted/pages

for file in *; do
title=`echo $file|sed 's!%2F!/!g'|perl -n -e "print ucfirst;"` # title begins with capital char
cat <<END | mysql -u wikinotes -pmrnotes66 wikinotes
INSERT INTO page
(page_id, page_namespace, page_title, page_counter, page_restrictions, page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
VALUES
(NULL,0, "$title", 0,'', 0, 1, RAND(), NOW()+0, 0, LENGTH("`cat $file`"));

INSERT INTO text (old_id, old_text, old_flags)
VALUES (NULL, "`cat $file`", "utf-8");

INSERT INTO revision
(rev_id, rev_page, rev_text_id, rev_comment, rev_minor_edit, rev_user, rev_user_text, rev_timestamp)
SELECT NULL, page_id, LAST_INSERT_ID(),"PhpWikiMigration", 0, 1 ,"Admin", NOW()+0 FROM page WHERE page_title = "$title";

UPDATE page,revision
SET page.page_latest = LAST_INSERT_ID()
WHERE page.page_id = revision.rev_page && revision.rev_id = LAST_INSERT_ID();


END
done

Weblinks