(the following article and code applies only to phpwiki version 1.1.x and 1.2.x. Previous and future versions of this software use different methods of formatting and so will require changes to the scripts used here)
If you have a set of articles on a phpwiki that you can’t afford to lose, and want to move to Kete then theres a simple two part process you can follow to do just that. Over the next two blogs posts, I’m going to show you just how it’s done.
Kete can import text using a simple XML import. And in some cases, it can be as simple as exporting your mysql table to an XML formatted file, and sending it to Kete. But in the case of Phpwiki, special markup is stored in the database which Kete doesn’t know how to interpret. So while the bulk of the text would be imported, all styling and links you have will no longer work, and if you have a lot of articles, then it would get annoying to have to update each one.
So to get around this, we write our own XML export script, which takes the special syntax, runs it through Phpwiki’s transform.php file, which returns an HTML formatted string we can then use. But we have another problem. Phpwiki’s transform file is executed procedurally, which means it starts with something at the top, works its magic, and then outputs what it has at the end. It also has one function in the file, so including the file multiple times would cause problems.
file_get_contents is the answer. We have a main script that loops through the records and gets each current entry. When it comes to outputting the content, we send the title of the page we want returned to another script, which gets the contents of that page using a modified version of phpwiki’s display.php, assigns it to the right variable and includes the transform file near the end. The resulting HTML is brought back to the original script, and inserted into the XML, before it loops to the next entry and repeats the process.
Add in a few lines of code to fix search links, remove annoyingly placed Phpwiki developer comments, and escape content, and the export script works like a charm, producing an XML formatted file with the latest content which can now be imported into Kete. You can check out the finished source code of the exporter online at MediaFire.
- exportToHtml.php: http://www.mediafire.com/?dv9zug1g0rz
- parseWikiToHtml.php: http://www.mediafire.com/?yapjdul1jt0
To use the scripts, open each file and edit the defined constants at the top of the scripts. Then upload those to the base of your wiki (http://yoururl.com/wiki/ for example), and navigate with your browser to http://yoururl.com/wiki/exportToHtml.php . The resulting XML document is what you’ll use to import in the next step. Save this file to your desktop by going to File > Save page As, and name it records.xml.
Stay tuned for part 2 where I explain how to import this XML file into Kete.