1, 'AuthorLink' => 1)); SDV($ImportExcludeEditFunctions, array('CheckBlocklist')); SDV($ImportTime, 15); SDV($ImportCount, 0); SDV($ImportSkip, 0); SDV($HandleActions['import'], 'HandleImport'); SDV($HandleAuth['import'], 'admin'); if ($action == 'browse') register_shutdown_function('ImportCheck', getcwd()); function HandleImport($pagename, $auth = 'admin') { global $HandleImportFmt, $PageStartFmt, $PageEndFmt; $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); if (!$page) Abort("Insufficient permissions for import"); list($usec0, $sec0) = explode(' ', microtime()); header('Content-type: text/plain'); ImportUpdate('cb_ImportLog'); list($usec1, $sec1) = explode(' ', microtime()); $time = sprintf("%.2f", $sec1 + $usec1 - $sec0 - $usec0); print FmtPageName("\nImported \$ImportCount pages in $time seconds\n", $pagename); flush(); } function cb_ImportLog($x) { print "$x\n"; flush(); } function ImportCheck($cwd = NULL) { global $LastImportFile, $ImportFreq, $ImportDir; if ($cwd) { flush(); chdir($cwd); } $t = @filemtime($LastImportFile); $check = $ImportFreq && (time() > $t + $ImportFreq); if (!$check) foreach((array)$ImportDir as $dir) if (@filemtime($dir) > $t) { $check = true; break; } if ($check) ImportUpdate(); } function ImportUpdate($logfn = 'StopWatch') { global $LastImportFile, $ImportDir, $ImportFilePattern, $EnableImportRename, $Now, $ImportSaveGlobals, $ImportAuthor, $Author, $AuthorLink, $IsPagePosted, $EditFunctions, $ImportExcludeEditFunctions, $ImportTime, $ImportCount, $ImportSkip; $logfn("ImportUpdate: begin"); $abort = ignore_user_abort(true); Lock(2); foreach($ImportSaveGlobals as $k => $v) if ($v) $save[$k] = $GLOBALS[$k]; $Author = $ImportAuthor; $AuthorLink = ($Author) ? "[[~$Author]]" : '?'; $lastimport = array(); $nextimport = array(); if (is_readable($LastImportFile)) $lastimport = unserialize(file_get_contents($LastImportFile)); @touch($LastImportFile); $editfn = array_diff($EditFunctions, (array)$ImportExcludeEditFunctions); $timeout = time() + $ImportTime; foreach((array)$ImportDir as $dir) { $dfp = @opendir($dir); if (!$dfp) continue; $logfn("ImportUpdate: scanning '$dir'"); while ( ($fname = readdir($dfp)) !== false ) { if (!preg_match("/$ImportFilePattern/", $fname, $match)) continue; $pn = $match[1]; $fpath = "$dir/$fname"; clearstatcache(); $fmtime = filemtime($fpath); if ($fmtime <= @$lastimport[$fpath]) { $nextimport[$fpath] = $lastimport[$fpath]; $logfn("ImportUpdate: already processed '$fpath'"); continue; } if (time() > $timeout) { $logfn("ImportUpdate: timeout $fpath"); $ImportSkip++; continue; } $logfn("ImportUpdate: processing '$fpath' (pagename=$pn)"); $text = file_get_contents($fpath); $page = $new = ReadPage($pn); $new['text'] = $text; UpdatePage($pn, $page, $new, $editfn); if ($IsPagePosted) { if (IsEnabled($EnableImportRename, 1)) { $fpath2 = "$fpath,import-$Now"; if (@rename($fpath, $fpath2)) { $logfn("ImportUpdate: renamed $fpath -> $fpath2"); $fpath = $fpath2; } } $ImportCount++; $nextimport[$fpath] = filemtime($fpath); } else { $ImportSkip++; $logfn("ImportUpdate: failed saving $pn (\$IsPagePosted)"); } clearstatcache(); } } @unlink($LastImportFile); $fp = @fopen($LastImportFile, 'w'); if ($fp) { fputs($fp, serialize($nextimport)); fclose($fp); fixperms($LastImportFile); if ($ImportSkip) @touch($LastImportFile, 1167609600); # 2007-01-01 UTC } foreach($ImportSaveGlobals as $k=>$v) if ($v) $GLOBALS[$k] = $save[$k]; $logfn("ImportUpdate: end ($ImportCount updated, $ImportSkip skipped)"); ignore_user_abort($abort); }