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'); } }
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()); }
/** * 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"); } }
/** * 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 $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 />'); } }
/** * 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')); } }
/** * 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 />'); } }