<?php chdir(dirname(__FILE__)); include 'config.php'; include 'include.php'; $db = new WikiSyncDB(); $i = 0; foreach ($config as $domain => $c) { $mw = logInToMediaWiki($domain); $pages = $mw->request('query', array('list' => 'allpages', 'aplimit' => 5000)); foreach ($pages->query->allpages as $page) { $response = $mw->request('query', array('prop' => 'info', 'titles' => $page->title)); $pages = $response->query->pages; $info = get_object_vars($pages); $info = array_pop($info); $filename = $dropboxPath . $domain . ' -- ' . pageTitleToFilename($page->title) . '.txt'; echo $filename . "\n"; $wikitext = $mw->getPage($info->lastrevid); file_put_contents($filename, $wikitext); touch($filename, strtotime($info->touched), strtotime($info->touched)); $db->set($domain, $page->title . ' WikiUpdated', strtotime($info->touched)); $i++; if ($i % 10 == 0) { $db->write(); } } } $db->write(); echo "\n";
Fetch the raw article text, and save to a file named wiki.example.com -- PageTitle.txt in the dropbox folder */ foreach ($config as $wikiDomain => $wikiConfig) { $mw = logInToMediaWiki($wikiDomain); $feed = $mw->getRecentChanges(); $xml = simplexml_load_string($feed); foreach ($xml->entry as $entry) { if (preg_match('/--changed-in-dropbox--/', (string) $entry->summary) == FALSE) { if (preg_match('/diff=(\\d+)/', $entry->id, $match)) { $oldid = $match[1]; $title = $entry->title; $filename = $dropboxPath . $wikiDomain . ' -- ' . pageTitleToFilename($title) . '.txt'; # If the remote wiki article was updated after the last date we downloaded the article if (strtotime($entry->updated) > $db->get($wikiDomain, $title . ' WikiUpdated') && (!file_exists($filename) || strtotime($entry->updated) > filemtime($filename))) { # ...then download the new wiki article $db->set($wikiDomain, $title . ' WikiUpdated', strtotime($entry->updated)); echo $title . "\n"; echo "\t" . $filename . "\n"; echo "\tWiki page updated: " . date('Y-m-d H:i:s', strtotime($entry->updated)) . "\n"; echo "\tLocal page updated: " . date('Y-m-d H:i:s', $db->get($wikiDomain, $title . ' WikiUpdated')) . "\n"; if (file_exists($filename)) { echo "\tFile updated: " . date('Y-m-d H:i:s', filemtime($filename)) . "\n"; } else { echo "\tFile not found on disk\n"; } echo "\twriting new file\n"; echo "\n"; $source = $mw->getPage($oldid); file_put_contents($filename, $source); touch($filename, strtotime($entry->updated), strtotime($entry->updated)); }