Created
August 27, 2014 20:41
-
-
Save JCotton1123/9d5c295e23243fd99fd3 to your computer and use it in GitHub Desktop.
Media Wiki to Github Wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Export the pages from a Media Wiki instance into a directory for | |
import into a Github Wiki. | |
## Procedure | |
1) Set the database credentials in this file | |
2) Create the repository and wiki if not done already. Make sure | |
to specify the home page is marked down using the Media Wiki format. | |
3) Clone the repo | |
4) Run this script: `php media-wiki-to-github-wiki.php <repo-directory>` | |
5) mv Main_Page.mediawiki to Home.mediawiki if applicable | |
5) Add and commit the resulting files | |
## Gotchas | |
- Github doesn't seem to process Media Wiki tables correctly | |
*/ | |
$sql = <<<EOD | |
SELECT page_title as title, page_touched as updated, old_text as content | |
FROM revision,page,text | |
WHERE revision.rev_id=page.page_latest | |
AND text.old_id=revision.rev_text_id; | |
EOD; | |
define('DS', DIRECTORY_SEPARATOR); | |
$dest="."; | |
if($argc >= 2){ | |
$dest = $argv[1]; | |
} | |
$dbConn = new PDO('mysql:host=localhost;dbname=mediawiki;charset=utf8', 'app_mediawiki', 'password'); | |
$dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$stmt = $dbConn->query($sql); | |
while($page = $stmt->fetch(PDO::FETCH_ASSOC)) { | |
$title = $page['title']; | |
$lastUpdated = $page['updated']; | |
$content = $page['content']; | |
$filename = "${title}.mediawiki"; | |
$filename = str_replace("_", "-", $filename); | |
file_put_contents($dest . DS . $filename , $content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment