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 = htmlspecialchars( $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( !is_null( $articleName ) ) {
75 $importer->setTargetArticleName( $articleName );
77 $reporter = new ImportReporter( $importer, $isUpload, $interwiki );
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 ) {
179 $importer->setPageOutCallback( array( $this, 'reportPage' ) );
180 $this->mPageCount
= 0;
181 $this->mIsUpload
= $upload;
182 $this->mInterwiki
= $interwiki;
187 $wgOut->addHtml( "<ul>\n" );
190 function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
191 global $wgOut, $wgUser, $wgLang, $wgContLang;
193 $skin = $wgUser->getSkin();
197 $localCount = $wgLang->formatNum( $successCount );
198 $contentCount = $wgContLang->formatNum( $successCount );
200 if( $successCount > 0 ) {
201 $wgOut->addHtml( "<li>" . $skin->makeKnownLinkObj( $title ) .
203 wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
206 $log = new LogPage( 'import' );
207 if( $this->mIsUpload
) {
208 $detail = wfMsgForContent( 'import-logentry-upload-detail',
210 $log->addEntry( 'upload', $title, $detail );
212 $interwiki = '[[:' . $this->mInterwiki
. ':' .
213 $origTitle->getPrefixedText() . ']]';
214 $detail = wfMsgForContent( 'import-logentry-interwiki-detail',
215 $contentCount, $interwiki );
216 $log->addEntry( 'interwiki', $title, $detail );
219 $comment = $detail; // quick
220 $dbw = wfGetDB( DB_MASTER
);
221 $nullRevision = Revision
::newNullRevision(
222 $dbw, $title->getArticleId(), $comment, true );
223 $nullRevision->insertOn( $dbw );
225 $wgOut->addHtml( '<li>' . wfMsgExt( 'import-nonewrevisions', array( 'parse', ) ) . '</li>' );
232 if( $this->mPageCount
== 0 ) {
233 $wgOut->addHtml( "</ul>\n" );
234 return new WikiErrorMsg( "importnopages" );
236 $wgOut->addHtml( "</ul>\n" );
238 return $this->mPageCount
;
244 * @addtogroup SpecialPage
249 var $timestamp = "20010115000000";
256 function setTitle( $title ) {
257 if( is_object( $title ) ) {
258 $this->title
= $title;
259 } elseif( is_null( $title ) ) {
260 throw new MWException( "WikiRevision given a null title in import. You may need to adjust \$wgLegalTitleChars." );
262 throw new MWException( "WikiRevision given non-object title in import." );
266 function setID( $id ) {
270 function setTimestamp( $ts ) {
271 # 2003-08-05T18:30:02Z
272 $this->timestamp
= wfTimestamp( TS_MW
, $ts );
275 function setUsername( $user ) {
276 $this->user_text
= $user;
279 function setUserIP( $ip ) {
280 $this->user_text
= $ip;
283 function setText( $text ) {
287 function setComment( $text ) {
288 $this->comment
= $text;
291 function setMinor( $minor ) {
292 $this->minor
= (bool)$minor;
295 function getTitle() {
303 function getTimestamp() {
304 return $this->timestamp
;
308 return $this->user_text
;
315 function getComment() {
316 return $this->comment
;
319 function getMinor() {
323 function importOldRevision() {
324 $dbw = wfGetDB( DB_MASTER
);
326 # Sneak a single revision into place
327 $user = User
::newFromName( $this->getUser() );
329 $userId = intval( $user->getId() );
330 $userText = $user->getName();
333 $userText = $this->getUser();
336 // avoid memory leak...?
337 $linkCache =& LinkCache
::singleton();
340 $article = new Article( $this->title
);
341 $pageId = $article->getId();
343 # must create the page...
344 $pageId = $article->insertOn( $dbw );
349 $prior = Revision
::loadFromTimestamp( $dbw, $this->title
, $this->timestamp
);
350 if( !is_null( $prior ) ) {
351 // FIXME: this could fail slightly for multiple matches :P
352 wfDebug( __METHOD__
. ": skipping existing revision for [[" .
353 $this->title
->getPrefixedText() . "]], timestamp " .
354 $this->timestamp
. "\n" );
359 # FIXME: Use original rev_id optionally
360 # FIXME: blah blah blah
362 #if( $numrows > 0 ) {
363 # return wfMsg( "importhistoryconflict" );
367 $revision = new Revision( array(
369 'text' => $this->getText(),
370 'comment' => $this->getComment(),
372 'user_text' => $userText,
373 'timestamp' => $this->timestamp
,
374 'minor_edit' => $this->minor
,
376 $revId = $revision->insertOn( $dbw );
377 $changed = $article->updateIfNewerOn( $dbw, $revision );
380 wfDebug( __METHOD__
. ": running onArticleCreate\n" );
381 Article
::onArticleCreate( $this->title
);
383 wfDebug( __METHOD__
. ": running create updates\n" );
384 $article->createUpdates( $revision );
386 } elseif( $changed ) {
387 wfDebug( __METHOD__
. ": running onArticleEdit\n" );
388 Article
::onArticleEdit( $this->title
);
390 wfDebug( __METHOD__
. ": running edit updates\n" );
391 $article->editUpdates(
405 * implements Special:Import
406 * @addtogroup SpecialPage
410 var $mPageCallback = null;
411 var $mPageOutCallback = null;
412 var $mRevisionCallback = null;
413 var $mTargetNamespace = null;
414 var $mTargetArticleName = null;
417 function WikiImporter( $source ) {
418 $this->setRevisionCallback( array( &$this, "importRevision" ) );
419 $this->mSource
= $source;
422 function throwXmlError( $err ) {
423 $this->debug( "FAILURE: $err" );
424 wfDebug( "WikiImporter XML error: $err\n" );
429 function doImport() {
430 if( empty( $this->mSource
) ) {
431 return new WikiErrorMsg( "importnotext" );
434 $parser = xml_parser_create( "UTF-8" );
436 # case folding violates XML standard, turn it off
437 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING
, false );
439 xml_set_object( $parser, $this );
440 xml_set_element_handler( $parser, "in_start", "" );
442 $offset = 0; // for context extraction on error reporting
444 $chunk = $this->mSource
->readChunk();
445 if( !xml_parse( $parser, $chunk, $this->mSource
->atEnd() ) ) {
446 wfDebug( "WikiImporter::doImport encountered XML parsing error\n" );
447 return new WikiXmlError( $parser, wfMsgHtml( 'import-parse-failure' ), $chunk, $offset );
449 $offset +
= strlen( $chunk );
450 } while( $chunk !== false && !$this->mSource
->atEnd() );
451 xml_parser_free( $parser );
456 function debug( $data ) {
457 #wfDebug( "IMPORT: $data\n" );
460 function notice( $data ) {
461 global $wgCommandLineMode;
462 if( $wgCommandLineMode ) {
466 $wgOut->addHTML( "<li>" . htmlspecialchars( $data ) . "</li>\n" );
471 * Sets the action to perform as each new page in the stream is reached.
472 * @param callable $callback
475 function setPageCallback( $callback ) {
476 $previous = $this->mPageCallback
;
477 $this->mPageCallback
= $callback;
482 * Sets the action to perform as each page in the stream is completed.
483 * Callback accepts the page title (as a Title object), a second object
484 * with the original title form (in case it's been overridden into a
485 * local namespace), and a count of revisions.
487 * @param callable $callback
490 function setPageOutCallback( $callback ) {
491 $previous = $this->mPageOutCallback
;
492 $this->mPageOutCallback
= $callback;
497 * Sets the action to perform as each page revision is reached.
498 * @param callable $callback
501 function setRevisionCallback( $callback ) {
502 $previous = $this->mRevisionCallback
;
503 $this->mRevisionCallback
= $callback;
508 * Set a target namespace to override the defaults
510 function setTargetNamespace( $namespace ) {
511 if( is_null( $namespace ) ) {
512 // Don't override namespaces
513 $this->mTargetNamespace
= null;
514 } elseif( $namespace >= 0 ) {
515 // FIXME: Check for validity
516 $this->mTargetNamespace
= intval( $namespace );
523 * Set a target articlename to override the defaults
525 function setTargetArticleName( $articleName ) {
526 $this->mTargetArticleName
= is_null( $articleName ) ?
null : $articleName;
530 * Default per-revision callback, performs the import.
531 * @param WikiRevision $revision
534 function importRevision( &$revision ) {
535 $dbw = wfGetDB( DB_MASTER
);
536 return $dbw->deadlockLoop( array( &$revision, 'importOldRevision' ) );
540 * Alternate per-revision callback, for debugging.
541 * @param WikiRevision $revision
544 function debugRevisionHandler( &$revision ) {
545 $this->debug( "Got revision:" );
546 if( is_object( $revision->title
) ) {
547 $this->debug( "-- Title: " . $revision->title
->getPrefixedText() );
549 $this->debug( "-- Title: <invalid>" );
551 $this->debug( "-- User: " . $revision->user_text
);
552 $this->debug( "-- Timestamp: " . $revision->timestamp
);
553 $this->debug( "-- Comment: " . $revision->comment
);
554 $this->debug( "-- Text: " . $revision->text
);
558 * Notify the callback function when a new <page> is reached.
559 * @param Title $title
562 function pageCallback( $title ) {
563 if( is_callable( $this->mPageCallback
) ) {
564 call_user_func( $this->mPageCallback
, $title );
569 * Notify the callback function when a </page> is closed.
570 * @param Title $title
571 * @param Title $origTitle
572 * @param int $revisionCount
573 * @param int $successCount number of revisions for which callback returned true
576 function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) {
577 if( is_callable( $this->mPageOutCallback
) ) {
578 call_user_func( $this->mPageOutCallback
, $title, $origTitle,
579 $revisionCount, $successCount );
584 # XML parser callbacks from here out -- beware!
585 function donothing( $parser, $x, $y="" ) {
586 #$this->debug( "donothing" );
589 function in_start( $parser, $name, $attribs ) {
590 $this->debug( "in_start $name" );
591 if( $name != "mediawiki" ) {
592 return $this->throwXMLerror( "Expected <mediawiki>, got <$name>" );
594 xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" );
597 function in_mediawiki( $parser, $name, $attribs ) {
598 $this->debug( "in_mediawiki $name" );
599 if( $name == 'siteinfo' ) {
600 xml_set_element_handler( $parser, "in_siteinfo", "out_siteinfo" );
601 } elseif( $name == 'page' ) {
602 $this->workRevisionCount
= 0;
603 $this->workSuccessCount
= 0;
604 xml_set_element_handler( $parser, "in_page", "out_page" );
606 return $this->throwXMLerror( "Expected <page>, got <$name>" );
609 function out_mediawiki( $parser, $name ) {
610 $this->debug( "out_mediawiki $name" );
611 if( $name != "mediawiki" ) {
612 return $this->throwXMLerror( "Expected </mediawiki>, got </$name>" );
614 xml_set_element_handler( $parser, "donothing", "donothing" );
618 function in_siteinfo( $parser, $name, $attribs ) {
620 $this->debug( "in_siteinfo $name" );
630 return $this->throwXMLerror( "Element <$name> not allowed in <siteinfo>." );
634 function out_siteinfo( $parser, $name ) {
635 if( $name == "siteinfo" ) {
636 xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" );
641 function in_page( $parser, $name, $attribs ) {
642 $this->debug( "in_page $name" );
647 $this->appendfield
= $name;
648 $this->appenddata
= "";
649 $this->parenttag
= "page";
650 xml_set_element_handler( $parser, "in_nothing", "out_append" );
651 xml_set_character_data_handler( $parser, "char_append" );
654 if( is_object( $this->pageTitle
) ) {
655 $this->workRevision
= new WikiRevision
;
656 $this->workRevision
->setTitle( $this->pageTitle
);
657 $this->workRevisionCount++
;
659 // Skipping items due to invalid page title
660 $this->workRevision
= null;
662 xml_set_element_handler( $parser, "in_revision", "out_revision" );
665 return $this->throwXMLerror( "Element <$name> not allowed in a <page>." );
669 function out_page( $parser, $name ) {
670 $this->debug( "out_page $name" );
671 if( $name != "page" ) {
672 return $this->throwXMLerror( "Expected </page>, got </$name>" );
674 xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" );
676 $this->pageOutCallback( $this->pageTitle
, $this->origTitle
,
677 $this->workRevisionCount
, $this->workSuccessCount
);
679 $this->workTitle
= null;
680 $this->workRevision
= null;
681 $this->workRevisionCount
= 0;
682 $this->workSuccessCount
= 0;
683 $this->pageTitle
= null;
684 $this->origTitle
= null;
687 function in_nothing( $parser, $name, $attribs ) {
688 $this->debug( "in_nothing $name" );
689 return $this->throwXMLerror( "No child elements allowed here; got <$name>" );
691 function char_append( $parser, $data ) {
692 $this->debug( "char_append '$data'" );
693 $this->appenddata
.= $data;
695 function out_append( $parser, $name ) {
696 $this->debug( "out_append $name" );
697 if( $name != $this->appendfield
) {
698 return $this->throwXMLerror( "Expected </{$this->appendfield}>, got </$name>" );
700 xml_set_element_handler( $parser, "in_$this->parenttag", "out_$this->parenttag" );
701 xml_set_character_data_handler( $parser, "donothing" );
703 switch( $this->appendfield
) {
705 $this->workTitle
= $this->appenddata
;
707 if( $this->mTargetArticleName
!= '' ) {
708 // Import article with a different target article name
709 $this->workTitle
= $this->mTargetArticleName
;
711 $this->origTitle
= Title
::newFromText( $this->workTitle
);
712 if( !is_null( $this->mTargetNamespace
) && !is_null( $this->origTitle
) ) {
713 $this->pageTitle
= Title
::makeTitle( $this->mTargetNamespace
,
714 $this->origTitle
->getDbKey() );
716 $this->pageTitle
= Title
::newFromText( $this->workTitle
);
718 if( is_null( $this->pageTitle
) ) {
719 // Invalid page title? Ignore the page
720 $this->notice( "Skipping invalid page title '$this->workTitle'" );
722 $this->pageCallback( $this->workTitle
);
726 if ( $this->parenttag
== 'revision' ) {
727 if( $this->workRevision
)
728 $this->workRevision
->setID( $this->appenddata
);
732 if( $this->workRevision
)
733 $this->workRevision
->setText( $this->appenddata
);
736 if( $this->workRevision
)
737 $this->workRevision
->setUsername( $this->appenddata
);
740 if( $this->workRevision
)
741 $this->workRevision
->setUserIP( $this->appenddata
);
744 if( $this->workRevision
)
745 $this->workRevision
->setTimestamp( $this->appenddata
);
748 if( $this->workRevision
)
749 $this->workRevision
->setComment( $this->appenddata
);
752 if( $this->workRevision
)
753 $this->workRevision
->setMinor( true );
756 $this->debug( "Bad append: {$this->appendfield}" );
758 $this->appendfield
= "";
759 $this->appenddata
= "";
762 function in_revision( $parser, $name, $attribs ) {
763 $this->debug( "in_revision $name" );
770 $this->parenttag
= "revision";
771 $this->appendfield
= $name;
772 xml_set_element_handler( $parser, "in_nothing", "out_append" );
773 xml_set_character_data_handler( $parser, "char_append" );
776 xml_set_element_handler( $parser, "in_contributor", "out_contributor" );
779 return $this->throwXMLerror( "Element <$name> not allowed in a <revision>." );
783 function out_revision( $parser, $name ) {
784 $this->debug( "out_revision $name" );
785 if( $name != "revision" ) {
786 return $this->throwXMLerror( "Expected </revision>, got </$name>" );
788 xml_set_element_handler( $parser, "in_page", "out_page" );
790 if( $this->workRevision
) {
791 $ok = call_user_func_array( $this->mRevisionCallback
,
792 array( &$this->workRevision
, &$this ) );
794 $this->workSuccessCount++
;
799 function in_contributor( $parser, $name, $attribs ) {
800 $this->debug( "in_contributor $name" );
805 $this->parenttag
= "contributor";
806 $this->appendfield
= $name;
807 xml_set_element_handler( $parser, "in_nothing", "out_append" );
808 xml_set_character_data_handler( $parser, "char_append" );
811 $this->throwXMLerror( "Invalid tag <$name> in <contributor>" );
815 function out_contributor( $parser, $name ) {
816 $this->debug( "out_contributor $name" );
817 if( $name != "contributor" ) {
818 return $this->throwXMLerror( "Expected </contributor>, got </$name>" );
820 xml_set_element_handler( $parser, "in_revision", "out_revision" );
826 * @todo document (e.g. one-sentence class description).
827 * @addtogroup SpecialPage
829 class ImportStringSource
{
830 function ImportStringSource( $string ) {
831 $this->mString
= $string;
832 $this->mRead
= false;
839 function readChunk() {
840 if( $this->atEnd() ) {
844 return $this->mString
;
850 * @todo document (e.g. one-sentence class description).
851 * @addtogroup SpecialPage
853 class ImportStreamSource
{
854 function ImportStreamSource( $handle ) {
855 $this->mHandle
= $handle;
859 return feof( $this->mHandle
);
862 function readChunk() {
863 return fread( $this->mHandle
, 32768 );
866 static function newFromFile( $filename ) {
867 $file = @fopen
( $filename, 'rt' );
869 return new WikiErrorMsg( "importcantopen" );
871 return new ImportStreamSource( $file );
874 static function newFromUpload( $fieldname = "xmlimport" ) {
875 $upload =& $_FILES[$fieldname];
877 if( !isset( $upload ) ||
!$upload['name'] ) {
878 return new WikiErrorMsg( 'importnofile' );
880 if( !empty( $upload['error'] ) ) {
881 return new WikiErrorMsg( 'importuploaderror', $upload['error'] );
883 $fname = $upload['tmp_name'];
884 if( is_uploaded_file( $fname ) ) {
885 return ImportStreamSource
::newFromFile( $fname );
887 return new WikiErrorMsg( 'importnofile' );
891 function newFromURL( $url, $method = 'GET' ) {
892 wfDebug( __METHOD__
. ": opening $url\n" );
893 # Use the standard HTTP fetch function; it times out
894 # quicker and sorts out user-agent problems which might
895 # otherwise prevent importing from large sites, such
896 # as the Wikimedia cluster, etc.
897 $data = Http
::request( $method, $url );
898 if( $data !== false ) {
900 fwrite( $file, $data );
903 return new ImportStreamSource( $file );
905 return new WikiErrorMsg( 'importcantopen' );
909 public static function newFromInterwiki( $interwiki, $page, $history=false ) {
911 return new WikiErrorMsg( 'import-noarticle' );
913 $link = Title
::newFromText( "$interwiki:Special:Export/$page" );
914 if( is_null( $link ) ||
$link->getInterwiki() == '' ) {
915 return new WikiErrorMsg( 'importbadinterwiki' );
917 $params = $history ?
'history=1' : '';
918 $url = $link->getFullUrl( $params );
919 # For interwikis, use POST to avoid redirects.
920 return ImportStreamSource
::newFromURL( $url, "POST" );