예제 #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
 /**
  * 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 />');
     }
 }
예제 #4
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 />');
     }
 }