<?php /* Copyright 2008 Chris Carrigan (chris@waylands.net) This file is MtoPMwiki.php; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Note that this is a run one recipe. I've documented it and tidied it up after running it and it could do with a retest this is also the first programme I've writen in about 15 years so please forgive the ancient style */ if (!defined('PmWiki')) exit(); $RecipeInfo['MtoPMwiki']['Version'] = '2008-10-06'; /* Documentation This convers an extract file from MediaWiki to pmwiki Create the XML extract file as follows 1) In mediaWiki a)Use the all pages option to list all your pages (http://www.mediawiki.org/wiki/Special:AllPages) b)Use the export as HTML option to extract pages in to a file http://www.mediawiki.org/wiki/Special:Export 2) rename that file Mwiki.xml and place it in the subdirectory cookbook/filemaker/ along with this file 3) create a directory called newpages at the top level and set security so you can write to it 4) run this file by including it in the config file 5) move the new files from 'newfiles' to the wiki.d directory You may wish to move particular groups in which case only extract some of the files and change the $fcGroup variable below */ //set up configuration //fcMaxPages is for testing. If your wiki has lots of pages (mine had 1327) to test a few first set it to a low number. $fcGroup='LinInfo'; $fcMaxPages=100000; //load the file into a megastring $LoadedFile = file_get_contents("$FarmD/cookbook/filemaker/Mwiki.xml"); $LoadedXML = simplexml_load_string($LoadedFile); $fcNumPages = count($LoadedXML->page)-1; //iterate over the pages $fcThisPage=0; while (($fcThisPage <= $fcMaxPages)&& ($fcThisPage <= $fcNumPages)) { $fcPageText ="{$LoadedXML->page[$fcThisPage]->revision->text}"; $fcPageTitle="{$LoadedXML->page[$fcThisPage]->title}"; $fcUserName ="{$LoadedXML->page[$fcThisPage]->revision->contributor->username}"; //pmwiki requires capitalisation of each word that forms file name $fcPageTitle=ucwords(strtolower($fcPageTitle)); $fcPageTitle="$fcGroup.$fcPageTitle"; $fcPageName =str_replace(' ','',$fcPageTitle); $fcPageFileName="$FarmD/newfiles/$fcPageName"; ## uncomment this and set $fcMaxPages to 0 if you have problems ## print "Page $fcThisPage $fcPageTitle $fcPageFileName \n"; // pmwiki encoding - you may need to add more here depending on your site content // $fcPageText =str_replace('%','%25',$fcPageText); $fcPageText =str_replace('<','%3C',$fcPageText); $fcPageText =str_replace("\n",'%0a',$fcPageText); $fcPageContent="version=pmwiki-2.2.0-beta68 ordered=1 urlencoded=1 agent= author=$fcUserName charset=ISO-8859-1 csum= ctime=1220695294 host= name=$fcPageTitle rev=1 targets= text=$fcPageText "; file_put_contents($fcPageFileName,$fcPageContent); $fcThisPage=$fcThisPage+1; } ?>