Convert Mediawiki to Markdown (MediaWiki to GFM): Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) |
Admin (Diskussion | Beiträge) |
||
(3 dazwischenliegende Versionen des gleichen Benutzers werden nicht angezeigt) | |||
Zeile 28: | Zeile 28: | ||
+ | == Export Mediawiki Files to XML == | ||
+ | In order to convert from MediaWiki format to GFM and use in GitLab (or GitHub), you will first need to export all the pages you wish to convert from Mediawiki into an XML file. Here are a few simple steps to help you accomplish this quickly: | ||
+ | #MediaWiki -> Special Pages -> ‘All Pages’ | ||
+ | #With help from the filter tool at the top of ‘All Pages’, copy the page names to convert into a text file (one file name per line). | ||
+ | #MediaWiki -> Special Pages -> ‘Export’ | ||
+ | #Paste the list of pages into the Export field. | ||
+ | #Check: ‘Include only the current revision, not the full history’ | ||
+ | #Note: This convert script will only do latest version, not revisions. | ||
+ | #Uncheck: Include Templates | ||
+ | #Check: Save as file | ||
+ | #Click on the ‘Export’ button. | ||
+ | #An XML file will be saved locally. | ||
+ | #Use this convert.php script to convert the XML file a set of GFM formatted pages. | ||
+ | == Installation of Mediawiki to GitHub Flavoured Markdown == | ||
+ | <source lang="bash"> | ||
+ | git clone https://github.com/outofcontrol/mediawiki-to-gfm.git | ||
+ | cd mediawiki-to-gfm | ||
+ | composer update --no-dev | ||
+ | </source> | ||
+ | == Run == | ||
+ | <source lang="bash">./convert.php --filename=/path/to/your/mediawiki_export.xml --output=/path/to/converted/files --flatten </source> | ||
+ | |||
+ | === Options === | ||
+ | <pre> | ||
+ | ./convert.php --filename=/path/to/your/mediawiki_export.xml --output=/path/to/converted/files --format=gfm --addmeta --flatten --indexes | ||
+ | |||
+ | --filename : Location of the mediawiki exported XML file to convert | ||
+ | to GFM format (Required) | ||
+ | --output : Location where you would like to save the converted files | ||
+ | (Default: ./output) | ||
+ | --format : What format would you like to convert to. Default is GFM | ||
+ | (for use in GitLab and GitHub) See pandoc documentation | ||
+ | for more formats (Default: 'gfm') | ||
+ | --addmeta : This flag will add a Permalink to each file (Default: false) | ||
+ | --flatten : This flag will force all pages to be saved in a single level | ||
+ | directory. File names will be converted in the following way: | ||
+ | Mediawiki_folder/My_File_Name -> Mediawiki_folder_My_File_Name | ||
+ | and saved in a file called 'Mediawiki_folder_My_File_Name.md' | ||
+ | (Default: false) | ||
+ | --help : This help message (almost) | ||
+ | </pre> | ||
Aktuelle Version vom 29. Oktober 2021, 13:41 Uhr
I am using Mediawiki with the "Wikitext" syntax for many years, but now I'm at a point where I want to switch to the "Markdown" syntax.
Here I show you how you can "simply" switch your Mediawiki sites to Markdown files.
First thanks @PhilipAshlock and @OutOfControl for the great GitHub project that makes this even possbile: https://github.com/outofcontrol/mediawiki-to-gfm
Inhaltsverzeichnis
Requirements
- PHP: Tested in PHP 7.0, 7.1 and 7.2
sudo apt update sudo apt -y install php7.3
- Pandoc: Installation instructions are here https://pandoc.org/installing.html (Tested on version 2.0.1.1 and 2.0.2)
sudo apt install pandoc
- Your MediaWiki site: https://www.mediawiki.org/wiki/MediaWiki (Tested on version 1.27.x and 1.29.x)
- Composer: Installation instructions are here https://getcomposer.org/download/
sudo apt install php-xml sudo apt install php-mbstring php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
Export Mediawiki Files to XML
In order to convert from MediaWiki format to GFM and use in GitLab (or GitHub), you will first need to export all the pages you wish to convert from Mediawiki into an XML file. Here are a few simple steps to help you accomplish this quickly:
- MediaWiki -> Special Pages -> ‘All Pages’
- With help from the filter tool at the top of ‘All Pages’, copy the page names to convert into a text file (one file name per line).
- MediaWiki -> Special Pages -> ‘Export’
- Paste the list of pages into the Export field.
- Check: ‘Include only the current revision, not the full history’
- Note: This convert script will only do latest version, not revisions.
- Uncheck: Include Templates
- Check: Save as file
- Click on the ‘Export’ button.
- An XML file will be saved locally.
- Use this convert.php script to convert the XML file a set of GFM formatted pages.
Installation of Mediawiki to GitHub Flavoured Markdown
git clone https://github.com/outofcontrol/mediawiki-to-gfm.git cd mediawiki-to-gfm composer update --no-dev
Run
./convert.php --filename=/path/to/your/mediawiki_export.xml --output=/path/to/converted/files --flatten
Options
./convert.php --filename=/path/to/your/mediawiki_export.xml --output=/path/to/converted/files --format=gfm --addmeta --flatten --indexes --filename : Location of the mediawiki exported XML file to convert to GFM format (Required) --output : Location where you would like to save the converted files (Default: ./output) --format : What format would you like to convert to. Default is GFM (for use in GitLab and GitHub) See pandoc documentation for more formats (Default: 'gfm') --addmeta : This flag will add a Permalink to each file (Default: false) --flatten : This flag will force all pages to be saved in a single level directory. File names will be converted in the following way: Mediawiki_folder/My_File_Name -> Mediawiki_folder_My_File_Name and saved in a file called 'Mediawiki_folder_My_File_Name.md' (Default: false) --help : This help message (almost)