40 $this->mHandle = $handle;
47 return feof( $this->mHandle );
54 return fread( $this->mHandle, 32768 );
62 Wikimedia\suppressWarnings();
63 $file = fopen( $filename,
'rt' );
64 Wikimedia\restoreWarnings();
66 return Status::newFatal(
"importcantopen" );
76 $upload =& $_FILES[$fieldname];
78 if ( $upload ===
null || !$upload[
'name'] ) {
79 return Status::newFatal(
'importnofile' );
81 if ( !empty( $upload[
'error'] ) ) {
82 switch ( $upload[
'error'] ) {
83 case UPLOAD_ERR_INI_SIZE:
85 return Status::newFatal(
'importuploaderrorsize' );
86 case UPLOAD_ERR_FORM_SIZE:
90 return Status::newFatal(
'importuploaderrorsize' );
91 case UPLOAD_ERR_PARTIAL:
93 return Status::newFatal(
'importuploaderrorpartial' );
94 case UPLOAD_ERR_NO_TMP_DIR:
96 return Status::newFatal(
'importuploaderrortemp' );
101 $fname = $upload[
'tmp_name'];
102 if ( is_uploaded_file( $fname ) ) {
105 return Status::newFatal(
'importnofile' );
116 wfDebug( __METHOD__ .
": opening $url" );
117 # Use the standard HTTP fetch function; it times out
118 # quicker and sorts out user-agent problems which might
119 # otherwise prevent importing from large sites, such
120 # as the Wikimedia cluster, etc.
121 $data = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
125 'followRedirects' =>
true,
130 if ( $data !==
null ) {
132 fwrite(
$file, $data );
137 return Status::newFatal(
'importcantopen' );
150 $templates =
false, $pageLinkDepth = 0
153 return Status::newFatal(
'import-noarticle' );
156 # Look up the first interwiki prefix, and let the foreign site handle
157 # subsequent interwiki prefixes
158 $firstIwPrefix = strtok( $interwiki,
':' );
159 $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup();
160 $firstIw = $interwikiLookup->fetch( $firstIwPrefix );
162 return Status::newFatal(
'importbadinterwiki' );
165 $additionalIwPrefixes = strtok(
'' );
166 if ( $additionalIwPrefixes ) {
167 $additionalIwPrefixes .=
':';
169 # Have to do a DB-key replacement ourselves; otherwise spaces get
170 # URL-encoded to +, which is wrong in this case. Similar to logic in
172 $link = $firstIw->getURL( strtr(
"{$additionalIwPrefixes}Special:Export/$page",
177 $params[
'history'] = 1;
180 $params[
'templates'] = 1;
182 if ( $pageLinkDepth ) {
183 $params[
'pagelink-depth'] = $pageLinkDepth;
187 # For interwikis, use POST to avoid redirects.
$wgHTTPImportTimeout
Timeout for HTTP requests done internally for transwiki imports, in seconds.
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')
Source interface for XML import.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.