29use Wikimedia\AtEase\AtEase;
43 $this->mHandle = $handle;
50 return feof( $this->mHandle );
57 return fread( $this->mHandle, 32768 );
65 AtEase::suppressWarnings();
66 $file = fopen( $filename,
'rt' );
67 AtEase::restoreWarnings();
69 return Status::newFatal(
"importcantopen" );
79 $upload =& $_FILES[$fieldname];
81 if ( $upload ===
null || !$upload[
'name'] ) {
82 return Status::newFatal(
'importnofile' );
84 if ( !empty( $upload[
'error'] ) ) {
85 switch ( $upload[
'error'] ) {
86 case UPLOAD_ERR_INI_SIZE:
88 return Status::newFatal(
'importuploaderrorsize' );
89 case UPLOAD_ERR_FORM_SIZE:
93 return Status::newFatal(
'importuploaderrorsize' );
94 case UPLOAD_ERR_PARTIAL:
96 return Status::newFatal(
'importuploaderrorpartial' );
97 case UPLOAD_ERR_NO_TMP_DIR:
99 return Status::newFatal(
'importuploaderrortemp' );
104 $fname = $upload[
'tmp_name'];
105 if ( is_uploaded_file( $fname ) ) {
108 return Status::newFatal(
'importnofile' );
118 $httpImportTimeout = MediaWikiServices::getInstance()->getMainConfig()->get(
119 MainConfigNames::HTTPImportTimeout );
120 wfDebug( __METHOD__ .
": opening $url" );
121 # Use the standard HTTP fetch function; it times out
122 # quicker and sorts out user-agent problems which might
123 # otherwise prevent importing from large sites, such
124 # as the Wikimedia cluster, etc.
125 $data = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
129 'followRedirects' =>
true,
130 'timeout' => $httpImportTimeout
134 if ( $data !==
null ) {
136 fwrite(
$file, $data );
141 return Status::newFatal(
'importcantopen' );
154 $templates =
false, $pageLinkDepth = 0
157 return Status::newFatal(
'import-noarticle' );
160 # Look up the first interwiki prefix, and let the foreign site handle
161 # subsequent interwiki prefixes
162 $firstIwPrefix = strtok( $interwiki,
':' );
163 $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup();
164 $firstIw = $interwikiLookup->fetch( $firstIwPrefix );
166 return Status::newFatal(
'importbadinterwiki' );
169 $additionalIwPrefixes = strtok(
'' );
170 if ( $additionalIwPrefixes ) {
171 $additionalIwPrefixes .=
':';
173 # Have to do a DB-key replacement ourselves; otherwise spaces get
174 # URL-encoded to +, which is wrong in this case. Similar to logic in
176 $link = $firstIw->getURL( strtr(
"{$additionalIwPrefixes}Special:Export/$page",
181 $params[
'history'] = 1;
184 $params[
'templates'] = 1;
186 if ( $pageLinkDepth ) {
187 $params[
'pagelink-depth'] = $pageLinkDepth;
191 # 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.