コード例 #1
0
<?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";
コード例 #2
0
<?php

chdir(dirname(__FILE__));
include 'config.php';
include 'include.php';
$db = new WikiSyncDB();
/*
  From Mediawiki:
  	Read the RecentChanges feed and find articles that have been updated
  	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";