29use Wikimedia\AtEase\AtEase;
43 $this->mHandle = $handle;
50 return feof( $this->mHandle );
57 return fread( $this->mHandle, 32768 );
64 return stream_get_meta_data( $this->mHandle )[
'seekable'] ??
false;
71 public function seek(
int $offset ) {
72 return fseek( $this->mHandle, $offset );
80 AtEase::suppressWarnings();
81 $file = fopen( $filename,
'rt' );
82 AtEase::restoreWarnings();
84 return Status::newFatal(
"importcantopen" );
94 $upload =& $_FILES[$fieldname];
96 if ( $upload ===
null || !$upload[
'name'] ) {
97 return Status::newFatal(
'importnofile' );
99 if ( !empty( $upload[
'error'] ) ) {
100 switch ( $upload[
'error'] ) {
101 case UPLOAD_ERR_INI_SIZE:
103 return Status::newFatal(
'importuploaderrorsize' );
104 case UPLOAD_ERR_FORM_SIZE:
108 return Status::newFatal(
'importuploaderrorsize' );
109 case UPLOAD_ERR_PARTIAL:
111 return Status::newFatal(
'importuploaderrorpartial' );
112 case UPLOAD_ERR_NO_TMP_DIR:
114 return Status::newFatal(
'importuploaderrortemp' );
119 $fname = $upload[
'tmp_name'];
120 if ( is_uploaded_file( $fname ) ) {
123 return Status::newFatal(
'importnofile' );
133 $httpImportTimeout = MediaWikiServices::getInstance()->getMainConfig()->get(
134 MainConfigNames::HTTPImportTimeout );
135 wfDebug( __METHOD__ .
": opening $url" );
136 # Use the standard HTTP fetch function; it times out
137 # quicker and sorts out user-agent problems which might
138 # otherwise prevent importing from large sites, such
139 # as the Wikimedia cluster, etc.
140 $data = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
144 'followRedirects' =>
true,
145 'timeout' => $httpImportTimeout
149 if ( $data !==
null ) {
151 fwrite(
$file, $data );
156 return Status::newFatal(
'importcantopen' );
169 $templates =
false, $pageLinkDepth = 0
172 return Status::newFatal(
'import-noarticle' );
175 # Look up the first interwiki prefix, and let the foreign site handle
176 # subsequent interwiki prefixes
177 $firstIwPrefix = strtok( $interwiki,
':' );
178 $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup();
179 $firstIw = $interwikiLookup->fetch( $firstIwPrefix );
181 return Status::newFatal(
'importbadinterwiki' );
184 $additionalIwPrefixes = strtok(
'' );
185 if ( $additionalIwPrefixes ) {
186 $additionalIwPrefixes .=
':';
188 # Have to do a DB-key replacement ourselves; otherwise spaces get
189 # URL-encoded to +, which is wrong in this case. Similar to logic in
191 $link = $firstIw->getURL( strtr(
"{$additionalIwPrefixes}Special:Export/$page",
196 $params[
'history'] = 1;
199 $params[
'templates'] = 1;
201 if ( $pageLinkDepth ) {
202 $params[
'pagelink-depth'] = $pageLinkDepth;
206 # For interwikis, use POST to avoid redirects.
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.