https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108232
Revision: 108232
Author: ialex
Date: 2012-01-06 14:21:16 +0000 (Fri, 06 Jan 2012)
Log Message:
-----------
* 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
Modified Paths:
--------------
trunk/phase3/includes/Import.php
trunk/phase3/includes/specials/SpecialImport.php
trunk/phase3/languages/messages/MessagesEn.php
trunk/phase3/maintenance/language/messages.inc
Modified: trunk/phase3/includes/Import.php
===================================================================
--- trunk/phase3/includes/Import.php 2012-01-06 14:17:03 UTC (rev 108231)
+++ trunk/phase3/includes/Import.php 2012-01-06 14:21:16 UTC (rev 108232)
@@ -34,7 +34,7 @@
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 @@
wfDebug( "IMPORT: $data\n" );
}
- private function notice( $data ) {
- global $wgCommandLineMode;
- if( $wgCommandLineMode ) {
- print "$data\n";
- } else {
- global $wgOut;
- $wgOut->addHTML( "<li>" . htmlspecialchars( $data ) .
"</li>\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";
}
}
@@ -102,6 +103,16 @@
}
/**
+ * 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
* @return callback
@@ -780,21 +791,21 @@
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;
}
Modified: trunk/phase3/includes/specials/SpecialImport.php
===================================================================
--- trunk/phase3/includes/specials/SpecialImport.php 2012-01-06 14:17:03 UTC
(rev 108231)
+++ trunk/phase3/includes/specials/SpecialImport.php 2012-01-06 14:21:16 UTC
(rev 108232)
@@ -321,6 +321,7 @@
$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 @@
$this->getOutput()->addHTML( "<ul>\n" );
}
+ function reportNotice( $msg, array $params ) {
+ $this->getOutput()->addHTML( Html::element( 'li', array(),
$this->msg( $msg, $params )->text() ) );
+ }
+
function reportLogItem( /* ... */ ) {
$this->mLogItemCount++;
if ( is_callable( $this->mOriginalLogCallback ) ) {
@@ -352,6 +357,11 @@
$args = func_get_args();
call_user_func_array( $this->mOriginalPageOutCallback, $args );
+ if ( $title === null ) {
+ # Invalid or non-importable title; a notice is already
displayed
+ return;
+ }
+
$this->mPageCount++;
$localCount = $this->getLanguage()->formatNum( $successCount );
Modified: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php 2012-01-06 14:17:03 UTC
(rev 108231)
+++ trunk/phase3/languages/messages/MessagesEn.php 2012-01-06 14:21:16 UTC
(rev 108232)
@@ -3400,6 +3400,7 @@
'import-error-create' => 'Page "$1" is not imported because you are not
allowed to create it.',
'import-error-interwiki' => 'Page "$1" is not imported because its name is
reserved for external linking (interwiki).',
'import-error-special' => 'Page "$1" is not imported because it belongs
to a special namespace that does not allow pages.',
+'import-error-invalid' => 'Page "$1" is not imported because its name is
invalid.',
# Import log
'importlogpage' => 'Import log',
Modified: trunk/phase3/maintenance/language/messages.inc
===================================================================
--- trunk/phase3/maintenance/language/messages.inc 2012-01-06 14:17:03 UTC
(rev 108231)
+++ trunk/phase3/maintenance/language/messages.inc 2012-01-06 14:21:16 UTC
(rev 108232)
@@ -2355,6 +2355,7 @@
'import-error-create',
'import-error-interwiki',
'import-error-special',
+ 'import-error-invalid',
),
'importlog' => array(
'importlogpage',
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs