From: daniel Date: Tue, 10 Feb 2015 10:34:09 +0000 (+0100) Subject: Common interface for ImportStreamSource and ImportStringSource. X-Git-Tag: 1.31.0-rc.0~12473^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=891cc28a9793ba94429020b33b6f8d85aa409ef1;p=lhc%2Fweb%2Fwiklou.git Common interface for ImportStreamSource and ImportStringSource. ImportStringSource is handy for testing, but was unusable due to type hints against ImportStreamSource. Introducing a common interface implemented by both fixes this. Change-Id: I820ffd8312789c26f55c18b6c46be191a550870a --- diff --git a/autoload.php b/autoload.php index 5c515a0103..c11a5bc3f1 100644 --- a/autoload.php +++ b/autoload.php @@ -535,6 +535,7 @@ $wgAutoloadLocalClasses = array( 'ImageQueryPage' => __DIR__ . '/includes/specialpage/ImageQueryPage.php', 'ImportReporter' => __DIR__ . '/includes/specials/SpecialImport.php', 'ImportSiteScripts' => __DIR__ . '/maintenance/importSiteScripts.php', + 'ImportSource' => __DIR__ . '/includes/Import.php', 'ImportStreamSource' => __DIR__ . '/includes/Import.php', 'ImportStringSource' => __DIR__ . '/includes/Import.php', 'ImportTitleFactory' => __DIR__ . '/includes/title/ImportTitleFactory.php', diff --git a/includes/Import.php b/includes/Import.php index 9d1bbc0c73..36028eab92 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -45,10 +45,10 @@ class WikiImporter { /** * Creates an ImportXMLReader drawing from the source provided - * @param ImportStreamSource $source + * @param ImportSource $source * @param Config $config */ - function __construct( ImportStreamSource $source, Config $config = null ) { + function __construct( ImportSource $source, Config $config = null ) { $this->reader = new XMLReader(); if ( !$config ) { wfDeprecated( __METHOD__ . ' without a Config instance', '1.25' ); @@ -967,10 +967,10 @@ class UploadSourceAdapter { private $mPosition; /** - * @param ImportStreamSource $source + * @param ImportSource $source * @return string */ - static function registerSource( ImportStreamSource $source ) { + static function registerSource( ImportSource $source ) { $id = wfRandomString(); self::$sourceRegistrations[$id] = $source; @@ -1708,6 +1708,30 @@ class WikiRevision { } +/** + * Source interface for XML import. + */ +interface ImportSource { + + /** + * Indicates whether the end of the input has been reached. + * Will return true after a finite number of calls to readChunk. + * + * @return bool true if there is no more input, false otherwise. + */ + function atEnd(); + + /** + * Return a chunk of the input, as a (possibly empty) string. + * When the end of input is reached, readChunk() returns false. + * If atEnd() returns false, readChunk() will return a string. + * If atEnd() returns true, readChunk() will return false. + * + * @return bool|string + */ + function readChunk(); +} + /** * Used for importing XML dumps where the content of the dump is in a string. * This class is ineffecient, and should only be used for small dumps. @@ -1715,7 +1739,7 @@ class WikiRevision { * * @ingroup SpecialPage */ -class ImportStringSource { +class ImportStringSource implements ImportSource { function __construct( $string ) { $this->mString = $string; $this->mRead = false; @@ -1744,7 +1768,7 @@ class ImportStringSource { * Imports a XML dump from a file (either from file upload, files on disk, or HTTP) * @ingroup SpecialPage */ -class ImportStreamSource { +class ImportStreamSource implements ImportSource { function __construct( $handle ) { $this->mHandle = $handle; }