r108232 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108231‎ | r108232 | r108233 >
Date:14:21, 6 January 2012
Author:ialex
Status:ok
Tags:
Comment:
* 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 (modified) (history)
  • /trunk/phase3/includes/specials/SpecialImport.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -2355,6 +2355,7 @@
23562356 'import-error-create',
23572357 'import-error-interwiki',
23582358 'import-error-special',
 2359+ 'import-error-invalid',
23592360 ),
23602361 'importlog' => array(
23612362 'importlogpage',
Index: trunk/phase3/includes/specials/SpecialImport.php
@@ -321,6 +321,7 @@
322322 $importer->setPageOutCallback( array( $this, 'reportPage' ) );
323323 $this->mOriginalLogCallback =
324324 $importer->setLogItemCallback( array( $this, 'reportLogItem' ) );
 325+ $importer->setNoticeCallback( array( $this, 'reportNotice' ) );
325326 $this->mPageCount = 0;
326327 $this->mIsUpload = $upload;
327328 $this->mInterwiki = $interwiki;
@@ -331,6 +332,10 @@
332333 $this->getOutput()->addHTML( "<ul>\n" );
333334 }
334335
 336+ function reportNotice( $msg, array $params ) {
 337+ $this->getOutput()->addHTML( Html::element( 'li', array(), $this->msg( $msg, $params )->text() ) );
 338+ }
 339+
335340 function reportLogItem( /* ... */ ) {
336341 $this->mLogItemCount++;
337342 if ( is_callable( $this->mOriginalLogCallback ) ) {
@@ -352,6 +357,11 @@
353358 $args = func_get_args();
354359 call_user_func_array( $this->mOriginalPageOutCallback, $args );
355360
 361+ if ( $title === null ) {
 362+ # Invalid or non-importable title; a notice is already displayed
 363+ return;
 364+ }
 365+
356366 $this->mPageCount++;
357367
358368 $localCount = $this->getLanguage()->formatNum( $successCount );
Index: trunk/phase3/includes/Import.php
@@ -34,7 +34,7 @@
3535 private $reader = null;
3636 private $mLogItemCallback, $mUploadCallback, $mRevisionCallback, $mPageCallback;
3737 private $mSiteInfoCallback, $mTargetNamespace, $mPageOutCallback;
38 - private $mDebug;
 38+ private $mNoticeCallback, $mDebug;
3939 private $mImportUploads, $mImageBasePath;
4040 private $mNoUpdates = false;
4141
@@ -75,13 +75,14 @@
7676 wfDebug( "IMPORT: $data\n" );
7777 }
7878
79 - private function notice( $data ) {
80 - global $wgCommandLineMode;
81 - if( $wgCommandLineMode ) {
82 - print "$data\n";
83 - } else {
84 - global $wgOut;
85 - $wgOut->addHTML( "<li>" . htmlspecialchars( $data ) . "</li>\n" );
 79+ private function notice( $msg /*, $param, ...*/ ) {
 80+ $params = func_get_args();
 81+ array_shift( $params );
 82+
 83+ if ( is_callable( $this->mNoticeCallback ) ) {
 84+ call_user_func( $this->mNoticeCallback, $msg, $params );
 85+ } else { # No ImportReporter -> CLI
 86+ echo wfMessage( $msg, $params )->text() . "\n";
8687 }
8788 }
8889
@@ -102,6 +103,16 @@
103104 }
104105
105106 /**
 107+ * Set a callback that displays notice messages
 108+ *
 109+ * @param $callback callback
 110+ * @return callback
 111+ */
 112+ public function setNoticeCallback( $callback ) {
 113+ return wfSetVar( $this->mNoticeCallback, $callback );
 114+ }
 115+
 116+ /**
106117 * Sets the action to perform as each new page in the stream is reached.
107118 * @param $callback callback
108119 * @return callback
@@ -780,21 +791,21 @@
781792
782793 if( is_null( $title ) ) {
783794 # Invalid page title? Ignore the page
784 - $this->notice( "Skipping invalid page title '$workTitle'" );
 795+ $this->notice( 'import-error-invalid', $workTitle );
785796 return false;
786797 } elseif( $title->isExternal() ) {
787 - $this->notice( wfMessage( 'import-error-interwiki', $title->getText() )->text() );
 798+ $this->notice( 'import-error-interwiki', $title->getPrefixedText() );
788799 return false;
789800 } elseif( !$title->canExist() ) {
790 - $this->notice( wfMessage( 'import-error-special', $title->getText() )->text() );
 801+ $this->notice( 'import-error-special', $title->getPrefixedText() );
791802 return false;
792803 } elseif( !$title->userCan( 'edit' ) && !$wgCommandLineMode ) {
793804 # Do not import if the importing wiki user cannot edit this page
794 - $this->notice( wfMessage( 'import-error-edit', $title->getText() )->text() );
 805+ $this->notice( 'import-error-edit', $title->getPrefixedText() );
795806 return false;
796807 } elseif( !$title->exists() && !$title->userCan( 'create' ) && !$wgCommandLineMode ) {
797808 # Do not import if the importing wiki user cannot create this page
798 - $this->notice( wfMessage( 'import-error-create', $title->getText() )->text() );
 809+ $this->notice( 'import-error-create', $title->getPrefixedText() );
799810 return false;
800811 }
801812
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -3400,6 +3400,7 @@
34013401 'import-error-create' => 'Page "$1" is not imported because you are not allowed to create it.',
34023402 'import-error-interwiki' => 'Page "$1" is not imported because its name is reserved for external linking (interwiki).',
34033403 'import-error-special' => 'Page "$1" is not imported because it belongs to a special namespace that does not allow pages.',
 3404+'import-error-invalid' => 'Page "$1" is not imported because its name is invalid.',
34043405
34053406 # Import log
34063407 'importlogpage' => 'Import log',

Status & tagging log