From: Alexandre Emsenhuber Date: Fri, 6 Jan 2012 14:21:16 +0000 (+0000) Subject: * Added callback to send notices from WikiImporter and use it in ImportReporter so... X-Git-Tag: 1.31.0-rc.0~25481 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=c24fbd4aff3d0f9b3a3812b4fe99e579a97f156b;p=lhc%2Fweb%2Fwiklou.git * Added callback to send notices from WikiImporter and use it in ImportReporter so that it can use the context to get messages and send them to OutputPage (also removes on usage of $wgCommandLineMode) * Early abort on invalid title in ImportReporter::reportPage() since a notice has already been sent * Localised message saying the title is invalid --- diff --git a/includes/Import.php b/includes/Import.php index c79b963273..94c77b859f 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -34,7 +34,7 @@ class WikiImporter { private $reader = null; private $mLogItemCallback, $mUploadCallback, $mRevisionCallback, $mPageCallback; private $mSiteInfoCallback, $mTargetNamespace, $mPageOutCallback; - private $mDebug; + private $mNoticeCallback, $mDebug; private $mImportUploads, $mImageBasePath; private $mNoUpdates = false; @@ -75,13 +75,14 @@ class WikiImporter { wfDebug( "IMPORT: $data\n" ); } - private function notice( $data ) { - global $wgCommandLineMode; - if( $wgCommandLineMode ) { - print "$data\n"; - } else { - global $wgOut; - $wgOut->addHTML( "
  • " . htmlspecialchars( $data ) . "
  • \n" ); + private function notice( $msg /*, $param, ...*/ ) { + $params = func_get_args(); + array_shift( $params ); + + if ( is_callable( $this->mNoticeCallback ) ) { + call_user_func( $this->mNoticeCallback, $msg, $params ); + } else { # No ImportReporter -> CLI + echo wfMessage( $msg, $params )->text() . "\n"; } } @@ -101,6 +102,16 @@ class WikiImporter { $this->mNoUpdates = $noupdates; } + /** + * Set a callback that displays notice messages + * + * @param $callback callback + * @return callback + */ + public function setNoticeCallback( $callback ) { + return wfSetVar( $this->mNoticeCallback, $callback ); + } + /** * Sets the action to perform as each new page in the stream is reached. * @param $callback callback @@ -780,21 +791,21 @@ class WikiImporter { if( is_null( $title ) ) { # Invalid page title? Ignore the page - $this->notice( "Skipping invalid page title '$workTitle'" ); + $this->notice( 'import-error-invalid', $workTitle ); return false; } elseif( $title->isExternal() ) { - $this->notice( wfMessage( 'import-error-interwiki', $title->getText() )->text() ); + $this->notice( 'import-error-interwiki', $title->getPrefixedText() ); return false; } elseif( !$title->canExist() ) { - $this->notice( wfMessage( 'import-error-special', $title->getText() )->text() ); + $this->notice( 'import-error-special', $title->getPrefixedText() ); return false; } elseif( !$title->userCan( 'edit' ) && !$wgCommandLineMode ) { # Do not import if the importing wiki user cannot edit this page - $this->notice( wfMessage( 'import-error-edit', $title->getText() )->text() ); + $this->notice( 'import-error-edit', $title->getPrefixedText() ); return false; } elseif( !$title->exists() && !$title->userCan( 'create' ) && !$wgCommandLineMode ) { # Do not import if the importing wiki user cannot create this page - $this->notice( wfMessage( 'import-error-create', $title->getText() )->text() ); + $this->notice( 'import-error-create', $title->getPrefixedText() ); return false; } diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index e8c5762d2c..a2380fbe7a 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -321,6 +321,7 @@ class ImportReporter extends ContextSource { $importer->setPageOutCallback( array( $this, 'reportPage' ) ); $this->mOriginalLogCallback = $importer->setLogItemCallback( array( $this, 'reportLogItem' ) ); + $importer->setNoticeCallback( array( $this, 'reportNotice' ) ); $this->mPageCount = 0; $this->mIsUpload = $upload; $this->mInterwiki = $interwiki; @@ -331,6 +332,10 @@ class ImportReporter extends ContextSource { $this->getOutput()->addHTML( "