From be46ffa771e9bc6b09526b8acfd09d468987f91e Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Thu, 14 Jul 2016 06:28:16 -0400 Subject: [PATCH] DumpStringOutput: Rename getOutput() to __toString() Though getOutput() is what first came to mind, I do not particularly like the name, partly because it is used in many, many places as a method that returns an OutputPage object. * Renamed the method to __toString(). This is appropriate because each instance, at any given time, corresponds to a single string value (and exceptions cannot occur during this conversion). * Removed unnecessary variables from ApiQuery and ExportTest. In these and most other cases, it should no longer be necessary to call getOutput() explicitly. Change-Id: Icf202743d1f332f8981338f42eb6e3e5a04abdf1 --- includes/api/ApiQuery.php | 5 ++--- includes/export/DumpStringOutput.php | 2 +- tests/phpunit/includes/ExportTest.php | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 1e912561bc..5eb86ab3c7 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -450,7 +450,6 @@ class ApiQuery extends ApiBase { $exporter->pageByTitle( $title ); } $exporter->closeStream(); - $exportxml = $sink->getOutput(); // Don't check the size of exported stuff // It's not continuable, so it would cause more @@ -458,10 +457,10 @@ class ApiQuery extends ApiBase { if ( $this->mParams['exportnowrap'] ) { $result->reset(); // Raw formatter will handle this - $result->addValue( null, 'text', $exportxml, ApiResult::NO_SIZE_CHECK ); + $result->addValue( null, 'text', $sink, ApiResult::NO_SIZE_CHECK ); $result->addValue( null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK ); } else { - $result->addValue( 'query', 'export', $exportxml, ApiResult::NO_SIZE_CHECK ); + $result->addValue( 'query', 'export', $sink, ApiResult::NO_SIZE_CHECK ); $result->addValue( 'query', ApiResult::META_BC_SUBELEMENTS, [ 'export' ] ); } } diff --git a/includes/export/DumpStringOutput.php b/includes/export/DumpStringOutput.php index 5168225179..837a62d628 100644 --- a/includes/export/DumpStringOutput.php +++ b/includes/export/DumpStringOutput.php @@ -39,7 +39,7 @@ class DumpStringOutput extends DumpOutput { * * @return string */ - public function getOutput() { + public function __toString() { return $this->output; } } diff --git a/tests/phpunit/includes/ExportTest.php b/tests/phpunit/includes/ExportTest.php index c07708158b..a5d357066b 100644 --- a/tests/phpunit/includes/ExportTest.php +++ b/tests/phpunit/includes/ExportTest.php @@ -35,10 +35,9 @@ class ExportTest extends MediaWikiLangTestCase { $exporter->openStream(); $exporter->pageByTitle( $title ); $exporter->closeStream(); - $xmlString = $sink->getOutput(); // This throws error if invalid xml output - $xmlObject = simplexml_load_string( $xmlString ); + $xmlObject = simplexml_load_string( $sink ); /** * Check namespaces match xml -- 2.20.1