tips:mediawiki_to_dokuwiki_converter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tips:mediawiki_to_dokuwiki_converter [2012-07-30 16:51] – add font converter 92.103.27.162 | tips:mediawiki_to_dokuwiki_converter [2024-05-05 09:49] (current) – [Web Based Version] Wirbel78 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== MediaWiki to DokuWiki Converter ====== | ====== MediaWiki to DokuWiki Converter ====== | ||
+ | ===== Automatic script ===== | ||
+ | |||
+ | This script will automatically convert a MediaWiki install to DokuWiki. No configuration is required as all it needs is the path to '' | ||
+ | |||
+ | The '' | ||
+ | |||
+ | Find on GitHub: \\ https:// | ||
+ | |||
+ | ===== yamdwe tool ===== | ||
+ | |||
+ | " | ||
+ | |||
+ | https:// | ||
+ | |||
+ | **Pros**: | ||
+ | * It uses the MediaWiki API so can create a local DokuWiki from a remote MediaWiki install. Automatically imports full revision history for each page, imports media and (optionally) imports users & passwords if it has database access. | ||
+ | * Uses [[http:// | ||
+ | |||
+ | **Cons**: | ||
+ | * Is Python based so it's more involved to set up than most of the other tools listed here (install steps for Linux are provided.) | ||
+ | * Slow for large amounts of Mediawiki content | ||
+ | * Categories are not converted (the content within the category pages) | ||
+ | ===== Older scripts: ===== | ||
===== Updated Scripts for Converting Mediawiki 1.15.1 to Anteater. ===== | ===== Updated Scripts for Converting Mediawiki 1.15.1 to Anteater. ===== | ||
Line 19: | Line 42: | ||
Hey, I was playing with AWK and Perl a little bit. I created a MediaWiki to DokuWiki Converter. | Hey, I was playing with AWK and Perl a little bit. I created a MediaWiki to DokuWiki Converter. | ||
- | A online converter is now hosted at [[http:// | + | A online converter is now hosted at [[http:// |
==== Requirements ==== | ==== Requirements ==== | ||
* bash | * bash | ||
Line 44: | Line 67: | ||
==== Source ===== | ==== Source ===== | ||
File mediawiki2dokuwiki.sh: | File mediawiki2dokuwiki.sh: | ||
- | <code bash> | + | <code bash mediawiki2dokuwiki.sh> |
#! /bin/sh | #! /bin/sh | ||
# Mediawiki2Dokuwiki Converter | # Mediawiki2Dokuwiki Converter | ||
Line 375: | Line 398: | ||
- | Here you can find the package: http:// | + | Here you can find the package: http:// |
This is the main script. | This is the main script. | ||
Line 469: | Line 492: | ||
--- [[user> | --- [[user> | ||
- | ===== Another automatic script ===== | ||
- | This script will automatically convert a MediaWiki install to DokuWiki. No configuration is required as all it needs is the path to LocalSettings.php. The above shell script did not work as expected as DokuWiki did not find the pages after they were injected manually. Instead, this script uses DokuWiki' | + | ====== Mediawiki 2 Dokuwiki Converter ====== |
- | The mw2dw-conv_sed.sh script has been converted into native PHP so shell access is not required. Also runs from the web server if desired. | + | <code perl> |
+ | #! /bin/sh | ||
+ | # Mediawiki2Dokuwiki Converter | ||
+ | # originally by Johannes Buchner < | ||
+ | # License: GPL (http:// | ||
- | Find on GitHub: https://github.com/tetsuo13/MediaWiki-to-DokuWiki-Importer | + | # Headings |
+ | cat mediawiki | \ | ||
+ | perl -pe 's/^[ ]*=([^=])/<h1> ${1}/g' | \ | ||
+ | perl -pe 's/([^=])=[ ]*$/${1} < | ||
+ | | ||
+ | | ||
+ | | ||
+ | perl -pe ' | ||
+ | perl -pe 's/^[ ]*====([^=])/< | ||
+ | perl -pe ' | ||
+ | perl -pe 's/^[ ]*=====([^=])/< | ||
+ | perl -pe ' | ||
+ | perl -pe 's/^[ ]*======([^=])/< | ||
+ | perl -pe ' | ||
+ | > mediawiki1 | ||
- | ===== A PHP page which combines all of the above ===== | + | cat mediawiki1 | \ |
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | cat > mediawiki2 | ||
- | Having a webspace with no shell access I combined all of the above to have a single page which imports a mediawiki page via a DB connection. | + | # lists |
+ | cat mediawiki2 | | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | cat > mediawiki3 | ||
+ | #[link] => [[link]] | ||
+ | cat mediawiki3 | | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | perl -pe ' | ||
+ | > mediawiki4 | ||
+ | #[[url text]] => [[url|text]] | ||
+ | cat mediawiki4 | | ||
+ | perl -pe ' | ||
+ | > mediawiki5 | ||
- | <file php mw2dw.php> | + | # bold, italic |
+ | cat mediawiki5 | | ||
+ | perl -pe " | ||
+ | perl -pe " | ||
+ | | ||
- | <?php | + | # talks |
- | /** | + | cat mediawiki6 | |
- | * MediaWiki2DokuWiki. Imports a MediaWiki install into DokuWiki. | + | perl -pe "s/^[ ]*:/>/ |
- | * | + | perl -pe " |
- | * Copyright (C) 2011 Andrei Nicholson | + | perl -pe " |
- | * | + | perl -pe " |
- | * This program is free software: you can redistribute it and/or modify | + | perl -pe "s/>>>>: |
- | * it under the terms of the GNU General Public License as published by | + | |
- | * the Free Software Foundation, either version 3 of the License, or | + | perl -pe "s/>>>>>>:/>>>>>>>/ |
- | * (at your option) any later version. | + | > mediawiki7 |
- | * | + | |
- | * This program is distributed in the hope that it will be useful, | + | |
- | * but WITHOUT ANY WARRANTY; without even the implied warranty of | + | |
- | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | |
- | * GNU General Public License for more details. | + | |
- | * | + | |
- | * You should have received a copy of the GNU General Public License | + | |
- | * along with this program. If not, see <http://www.gnu.org/licenses/>. | + | |
- | * | + | |
- | * @author Andrei Nicholson | + | |
- | * @since 2011-11-18 | + | |
- | */ | + | |
- | ini_set(' | + | cat mediawiki7 |
- | error_reporting(E_ALL | + | |
- | + | | |
- | // Path to root DokuWiki install. Required by include files. | + | > mediawiki8 |
- | define(' | + | |
- | + | ||
- | require_once DOKU_INC . ' | + | |
- | require_once DOKU_INC . ' | + | |
- | + | ||
- | if (urldecode($_REQUEST[' | + | |
- | print "< | + | |
- | $mwikiSettingsPath = realpath($_SERVER[' | + | |
- | $mwikiSettingsPath = urldecode($_REQUEST[' | + | |
- | + | ||
- | if (!file_exists($mwikiSettingsPath)) { | + | |
- | exit(" | + | |
- | } | + | |
- | + | ||
- | $mwikiSettings = file($mwikiSettingsPath, | + | |
- | FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); | + | |
- | + | ||
- | $mwikiDb = dbConnectionSettings($mwikiSettings); | + | |
- | print_r($mwikiDb); | + | |
- | + | ||
- | if ( (int)count($mwikiDb) <= 8 ) { | + | |
- | exit(' | + | |
- | } | + | |
- | + | ||
- | $db = dbConnect($mwikiDb); | + | |
- | convert($db, | + | |
- | print "< | + | |
- | } else { | + | |
- | print "< | + | |
- | print "< | + | |
- | print "< | + | |
- | print "< | + | |
- | print "</ | + | |
- | } | + | |
- | + | ||
- | / | + | |
- | * Convert pages from MediaWiki. | + | |
- | * | + | |
- | * @param PDO $db DB handle. | + | |
- | * @param array $mwikiDb DB attributes. | + | |
- | */ | + | |
- | function convert(PDO $db, array $mwikiDb) { | + | |
- | $prefix = $mwikiDb[' | + | |
- | + | ||
- | $sql = " | + | |
- | FROM {$prefix}page p | + | |
- | INNER JOIN {$prefix}revision r ON | + | |
- | p.page_latest = r.rev_id | + | |
- | INNER JOIN {$prefix}text t ON | + | |
- | r.rev_text_id = t.old_id | + | |
- | ORDER BY p.page_title"; | + | |
- | + | ||
- | try { | + | |
- | $statement = $db-> | + | |
- | + | ||
- | if (!$statement-> | + | |
- | $error = $statement-> | + | |
- | exit(' | + | |
- | } | + | |
- | + | ||
- | while ($row = $statement-> | + | |
- | echo ' | + | |
- | //if ($i++ > 10) {break;} | + | |
- | switch ($row[' | + | |
- | case 0: | + | |
- | processPage($row); | + | |
- | break; | + | |
- | + | ||
- | case 6: | + | |
- | processImage($row); | + | |
- | break; | + | |
- | + | ||
- | default: | + | |
- | echo ' | + | |
- | } | + | |
- | echo PHP_EOL; | + | |
- | } | + | |
- | } catch (PDOException $e) { | + | |
- | exit(' | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Inject new page into DokuWiki. | + | |
- | * | + | |
- | * @param array $record Info on page. | + | |
- | */ | + | |
- | function processPage(array $record) { | + | |
- | + | ||
- | $page = $record[' | + | |
- | //print $page; | + | |
- | $file = explode(PHP_EOL, | + | |
- | + | ||
- | foreach ($file as $i=> | + | |
- | // | + | |
- | + | ||
- | | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace(" | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | + | ||
- | $line = preg_replace("/< | + | |
- | $line = preg_replace("/< | + | |
- | $line = preg_replace("/< | + | |
- | $line = preg_replace("/< | + | |
- | $line = preg_replace("/< | + | |
- | $line = preg_replace("/< | + | |
- | + | ||
- | //lists | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | + | ||
- | $line = preg_replace("/ | + | |
- | $line = preg_replace(" | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | + | ||
- | //[link] => [[link]] | + | |
- | //$line = preg_replace("/ | + | |
- | + | ||
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/ | + | |
- | + | ||
- | // [[url text]] => [[url|text]] | + | |
- | $line = preg_replace("/ | + | |
- | + | ||
- | // bold, italic | + | |
- | $line = preg_replace("/'''/"," | + | |
- | $line = preg_replace("/''/"," | + | |
- | + | ||
- | //talks | + | |
- | $line = preg_replace("/ | + | |
- | $line = preg_replace("/>:/", | + | |
- | $line = preg_replace("/>>:/", | + | |
- | $line = preg_replace("/>>>:/", | + | |
- | $line = preg_replace("/>>>>:/", | + | |
- | $line = preg_replace("/>>>>>:/", | + | |
- | $line = preg_replace("/>>>>>>:/", | + | |
- | + | ||
- | //code | + | |
- | $line = preg_replace("/< | + | |
- | $line = preg_replace(" | + | |
- | + | ||
- | $out[$i] = $line; | + | |
- | } | + | |
- | + | ||
- | $page = implode(PHP_EOL, | + | |
- | + | ||
- | saveWikiText($record[' | + | |
- | con('', | + | |
- | ' | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Inject image. | + | |
- | * | + | |
- | * @param array $record Info on page. | + | |
- | */ | + | |
- | function processImage(array $record) { | + | |
- | echo ' | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Connect to the DB and return handle. | + | |
- | * | + | |
- | * @param array $mwikiDb DB attributes. | + | |
- | * | + | |
- | * @return PDO DB handle. | + | |
- | */ | + | |
- | function dbConnect(array $mwikiDb) { | + | |
- | $dsn = $mwikiDb[' | + | |
- | . ' | + | |
- | + | ||
- | try { | + | |
- | $db = new PDO($dsn, $mwikiDb[' | + | |
- | } catch (PDOException $e) { | + | |
- | exit(' | + | |
- | } | + | |
- | return $db; | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Strip DB connection settings from LocalSettings.php. | + | |
- | * | + | |
- | * @param array $mwikiSettings Content of LocalSettings.php with each line as | + | |
- | * an element in the array. | + | |
- | * | + | |
- | * @return array DB attributes. | + | |
- | */ | + | |
- | function dbConnectionSettings(array $mwikiSettings) { | + | |
- | foreach ($mwikiSettings as $line) { | + | |
- | if (substr($line, | + | |
- | continue; | + | |
- | } | + | |
- | + | ||
- | $x = explode(' | + | |
- | + | ||
- | if (!is_array($x) || count($x) != 2) { | + | |
- | continue; | + | |
- | } | + | |
- | + | ||
- | $val = trim($x[1]); | + | |
- | + | ||
- | // Strip leading dollar sign from key. Strip leading quote, trailing | + | |
- | // quote and semicolon from value. | + | |
- | $db[substr(trim($x[0]), | + | |
- | } | + | |
- | + | ||
- | return $db; | + | |
- | } | + | |
- | ?> | + | |
+ | cat mediawiki8 > dokuwiki | ||
+ | </ | ||
- | </ |
tips/mediawiki_to_dokuwiki_converter.1343659881.txt.gz · Last modified: 2012-07-30 16:51 by 92.103.27.162