Пример #1
0
 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());
 }
Пример #3
0
 /**
  * @param Title $title
  * @param Title $origTitle
  * @param int $revisionCount
  * @param int $successCount
  * @param array $pageInfo
  * @return void
  */
 function reportPage($title, $origTitle, $revisionCount, $successCount, $pageInfo)
 {
     // Add a result entry
     $r = array();
     if ($title === null) {
         # Invalid or non-importable title
         $r['title'] = $pageInfo['title'];
         $r['invalid'] = true;
     } else {
         ApiQueryBase::addTitleInfo($r, $title);
         $r['revisions'] = intval($successCount);
     }
     $this->mResultArr[] = $r;
     // Piggyback on the parent to do the logging
     parent::reportPage($title, $origTitle, $revisionCount, $successCount, $pageInfo);
 }
Пример #4
0
/**
 * 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");
    }
}
Пример #5
0
 /**
  * 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 />');
     }
 }
	function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo = '' ) {
		// Add a result entry
		$r = array();
		ApiQueryBase::addTitleInfo($r, $title);
		$r['revisions'] = intval($successCount);
		$this->mResultArr[] = $r;

		# call the parent to do the logging
		# avoid bug in 1.15.4 Special:Import (new file page text without the file uploaded)
		# PHP Fatal error:  Call to a member function insertOn() on a non-object in E:\www\psychologos\includes\specials\SpecialImport.php on line 334
		// do not create informational null revisions
		// because they are placed on top of real user made revisions,
		// making the binary search algorithm used to compare local and remote revs to fail
		// TODO: change the binary search algorithm to two/three level hashes
		if ( WikiSyncSetup::$report_null_revisions && $title->getArticleId() !== 0 ) {
			parent::reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo );
		}
	}
Пример #7
0
 /**
  * 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 />');
     }
 }
Пример #8
0
 /**
  * @param $title Title
  * @param $origTitle Title
  * @param $revisionCount int
  * @param $successCount int
  * @param $pageInfo
  * @return void
  */
 function reportPage($title, $origTitle, $revisionCount, $successCount, $pageInfo)
 {
     // Add a result entry
     $r = array();
     ApiQueryBase::addTitleInfo($r, $title);
     $r['revisions'] = intval($successCount);
     $this->mResultArr[] = $r;
     // Piggyback on the parent to do the logging
     parent::reportPage($title, $origTitle, $revisionCount, $successCount, $pageInfo);
 }
/**
 * 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'));
    }
}
Пример #10
0
 /**
  * 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 />');
     }
 }