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 ); }
/** * 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); }
/** * Do the actual import */ private function doImport() { global $wgOut, $wgRequest, $wgUser, $wgImportSources; $isUpload = false; $this->namespace = $wgRequest->getIntOrNull('namespace'); $sourceName = $wgRequest->getVal("source"); $this->logcomment = $wgRequest->getText('log-comment'); 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"); $source = ImportStreamSource::newFromInterwiki($this->interwiki, $this->frompage, $this->history); } } 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 ($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 />'); } }
/** * 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 />'); } }