16use Wikimedia\AtEase\AtEase;
30 $this->mHandle = $handle;
37 return feof( $this->mHandle );
44 return fread( $this->mHandle, 32768 );
51 return stream_get_meta_data( $this->mHandle )[
'seekable'] ??
false;
58 public function seek(
int $offset ) {
59 return fseek( $this->mHandle, $offset );
67 AtEase::suppressWarnings();
68 $file = fopen( $filename,
'rt' );
69 AtEase::restoreWarnings();
71 return Status::newFatal(
"importcantopen" );
82 $upload =& $_FILES[$fieldname];
84 if ( $upload ===
null || !$upload[
'name'] ) {
85 return Status::newFatal(
'importnofile' );
87 if ( !empty( $upload[
'error'] ) ) {
88 switch ( $upload[
'error'] ) {
89 case UPLOAD_ERR_INI_SIZE:
91 return Status::newFatal(
'importuploaderrorsize' );
92 case UPLOAD_ERR_FORM_SIZE:
96 return Status::newFatal(
'importuploaderrorsize' );
97 case UPLOAD_ERR_PARTIAL:
99 return Status::newFatal(
'importuploaderrorpartial' );
100 case UPLOAD_ERR_NO_TMP_DIR:
102 return Status::newFatal(
'importuploaderrortemp' );
107 $fname = $upload[
'tmp_name'];
108 if ( is_uploaded_file( $fname ) || defined(
'MW_PHPUNIT_TEST' ) ) {
109 return self::newFromFile( $fname );
111 return Status::newFatal(
'importnofile' );
121 $httpImportTimeout = MediaWikiServices::getInstance()->getMainConfig()->get(
122 MainConfigNames::HTTPImportTimeout );
123 wfDebug( __METHOD__ .
": opening $url" );
124 # Use the standard HTTP fetch function; it times out
125 # quicker and sorts out user-agent problems which might
126 # otherwise prevent importing from large sites, such
127 # as the Wikimedia cluster, etc.
128 $data = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
132 'followRedirects' =>
true,
133 'timeout' => $httpImportTimeout
137 if ( $data !==
null ) {
139 fwrite( $file, $data );
144 return Status::newFatal(
'importcantopen' );
157 $templates =
false, $pageLinkDepth = 0
160 return Status::newFatal(
'import-noarticle' );
163 # Look up the first interwiki prefix, and let the foreign site handle
164 # subsequent interwiki prefixes
165 $firstIwPrefix = strtok( $interwiki,
':' );
166 $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup();
167 $firstIw = $interwikiLookup->fetch( $firstIwPrefix );
169 return Status::newFatal(
'importbadinterwiki' );
172 $additionalIwPrefixes = strtok(
'' );
173 if ( $additionalIwPrefixes ) {
174 $additionalIwPrefixes .=
':';
176 # Have to do a DB-key replacement ourselves; otherwise spaces get
177 # URL-encoded to +, which is wrong in this case. Similar to logic in
179 $link = $firstIw->getURL( strtr(
"{$additionalIwPrefixes}Special:Export/$page",
184 $params[
'history'] = 1;
187 $params[
'templates'] = 1;
189 if ( $pageLinkDepth ) {
190 $params[
'pagelink-depth'] = $pageLinkDepth;
194 # For interwikis, use POST to avoid redirects.
195 return self::newFromURL(
$url,
"POST" );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
static newFromInterwiki( $interwiki, $page, $history=false, $templates=false, $pageLinkDepth=0)
static newFromFile( $filename)
static newFromUpload( $fieldname="xmlimport")
static newFromURL( $url, $method='GET')
A class containing constants representing the names of configuration variables.
Source interface for XML import.