public function execute() { if (!($this->hasOption('file') ^ $this->hasOption('dump'))) { $this->error("You must provide a file or dump", true); } $this->checkOptions(); if ($this->hasOption('file')) { $revision = new WikiRevision(); $revision->setText(file_get_contents($this->getOption('file'))); $revision->setTitle(Title::newFromText(rawurldecode(basename($this->getOption('file'), '.txt')))); $this->handleRevision($revision); return; } $this->startTime = microtime(true); if ($this->getOption('dump') == '-') { $source = new ImportStreamSource($this->getStdin()); } else { $this->error("Sorry, I don't support dump filenames yet. Use - and provide it on stdin on the meantime.", true); } $importer = new WikiImporter($source); $importer->setRevisionCallback(array(&$this, 'handleRevision')); $this->from = $this->getOption('from', null); $this->count = 0; $importer->doImport(); $this->conclusions(); $delta = microtime(true) - $this->startTime; $this->error("Done {$this->count} revisions in " . round($delta, 2) . " seconds "); if ($delta > 0) { $this->error(round($this->count / $delta, 2) . " pages/sec"); } # Perform the memory_get_peak_usage() when all the other data has been output so there's no damage if it dies. # It is only available since 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit) $this->error("Memory peak usage of " . memory_get_peak_usage() . " bytes\n"); }
function run() { $this->startTime = wfTime(); $file = fopen('php://stdin', 'rt'); $source = new ImportStreamSource($file); $importer = new WikiImporter($source); $importer->setRevisionCallback(array(&$this, 'handleRevision')); return $importer->doImport(); }
public function execute() { $this->outputDirectory = $this->getOption('output-dir'); $this->startTime = wfTime(); $source = new ImportStreamSource($this->getStdin()); $importer = new WikiImporter($source); $importer->setRevisionCallback(array(&$this, 'handleRevision')); return $importer->doImport(); }
public function execute() { $this->outputDirectory = $this->getOption('output-dir'); $this->prefix = $this->getOption('prefix', 'wiki'); $this->startTime = microtime(true); if ($this->hasOption('parser')) { global $wgParserConf; $wgParserConf['class'] = $this->getOption('parser'); $this->prefix .= "-{$wgParserConf['class']}"; } $source = new ImportStreamSource($this->getStdin()); $importer = new WikiImporter($source); $importer->setRevisionCallback(array(&$this, 'handleRevision')); $importer->doImport(); $delta = microtime(true) - $this->startTime; $this->error("Rendered {$this->count} pages in " . round($delta, 2) . " seconds "); if ($delta > 0) { $this->error(round($this->count / $delta, 2) . " pages/sec"); } $this->error("\n"); }
function importFromHandle($handle) { $this->startTime = microtime(true); $source = new ImportStreamSource($handle); $importer = new WikiImporter($source, $this->getConfig()); if ($this->hasOption('debug')) { $importer->setDebug(true); } if ($this->hasOption('no-updates')) { $importer->setNoUpdates(true); } $importer->setPageCallback(array(&$this, 'reportPage')); $this->importCallback = $importer->setRevisionCallback(array(&$this, 'handleRevision')); $this->uploadCallback = $importer->setUploadCallback(array(&$this, 'handleUpload')); $this->logItemCallback = $importer->setLogItemCallback(array(&$this, 'handleLogItem')); if ($this->uploads) { $importer->setImportUploads(true); } if ($this->imageBasePath) { $importer->setImageBasePath($this->imageBasePath); } if ($this->dryRun) { $importer->setPageOutCallback(null); } return $importer->doImport(); }
function importFromHandle($handle) { $this->startTime = wfTime(); $source = new ImportStreamSource($handle); $importer = new WikiImporter($source); $importer->setPageCallback(array(&$this, 'reportPage')); $this->importCallback = $importer->setRevisionCallback(array(&$this, 'handleRevision')); $importer->doImport(); }
function importFromHandle($handle) { $this->startTime = microtime(true); $source = new ImportStreamSource($handle); $importer = new WikiImporter($source, $this->getConfig()); if ($this->hasOption('debug')) { $importer->setDebug(true); } if ($this->hasOption('no-updates')) { $importer->setNoUpdates(true); } if ($this->hasOption('rootpage')) { $statusRootPage = $importer->setTargetRootPage($this->getOption('rootpage')); if (!$statusRootPage->isGood()) { // Die here so that it doesn't print "Done!" $this->error($statusRootPage->getMessage()->text(), 1); return false; } } $importer->setPageCallback([$this, 'reportPage']); $this->importCallback = $importer->setRevisionCallback([$this, 'handleRevision']); $this->uploadCallback = $importer->setUploadCallback([$this, 'handleUpload']); $this->logItemCallback = $importer->setLogItemCallback([$this, 'handleLogItem']); if ($this->uploads) { $importer->setImportUploads(true); } if ($this->imageBasePath) { $importer->setImageBasePath($this->imageBasePath); } if ($this->dryRun) { $importer->setPageOutCallback(null); } return $importer->doImport(); }
function restoreText($revIds, $xml) { global $wgTmpDirectory, $wgDBname; if (!count($revIds)) { return; } print "Restoring text from XML backup...\n"; $revFileName = "{$wgTmpDirectory}/broken-revlist-{$wgDBname}"; $filteredXmlFileName = "{$wgTmpDirectory}/filtered-{$wgDBname}.xml"; // Write revision list if (!file_put_contents($revFileName, implode("\n", $revIds))) { echo "Error writing revision list, can't restore text\n"; return; } // Run mwdumper echo "Filtering XML dump...\n"; $exitStatus = 0; passthru('mwdumper ' . wfEscapeShellArg("--output=file:{$filteredXmlFileName}", "--filter=revlist:{$revFileName}", $xml), $exitStatus); if ($exitStatus) { echo "mwdumper died with exit status {$exitStatus}\n"; return; } $file = fopen($filteredXmlFileName, 'r'); if (!$file) { echo "Unable to open filtered XML file\n"; return; } $dbr =& wfGetDB(DB_SLAVE); $dbw =& wfGetDB(DB_MASTER); $dbr->ping(); $dbw->ping(); $source = new ImportStreamSource($file); $importer = new WikiImporter($source); $importer->setRevisionCallback(array(&$this, 'importRevision')); $importer->doImport(); }
function importFromHandle($handle) { $this->startTime = wfTime(); $source = new ImportStreamSource($handle); $importer = new WikiImporter($source); $importer->setDebug($this->debug); $importer->setPageCallback(array(&$this, 'reportPage')); $this->importCallback = $importer->setRevisionCallback(array(&$this, 'handleRevision')); $this->uploadCallback = $importer->setUploadCallback(array(&$this, 'handleUpload')); $this->logItemCallback = $importer->setLogItemCallback(array(&$this, 'handleLogItem')); return $importer->doImport(); }
/** * Creates or updates articles in this wiki based on the XML passed in $xml. * It is given in the format delivered by the export of Mediawiki. * * @param string $xml * XML representation of wiki articles. */ private function createArticlesFromXML($xml) { $source = new ImportStringSource($xml); $importer = new WikiImporter($source); $importer->setDebug(true); $importer->setPageCallback(array(&$this, 'reportPage')); $this->mImportCallback = $importer->setRevisionCallback(array(&$this, 'handleRevision')); $importer->doImport(); }