3 * MediaWiki page data importer
4 * Copyright (C) 2003,2005 Brion Vibber <brion@pobox.com>
5 * http://www.mediawiki.org/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @addtogroup SpecialPage
28 function wfSpecialImport( $page = '' ) {
29 global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources;
30 global $wgImportTargetNamespace;
34 $namespace = $wgImportTargetNamespace;
38 if( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit') {
40 $articleName = $wgRequest->getText( 'articlename' );
41 $namespace = $wgRequest->getIntOrNull( 'namespace' );
43 switch( $wgRequest->getVal( "source" ) ) {
46 if( $wgUser->isAllowed( 'importupload' ) ) {
47 $source = ImportStreamSource
::newFromUpload( "xmlimport" );
49 return $wgOut->permissionRequired( 'importupload' );
53 $interwiki = $wgRequest->getVal( 'interwiki' );
54 $history = $wgRequest->getCheck( 'interwikiHistory' );
55 $frompage = $wgRequest->getText( "frompage" );
56 $source = ImportStreamSource
::newFromInterwiki(
62 $source = new WikiErrorMsg( "importunknownsource" );
65 if( WikiError
::isError( $source ) ) {
66 $wgOut->addWikiText( '<p class="error">' . wfMsg( "importfailed", wfEscapeWikiText( $source->getMessage() ) ) . '</p>' );
68 $wgOut->addWikiText( wfMsg( "importstart" ) );
70 $importer = new WikiImporter( $source );
71 if( !is_null( $namespace ) ) {
72 $importer->setTargetNamespace( $namespace );
74 if( $articleName !== '' ) {
75 $importer->setTargetArticleName( $articleName );
77 $reporter = new ImportReporter( $importer, $isUpload, $interwiki, $frompage );
80 $result = $importer->doImport();
81 $resultCount = $reporter->close();
83 if( WikiError
::isError( $result ) ) {
84 # No source or XML parse error
85 $wgOut->addWikiText( '<p class="error">' . wfMsg( "importfailed", wfEscapeWikiText( $result->getMessage() ) ) . '</p>' );
86 } elseif( WikiError
::isError( $resultCount ) ) {
88 $wgOut->addWikiText( '<p class="error">' . wfMsg( "importfailed", wfEscapeWikiText( $resultCount->getMessage() ) ) . '</p>' );
91 $wgOut->addWikiText( wfMsg( "importsuccess" ) );
93 $wgOut->addWikiText( '<hr />' );
97 $action = $wgTitle->escapeLocalUrl( 'action=submit' );
99 if( $wgUser->isAllowed( 'importupload' ) ) {
100 $wgOut->addWikiText( wfMsg( "importtext" ) );
102 Xml
::openElement( 'fieldset' ).
103 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
104 Xml
::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) .
105 Xml
::hidden( 'action', 'submit' ) .
106 Xml
::hidden( 'source', 'upload' ) .
107 Xml
::hidden( 'MAX_FILE_SIZE', '2000000' ) .
108 "<input type='file' name='xmlimport' value='' size='30' />" . // No Xml function for type=file? Todo?
109 Xml
::submitButton( wfMsg( 'uploadbtn' ) ) .
110 Xml
::closeElement( 'form' ) .
111 Xml
::closeElement( 'fieldset' ) );
113 if( empty( $wgImportSources ) ) {
114 $wgOut->addWikiText( wfMsg( 'importnosources' ) );
118 if( !empty( $wgImportSources ) ) {
120 Xml
::openElement( 'fieldset' ) .
121 Xml
::element( 'legend', null, wfMsg( 'importinterwiki' ) ) .
122 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) .
123 wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) .
124 Xml
::hidden( 'action', 'submit' ) .
125 Xml
::hidden( 'source', 'interwiki' ) .
126 Xml
::openElement( 'table' ) .
129 Xml
::openElement( 'select', array( 'name' => 'interwiki' ) ) );
130 foreach( $wgImportSources as $prefix ) {
131 $iw = htmlspecialchars( $prefix );
132 $selected = ($interwiki === $prefix) ?
' selected="selected"' : '';
133 $wgOut->addHTML( Xml
::option( $iw, $iw, $selected ) );
136 Xml
::closeElement( 'select' ) .
139 Xml
::input( 'frompage', 50, $frompage ) .
145 Xml
::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $history ) .
151 Xml
::inputLabel( wfMsg( 'import-articlename' ), 'articlename', 'articlename', 50, $articleName ) .
157 Xml
::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) .
158 Xml
::namespaceSelector( $namespace, '' ) .
164 Xml
::submitButton( wfMsg( 'import-interwiki-submit' ) ) .
167 Xml
::closeElement( 'table' ).
168 Xml
::closeElement( 'form' ) .
169 Xml
::closeElement( 'fieldset' ) );
175 * @addtogroup SpecialPage
177 class ImportReporter
{
178 function __construct( $importer, $upload, $interwiki, $frompage ) {
179 $importer->setPageOutCallback( array( $this, 'reportPage' ) );
180 $this->mPageCount
= 0;
181 $this->mIsUpload
= $upload;
182 $this->mInterwiki
= $interwiki;
183 $this->mFrompage
= $frompage;
188 $wgOut->addHtml( "<ul>\n" );
191 function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
192 global $wgOut, $wgUser, $wgLang, $wgContLang;
194 $skin = $wgUser->getSkin();
198 $localCount = $wgLang->formatNum( $successCount );
199 $contentCount = $wgContLang->formatNum( $successCount );
201 if( $successCount > 0 ) {
202 $wgOut->addHtml( "<li>" . $skin->makeKnownLinkObj( $title ) .
204 wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
207 $log = new LogPage( 'import' );
208 if( $this->mIsUpload
) {
209 $detail = wfMsgForContent( 'import-logentry-upload-detail',
211 $log->addEntry( 'upload', $title, $detail );
213 // Show the source article name in log
214 $origin = $this->mFrompage
!= $origTitle->getPrefixedText()
216 : $origTitle->getPrefixedText();
217 $interwiki = '[[:' . $this->mInterwiki
. ':' . $origin . ']]';
218 $detail = wfMsgForContent( 'import-logentry-interwiki-detail',
219 $contentCount, $interwiki );
220 $log->addEntry( 'interwiki', $title, $detail );
223 $comment = $detail; // quick
224 $dbw = wfGetDB( DB_MASTER
);
225 $nullRevision = Revision
::newNullRevision(
226 $dbw, $title->getArticleId(), $comment, true );
227 $nullRevision->insertOn( $dbw );
229 $wgOut->addHtml( '<li>' . wfMsgExt( 'import-nonewrevisions', array( 'parse', ) ) . '</li>' );
236 if( $this->mPageCount
== 0 ) {
237 $wgOut->addHtml( "</ul>\n" );
238 return new WikiErrorMsg( "importnopages" );
240 $wgOut->addHtml( "</ul>\n" );
242 return $this->mPageCount
;
248 * @addtogroup SpecialPage
253 var $timestamp = "20010115000000";
260 function setTitle( $title ) {
261 if( is_object( $title ) ) {
262 $this->title
= $title;
263 } elseif( is_null( $title ) ) {
264 throw new MWException( "WikiRevision given a null title in import. You may need to adjust \$wgLegalTitleChars." );
266 throw new MWException( "WikiRevision given non-object title in import." );
270 function setID( $id ) {
274 function setTimestamp( $ts ) {
275 # 2003-08-05T18:30:02Z
276 $this->timestamp
= wfTimestamp( TS_MW
, $ts );
279 function setUsername( $user ) {
280 $this->user_text
= $user;
283 function setUserIP( $ip ) {
284 $this->user_text
= $ip;
287 function setText( $text ) {
291 function setComment( $text ) {
292 $this->comment
= $text;
295 function setMinor( $minor ) {
296 $this->minor
= (bool)$minor;
299 function getTitle() {
307 function getTimestamp() {
308 return $this->timestamp
;
312 return $this->user_text
;
319 function getComment() {
320 return $this->comment
;
323 function getMinor() {
327 function importOldRevision() {
328 $dbw = wfGetDB( DB_MASTER
);
330 # Sneak a single revision into place
331 $user = User
::newFromName( $this->getUser() );
333 $userId = intval( $user->getId() );
334 $userText = $user->getName();
337 $userText = $this->getUser();
340 // avoid memory leak...?
341 $linkCache =& LinkCache
::singleton();
344 $article = new Article( $this->title
);
345 $pageId = $article->getId();
347 # must create the page...
348 $pageId = $article->insertOn( $dbw );
353 $prior = Revision
::loadFromTimestamp( $dbw, $this->title
, $this->timestamp
);
354 if( !is_null( $prior ) ) {
355 // FIXME: this could fail slightly for multiple matches :P
356 wfDebug( __METHOD__
. ": skipping existing revision for [[" .
357 $this->title
->getPrefixedText() . "]], timestamp " .
358 $this->timestamp
. "\n" );
363 # FIXME: Use original rev_id optionally
364 # FIXME: blah blah blah
366 #if( $numrows > 0 ) {
367 # return wfMsg( "importhistoryconflict" );
371 $revision = new Revision( array(
373 'text' => $this->getText(),
374 'comment' => $this->getComment(),
376 'user_text' => $userText,
377 'timestamp' => $this->timestamp
,
378 'minor_edit' => $this->minor
,
380 $revId = $revision->insertOn( $dbw );
381 $changed = $article->updateIfNewerOn( $dbw, $revision );
384 wfDebug( __METHOD__
. ": running onArticleCreate\n" );
385 Article
::onArticleCreate( $this->title
);
387 wfDebug( __METHOD__
. ": running create updates\n" );
388 $article->createUpdates( $revision );
390 } elseif( $changed ) {
391 wfDebug( __METHOD__
. ": running onArticleEdit\n" );
392 Article
::onArticleEdit( $this->title
);
394 wfDebug( __METHOD__
. ": running edit updates\n" );
395 $article->editUpdates(
409 * implements Special:Import
410 * @addtogroup SpecialPage
414 var $mPageCallback = null;
415 var $mPageOutCallback = null;
416 var $mRevisionCallback = null;
417 var $mTargetNamespace = null;
418 var $mTargetArticleName = null;
421 function WikiImporter( $source ) {
422 $this->setRevisionCallback( array( &$this, "importRevision" ) );
423 $this->mSource
= $source;
426 function throwXmlError( $err ) {
427 $this->debug( "FAILURE: $err" );
428 wfDebug( "WikiImporter XML error: $err\n" );
433 function doImport() {
434 if( empty( $this->mSource
) ) {
435 return new WikiErrorMsg( "importnotext" );
438 $parser = xml_parser_create( "UTF-8" );
440 # case folding violates XML standard, turn it off
441 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING
, false );
443 xml_set_object( $parser, $this );
444 xml_set_element_handler( $parser, "in_start", "" );
446 $offset = 0; // for context extraction on error reporting
448 $chunk = $this->mSource
->readChunk();
449 if( !xml_parse( $parser, $chunk, $this->mSource
->atEnd() ) ) {
450 wfDebug( "WikiImporter::doImport encountered XML parsing error\n" );
451 return new WikiXmlError( $parser, wfMsgHtml( 'import-parse-failure' ), $chunk, $offset );
453 $offset +
= strlen( $chunk );
454 } while( $chunk !== false && !$this->mSource
->atEnd() );
455 xml_parser_free( $parser );
460 function debug( $data ) {
461 #wfDebug( "IMPORT: $data\n" );
464 function notice( $data ) {
465 global $wgCommandLineMode;
466 if( $wgCommandLineMode ) {
470 $wgOut->addHTML( "<li>" . htmlspecialchars( $data ) . "</li>\n" );
475 * Sets the action to perform as each new page in the stream is reached.
476 * @param callable $callback
479 function setPageCallback( $callback ) {
480 $previous = $this->mPageCallback
;
481 $this->mPageCallback
= $callback;
486 * Sets the action to perform as each page in the stream is completed.
487 * Callback accepts the page title (as a Title object), a second object
488 * with the original title form (in case it's been overridden into a
489 * local namespace), and a count of revisions.
491 * @param callable $callback
494 function setPageOutCallback( $callback ) {
495 $previous = $this->mPageOutCallback
;
496 $this->mPageOutCallback
= $callback;
501 * Sets the action to perform as each page revision is reached.
502 * @param callable $callback
505 function setRevisionCallback( $callback ) {
506 $previous = $this->mRevisionCallback
;
507 $this->mRevisionCallback
= $callback;
512 * Set a target namespace to override the defaults
514 function setTargetNamespace( $namespace ) {
515 if( is_null( $namespace ) ) {
516 // Don't override namespaces
517 $this->mTargetNamespace
= null;
518 } elseif( $namespace >= 0 ) {
519 // FIXME: Check for validity
520 $this->mTargetNamespace
= intval( $namespace );
527 * Set a target articlename to override the defaults
529 function setTargetArticleName( $articleName ) {
530 $this->mTargetArticleName
= $articleName;
534 * Default per-revision callback, performs the import.
535 * @param WikiRevision $revision
538 function importRevision( &$revision ) {
539 $dbw = wfGetDB( DB_MASTER
);
540 return $dbw->deadlockLoop( array( &$revision, 'importOldRevision' ) );
544 * Alternate per-revision callback, for debugging.
545 * @param WikiRevision $revision
548 function debugRevisionHandler( &$revision ) {
549 $this->debug( "Got revision:" );
550 if( is_object( $revision->title
) ) {
551 $this->debug( "-- Title: " . $revision->title
->getPrefixedText() );
553 $this->debug( "-- Title: <invalid>" );
555 $this->debug( "-- User: " . $revision->user_text
);
556 $this->debug( "-- Timestamp: " . $revision->timestamp
);
557 $this->debug( "-- Comment: " . $revision->comment
);
558 $this->debug( "-- Text: " . $revision->text
);
562 * Notify the callback function when a new <page> is reached.
563 * @param Title $title
566 function pageCallback( $title ) {
567 if( is_callable( $this->mPageCallback
) ) {
568 call_user_func( $this->mPageCallback
, $title );
573 * Notify the callback function when a </page> is closed.
574 * @param Title $title
575 * @param Title $origTitle
576 * @param int $revisionCount
577 * @param int $successCount number of revisions for which callback returned true
580 function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) {
581 if( is_callable( $this->mPageOutCallback
) ) {
582 call_user_func( $this->mPageOutCallback
, $title, $origTitle,
583 $revisionCount, $successCount );
588 # XML parser callbacks from here out -- beware!
589 function donothing( $parser, $x, $y="" ) {
590 #$this->debug( "donothing" );
593 function in_start( $parser, $name, $attribs ) {
594 $this->debug( "in_start $name" );
595 if( $name != "mediawiki" ) {
596 return $this->throwXMLerror( "Expected <mediawiki>, got <$name>" );
598 xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" );
601 function in_mediawiki( $parser, $name, $attribs ) {
602 $this->debug( "in_mediawiki $name" );
603 if( $name == 'siteinfo' ) {
604 xml_set_element_handler( $parser, "in_siteinfo", "out_siteinfo" );
605 } elseif( $name == 'page' ) {
606 $this->workRevisionCount
= 0;
607 $this->workSuccessCount
= 0;
608 xml_set_element_handler( $parser, "in_page", "out_page" );
610 return $this->throwXMLerror( "Expected <page>, got <$name>" );
613 function out_mediawiki( $parser, $name ) {
614 $this->debug( "out_mediawiki $name" );
615 if( $name != "mediawiki" ) {
616 return $this->throwXMLerror( "Expected </mediawiki>, got </$name>" );
618 xml_set_element_handler( $parser, "donothing", "donothing" );
622 function in_siteinfo( $parser, $name, $attribs ) {
624 $this->debug( "in_siteinfo $name" );
634 return $this->throwXMLerror( "Element <$name> not allowed in <siteinfo>." );
638 function out_siteinfo( $parser, $name ) {
639 if( $name == "siteinfo" ) {
640 xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" );
645 function in_page( $parser, $name, $attribs ) {
646 $this->debug( "in_page $name" );
651 $this->appendfield
= $name;
652 $this->appenddata
= "";
653 $this->parenttag
= "page";
654 xml_set_element_handler( $parser, "in_nothing", "out_append" );
655 xml_set_character_data_handler( $parser, "char_append" );
658 if( is_object( $this->pageTitle
) ) {
659 $this->workRevision
= new WikiRevision
;
660 $this->workRevision
->setTitle( $this->pageTitle
);
661 $this->workRevisionCount++
;
663 // Skipping items due to invalid page title
664 $this->workRevision
= null;
666 xml_set_element_handler( $parser, "in_revision", "out_revision" );
669 return $this->throwXMLerror( "Element <$name> not allowed in a <page>." );
673 function out_page( $parser, $name ) {
674 $this->debug( "out_page $name" );
675 if( $name != "page" ) {
676 return $this->throwXMLerror( "Expected </page>, got </$name>" );
678 xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" );
680 $this->pageOutCallback( $this->pageTitle
, $this->origTitle
,
681 $this->workRevisionCount
, $this->workSuccessCount
);
683 $this->workTitle
= null;
684 $this->workRevision
= null;
685 $this->workRevisionCount
= 0;
686 $this->workSuccessCount
= 0;
687 $this->pageTitle
= null;
688 $this->origTitle
= null;
691 function in_nothing( $parser, $name, $attribs ) {
692 $this->debug( "in_nothing $name" );
693 return $this->throwXMLerror( "No child elements allowed here; got <$name>" );
695 function char_append( $parser, $data ) {
696 $this->debug( "char_append '$data'" );
697 $this->appenddata
.= $data;
699 function out_append( $parser, $name ) {
700 $this->debug( "out_append $name" );
701 if( $name != $this->appendfield
) {
702 return $this->throwXMLerror( "Expected </{$this->appendfield}>, got </$name>" );
704 xml_set_element_handler( $parser, "in_$this->parenttag", "out_$this->parenttag" );
705 xml_set_character_data_handler( $parser, "donothing" );
707 switch( $this->appendfield
) {
709 $this->workTitle
= $this->appenddata
;
711 if( $this->mTargetArticleName
!= '' ) {
712 // Import article with a different target article name
713 $this->workTitle
= $this->mTargetArticleName
;
715 $this->origTitle
= Title
::newFromText( $this->workTitle
);
716 if( !is_null( $this->mTargetNamespace
) && !is_null( $this->origTitle
) ) {
717 $this->pageTitle
= Title
::makeTitle( $this->mTargetNamespace
,
718 $this->origTitle
->getDbKey() );
720 $this->pageTitle
= Title
::newFromText( $this->workTitle
);
722 if( is_null( $this->pageTitle
) ) {
723 // Invalid page title? Ignore the page
724 $this->notice( "Skipping invalid page title '$this->workTitle'" );
726 $this->pageCallback( $this->workTitle
);
730 if ( $this->parenttag
== 'revision' ) {
731 if( $this->workRevision
)
732 $this->workRevision
->setID( $this->appenddata
);
736 if( $this->workRevision
)
737 $this->workRevision
->setText( $this->appenddata
);
740 if( $this->workRevision
)
741 $this->workRevision
->setUsername( $this->appenddata
);
744 if( $this->workRevision
)
745 $this->workRevision
->setUserIP( $this->appenddata
);
748 if( $this->workRevision
)
749 $this->workRevision
->setTimestamp( $this->appenddata
);
752 if( $this->workRevision
)
753 $this->workRevision
->setComment( $this->appenddata
);
756 if( $this->workRevision
)
757 $this->workRevision
->setMinor( true );
760 $this->debug( "Bad append: {$this->appendfield}" );
762 $this->appendfield
= "";
763 $this->appenddata
= "";
766 function in_revision( $parser, $name, $attribs ) {
767 $this->debug( "in_revision $name" );
774 $this->parenttag
= "revision";
775 $this->appendfield
= $name;
776 xml_set_element_handler( $parser, "in_nothing", "out_append" );
777 xml_set_character_data_handler( $parser, "char_append" );
780 xml_set_element_handler( $parser, "in_contributor", "out_contributor" );
783 return $this->throwXMLerror( "Element <$name> not allowed in a <revision>." );
787 function out_revision( $parser, $name ) {
788 $this->debug( "out_revision $name" );
789 if( $name != "revision" ) {
790 return $this->throwXMLerror( "Expected </revision>, got </$name>" );
792 xml_set_element_handler( $parser, "in_page", "out_page" );
794 if( $this->workRevision
) {
795 $ok = call_user_func_array( $this->mRevisionCallback
,
796 array( &$this->workRevision
, &$this ) );
798 $this->workSuccessCount++
;
803 function in_contributor( $parser, $name, $attribs ) {
804 $this->debug( "in_contributor $name" );
809 $this->parenttag
= "contributor";
810 $this->appendfield
= $name;
811 xml_set_element_handler( $parser, "in_nothing", "out_append" );
812 xml_set_character_data_handler( $parser, "char_append" );
815 $this->throwXMLerror( "Invalid tag <$name> in <contributor>" );
819 function out_contributor( $parser, $name ) {
820 $this->debug( "out_contributor $name" );
821 if( $name != "contributor" ) {
822 return $this->throwXMLerror( "Expected </contributor>, got </$name>" );
824 xml_set_element_handler( $parser, "in_revision", "out_revision" );
830 * @todo document (e.g. one-sentence class description).
831 * @addtogroup SpecialPage
833 class ImportStringSource
{
834 function ImportStringSource( $string ) {
835 $this->mString
= $string;
836 $this->mRead
= false;
843 function readChunk() {
844 if( $this->atEnd() ) {
848 return $this->mString
;
854 * @todo document (e.g. one-sentence class description).
855 * @addtogroup SpecialPage
857 class ImportStreamSource
{
858 function ImportStreamSource( $handle ) {
859 $this->mHandle
= $handle;
863 return feof( $this->mHandle
);
866 function readChunk() {
867 return fread( $this->mHandle
, 32768 );
870 static function newFromFile( $filename ) {
871 $file = @fopen
( $filename, 'rt' );
873 return new WikiErrorMsg( "importcantopen" );
875 return new ImportStreamSource( $file );
878 static function newFromUpload( $fieldname = "xmlimport" ) {
879 $upload =& $_FILES[$fieldname];
881 if( !isset( $upload ) ||
!$upload['name'] ) {
882 return new WikiErrorMsg( 'importnofile' );
884 if( !empty( $upload['error'] ) ) {
885 return new WikiErrorMsg( 'importuploaderror', $upload['error'] );
887 $fname = $upload['tmp_name'];
888 if( is_uploaded_file( $fname ) ) {
889 return ImportStreamSource
::newFromFile( $fname );
891 return new WikiErrorMsg( 'importnofile' );
895 function newFromURL( $url, $method = 'GET' ) {
896 wfDebug( __METHOD__
. ": opening $url\n" );
897 # Use the standard HTTP fetch function; it times out
898 # quicker and sorts out user-agent problems which might
899 # otherwise prevent importing from large sites, such
900 # as the Wikimedia cluster, etc.
901 $data = Http
::request( $method, $url );
902 if( $data !== false ) {
904 fwrite( $file, $data );
907 return new ImportStreamSource( $file );
909 return new WikiErrorMsg( 'importcantopen' );
913 public static function newFromInterwiki( $interwiki, $page, $history=false ) {
915 return new WikiErrorMsg( 'import-noarticle' );
917 $link = Title
::newFromText( "$interwiki:Special:Export/$page" );
918 if( is_null( $link ) ||
$link->getInterwiki() == '' ) {
919 return new WikiErrorMsg( 'importbadinterwiki' );
921 $params = $history ?
'history=1' : '';
922 $url = $link->getFullUrl( $params );
923 # For interwikis, use POST to avoid redirects.
924 return ImportStreamSource
::newFromURL( $url, "POST" );