Get mediaWiki articles into phpMyFAQ is a quick and dirty utility I wrote to import my mediawiki articles into myPHPFAQ. I built it for myself, as a one-off, so it is not tested on anything by my system. Feel free to use it, but if it eats your hard drive or anything else, I am not responsible.

One safety point I did do is not allow it to actually touch the MyPHPFAQ database. Instead, it creates an SQL file you can use as input to the mysql command. That is when it destroys all your data. BE WARNED. Make sure you have a good backup.

This procedure worked against MediaWiki 1.18.0 and phpMyFAQ 2.0.6.

Open the database for mediawiki and execute the following command:
select page_title from page;
Now, open your wiki and go to Special Pages | Export Pages
Paste the output from the above query into the big box (clean it up first by getting rid of all the leading and trailing stuff from MySQL)
Put a check in "Include only the current revision, not the full history" and "Save as a file", the hit the Export button.
This gives you an XML file that is ready to be processed by this script.

Ok, on the box that will do the processing, you need to have Perl (duh, it is a Perl script), DBI and Text::MediawikiFormat 'wikiformat'. DBI because I am lazy and don't want to write a sub to clean up the input (I only use the quote method in it), and Text::MediawikiFormat to convert the mediwiki markup to HTML.

You also need to create a directory to put the output files in (the script only checks that the directory exists).

Edit the top few lines of the script to set a database. It can be any database the script can log into. As I have said, I don't modify the database, I only use this to load the drivers so we can use the proper DBI->quote()

Run the program. It takes input from STDIN, so:

./ < wiki.linuxservertech.xml

replacing wiki.linuxservertech.xml with whatever you called your output from media wiki. The output directory will contain one file for every article processed and an SQL file. The html files are simply something I did because I could. You can do whatever you want with those. To import your files into phpMyFAQ, connect to the database and run the SQL script on it.

WARNING: As it stands, the generated SQL script will remove any articles from the wiki before creating the new ones. That means anything you have in there will be erased! Make a backup. You should be able to modify the script easily to not do this if you know any SQL.

I'm not interested in supporting this, but I will answer a few questions if you want. Go to and click About Us | Contact Us to send me an e-mail.

Attached files:

Last update:
2014-08-04 05:55
Average rating: 5 (1 Vote)

You can comment this FAQ

Chuck Norris has counted to infinity. Twice.