DumpStringOutput: Rename getOutput() to __toString()
authorKevin Israel <pleasestand@live.com>
Thu, 14 Jul 2016 10:28:16 +0000 (06:28 -0400)
committerKevin Israel <pleasestand@live.com>
Thu, 14 Jul 2016 10:28:16 +0000 (06:28 -0400)
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
includes/export/DumpStringOutput.php
tests/phpunit/includes/ExportTest.php

index 1e91256..5eb86ab 100644 (file)
@@ -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' ] );
                }
        }
index 5168225..837a62d 100644 (file)
@@ -39,7 +39,7 @@ class DumpStringOutput extends DumpOutput {
         *
         * @return string
         */
-       public function getOutput() {
+       public function __toString() {
                return $this->output;
        }
 }
index c077081..a5d3570 100644 (file)
@@ -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