31 $this->mHandle = $handle;
38 return feof( $this->mHandle );
45 return fread( $this->mHandle, 32768 );
52 return stream_get_meta_data( $this->mHandle )[
'seekable'] ??
false;
59 public function seek(
int $offset ) {
60 return fseek( $this->mHandle, $offset );
69 $file = @fopen( $filename,
'rt' );
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' ) ) {
111 return Status::newFatal(
'importnofile' );
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.
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,
':' );
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.
200class_alias( ImportStreamSource::class,
'ImportStreamSource' );
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...
A class containing constants representing the names of configuration variables.
const HTTPImportTimeout
Name constant for the HTTPImportTimeout setting, for use with Config::get()