X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialImport.php;h=1bc6c92d614be474338588d286888e1c6a64cacd;hb=4bee65ffa93ce531a5e647e995b6e7b07403dd43;hp=68b002466aaffdab6b85702271e941e0142e33c9;hpb=467c28ec57a5fc157e0016f1316887753ef2ff07;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index 68b002466a..1bc6c92d61 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -30,7 +30,6 @@ * @ingroup SpecialPage */ class SpecialImport extends SpecialPage { - private $interwiki = false; private $namespace; private $rootpage = ''; @@ -108,13 +107,13 @@ class SpecialImport extends SpecialPage { $source = Status::newFatal( 'import-token-mismatch' ); } elseif ( $sourceName == 'upload' ) { $isUpload = true; - if( $user->isAllowed( 'importupload' ) ) { + if ( $user->isAllowed( 'importupload' ) ) { $source = ImportStreamSource::newFromUpload( "xmlimport" ); } else { throw new PermissionsError( 'importupload' ); } } elseif ( $sourceName == "interwiki" ) { - if( !$user->isAllowed( 'import' ) ) { + if ( !$user->isAllowed( 'import' ) ) { throw new PermissionsError( 'import' ); } $this->interwiki = $request->getVal( 'interwiki' ); @@ -136,24 +135,40 @@ class SpecialImport extends SpecialPage { } $out = $this->getOutput(); - if( !$source->isGood() ) { - $out->wrapWikiMsg( "

\n$1\n

", array( 'importfailed', $source->getWikiText() ) ); + if ( !$source->isGood() ) { + $out->wrapWikiMsg( + "

\n$1\n

", + array( 'importfailed', $source->getWikiText() ) + ); } else { $importer = new WikiImporter( $source->value ); - if( !is_null( $this->namespace ) ) { + if ( !is_null( $this->namespace ) ) { $importer->setTargetNamespace( $this->namespace ); } - if( !is_null( $this->rootpage ) ) { + if ( !is_null( $this->rootpage ) ) { $statusRootPage = $importer->setTargetRootPage( $this->rootpage ); - if( !$statusRootPage->isGood() ) { - $out->wrapWikiMsg( "

\n$1\n

", array( 'import-options-wrong', $statusRootPage->getWikiText(), count( $statusRootPage->getErrorsArray() ) ) ); + if ( !$statusRootPage->isGood() ) { + $out->wrapWikiMsg( + "

\n$1\n

", + array( + 'import-options-wrong', + $statusRootPage->getWikiText(), + count( $statusRootPage->getErrorsArray() ) + ) + ); + return; } } $out->addWikiMsg( "importstart" ); - $reporter = new ImportReporter( $importer, $isUpload, $this->interwiki, $this->logcomment ); + $reporter = new ImportReporter( + $importer, + $isUpload, + $this->interwiki, + $this->logcomment + ); $reporter->setContext( $this->getContext() ); $exception = false; @@ -167,10 +182,16 @@ class SpecialImport extends SpecialPage { if ( $exception ) { # No source or XML parse error - $out->wrapWikiMsg( "

\n$1\n

", array( 'importfailed', $exception->getMessage() ) ); - } elseif( !$result->isGood() ) { + $out->wrapWikiMsg( + "

\n$1\n

", + array( 'importfailed', $exception->getMessage() ) + ); + } elseif ( !$result->isGood() ) { # Zero revisions - $out->wrapWikiMsg( "

\n$1\n

", array( 'importfailed', $result->getWikiText() ) ); + $out->wrapWikiMsg( + "

\n$1\n

", + array( 'importfailed', $result->getWikiText() ) + ); } else { # Success! $out->addWikiMsg( 'importsuccess' ); @@ -186,158 +207,191 @@ class SpecialImport extends SpecialPage { $user = $this->getUser(); $out = $this->getOutput(); - if( $user->isAllowed( 'importupload' ) ) { + if ( $user->isAllowed( 'importupload' ) ) { $out->addHTML( Xml::fieldset( $this->msg( 'import-upload' )->text() ) . - Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', - 'action' => $action, 'id' => 'mw-import-upload-form' ) ) . - $this->msg( 'importtext' )->parseAsBlock() . - Html::hidden( 'action', 'submit' ) . - Html::hidden( 'source', 'upload' ) . - Xml::openElement( 'table', array( 'id' => 'mw-import-table-upload' ) ) . - - " + Xml::openElement( + 'form', + array( + 'enctype' => 'multipart/form-data', + 'method' => 'post', + 'action' => $action, + 'id' => 'mw-import-upload-form' + ) + ) . + $this->msg( 'importtext' )->parseAsBlock() . + Html::hidden( 'action', 'submit' ) . + Html::hidden( 'source', 'upload' ) . + Xml::openElement( 'table', array( 'id' => 'mw-import-table-upload' ) ) . + " " . - Xml::label( $this->msg( 'import-upload-filename' )->text(), 'xmlimport' ) . + Xml::label( $this->msg( 'import-upload-filename' )->text(), 'xmlimport' ) . " " . - Html::input( 'xmlimport', '', 'file', array( 'id' => 'xmlimport' ) ) . ' ' . + Html::input( 'xmlimport', '', 'file', array( 'id' => 'xmlimport' ) ) . ' ' . " " . - Xml::label( $this->msg( 'import-comment' )->text(), 'mw-import-comment' ) . + Xml::label( $this->msg( 'import-comment' )->text(), 'mw-import-comment' ) . " " . - Xml::input( 'log-comment', 50, '', - array( 'id' => 'mw-import-comment', 'type' => 'text' ) ) . ' ' . + Xml::input( 'log-comment', 50, '', + array( 'id' => 'mw-import-comment', 'type' => 'text' ) ) . ' ' . " " . - Xml::label( $this->msg( 'import-interwiki-rootpage' )->text(), 'mw-interwiki-rootpage-upload' ) . + Xml::label( $this->msg( 'import-interwiki-rootpage' )->text(), 'mw-interwiki-rootpage-upload' ) . " " . - Xml::input( 'rootpage', 50, $this->rootpage, - array( 'id' => 'mw-interwiki-rootpage-upload', 'type' => 'text' ) ) . ' ' . + Xml::input( 'rootpage', 50, $this->rootpage, + array( 'id' => 'mw-interwiki-rootpage-upload', 'type' => 'text' ) ) . ' ' . " " . - Xml::submitButton( $this->msg( 'uploadbtn' )->text() ) . + Xml::submitButton( $this->msg( 'uploadbtn' )->text() ) . " " . - Xml::closeElement( 'table' ) . - Html::hidden( 'editToken', $user->getEditToken() ) . - Xml::closeElement( 'form' ) . - Xml::closeElement( 'fieldset' ) + Xml::closeElement( 'table' ) . + Html::hidden( 'editToken', $user->getEditToken() ) . + Xml::closeElement( 'form' ) . + Xml::closeElement( 'fieldset' ) ); } else { - if( empty( $wgImportSources ) ) { + if ( empty( $wgImportSources ) ) { $out->addWikiMsg( 'importnosources' ); } } - if( $user->isAllowed( 'import' ) && !empty( $wgImportSources ) ) { + if ( $user->isAllowed( 'import' ) && !empty( $wgImportSources ) ) { # Show input field for import depth only if $wgExportMaxLinkDepth > 0 $importDepth = ''; - if( $wgExportMaxLinkDepth > 0 ) { + if ( $wgExportMaxLinkDepth > 0 ) { $importDepth = " " . - $this->msg( 'export-pagelinks' )->parse() . - " + $this->msg( 'export-pagelinks' )->parse() . + " " . - Xml::input( 'pagelink-depth', 3, 0 ) . - " - "; + Xml::input( 'pagelink-depth', 3, 0 ) . + " + "; } $out->addHTML( Xml::fieldset( $this->msg( 'importinterwiki' )->text() ) . - Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'mw-import-interwiki-form' ) ) . - $this->msg( 'import-interwiki-text' )->parseAsBlock() . - Html::hidden( 'action', 'submit' ) . - Html::hidden( 'source', 'interwiki' ) . - Html::hidden( 'editToken', $user->getEditToken() ) . - Xml::openElement( 'table', array( 'id' => 'mw-import-table-interwiki' ) ) . - " + Xml::openElement( + 'form', + array( + 'method' => 'post', + 'action' => $action, + 'id' => 'mw-import-interwiki-form' + ) + ) . + $this->msg( 'import-interwiki-text' )->parseAsBlock() . + Html::hidden( 'action', 'submit' ) . + Html::hidden( 'source', 'interwiki' ) . + Html::hidden( 'editToken', $user->getEditToken() ) . + Xml::openElement( 'table', array( 'id' => 'mw-import-table-interwiki' ) ) . + " " . - Xml::label( $this->msg( 'import-interwiki-source' )->text(), 'interwiki' ) . + Xml::label( $this->msg( 'import-interwiki-source' )->text(), 'interwiki' ) . " " . - Xml::openElement( 'select', array( 'name' => 'interwiki', 'id' => 'interwiki' ) ) + Xml::openElement( + 'select', + array( 'name' => 'interwiki', 'id' => 'interwiki' ) + ) ); - foreach( $wgImportSources as $prefix ) { + + foreach ( $wgImportSources as $prefix ) { $selected = ( $this->interwiki === $prefix ) ? ' selected="selected"' : ''; $out->addHTML( Xml::option( $prefix, $prefix, $selected ) ); } $out->addHTML( - Xml::closeElement( 'select' ) . - Xml::input( 'frompage', 50, $this->frompage, array( 'id' => 'frompage' ) ) . + Xml::closeElement( 'select' ) . + Xml::input( 'frompage', 50, $this->frompage, array( 'id' => 'frompage' ) ) . " " . - Xml::checkLabel( $this->msg( 'import-interwiki-history' )->text(), 'interwikiHistory', 'interwikiHistory', $this->history ) . + Xml::checkLabel( + $this->msg( 'import-interwiki-history' )->text(), + 'interwikiHistory', + 'interwikiHistory', + $this->history + ) . " " . - Xml::checkLabel( $this->msg( 'import-interwiki-templates' )->text(), 'interwikiTemplates', 'interwikiTemplates', $this->includeTemplates ) . + Xml::checkLabel( + $this->msg( 'import-interwiki-templates' )->text(), + 'interwikiTemplates', + 'interwikiTemplates', + $this->includeTemplates + ) . " $importDepth " . - Xml::label( $this->msg( 'import-interwiki-namespace' )->text(), 'namespace' ) . + Xml::label( $this->msg( 'import-interwiki-namespace' )->text(), 'namespace' ) . " " . - Html::namespaceSelector( - array( - 'selected' => $this->namespace, - 'all' => '', - ), array( - 'name' => 'namespace', - 'id' => 'namespace', - 'class' => 'namespaceselector', - ) - ) . + Html::namespaceSelector( + array( + 'selected' => $this->namespace, + 'all' => '', + ), array( + 'name' => 'namespace', + 'id' => 'namespace', + 'class' => 'namespaceselector', + ) + ) . " " . - Xml::label( $this->msg( 'import-comment' )->text(), 'mw-interwiki-comment' ) . + Xml::label( $this->msg( 'import-comment' )->text(), 'mw-interwiki-comment' ) . " " . - Xml::input( 'log-comment', 50, '', - array( 'id' => 'mw-interwiki-comment', 'type' => 'text' ) ) . ' ' . + Xml::input( 'log-comment', 50, '', + array( 'id' => 'mw-interwiki-comment', 'type' => 'text' ) ) . ' ' . " " . - Xml::label( $this->msg( 'import-interwiki-rootpage' )->text(), 'mw-interwiki-rootpage-interwiki' ) . + Xml::label( + $this->msg( 'import-interwiki-rootpage' )->text(), + 'mw-interwiki-rootpage-interwiki' + ) . " " . - Xml::input( 'rootpage', 50, $this->rootpage, - array( 'id' => 'mw-interwiki-rootpage-interwiki', 'type' => 'text' ) ) . ' ' . + Xml::input( 'rootpage', 50, $this->rootpage, + array( 'id' => 'mw-interwiki-rootpage-interwiki', 'type' => 'text' ) ) . ' ' . " " . - Xml::submitButton( $this->msg( 'import-interwiki-submit' )->text(), Linker::tooltipAndAccesskeyAttribs( 'import' ) ) . + Xml::submitButton( + $this->msg( 'import-interwiki-submit' )->text(), + Linker::tooltipAndAccesskeyAttribs( 'import' ) + ) . " " . - Xml::closeElement( 'table' ) . - Xml::closeElement( 'form' ) . - Xml::closeElement( 'fieldset' ) + Xml::closeElement( 'table' ) . + Xml::closeElement( 'form' ) . + Xml::closeElement( 'fieldset' ) ); } } @@ -357,9 +411,15 @@ class ImportReporter extends ContextSource { private $mOriginalPageOutCallback = null; private $mLogItemCount = 0; + /** + * @param WikiImporter $importer + * @param $upload + * @param $interwiki + * @param string|bool $reason + */ function __construct( $importer, $upload, $interwiki, $reason = false ) { $this->mOriginalPageOutCallback = - $importer->setPageOutCallback( array( $this, 'reportPage' ) ); + $importer->setPageOutCallback( array( $this, 'reportPage' ) ); $this->mOriginalLogCallback = $importer->setLogItemCallback( array( $this, 'reportLogItem' ) ); $importer->setNoticeCallback( array( $this, 'reportNotice' ) ); @@ -403,20 +463,21 @@ class ImportReporter extends ContextSource { $this->mPageCount++; - if( $successCount > 0 ) { - $this->getOutput()->addHTML( "
  • " . Linker::linkKnown( $title ) . " " . - $this->msg( 'import-revision-count' )->numParams( $successCount )->escaped() . - "
  • \n" + if ( $successCount > 0 ) { + $this->getOutput()->addHTML( + "
  • " . Linker::linkKnown( $title ) . " " . + $this->msg( 'import-revision-count' )->numParams( $successCount )->escaped() . + "
  • \n" ); $log = new LogPage( 'import' ); - if( $this->mIsUpload ) { + if ( $this->mIsUpload ) { $detail = $this->msg( 'import-logentry-upload-detail' )->numParams( $successCount )->inContentLanguage()->text(); if ( $this->reason ) { $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->reason; } - $log->addEntry( 'upload', $title, $detail ); + $log->addEntry( 'upload', $title, $detail, array(), $this->getUser() ); } else { $interwiki = '[[:' . $this->mInterwiki . ':' . $origTitle->getPrefixedText() . ']]'; @@ -425,7 +486,7 @@ class ImportReporter extends ContextSource { if ( $this->reason ) { $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->reason; } - $log->addEntry( 'interwiki', $title, $detail ); + $log->addEntry( 'interwiki', $title, $detail, array(), $this->getUser() ); } $comment = $detail; // quick @@ -450,8 +511,9 @@ class ImportReporter extends ContextSource { if ( $this->mLogItemCount > 0 ) { $msg = $this->msg( 'imported-log-entries' )->numParams( $this->mLogItemCount )->parse(); $out->addHTML( Xml::tags( 'li', null, $msg ) ); - } elseif( $this->mPageCount == 0 && $this->mLogItemCount == 0 ) { + } elseif ( $this->mPageCount == 0 && $this->mLogItemCount == 0 ) { $out->addHTML( "\n" ); + return Status::newFatal( 'importnopages' ); } $out->addHTML( "\n" );