From 6913d74bef5cc33ffe7a07ddf8aed279a526e2f7 Mon Sep 17 00:00:00 2001 From: Raimond Spekking Date: Wed, 18 Jul 2007 11:10:43 +0000 Subject: [PATCH] * (bug 6808) Allow import to different page name * (bug 6436) Localization of Special:Import XML parser Error message(s). Reworking error message handling as the former behaviour showed success though import failed Proper XML functions for input forms --- RELEASE-NOTES | 2 + includes/SpecialImport.php | 134 +++++++++++++++++++----------- includes/WikiError.php | 2 +- languages/messages/MessagesDe.php | 11 ++- languages/messages/MessagesEn.php | 7 +- maintenance/language/messages.inc | 5 ++ 6 files changed, 106 insertions(+), 55 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b607d29afe..1bd5f40626 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -152,6 +152,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN inline, as in most browsers * Pass the user as an argument to 'isValidPassword' hook callbacks; see docs/hooks.txt for more information +* (bug 6808) Allow import to different page name +* (bug 6436) Localization of Special:Import XML parser Error message(s). == Bugfixes since 1.10 == diff --git a/includes/SpecialImport.php b/includes/SpecialImport.php index 5cf8bf8988..6274d0a42a 100644 --- a/includes/SpecialImport.php +++ b/includes/SpecialImport.php @@ -30,12 +30,14 @@ function wfSpecialImport( $page = '' ) { global $wgImportTargetNamespace; $interwiki = false; + $articleName = ''; $namespace = $wgImportTargetNamespace; $frompage = ''; $history = true; if( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit') { $isUpload = false; + $articleName = htmlspecialchars( $wgRequest->getText( 'articlename' ) ); $namespace = $wgRequest->getIntOrNull( 'namespace' ); switch( $wgRequest->getVal( "source" ) ) { @@ -61,7 +63,7 @@ function wfSpecialImport( $page = '' ) { } if( WikiError::isError( $source ) ) { - $wgOut->addWikiText( wfEscapeWikiText( $source->getMessage() ) ); + $wgOut->addWikiText( '

' . wfMsg( "importfailed", wfEscapeWikiText( $source->getMessage() ) ) . '

' ); } else { $wgOut->addWikiText( wfMsg( "importstart" ) ); @@ -69,19 +71,26 @@ function wfSpecialImport( $page = '' ) { if( !is_null( $namespace ) ) { $importer->setTargetNamespace( $namespace ); } + if( !is_null( $articleName ) ) { + $importer->setTargetArticleName( $articleName ); + } $reporter = new ImportReporter( $importer, $isUpload, $interwiki ); $reporter->open(); $result = $importer->doImport(); - $reporter->close(); + $resultCount = $reporter->close(); if( WikiError::isError( $result ) ) { - $wgOut->addWikiText( wfMsg( "importfailed", - wfEscapeWikiText( $result->getMessage() ) ) ); + # No source or XML parse error + $wgOut->addWikiText( '

' . wfMsg( "importfailed", wfEscapeWikiText( $result->getMessage() ) ) . '

' ); + } elseif( WikiError::isError( $resultCount ) ) { + # Zero revisions + $wgOut->addWikiText( '

' . wfMsg( "importfailed", wfEscapeWikiText( $resultCount->getMessage() ) ) . '

' ); } else { # Success! $wgOut->addWikiText( wfMsg( "importsuccess" ) ); } + $wgOut->addWikiText( '
' ); } } @@ -89,18 +98,17 @@ function wfSpecialImport( $page = '' ) { if( $wgUser->isAllowed( 'importupload' ) ) { $wgOut->addWikiText( wfMsg( "importtext" ) ); - $wgOut->addHTML( " -
- " . wfMsgHtml('upload') . " -
- - - - - -
-
-" ); + $wgOut->addHTML( + Xml::openElement( 'fieldset' ). + Xml::element( 'legend', null, wfMsg( 'upload' ) ) . + Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) . + Xml::hidden( 'action', 'submit' ) . + Xml::hidden( 'source', 'upload' ) . + Xml::hidden( 'MAX_FILE_SIZE', '2000000' ) . + "" . // No Xml function for type=file? Todo? + Xml::submitButton( wfMsg( 'uploadbtn' ) ) . + Xml::closeElement( 'form' ) . + Xml::closeElement( 'fieldset' ) ); } else { if( empty( $wgImportSources ) ) { $wgOut->addWikiText( wfMsg( 'importnosources' ) ); @@ -108,53 +116,57 @@ function wfSpecialImport( $page = '' ) { } if( !empty( $wgImportSources ) ) { - $wgOut->addHTML( " -
- " . wfMsgHtml('importinterwiki') . " -
" . - $wgOut->parse( wfMsg( 'import-interwiki-text' ) ) . " - - - - - + + $wgOut->addHTML( + Xml::closeElement( 'select' ) . + " - + -
-
" . + Xml::openElement( 'select', array( 'name' => 'interwiki' ) ) ); foreach( $wgImportSources as $prefix ) { $iw = htmlspecialchars( $prefix ); $selected = ($interwiki === $prefix) ? ' selected="selected"' : ''; - $wgOut->addHTML( "\n" ); + $wgOut->addHTML( Xml::option( $iw, $iw, $selected ) ); } - $wgOut->addHTML( " - - " . - wfInput( 'frompage', 50, $frompage ) . + Xml::input( 'frompage', 50, $frompage ) . "
" . - wfCheckLabel( wfMsg( 'import-interwiki-history' ), - 'interwikiHistory', 'interwikiHistory', $history ) . + Xml::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $history ) . "
- " . wfMsgHtml( 'import-interwiki-namespace' ) . " " . - HTMLnamespaceselector( $namespace, '' ) . " - " . + Xml::inputLabel( wfMsg( 'import-articlename' ), 'articlename', 'articlename', 50, $articleName ) . + "
" . - wfSubmitButton( wfMsg( 'import-interwiki-submit' ) ) . + Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) . + Xml::namespaceSelector( $namespace, '' ) . "
-
-
-" ); + + + " . + Xml::submitButton( wfMsg( 'import-interwiki-submit' ) ) . + " + " . + Xml::closeElement( 'table' ). + Xml::closeElement( 'form' ) . + Xml::closeElement( 'fieldset' ) ); } } @@ -185,12 +197,12 @@ class ImportReporter { $localCount = $wgLang->formatNum( $successCount ); $contentCount = $wgContLang->formatNum( $successCount ); - $wgOut->addHtml( "
  • " . $skin->makeKnownLinkObj( $title ) . - " " . - wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) . - "
  • \n" ); - if( $successCount > 0 ) { + $wgOut->addHtml( "
  • " . $skin->makeKnownLinkObj( $title ) . + " " . + wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) . + "
  • \n" ); + $log = new LogPage( 'import' ); if( $this->mIsUpload ) { $detail = wfMsgForContent( 'import-logentry-upload-detail', @@ -209,15 +221,21 @@ class ImportReporter { $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleId(), $comment, true ); $nullRevision->insertOn( $dbw ); + } else { + $wgOut->addHtml( '
  • ' . wfMsgExt( 'import-nonewrevisions', array( 'parse', ) ) . '
  • ' ); } + } function close() { global $wgOut; if( $this->mPageCount == 0 ) { - $wgOut->addHtml( "
  • " . wfMsgHtml( 'importnopages' ) . "
  • \n" ); + $wgOut->addHtml( "\n" ); + return new WikiErrorMsg( "importnopages" ); } $wgOut->addHtml( "\n" ); + + return $this->mPageCount; } } @@ -393,6 +411,7 @@ class WikiImporter { var $mPageOutCallback = null; var $mRevisionCallback = null; var $mTargetNamespace = null; + var $mTargetArticleName = null; var $lastfield; function WikiImporter( $source ) { @@ -425,7 +444,7 @@ class WikiImporter { $chunk = $this->mSource->readChunk(); if( !xml_parse( $parser, $chunk, $this->mSource->atEnd() ) ) { wfDebug( "WikiImporter::doImport encountered XML parsing error\n" ); - return new WikiXmlError( $parser, 'XML import parse failure', $chunk, $offset ); + return new WikiXmlError( $parser, wfMsgHtml( 'import-parse-failure' ), $chunk, $offset ); } $offset += strlen( $chunk ); } while( $chunk !== false && !$this->mSource->atEnd() ); @@ -500,6 +519,13 @@ class WikiImporter { } } + /** + * Set a target articlename to override the defaults + */ + function setTargetArticleName( $articleName ) { + $this->mTargetArticleName = is_null( $articleName ) ? null : $articleName; + } + /** * Default per-revision callback, performs the import. * @param WikiRevision $revision @@ -677,6 +703,11 @@ class WikiImporter { switch( $this->appendfield ) { case "title": $this->workTitle = $this->appenddata; + + if( $this->mTargetArticleName != '' ) { + // Import article with a different target article name + $this->workTitle = $this->mTargetArticleName; + } $this->origTitle = Title::newFromText( $this->workTitle ); if( !is_null( $this->mTargetNamespace ) && !is_null( $this->origTitle ) ) { $this->pageTitle = Title::makeTitle( $this->mTargetNamespace, @@ -876,6 +907,9 @@ class ImportStreamSource { } public static function newFromInterwiki( $interwiki, $page, $history=false ) { + if( $page == '' ) { + return new WikiErrorMsg( 'import-noarticle' ); + } $link = Title::newFromText( "$interwiki:Special:Export/$page" ); if( is_null( $link ) || $link->getInterwiki() == '' ) { return new WikiErrorMsg( 'importbadinterwiki' ); diff --git a/includes/WikiError.php b/includes/WikiError.php index efb645bbd6..d334066f54 100644 --- a/includes/WikiError.php +++ b/includes/WikiError.php @@ -101,7 +101,7 @@ class WikiXmlError extends WikiError { /** @return string */ function getMessage() { - return sprintf( '%s at line %d, col %d (byte %d%s): %s', + return sprintf( wfMsgHtml( 'xml-error-string', '%s', '%d', '%d', '%d%s', '%s' ), $this->mMessage, $this->mLine, $this->mColumn, diff --git a/languages/messages/MessagesDe.php b/languages/messages/MessagesDe.php index a24f309975..043e5faf05 100644 --- a/languages/messages/MessagesDe.php +++ b/languages/messages/MessagesDe.php @@ -1726,19 +1726,24 @@ Alle Transwiki Import-Aktionen werden im [[Special:Log/import|Import-Logbuch]] p 'import-interwiki-submit' => 'Import', 'import-interwiki-namespace' => 'Importiere die Seite in den Namensraum:', 'importtext' => 'Auf dieser Spezialseite können über [[{{ns:special}}:Export]] exportierte Seiten in dieses Wiki importiert werden.', -'importstart' => 'Importiere Seiten …', +'importstart' => 'Importiere Seite …', 'import-revision-count' => '– {{PLURAL:$1|1 Version|$1 Versionen}}', -'importnopages' => 'Keine Seiten zum Importieren vorhanden.', +'importnopages' => 'Keine Seite zum Importieren vorhanden.', 'importfailed' => 'Import fehlgeschlagen: $1', 'importunknownsource' => 'Unbekannte Importquelle', 'importcantopen' => 'Importdatei konnte nicht geöffnet werden', 'importbadinterwiki' => 'Falscher Interwiki-Link', 'importnotext' => 'Leer oder kein Text', -'importsuccess' => 'Import erfolgreich!', +'importsuccess' => 'Import abgeschlossen!', 'importhistoryconflict' => 'Es existieren bereits ältere Versionen, welche mit diesen kollidieren. Möglicherweise wurde die Seite bereits vorher importiert.', 'importnosources' => 'Für den Transwiki-Import sind keine Quellen definiert. Das direkte Hochladen von Versionen ist gesperrt.', 'importnofile' => 'Es ist keine Importdatei ausgewählt worden!', 'importuploaderror' => 'Das Hochladen der Importdatei ist fehlgeschlagen. Vielleicht ist die Datei größer als erlaubt.', +'import-parse-failure' => 'Fehler beim XML-Import:', +'import-articlename' => 'Neuer Artikelname:', +'import-noarticle' => 'Es wurde kein zu importierender Artikel angegeben!', +'import-nonewrevisions' => 'Es sind keine neuen Versionen zum Import vorhanden, alle Versionen wurden bereits früher importiert.', +'xml-error-string' => '$1 Zeile $2, Spalte $3, (Byte $4): $5' , # Import log 'importlogpage' => 'Import-Logbuch', diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index a741eca4a1..d94aadff88 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2158,11 +2158,16 @@ All transwiki import actions are logged at the [[Special:Log/import|import log]] 'importcantopen' => "Couldn't open import file", 'importbadinterwiki' => 'Bad interwiki link', 'importnotext' => 'Empty or no text', -'importsuccess' => 'Import succeeded!', +'importsuccess' => 'Import finished!', 'importhistoryconflict' => 'Conflicting history revision exists (may have imported this page before)', 'importnosources' => 'No transwiki import sources have been defined and direct history uploads are disabled.', 'importnofile' => 'No import file was uploaded.', 'importuploaderror' => 'Upload of import file failed; perhaps the file is bigger than the allowed upload size.', +'import-parse-failure' => 'XML import parse failure', +'import-articlename' => 'New article name:', +'import-noarticle' => 'No article to import!', +'import-nonewrevisions' => 'All revisions were previously imported.', +'xml-error-string' => '$1 at line $2, col $3 (byte $4): $5', # Import log 'importlogpage' => 'Import log', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index fa0cfb8ed9..cd6a3ee99c 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1441,6 +1441,11 @@ $wgMessageStructure = array( 'importnosources', 'importnofile', 'importuploaderror', + 'import-parse-failure', + 'import-articlename', + 'import-noarticle', + 'import-nonewrevisions', + 'xml-error-string', ), 'importlog' => array( 'importlogpage', -- 2.20.1