[WikiImporter::notice] use wfDebug instead of echo in notice()
authorYifei He <eflyjason@gmail.com>
Fri, 22 Dec 2017 03:12:28 +0000 (11:12 +0800)
committerYifei He <eflyjason@gmail.com>
Fri, 22 Dec 2017 04:24:42 +0000 (12:24 +0800)
Make the default notice implementation of notice() function to
send the notice to wfDebug() instead of simply echo to prevent XSS

Bug: T177997
Change-Id: I9ffb597e0642afc1603cdd15e2d09c6f2584b448

includes/import/WikiImporter.php
maintenance/dumpIterator.php
maintenance/importDump.php
maintenance/renderDump.php
maintenance/storage/checkStorage.php

index 28f3f82..ed5ec1a 100644 (file)
@@ -125,7 +125,9 @@ class WikiImporter {
                if ( is_callable( $this->mNoticeCallback ) ) {
                        call_user_func( $this->mNoticeCallback, $msg, $params );
                } else { # No ImportReporter -> CLI
                if ( is_callable( $this->mNoticeCallback ) ) {
                        call_user_func( $this->mNoticeCallback, $msg, $params );
                } else { # No ImportReporter -> CLI
-                       echo wfMessage( $msg, $params )->text() . "\n";
+                       // T177997: the command line importers should call setNoticeCallback()
+                       // for their own custom callback to echo the notice
+                       wfDebug( wfMessage( $msg, $params )->text() . "\n" );
                }
        }
 
                }
        }
 
index 254f368..707f4b3 100644 (file)
@@ -77,6 +77,9 @@ abstract class DumpIterator extends Maintenance {
 
                $importer->setRevisionCallback(
                        [ $this, 'handleRevision' ] );
 
                $importer->setRevisionCallback(
                        [ $this, 'handleRevision' ] );
+               $importer->setNoticeCallback( function ( $msg, $params ) {
+                       echo wfMessage( $msg, $params )->text() . "\n";
+               } );
 
                $this->from = $this->getOption( 'from', null );
                $this->count = 0;
 
                $this->from = $this->getOption( 'from', null );
                $this->count = 0;
index 2923b38..918c1ab 100644 (file)
@@ -322,6 +322,9 @@ TEXT
                        $this->pageCount = $nthPage - 1;
                }
                $importer->setPageCallback( [ $this, 'reportPage' ] );
                        $this->pageCount = $nthPage - 1;
                }
                $importer->setPageCallback( [ $this, 'reportPage' ] );
+               $importer->setNoticeCallback( function ( $msg, $params ) {
+                       echo wfMessage( $msg, $params )->text() . "\n";
+               } );
                $this->importCallback = $importer->setRevisionCallback(
                        [ $this, 'handleRevision' ] );
                $this->uploadCallback = $importer->setUploadCallback(
                $this->importCallback = $importer->setRevisionCallback(
                        [ $this, 'handleRevision' ] );
                $this->uploadCallback = $importer->setUploadCallback(
index 68a371c..458556f 100644 (file)
@@ -66,6 +66,9 @@ class DumpRenderer extends Maintenance {
 
                $importer->setRevisionCallback(
                        [ $this, 'handleRevision' ] );
 
                $importer->setRevisionCallback(
                        [ $this, 'handleRevision' ] );
+               $importer->setNoticeCallback( function ( $msg, $params ) {
+                       echo wfMessage( $msg, $params )->text() . "\n";
+               } );
 
                $importer->doImport();
 
 
                $importer->doImport();
 
index 6348e96..8f55b88 100644 (file)
@@ -493,6 +493,9 @@ class CheckStorage {
                        MediaWikiServices::getInstance()->getMainConfig()
                );
                $importer->setRevisionCallback( [ $this, 'importRevision' ] );
                        MediaWikiServices::getInstance()->getMainConfig()
                );
                $importer->setRevisionCallback( [ $this, 'importRevision' ] );
+               $importer->setNoticeCallback( function ( $msg, $params ) {
+                       echo wfMessage( $msg, $params )->text() . "\n";
+               } );
                $importer->doImport();
        }
 
                $importer->doImport();
        }