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
23 * @ingroup SpecialPage
29 function wfSpecialImport( $page = '' ) {
30 global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources;
31 global $wgImportTargetNamespace;
34 $namespace = $wgImportTargetNamespace;
39 $wgOut->readOnlyPage();
43 if( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit') {
45 $namespace = $wgRequest->getIntOrNull( 'namespace' );
47 switch( $wgRequest->getVal( "source" ) ) {
50 if( $wgUser->isAllowed( 'importupload' ) ) {
51 $source = ImportStreamSource
::newFromUpload( "xmlimport" );
53 return $wgOut->permissionRequired( 'importupload' );
57 $interwiki = $wgRequest->getVal( 'interwiki' );
58 $history = $wgRequest->getCheck( 'interwikiHistory' );
59 $frompage = $wgRequest->getText( "frompage" );
60 $source = ImportStreamSource
::newFromInterwiki(
66 $source = new WikiErrorMsg( "importunknownsource" );
69 if( WikiError
::isError( $source ) ) {
70 $wgOut->wrapWikiMsg( '<p class="error">$1</p>', array( 'importfailed', $source->getMessage() ) );
72 $wgOut->addWikiMsg( "importstart" );
74 $importer = new WikiImporter( $source );
75 if( !is_null( $namespace ) ) {
76 $importer->setTargetNamespace( $namespace );
78 $reporter = new ImportReporter( $importer, $isUpload, $interwiki );
81 $result = $importer->doImport();
82 $resultCount = $reporter->close();
84 if( WikiError
::isError( $result ) ) {
85 # No source or XML parse error
86 $wgOut->wrapWikiMsg( '<p class="error">$1</p>', array( 'importfailed', $result->getMessage() ) );
87 } elseif( WikiError
::isError( $resultCount ) ) {
89 $wgOut->wrapWikiMsg( '<p class="error">$1</p>', array( 'importfailed', $resultCount->getMessage() ) );
92 $wgOut->addWikiMsg( 'importsuccess' );
94 $wgOut->addWikiText( '<hr />' );
98 $action = $wgTitle->getLocalUrl( 'action=submit' );
100 if( $wgUser->isAllowed( 'importupload' ) ) {
101 $wgOut->addWikiMsg( "importtext" );
103 Xml
::openElement( 'fieldset' ).
104 Xml
::element( 'legend', null, wfMsg( 'import-upload' ) ) .
105 Xml
::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) .
106 Xml
::hidden( 'action', 'submit' ) .
107 Xml
::hidden( 'source', 'upload' ) .
108 Xml
::input( 'xmlimport', 50, '', array( 'type' => 'file' ) ) . ' ' .
109 Xml
::submitButton( wfMsg( 'uploadbtn' ) ) .
110 Xml
::closeElement( 'form' ) .
111 Xml
::closeElement( 'fieldset' )
114 if( empty( $wgImportSources ) ) {
115 $wgOut->addWikiMsg( 'importnosources' );
119 if( !empty( $wgImportSources ) ) {
121 Xml
::openElement( 'fieldset' ) .
122 Xml
::element( 'legend', null, wfMsg( 'importinterwiki' ) ) .
123 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) .
124 wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) .
125 Xml
::hidden( 'action', 'submit' ) .
126 Xml
::hidden( 'source', 'interwiki' ) .
127 Xml
::openElement( 'table', array( 'id' => 'mw-import-table' ) ) .
130 Xml
::openElement( 'select', array( 'name' => 'interwiki' ) )
132 foreach( $wgImportSources as $prefix ) {
133 $selected = ( $interwiki === $prefix ) ?
' selected="selected"' : '';
134 $wgOut->addHTML( Xml
::option( $prefix, $prefix, $selected ) );
137 Xml
::closeElement( 'select' ) .
140 Xml
::input( 'frompage', 50, $frompage ) .
147 Xml
::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $history ) .
154 Xml
::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) .
155 Xml
::namespaceSelector( $namespace, '' ) .
162 Xml
::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) .
165 Xml
::closeElement( 'table' ).
166 Xml
::closeElement( 'form' ) .
167 Xml
::closeElement( 'fieldset' )