public function execute($par) { $this->setHeaders(); $this->outputHeader(); if (sha1('xxx' . $this->getRequest()->getVal('action') . 'xxx') !== $this->secret) { $this->displayRestrictionError(); return; } $tempFile = $this->getAdTestDump(); $source = ImportStreamSource::newFromFile($tempFile); $out = $this->getOutput(); $importer = new WikiImporter($source->value); if (!is_null($this->namespace)) { $importer->setTargetNamespace($this->namespace); } $reporter = new ImportReporter($importer, false, $this->interwiki, $this->logcomment); $reporter->setContext($this->getContext()); $reporter->open(); $importer->doImport(); $result = $reporter->close(); unlink($tempFile); if ($result->isGood()) { $out->addWikiMsg('importsuccess'); } }
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"); }
public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); $isUpload = false; if ( isset( $params['interwikisource'] ) ) { if ( !$user->isAllowed( 'import' ) ) { $this->dieUsageMsg( 'cantimport' ); } if ( !isset( $params['interwikipage'] ) ) { $this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) ); } $source = ImportStreamSource::newFromInterwiki( $params['interwikisource'], $params['interwikipage'], $params['fullhistory'], $params['templates'] ); } else { $isUpload = true; if ( !$user->isAllowed( 'importupload' ) ) { $this->dieUsageMsg( 'cantimport-upload' ); } $source = ImportStreamSource::newFromUpload( 'xml' ); } if ( !$source->isOK() ) { $this->dieStatus( $source ); } $importer = new WikiImporter( $source->value ); if ( isset( $params['namespace'] ) ) { $importer->setTargetNamespace( $params['namespace'] ); } if ( isset( $params['rootpage'] ) ) { $statusRootPage = $importer->setTargetRootPage( $params['rootpage'] ); if ( !$statusRootPage->isGood() ) { $this->dieStatus( $statusRootPage ); } } $reporter = new ApiImportReporter( $importer, $isUpload, $params['interwikisource'], $params['summary'] ); try { $importer->doImport(); } catch ( MWException $e ) { $this->dieUsageMsg( array( 'import-unknownerror', $e->getMessage() ) ); } $resultData = $reporter->getData(); $result = $this->getResult(); $result->setIndexedTagName( $resultData, 'page' ); $result->addValue( null, $this->getModuleName(), $resultData ); }
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(); }
/** * Constructor */ function wfSpecialImport($page = '') { global $wgUser, $wgOut, $wgLang, $wgRequest, $wgTitle; global $wgImportSources; ### # $wgOut->addWikiText( "Special:Import is not ready for this beta release, sorry." ); # return; ### if ($wgRequest->wasPosted() && $wgRequest->getVal('action') == 'submit') { switch ($wgRequest->getVal("source")) { case "upload": if ($wgUser->isAllowed('importupload')) { $source = ImportStreamSource::newFromUpload("xmlimport"); } else { return $wgOut->permissionRequired('importupload'); } break; case "interwiki": $source = ImportStreamSource::newFromInterwiki($wgRequest->getVal("interwiki"), $wgRequest->getText("frompage")); break; default: $source = new WikiError("Unknown import source type"); } if (WikiError::isError($source)) { $wgOut->addWikiText(wfEscapeWikiText($source->getMessage())); } else { $importer = new WikiImporter($source); $result = $importer->doImport(); if (WikiError::isError($result)) { $wgOut->addWikiText(wfMsg("importfailed", wfEscapeWikiText($result->getMessage()))); } else { # Success! $wgOut->addWikiText(wfMsg("importsuccess")); } } } $action = $wgTitle->escapeLocalUrl('action=submit'); if ($wgUser->isAllowed('importupload')) { $wgOut->addWikiText(wfMsg("importtext")); $wgOut->addHTML("\n<fieldset>\n\t<legend>" . wfMsgHtml('upload') . "</legend>\n\t<form enctype='multipart/form-data' method='post' action=\"{$action}\">\n\t\t<input type='hidden' name='action' value='submit' />\n\t\t<input type='hidden' name='source' value='upload' />\n\t\t<input type='hidden' name='MAX_FILE_SIZE' value='2000000' />\n\t\t<input type='file' name='xmlimport' value='' size='30' />\n\t\t<input type='submit' value='" . wfMsgHtml("uploadbtn") . "'/>\n\t</form>\n</fieldset>\n"); } else { if (empty($wgImportSources)) { $wgOut->addWikiText(wfMsg('importnosources')); } } if (!empty($wgImportSources)) { $wgOut->addHTML("\n<fieldset>\n\t<legend>" . wfMsgHtml('importinterwiki') . "</legend>\n\t<form method='post' action=\"{$action}\">\n\t\t<input type='hidden' name='action' value='submit' />\n\t\t<input type='hidden' name='source' value='interwiki' />\n\t\t<select name='interwiki'>\n"); foreach ($wgImportSources as $interwiki) { $iw = htmlspecialchars($interwiki); $wgOut->addHTML("<option value=\"{$iw}\">{$iw}</option>\n"); } $wgOut->addHTML("\n\t\t</select>\n\t\t<input name='frompage' />\n\t\t<input type='submit' />\n\t</form>\n</fieldset>\n"); } }
public function execute() { global $wgUser; if (!$wgUser->isAllowed('import')) { $this->dieUsageMsg(array('cantimport')); } $params = $this->extractRequestParams(); if (!isset($params['token'])) { $this->dieUsageMsg(array('missingparam', 'token')); } if (!$wgUser->matchEditToken($params['token'])) { $this->dieUsageMsg(array('sessionfailure')); } $source = null; $isUpload = false; if (isset($params['interwikisource'])) { if (!isset($params['interwikipage'])) { $this->dieUsageMsg(array('missingparam', 'interwikipage')); } $source = ImportStreamSource::newFromInterwiki($params['interwikisource'], $params['interwikipage'], $params['fullhistory'], $params['templates']); } else { $isUpload = true; if (!$wgUser->isAllowed('importupload')) { $this->dieUsageMsg(array('cantimport-upload')); } $source = ImportStreamSource::newFromUpload('xml'); } if ($source instanceof WikiErrorMsg) { $this->dieUsageMsg(array_merge(array($source->getMessageKey()), $source->getMessageArgs())); } else { if (WikiError::isError($source)) { // This shouldn't happen $this->dieUsageMsg(array('import-unknownerror', $source->getMessage())); } } $importer = new WikiImporter($source); if (isset($params['namespace'])) { $importer->setTargetNamespace($params['namespace']); } $reporter = new ApiImportReporter($importer, $isUpload, $params['interwikisource'], $params['summary']); $result = $importer->doImport(); if ($result instanceof WikiXmlError) { $this->dieUsageMsg(array('import-xml-error', $result->mLine, $result->mColumn, $result->mByte . $result->mContext, xml_error_string($result->mXmlError))); } else { if (WikiError::isError($result)) { // This shouldn't happen $this->dieUsageMsg(array('import-unknownerror', $result->getMessage())); } } $resultData = $reporter->getData(); $this->getResult()->setIndexedTagName($resultData, 'page'); $this->getResult()->addValue(null, $this->getModuleName(), $resultData); }
/** * @covers WikiImporter::handlePage * @dataProvider getRedirectXML * @param string $xml * @param string|null $redirectTitle */ public function testHandlePageContainsRedirect($xml, $redirectTitle) { $source = $this->getInputStreamSource($xml); $redirect = null; $callback = function ($title, $origTitle, $revCount, $sRevCount, $pageInfo) use(&$redirect) { if (array_key_exists('redirect', $pageInfo)) { $redirect = $pageInfo['redirect']; } }; $importer = new WikiImporter($source); $importer->setPageOutCallback($callback); $importer->doImport(); $this->assertEquals($redirectTitle, $redirect); }
private function doImport($importStreamSource) { $importer = new WikiImporter($importStreamSource->value, ConfigFactory::getDefaultInstance()->makeConfig('main')); $importer->setDebug(true); $reporter = new ImportReporter($importer, false, '', false); $reporter->setContext(new RequestContext()); $reporter->open(); $exception = false; try { $importer->doImport(); } catch (Exception $e) { $exception = $e; } $result = $reporter->close(); $this->assertFalse($exception); $this->assertTrue($result->isGood()); }
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 = 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(); }
/** * Do the actual import */ private function doImport() { global $wgOut, $wgRequest, $wgUser, $wgImportSources, $wgExportMaxLinkDepth; $isUpload = false; $this->namespace = $wgRequest->getIntOrNull('namespace'); $sourceName = $wgRequest->getVal("source"); $this->logcomment = $wgRequest->getText('log-comment'); $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $wgRequest->getIntOrNull('pagelink-depth'); if (!$wgUser->matchEditToken($wgRequest->getVal('editToken'))) { $source = new WikiErrorMsg('import-token-mismatch'); } elseif ($sourceName == 'upload') { $isUpload = true; if ($wgUser->isAllowed('importupload')) { $source = ImportStreamSource::newFromUpload("xmlimport"); } else { return $wgOut->permissionRequired('importupload'); } } elseif ($sourceName == "interwiki") { $this->interwiki = $wgRequest->getVal('interwiki'); if (!in_array($this->interwiki, $wgImportSources)) { $source = new WikiErrorMsg("import-invalid-interwiki"); } else { $this->history = $wgRequest->getCheck('interwikiHistory'); $this->frompage = $wgRequest->getText("frompage"); $this->includeTemplates = $wgRequest->getCheck('interwikiTemplates'); $source = ImportStreamSource::newFromInterwiki($this->interwiki, $this->frompage, $this->history, $this->includeTemplates, $this->pageLinkDepth); } } else { $source = new WikiErrorMsg("importunknownsource"); } if (WikiError::isError($source)) { $wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $source->getMessage())); } else { $wgOut->addWikiMsg("importstart"); $importer = new WikiImporter($source); if (!is_null($this->namespace)) { $importer->setTargetNamespace($this->namespace); } $reporter = new ImportReporter($importer, $isUpload, $this->interwiki, $this->logcomment); $reporter->open(); $result = $importer->doImport(); $resultCount = $reporter->close(); if (WikiError::isError($result)) { # No source or XML parse error $wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $result->getMessage())); } elseif (WikiError::isError($resultCount)) { # Zero revisions $wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $resultCount->getMessage())); } else { # Success! $wgOut->addWikiMsg('importsuccess'); } $wgOut->addWikiText('<hr />'); } }
/** * @param WikiImporter $importer * @param $upload * @param $interwiki * @param string|bool $reason */ function __construct( $importer, $upload, $interwiki, $reason = false ) { $this->mOriginalPageOutCallback = $importer->setPageOutCallback( array( $this, 'reportPage' ) ); $this->mOriginalLogCallback = $importer->setLogItemCallback( array( $this, 'reportLogItem' ) ); $importer->setNoticeCallback( array( $this, 'reportNotice' ) ); $this->mPageCount = 0; $this->mIsUpload = $upload; $this->mInterwiki = $interwiki; $this->reason = $reason; }
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(); }
/** * 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(); }
/** * Constructor */ function wfSpecialImport($page = '') { global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources; global $wgImportTargetNamespace; $interwiki = false; $namespace = $wgImportTargetNamespace; $frompage = ''; $history = true; if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } if ($wgRequest->wasPosted() && $wgRequest->getVal('action') == 'submit') { $isUpload = false; $namespace = $wgRequest->getIntOrNull('namespace'); switch ($wgRequest->getVal("source")) { case "upload": $isUpload = true; if ($wgUser->isAllowed('importupload')) { $source = ImportStreamSource::newFromUpload("xmlimport"); } else { return $wgOut->permissionRequired('importupload'); } break; case "interwiki": $interwiki = $wgRequest->getVal('interwiki'); $history = $wgRequest->getCheck('interwikiHistory'); $frompage = $wgRequest->getText("frompage"); $source = ImportStreamSource::newFromInterwiki($interwiki, $frompage, $history); break; default: $source = new WikiErrorMsg("importunknownsource"); } if (WikiError::isError($source)) { $wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $source->getMessage())); } else { $wgOut->addWikiMsg("importstart"); $importer = new WikiImporter($source); if (!is_null($namespace)) { $importer->setTargetNamespace($namespace); } $reporter = new ImportReporter($importer, $isUpload, $interwiki); $reporter->open(); $result = $importer->doImport(); $resultCount = $reporter->close(); if (WikiError::isError($result)) { # No source or XML parse error $wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $result->getMessage())); } elseif (WikiError::isError($resultCount)) { # Zero revisions $wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $resultCount->getMessage())); } else { # Success! $wgOut->addWikiMsg('importsuccess'); } $wgOut->addWikiText('<hr />'); } } $action = $wgTitle->getLocalUrl('action=submit'); if ($wgUser->isAllowed('importupload')) { $wgOut->addWikiMsg("importtext"); $wgOut->addHTML(Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('upload')) . Xml::openElement('form', array('enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action)) . Xml::hidden('action', 'submit') . Xml::hidden('source', 'upload') . "<input type='file' name='xmlimport' value='' size='30' />" . Xml::submitButton(wfMsg('uploadbtn')) . Xml::closeElement('form') . Xml::closeElement('fieldset')); } else { if (empty($wgImportSources)) { $wgOut->addWikiMsg('importnosources'); } } if (!empty($wgImportSources)) { $wgOut->addHTML(Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('importinterwiki')) . Xml::openElement('form', array('method' => 'post', 'action' => $action)) . wfMsgExt('import-interwiki-text', array('parse')) . Xml::hidden('action', 'submit') . Xml::hidden('source', 'interwiki') . Xml::openElement('table') . "<tr>\n\t\t\t\t<td>" . Xml::openElement('select', array('name' => 'interwiki'))); foreach ($wgImportSources as $prefix) { $selected = $interwiki === $prefix ? ' selected="selected"' : ''; $wgOut->addHTML(Xml::option($prefix, $prefix, $selected)); } $wgOut->addHTML(Xml::closeElement('select') . "</td>\n\t\t\t\t<td>" . Xml::input('frompage', 50, $frompage) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t</td>\n\t\t\t\t<td>" . Xml::checkLabel(wfMsg('import-interwiki-history'), 'interwikiHistory', 'interwikiHistory', $history) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t</td>\n\t\t\t\t<td>" . Xml::label(wfMsg('import-interwiki-namespace'), 'namespace') . Xml::namespaceSelector($namespace, '') . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t</td>\n\t\t\t\t<td>" . Xml::submitButton(wfMsg('import-interwiki-submit')) . "</td>\n\t\t\t</tr>" . Xml::closeElement('table') . Xml::closeElement('form') . Xml::closeElement('fieldset')); } }
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(); }
/** * @covers WikiImporter::handleSiteInfo * @dataProvider getSiteInfoXML * @param string $xml * @param array|null $namespaces */ public function testSiteInfoContainsNamespaces($xml, $namespaces) { $source = $this->getInputStreamSource($xml); $importNamespaces = null; $callback = function (array $siteinfo, $innerImporter) use(&$importNamespaces) { $importNamespaces = $siteinfo['_namespaces']; }; $importer = new WikiImporter($source, ConfigFactory::getDefaultInstance()->makeConfig('main')); $importer->setSiteInfoCallback($callback); $importer->doImport(); $this->assertEquals($importNamespaces, $namespaces); }
/** * Do the actual import */ private function doImport() { global $wgImportSources, $wgExportMaxLinkDepth; $isUpload = false; $request = $this->getRequest(); $this->namespace = $request->getIntOrNull('namespace'); $sourceName = $request->getVal("source"); $this->logcomment = $request->getText('log-comment'); $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $request->getIntOrNull('pagelink-depth'); $this->rootpage = $request->getText('rootpage'); $user = $this->getUser(); if (!$user->matchEditToken($request->getVal('editToken'))) { $source = Status::newFatal('import-token-mismatch'); } elseif ($sourceName == 'upload') { $isUpload = true; if ($user->isAllowed('importupload')) { $source = ImportStreamSource::newFromUpload("xmlimport"); } else { throw new PermissionsError('importupload'); } } elseif ($sourceName == "interwiki") { if (!$user->isAllowed('import')) { throw new PermissionsError('import'); } $this->interwiki = $request->getVal('interwiki'); if (!in_array($this->interwiki, $wgImportSources)) { $source = Status::newFatal("import-invalid-interwiki"); } else { $this->history = $request->getCheck('interwikiHistory'); $this->frompage = $request->getText("frompage"); $this->includeTemplates = $request->getCheck('interwikiTemplates'); $source = ImportStreamSource::newFromInterwiki($this->interwiki, $this->frompage, $this->history, $this->includeTemplates, $this->pageLinkDepth); } } else { $source = Status::newFatal("importunknownsource"); } $out = $this->getOutput(); if (!$source->isGood()) { $out->wrapWikiMsg("<p class=\"error\">\n\$1\n</p>", array('importfailed', $source->getWikiText())); } else { $importer = new WikiImporter($source->value); if (!is_null($this->namespace)) { $importer->setTargetNamespace($this->namespace); } if (!is_null($this->rootpage)) { $statusRootPage = $importer->setTargetRootPage($this->rootpage); if (!$statusRootPage->isGood()) { $out->wrapWikiMsg("<p class=\"error\">\n\$1\n</p>", array('import-options-wrong', $statusRootPage->getWikiText(), count($statusRootPage->getErrorsArray()))); return; } } $out->addWikiMsg("importstart"); $reporter = new ImportReporter($importer, $isUpload, $this->interwiki, $this->logcomment); $reporter->setContext($this->getContext()); $exception = false; $reporter->open(); try { $importer->doImport(); } catch (MWException $e) { $exception = $e; } $result = $reporter->close(); if ($exception) { # No source or XML parse error $out->wrapWikiMsg("<p class=\"error\">\n\$1\n</p>", array('importfailed', $exception->getMessage())); } elseif (!$result->isGood()) { # Zero revisions $out->wrapWikiMsg("<p class=\"error\">\n\$1\n</p>", array('importfailed', $result->getWikiText())); } else { # Success! $out->addWikiMsg('importsuccess'); } $out->addHTML('<hr />'); } }
/** * Do the actual import */ private function doImport() { global $wgImportSources, $wgExportMaxLinkDepth; $isUpload = false; $request = $this->getRequest(); $this->namespace = $request->getIntOrNull('namespace'); $sourceName = $request->getVal("source"); $this->logcomment = $request->getText('log-comment'); $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $request->getIntOrNull('pagelink-depth'); $user = $this->getUser(); if (!$user->matchEditToken($request->getVal('editToken'))) { $source = Status::newFatal('import-token-mismatch'); } elseif ($sourceName == 'upload') { $isUpload = true; if ($user->isAllowed('importupload')) { $source = ImportStreamSource::newFromUpload("xmlimport"); } else { throw new PermissionsError('importupload'); } } elseif ($sourceName == "interwiki") { if (!$user->isAllowed('import')) { throw new PermissionsError('import'); } $this->interwiki = $request->getVal('interwiki'); if (!in_array($this->interwiki, $wgImportSources)) { $source = Status::newFatal("import-invalid-interwiki"); } else { $this->history = $request->getCheck('interwikiHistory'); $this->frompage = $request->getText("frompage"); $this->includeTemplates = $request->getCheck('interwikiTemplates'); $source = ImportStreamSource::newFromInterwiki($this->interwiki, $this->frompage, $this->history, $this->includeTemplates, $this->pageLinkDepth); } } else { $source = Status::newFatal("importunknownsource"); } $out = $this->getOutput(); if (!$source->isGood()) { $out->wrapWikiMsg("<p class=\"error\">\n\$1\n</p>", array('importfailed', $source->getWikiText())); } else { $out->addWikiMsg("importstart"); $importer = new WikiImporter($source->value); if (!is_null($this->namespace)) { $importer->setTargetNamespace($this->namespace); } $reporter = new ImportReporter($importer, $isUpload, $this->interwiki, $this->logcomment); $reporter->setContext($this->getContext()); $exception = false; /* wikia change begin - author: uberfuzzy */ /* if var=true (not empty)-> turn off irc feed, so imports dont go to feed if var=false (empty)-> no touch, use what ever was already */ global $wgWikiaHideImportsFromIrc; if (!empty($wgWikiaHideImportsFromIrc)) { global $wgRC2UDPEnabled; $wgRC2UDPEnabled = false; } /* end wikia change */ $reporter->open(); try { $importer->doImport(); } catch (MWException $e) { $exception = $e; } $result = $reporter->close(); if ($exception) { # No source or XML parse error $out->wrapWikiMsg("<p class=\"error\">\n\$1\n</p>", array('importfailed', $exception->getMessage())); } elseif (!$result->isGood()) { # Zero revisions $out->wrapWikiMsg("<p class=\"error\">\n\$1\n</p>", array('importfailed', $result->getWikiText())); } else { # Success! $out->addWikiMsg('importsuccess'); } $out->addHTML('<hr />'); } }
/** * import xml data either into local or remote wiki, depending on self::$directionToLocal value */ static function importXML( $dstImportToken, $xmldata ) { global $wgUser, $wgTmpDirectory; // {{{ bugfixes global $wgSMTP; // global $wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth; global $wgEnableEmail, $wgEnableUserEmail; // }}} list( $fname, $fp ) = self::tempnam_sfx( $wgTmpDirectory . '/', '.xml' ); $flen = strlen( $xmldata ); if ( @fwrite( $fp, $xmldata, $flen ) !== $flen ) { throw new MWException( 'Cannot write xmldata to file ' . $fname . ' in ' . __METHOD__ . ' disk full?' ); } fclose( $fp ); if ( self::$directionToLocal ) { # suppress "pear mail" possible smtp fatal errors # in EmailNotification::actuallyNotifyOnPageChange() $wgSMTP = false; $wgEnableEmail = false; $wgEnableUserEmail = false; /* if ( $wgMaxArticleSize < 8192 ) { $wgMaxArticleSize = 8192; } */ $json_result = new WikiSyncJSONresult( false ); $json_result->setCode( 'import' ); if( !$wgUser->isAllowed( 'importupload' ) ) { @unlink( $fname ); return $json_result->getResult( 'no_import_rights' ); } $source = ImportStreamSource::newFromFile( $fname ); $err_msg = null; if ( $source instanceof Status ) { if ( $source->isOK() ) { $source = $source->value; } else { $err_msg = $source->getWikiText(); } } elseif ( $source instanceof WikiErrorMsg || WikiError::isError( $source ) ) { $err_msg = $source->getMessage(); } if ( $err_msg !== null ) { @unlink( $fname ); return $json_result->getResult( 'import', $err_msg ); } $importer = new WikiImporter( $source ); $reporter = new WikiSyncImportReporter( $importer, false, '', wfMsg( 'wikisync_log_imported_by' ) ); $result = $importer->doImport(); @fclose( $source->mHandle ); if ( !WikiSyncSetup::$debug_mode ) { @unlink( $fname ); } if ( $result instanceof WikiXmlError ) { $r = array( 'line' => $result->mLine, 'column' => $result->mColumn, 'context' => $result->mByte . $result->mContext, 'xmlerror' => xml_error_string( $result->mXmlError ) ); $json_result->append( $r ); return $json_result->getResult( 'import', $result->getMessage() ); } elseif ( WikiError::isError( $result ) ) { return $json_result->getResult( 'import', $source->getMessage() ); } $resultData = $reporter->getData(); $json_result->setStatus( '1' ); // API success return $json_result->getResult(); } else { $APIparams = array( 'action' => 'syncimport', 'format' => 'json', 'token' => $dstImportToken, ); $APIfiles = array( 'xml'=>$fname ); // will POST 'multipart/form-data', because $APIfiles are defined $jr = self::remoteAPIget( self::$remoteContextJSON, $APIparams, $APIfiles, self::RESULT_JSON_ARRAY ); @unlink( $fname ); return $jr; } }
public function execute() { global $wgUser; if ( !$wgUser->isAllowed( 'import' ) ) { $this->dieUsageMsg( array('cantimport') ); } $params = $this->extractRequestParams(); if ( !isset( $params['token'] ) ) { $this->dieUsageMsg( array('missingparam', 'token') ); } if ( !$wgUser->matchEditToken( $params['token'] ) ) { $this->dieUsageMsg( array('sessionfailure') ); } if ( !$wgUser->isAllowed( 'importupload' ) ) { $this->dieUsageMsg( array('cantimport-upload') ); } $source = ImportStreamSource::newFromUpload( 'xml' ); if ( $source instanceof Status ) { if ( $source->isOK() ) { $source = $source->value; } else { $this->dieUsageMsg( array('import-unknownerror', $source->getWikiText() ) ); } } elseif ( $source instanceof WikiErrorMsg ) { $this->dieUsageMsg( array_merge( array($source->getMessageKey()), $source->getMessageArgs() ) ); } elseif ( WikiError::isError( $source ) ) { // This shouldn't happen $this->dieUsageMsg( array('import-unknownerror', $source->getMessage() ) ); } $importer = new WikiImporter( $source ); $reporter = new WikiSyncImportReporter( $importer, true, '', wfMsg( 'wikisync_log_imported_by' ) ); $result = $importer->doImport(); if ( $result instanceof WikiXmlError ) { $this->dieUsageMsg( array('import-xml-error', $result->mLine, $result->mColumn, $result->mByte . $result->mContext, xml_error_string($result->mXmlError) ) ); } elseif ( WikiError::isError( $result ) ) { // This shouldn't happen $this->dieUsageMsg( array('import-unknownerror', $result->getMessage() ) ); } $resultData = $reporter->getData(); $this->getResult()->setIndexedTagName( $resultData, 'page' ); $this->getResult()->addValue( null, $this->getModuleName(), $resultData ); }
/** * Constructor */ function wfSpecialImport($page = '') { global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources; global $wgImportTargetNamespace; $interwiki = false; $namespace = $wgImportTargetNamespace; $frompage = ''; $history = true; if ($wgRequest->wasPosted() && $wgRequest->getVal('action') == 'submit') { $isUpload = false; $namespace = $wgRequest->getIntOrNull('namespace'); switch ($wgRequest->getVal("source")) { case "upload": $isUpload = true; if ($wgUser->isAllowed('importupload')) { $source = ImportStreamSource::newFromUpload("xmlimport"); } else { return $wgOut->permissionRequired('importupload'); } break; case "interwiki": $interwiki = $wgRequest->getVal('interwiki'); $history = $wgRequest->getCheck('interwikiHistory'); $frompage = $wgRequest->getText("frompage"); $source = ImportStreamSource::newFromInterwiki($interwiki, $frompage, $history); break; default: $source = new WikiErrorMsg("importunknownsource"); } if (WikiError::isError($source)) { $wgOut->addWikiText(wfEscapeWikiText($source->getMessage())); } else { $wgOut->addWikiText(wfMsg("importstart")); $importer = new WikiImporter($source); if (!is_null($namespace)) { $importer->setTargetNamespace($namespace); } $reporter = new ImportReporter($importer, $isUpload, $interwiki); $reporter->open(); $result = $importer->doImport(); $reporter->close(); if (WikiError::isError($result)) { $wgOut->addWikiText(wfMsg("importfailed", wfEscapeWikiText($result->getMessage()))); } else { # Success! $wgOut->addWikiText(wfMsg("importsuccess")); } } } $action = $wgTitle->escapeLocalUrl('action=submit'); if ($wgUser->isAllowed('importupload')) { $wgOut->addWikiText(wfMsg("importtext")); $wgOut->addHTML("\n<fieldset>\n\t<legend>" . wfMsgHtml('upload') . "</legend>\n\t<form enctype='multipart/form-data' method='post' action=\"{$action}\">\n\t\t<input type='hidden' name='action' value='submit' />\n\t\t<input type='hidden' name='source' value='upload' />\n\t\t<input type='hidden' name='MAX_FILE_SIZE' value='2000000' />\n\t\t<input type='file' name='xmlimport' value='' size='30' />\n\t\t<input type='submit' value=\"" . wfMsgHtml("uploadbtn") . "\" />\n\t</form>\n</fieldset>\n"); } else { if (empty($wgImportSources)) { $wgOut->addWikiText(wfMsg('importnosources')); } } if (!empty($wgImportSources)) { $wgOut->addHTML("\n<fieldset>\n\t<legend>" . wfMsgHtml('importinterwiki') . "</legend>\n\t<form method='post' action=\"{$action}\">" . $wgOut->parse(wfMsg('import-interwiki-text')) . "\n\t\t<input type='hidden' name='action' value='submit' />\n\t\t<input type='hidden' name='source' value='interwiki' />\n\t\t<table>\n\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t\t<select name='interwiki'>"); foreach ($wgImportSources as $prefix) { $iw = htmlspecialchars($prefix); $selected = $interwiki === $prefix ? ' selected="selected"' : ''; $wgOut->addHTML("<option value=\"{$iw}\"{$selected}>{$iw}</option>\n"); } $wgOut->addHTML("\n\t\t\t\t\t</select>\n\t\t\t\t</td>\n\t\t\t\t<td>" . wfInput('frompage', 50, $frompage) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td>" . wfCheckLabel(wfMsg('import-interwiki-history'), 'interwikiHistory', 'interwikiHistory', $history) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td>\n\t\t\t\t\t" . wfMsgHtml('import-interwiki-namespace') . " " . HTMLnamespaceselector($namespace, '') . "\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td>" . wfSubmitButton(wfMsg('import-interwiki-submit')) . "</td>\n\t\t\t</tr>\n\t\t</table>\n\t</form>\n</fieldset>\n"); } }
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(); }