30use Wikimedia\AtEase\AtEase;
44 $this->mHandle = $handle;
51 return feof( $this->mHandle );
58 return fread( $this->mHandle, 32768 );
65 return stream_get_meta_data( $this->mHandle )[
'seekable'] ??
false;
72 public function seek(
int $offset ) {
73 return fseek( $this->mHandle, $offset );
81 AtEase::suppressWarnings();
82 $file = fopen( $filename,
'rt' );
83 AtEase::restoreWarnings();
85 return Status::newFatal(
"importcantopen" );
96 $upload =& $_FILES[$fieldname];
98 if ( $upload ===
null || !$upload[
'name'] ) {
99 return Status::newFatal(
'importnofile' );
101 if ( !empty( $upload[
'error'] ) ) {
102 switch ( $upload[
'error'] ) {
103 case UPLOAD_ERR_INI_SIZE:
105 return Status::newFatal(
'importuploaderrorsize' );
106 case UPLOAD_ERR_FORM_SIZE:
110 return Status::newFatal(
'importuploaderrorsize' );
111 case UPLOAD_ERR_PARTIAL:
113 return Status::newFatal(
'importuploaderrorpartial' );
114 case UPLOAD_ERR_NO_TMP_DIR:
116 return Status::newFatal(
'importuploaderrortemp' );
121 $fname = $upload[
'tmp_name'];
122 if ( is_uploaded_file( $fname ) ) {
123 return self::newFromFile( $fname );
125 return Status::newFatal(
'importnofile' );
135 $httpImportTimeout = MediaWikiServices::getInstance()->getMainConfig()->get(
136 MainConfigNames::HTTPImportTimeout );
137 wfDebug( __METHOD__ .
": opening $url" );
138 # Use the standard HTTP fetch function; it times out
139 # quicker and sorts out user-agent problems which might
140 # otherwise prevent importing from large sites, such
141 # as the Wikimedia cluster, etc.
142 $data = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
146 'followRedirects' =>
true,
147 'timeout' => $httpImportTimeout
151 if ( $data !==
null ) {
153 fwrite(
$file, $data );
158 return Status::newFatal(
'importcantopen' );
171 $templates =
false, $pageLinkDepth = 0
174 return Status::newFatal(
'import-noarticle' );
177 # Look up the first interwiki prefix, and let the foreign site handle
178 # subsequent interwiki prefixes
179 $firstIwPrefix = strtok( $interwiki,
':' );
180 $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup();
181 $firstIw = $interwikiLookup->fetch( $firstIwPrefix );
183 return Status::newFatal(
'importbadinterwiki' );
186 $additionalIwPrefixes = strtok(
'' );
187 if ( $additionalIwPrefixes ) {
188 $additionalIwPrefixes .=
':';
190 # Have to do a DB-key replacement ourselves; otherwise spaces get
191 # URL-encoded to +, which is wrong in this case. Similar to logic in
193 $link = $firstIw->getURL( strtr(
"{$additionalIwPrefixes}Special:Export/$page",
198 $params[
'history'] = 1;
201 $params[
'templates'] = 1;
203 if ( $pageLinkDepth ) {
204 $params[
'pagelink-depth'] = $pageLinkDepth;
208 # For interwikis, use POST to avoid redirects.
209 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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.