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'); } }
protected function setUp() { parent::setUp(); $file = dirname(__DIR__) . '/data/import/ImportLinkCacheIntegrationTest.xml'; $this->importStreamSource = ImportStreamSource::newFromFile($file); if (!$this->importStreamSource->isGood()) { throw new Exception("Import source for {$file} failed"); } }
private function getInputStreamSource($xml) { $file = 'data:application/xml,' . $xml; $status = ImportStreamSource::newFromFile($file); if (!$status->isGood()) { throw new MWException("Cannot create InputStreamSource."); } return $status->value; }
private function getInputStreamSource($xml) { if (ini_get('allow_url_fopen') != 1) { $this->markTestSkipped('bug 73283: this test needs allow_url_fopen to be enabled'); } $file = 'data:application/xml,' . $xml; $status = ImportStreamSource::newFromFile($file); if (!$status->isGood()) { throw new MWException("Cannot create InputStreamSource."); } return $status->value; }
/** * @param string $fieldname * @return Status */ static function newFromUpload($fieldname = "xmlimport") { $upload =& $_FILES[$fieldname]; if ($upload === null || !$upload['name']) { return Status::newFatal('importnofile'); } if (!empty($upload['error'])) { switch ($upload['error']) { case 1: # The uploaded file exceeds the upload_max_filesize directive in php.ini. return Status::newFatal('importuploaderrorsize'); case 2: # The uploaded file exceeds the MAX_FILE_SIZE directive that # was specified in the HTML form. return Status::newFatal('importuploaderrorsize'); case 3: # The uploaded file was only partially uploaded return Status::newFatal('importuploaderrorpartial'); case 6: # Missing a temporary folder. return Status::newFatal('importuploaderrortemp'); # case else: # Currently impossible } } $fname = $upload['tmp_name']; if (is_uploaded_file($fname)) { return ImportStreamSource::newFromFile($fname); } else { return Status::newFatal('importnofile'); } }
function newFromURL($url) { wfDebug(__METHOD__ . ": opening {$url}\n"); # fopen-wrappers are normally turned off for security. ini_set("allow_url_fopen", true); $ret = ImportStreamSource::newFromFile($url); ini_set("allow_url_fopen", false); return $ret; }
function newFromURL($url) { # fopen-wrappers are normally turned off for security. ini_set("allow_url_fopen", true); $ret = ImportStreamSource::newFromFile($url); ini_set("allow_url_fopen", false); return $ret; }
/** * 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; } }
static function newFromUpload($fieldname = "xmlimport") { $upload =& $_FILES[$fieldname]; if (!isset($upload) || !$upload['name']) { return new WikiErrorMsg('importnofile'); } if (!empty($upload['error'])) { return new WikiErrorMsg('importuploaderror', $upload['error']); } $fname = $upload['tmp_name']; if (is_uploaded_file($fname)) { return ImportStreamSource::newFromFile($fname); } else { return new WikiErrorMsg('importnofile'); } }