API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group API
|
|
|
|
|
*/
|
2015-12-07 16:26:16 +00:00
|
|
|
class ApiErrorFormatterTest extends MediaWikiLangTestCase {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ApiErrorFormatter
|
|
|
|
|
*/
|
|
|
|
|
public function testErrorFormatterBasics() {
|
|
|
|
|
$result = new ApiResult( 8388608 );
|
|
|
|
|
$formatter = new ApiErrorFormatter( $result, Language::factory( 'de' ), 'wikitext', false );
|
|
|
|
|
$this->assertSame( 'de', $formatter->getLanguage()->getCode() );
|
|
|
|
|
|
|
|
|
|
$formatter->addMessagesFromStatus( null, Status::newGood() );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ ApiResult::META_TYPE => 'assoc' ],
|
|
|
|
|
$result->getResultData()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertSame( [], $formatter->arrayFromStatus( Status::newGood() ) );
|
|
|
|
|
|
|
|
|
|
$wrappedFormatter = TestingAccessWrapper::newFromObject( $formatter );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
'Blah "kbd" <X> 😊',
|
|
|
|
|
$wrappedFormatter->stripMarkup( 'Blah <kbd>kbd</kbd> <b><X></b> 😊' ),
|
|
|
|
|
'stripMarkup'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ApiErrorFormatter
|
|
|
|
|
* @dataProvider provideErrorFormatter
|
|
|
|
|
*/
|
|
|
|
|
public function testErrorFormatter( $format, $lang, $useDB,
|
|
|
|
|
$expect1, $expect2, $expect3
|
|
|
|
|
) {
|
|
|
|
|
$result = new ApiResult( 8388608 );
|
|
|
|
|
$formatter = new ApiErrorFormatter( $result, Language::factory( $lang ), $format, $useDB );
|
|
|
|
|
|
2015-01-16 19:00:07 +00:00
|
|
|
// Add default type
|
|
|
|
|
$expect1[ApiResult::META_TYPE] = 'assoc';
|
|
|
|
|
$expect2[ApiResult::META_TYPE] = 'assoc';
|
|
|
|
|
$expect3[ApiResult::META_TYPE] = 'assoc';
|
|
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->addWarning( 'string', 'mainpage' );
|
|
|
|
|
$formatter->addError( 'err', 'mainpage' );
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->assertEquals( $expect1, $result->getResultData(), 'Simple test' );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
|
|
|
|
|
$result->reset();
|
|
|
|
|
$formatter->addWarning( 'foo', 'mainpage' );
|
|
|
|
|
$formatter->addWarning( 'foo', 'mainpage' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$formatter->addWarning( 'foo', [ 'parentheses', 'foobar' ] );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$msg1 = wfMessage( 'mainpage' );
|
|
|
|
|
$formatter->addWarning( 'message', $msg1 );
|
2016-02-17 09:09:32 +00:00
|
|
|
$msg2 = new ApiMessage( 'mainpage', 'overriddenCode', [ 'overriddenData' => true ] );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->addWarning( 'messageWithData', $msg2 );
|
|
|
|
|
$formatter->addError( 'errWithData', $msg2 );
|
|
|
|
|
$this->assertSame( $expect2, $result->getResultData(), 'Complex test' );
|
|
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$this->removeModuleTag( $expect2['warnings'][2] ),
|
|
|
|
|
$formatter->formatMessage( $msg1 ),
|
|
|
|
|
'formatMessage test 1'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$this->removeModuleTag( $expect2['warnings'][3] ),
|
|
|
|
|
$formatter->formatMessage( $msg2 ),
|
|
|
|
|
'formatMessage test 2'
|
|
|
|
|
);
|
|
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$result->reset();
|
|
|
|
|
$status = Status::newGood();
|
|
|
|
|
$status->warning( 'mainpage' );
|
|
|
|
|
$status->warning( 'parentheses', 'foobar' );
|
|
|
|
|
$status->warning( $msg1 );
|
|
|
|
|
$status->warning( $msg2 );
|
|
|
|
|
$status->error( 'mainpage' );
|
|
|
|
|
$status->error( 'parentheses', 'foobar' );
|
|
|
|
|
$formatter->addMessagesFromStatus( 'status', $status );
|
|
|
|
|
$this->assertSame( $expect3, $result->getResultData(), 'Status test' );
|
|
|
|
|
|
|
|
|
|
$this->assertSame(
|
2016-10-19 16:54:25 +00:00
|
|
|
array_map( [ $this, 'removeModuleTag' ], $expect3['errors'] ),
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->arrayFromStatus( $status, 'error' ),
|
|
|
|
|
'arrayFromStatus test for error'
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
2016-10-19 16:54:25 +00:00
|
|
|
array_map( [ $this, 'removeModuleTag' ], $expect3['warnings'] ),
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->arrayFromStatus( $status, 'warning' ),
|
|
|
|
|
'arrayFromStatus test for warning'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
private function removeModuleTag( $s ) {
|
|
|
|
|
if ( is_array( $s ) ) {
|
|
|
|
|
unset( $s['module'] );
|
|
|
|
|
}
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
public static function provideErrorFormatter() {
|
2016-10-19 16:54:25 +00:00
|
|
|
$mainpageText = wfMessage( 'mainpage' )->inLanguage( 'de' )->useDatabase( false )->text();
|
|
|
|
|
$parensText = wfMessage( 'parentheses', 'foobar' )->inLanguage( 'de' )
|
|
|
|
|
->useDatabase( false )->text();
|
|
|
|
|
$mainpageHTML = wfMessage( 'mainpage' )->inLanguage( 'en' )->parse();
|
|
|
|
|
$parensHTML = wfMessage( 'parentheses', 'foobar' )->inLanguage( 'en' )->parse();
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$C = ApiResult::META_CONTENT;
|
|
|
|
|
$I = ApiResult::META_INDEXED_TAG_NAME;
|
2016-10-19 16:54:25 +00:00
|
|
|
$overriddenData = [ 'overriddenData' => true, ApiResult::META_TYPE => 'assoc' ];
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2016-10-19 16:54:25 +00:00
|
|
|
$tmp = [ 'wikitext', 'de', false,
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'text' => $mainpageText, 'module' => 'err', $C => 'text' ],
|
|
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'text' => $mainpageText, 'module' => 'string', $C => 'text' ],
|
|
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'overriddenCode', 'text' => $mainpageText,
|
|
|
|
|
'data' => $overriddenData, 'module' => 'errWithData', $C => 'text' ],
|
|
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'text' => $mainpageText, 'module' => 'foo', $C => 'text' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'text' => $parensText, 'module' => 'foo', $C => 'text' ],
|
|
|
|
|
[ 'code' => 'mainpage', 'text' => $mainpageText, 'module' => 'message', $C => 'text' ],
|
|
|
|
|
[ 'code' => 'overriddenCode', 'text' => $mainpageText,
|
|
|
|
|
'data' => $overriddenData, 'module' => 'messageWithData', $C => 'text' ],
|
|
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'text' => $mainpageText, 'module' => 'status', $C => 'text' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'text' => $parensText, 'module' => 'status', $C => 'text' ],
|
|
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'text' => $mainpageText, 'module' => 'status', $C => 'text' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'text' => $parensText, 'module' => 'status', $C => 'text' ],
|
|
|
|
|
[ 'code' => 'overriddenCode', 'text' => $mainpageText,
|
|
|
|
|
'data' => $overriddenData, 'module' => 'status', $C => 'text' ],
|
|
|
|
|
$I => 'warning',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[ 'plaintext' ] + $tmp, // For these messages, plaintext and wikitext are the same
|
|
|
|
|
[ 'html', 'en', true,
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
|
|
|
|
[ 'code' => 'mainpage', 'html' => $mainpageHTML, 'module' => 'err', $C => 'html' ],
|
|
|
|
|
$I => 'error',
|
|
|
|
|
],
|
|
|
|
|
'warnings' => [
|
|
|
|
|
[ 'code' => 'mainpage', 'html' => $mainpageHTML, 'module' => 'string', $C => 'html' ],
|
|
|
|
|
$I => 'warning',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
|
|
|
|
[ 'code' => 'overriddenCode', 'html' => $mainpageHTML,
|
|
|
|
|
'data' => $overriddenData, 'module' => 'errWithData', $C => 'html' ],
|
|
|
|
|
$I => 'error',
|
|
|
|
|
],
|
|
|
|
|
'warnings' => [
|
|
|
|
|
[ 'code' => 'mainpage', 'html' => $mainpageHTML, 'module' => 'foo', $C => 'html' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'html' => $parensHTML, 'module' => 'foo', $C => 'html' ],
|
|
|
|
|
[ 'code' => 'mainpage', 'html' => $mainpageHTML, 'module' => 'message', $C => 'html' ],
|
|
|
|
|
[ 'code' => 'overriddenCode', 'html' => $mainpageHTML,
|
|
|
|
|
'data' => $overriddenData, 'module' => 'messageWithData', $C => 'html' ],
|
|
|
|
|
$I => 'warning',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
|
|
|
|
[ 'code' => 'mainpage', 'html' => $mainpageHTML, 'module' => 'status', $C => 'html' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'html' => $parensHTML, 'module' => 'status', $C => 'html' ],
|
|
|
|
|
$I => 'error',
|
|
|
|
|
],
|
|
|
|
|
'warnings' => [
|
|
|
|
|
[ 'code' => 'mainpage', 'html' => $mainpageHTML, 'module' => 'status', $C => 'html' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'html' => $parensHTML, 'module' => 'status', $C => 'html' ],
|
|
|
|
|
[ 'code' => 'overriddenCode', 'html' => $mainpageHTML,
|
|
|
|
|
'data' => $overriddenData, 'module' => 'status', $C => 'html' ],
|
|
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[ 'raw', 'fr', true,
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'module' => 'err',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-10-19 16:54:25 +00:00
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'module' => 'string',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-10-19 16:54:25 +00:00
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'overriddenCode',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'data' => $overriddenData,
|
|
|
|
|
'module' => 'errWithData',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-10-19 16:54:25 +00:00
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'module' => 'foo',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'code' => 'parentheses',
|
|
|
|
|
'key' => 'parentheses',
|
|
|
|
|
'params' => [ 'foobar', $I => 'param' ],
|
|
|
|
|
'module' => 'foo',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'module' => 'message',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'overriddenCode',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'data' => $overriddenData,
|
|
|
|
|
'module' => 'messageWithData',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-10-19 16:54:25 +00:00
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'module' => 'status',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'code' => 'parentheses',
|
|
|
|
|
'key' => 'parentheses',
|
|
|
|
|
'params' => [ 'foobar', $I => 'param' ],
|
|
|
|
|
'module' => 'status',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-10-19 16:54:25 +00:00
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'module' => 'status',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-10-19 16:54:25 +00:00
|
|
|
[
|
|
|
|
|
'code' => 'parentheses',
|
|
|
|
|
'key' => 'parentheses',
|
|
|
|
|
'params' => [ 'foobar', $I => 'param' ],
|
|
|
|
|
'module' => 'status',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'code' => 'overriddenCode',
|
|
|
|
|
'key' => 'mainpage',
|
|
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'data' => $overriddenData,
|
|
|
|
|
'module' => 'status',
|
|
|
|
|
],
|
|
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[ 'none', 'fr', true,
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'module' => 'err' ],
|
|
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'module' => 'string' ],
|
|
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'overriddenCode', 'data' => $overriddenData,
|
|
|
|
|
'module' => 'errWithData' ],
|
|
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'module' => 'foo' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'module' => 'foo' ],
|
|
|
|
|
[ 'code' => 'mainpage', 'module' => 'message' ],
|
|
|
|
|
[ 'code' => 'overriddenCode', 'data' => $overriddenData,
|
|
|
|
|
'module' => 'messageWithData' ],
|
|
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'errors' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'module' => 'status' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'module' => 'status' ],
|
|
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
[ 'code' => 'mainpage', 'module' => 'status' ],
|
|
|
|
|
[ 'code' => 'parentheses', 'module' => 'status' ],
|
|
|
|
|
[ 'code' => 'overriddenCode', 'data' => $overriddenData, 'module' => 'status' ],
|
|
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ApiErrorFormatter_BackCompat
|
|
|
|
|
*/
|
|
|
|
|
public function testErrorFormatterBC() {
|
|
|
|
|
$mainpagePlain = wfMessage( 'mainpage' )->useDatabase( false )->plain();
|
|
|
|
|
$parensPlain = wfMessage( 'parentheses', 'foobar' )->useDatabase( false )->plain();
|
|
|
|
|
|
|
|
|
|
$result = new ApiResult( 8388608 );
|
|
|
|
|
$formatter = new ApiErrorFormatter_BackCompat( $result );
|
|
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->assertSame( 'en', $formatter->getLanguage()->getCode() );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( [], $formatter->arrayFromStatus( Status::newGood() ) );
|
|
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->addWarning( 'string', 'mainpage' );
|
2016-10-19 16:54:25 +00:00
|
|
|
$formatter->addWarning( 'raw',
|
|
|
|
|
new RawMessage( 'Blah <kbd>kbd</kbd> <b><X></b> 😞' )
|
|
|
|
|
);
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->addError( 'err', 'mainpage' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertSame( [
|
|
|
|
|
'error' => [
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'info' => $mainpagePlain,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
'raw' => [
|
|
|
|
|
'warnings' => 'Blah "kbd" <X> 😞',
|
|
|
|
|
ApiResult::META_CONTENT => 'warnings',
|
|
|
|
|
],
|
2016-02-17 09:09:32 +00:00
|
|
|
'string' => [
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
'warnings' => $mainpagePlain,
|
|
|
|
|
ApiResult::META_CONTENT => 'warnings',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
2015-01-16 19:00:07 +00:00
|
|
|
ApiResult::META_TYPE => 'assoc',
|
2016-02-17 09:09:32 +00:00
|
|
|
], $result->getResultData(), 'Simple test' );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
|
|
|
|
|
$result->reset();
|
|
|
|
|
$formatter->addWarning( 'foo', 'mainpage' );
|
|
|
|
|
$formatter->addWarning( 'foo', 'mainpage' );
|
2016-10-19 16:54:25 +00:00
|
|
|
$formatter->addWarning( 'xxx+foo', [ 'parentheses', 'foobar' ] );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$msg1 = wfMessage( 'mainpage' );
|
|
|
|
|
$formatter->addWarning( 'message', $msg1 );
|
2016-02-17 09:09:32 +00:00
|
|
|
$msg2 = new ApiMessage( 'mainpage', 'overriddenCode', [ 'overriddenData' => true ] );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->addWarning( 'messageWithData', $msg2 );
|
|
|
|
|
$formatter->addError( 'errWithData', $msg2 );
|
2016-10-19 16:54:25 +00:00
|
|
|
$formatter->addWarning( null, 'mainpage' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertSame( [
|
|
|
|
|
'error' => [
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
'code' => 'overriddenCode',
|
|
|
|
|
'info' => $mainpagePlain,
|
|
|
|
|
'overriddenData' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
2016-10-19 16:54:25 +00:00
|
|
|
'unknown' => [
|
|
|
|
|
'warnings' => $mainpagePlain,
|
|
|
|
|
ApiResult::META_CONTENT => 'warnings',
|
|
|
|
|
],
|
2016-02-17 09:09:32 +00:00
|
|
|
'messageWithData' => [
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
'warnings' => $mainpagePlain,
|
|
|
|
|
ApiResult::META_CONTENT => 'warnings',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'message' => [
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
'warnings' => $mainpagePlain,
|
|
|
|
|
ApiResult::META_CONTENT => 'warnings',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'foo' => [
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
'warnings' => "$mainpagePlain\n$parensPlain",
|
|
|
|
|
ApiResult::META_CONTENT => 'warnings',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
2015-01-16 19:00:07 +00:00
|
|
|
ApiResult::META_TYPE => 'assoc',
|
2016-02-17 09:09:32 +00:00
|
|
|
], $result->getResultData(), 'Complex test' );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->assertSame(
|
|
|
|
|
[
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'info' => 'Main Page',
|
|
|
|
|
],
|
|
|
|
|
$formatter->formatMessage( $msg1 )
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[
|
|
|
|
|
'code' => 'overriddenCode',
|
|
|
|
|
'info' => 'Main Page',
|
|
|
|
|
'overriddenData' => true,
|
|
|
|
|
],
|
|
|
|
|
$formatter->formatMessage( $msg2 )
|
|
|
|
|
);
|
|
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$result->reset();
|
|
|
|
|
$status = Status::newGood();
|
|
|
|
|
$status->warning( 'mainpage' );
|
|
|
|
|
$status->warning( 'parentheses', 'foobar' );
|
|
|
|
|
$status->warning( $msg1 );
|
|
|
|
|
$status->warning( $msg2 );
|
|
|
|
|
$status->error( 'mainpage' );
|
|
|
|
|
$status->error( 'parentheses', 'foobar' );
|
|
|
|
|
$formatter->addMessagesFromStatus( 'status', $status );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertSame( [
|
|
|
|
|
'error' => [
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
'code' => 'parentheses',
|
|
|
|
|
'info' => $parensPlain,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'warnings' => [
|
|
|
|
|
'status' => [
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
'warnings' => "$mainpagePlain\n$parensPlain",
|
|
|
|
|
ApiResult::META_CONTENT => 'warnings',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
2015-01-16 19:00:07 +00:00
|
|
|
ApiResult::META_TYPE => 'assoc',
|
2016-02-17 09:09:32 +00:00
|
|
|
], $result->getResultData(), 'Status test' );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
|
|
|
|
|
$I = ApiResult::META_INDEXED_TAG_NAME;
|
|
|
|
|
$this->assertSame(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2015-10-03 13:44:13 +00:00
|
|
|
'message' => 'mainpage',
|
2016-10-19 16:54:25 +00:00
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'type' => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-10-03 13:44:13 +00:00
|
|
|
'message' => 'parentheses',
|
2016-10-19 16:54:25 +00:00
|
|
|
'params' => [ 'foobar', $I => 'param' ],
|
|
|
|
|
'code' => 'parentheses',
|
|
|
|
|
'type' => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$I => 'error',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->arrayFromStatus( $status, 'error' ),
|
|
|
|
|
'arrayFromStatus test for error'
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2015-10-03 13:44:13 +00:00
|
|
|
'message' => 'mainpage',
|
2016-10-19 16:54:25 +00:00
|
|
|
'params' => [ $I => 'param' ],
|
|
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'type' => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-10-03 13:44:13 +00:00
|
|
|
'message' => 'parentheses',
|
2016-10-19 16:54:25 +00:00
|
|
|
'params' => [ 'foobar', $I => 'param' ],
|
|
|
|
|
'code' => 'parentheses',
|
|
|
|
|
'type' => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-10-03 13:44:13 +00:00
|
|
|
'message' => 'mainpage',
|
2016-02-17 09:09:32 +00:00
|
|
|
'params' => [ $I => 'param' ],
|
2016-10-19 16:54:25 +00:00
|
|
|
'code' => 'mainpage',
|
|
|
|
|
'type' => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-10-03 13:44:13 +00:00
|
|
|
'message' => 'mainpage',
|
2016-02-17 09:09:32 +00:00
|
|
|
'params' => [ $I => 'param' ],
|
2016-10-19 16:54:25 +00:00
|
|
|
'code' => 'overriddenCode',
|
|
|
|
|
'type' => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$I => 'warning',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$formatter->arrayFromStatus( $status, 'warning' ),
|
|
|
|
|
'arrayFromStatus test for warning'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 18:59:05 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetMessageFromException
|
|
|
|
|
* @covers ApiErrorFormatter::getMessageFromException
|
|
|
|
|
* @covers ApiErrorFormatter::formatException
|
|
|
|
|
* @param Exception $exception
|
|
|
|
|
* @param array $options
|
|
|
|
|
* @param array $expect
|
|
|
|
|
*/
|
|
|
|
|
public function testGetMessageFromException( $exception, $options, $expect ) {
|
|
|
|
|
$result = new ApiResult( 8388608 );
|
|
|
|
|
$formatter = new ApiErrorFormatter( $result, Language::factory( 'en' ), 'html', false );
|
|
|
|
|
|
|
|
|
|
$msg = $formatter->getMessageFromException( $exception, $options );
|
|
|
|
|
$this->assertInstanceOf( Message::class, $msg );
|
|
|
|
|
$this->assertInstanceOf( IApiMessage::class, $msg );
|
|
|
|
|
$this->assertSame( $expect, [
|
|
|
|
|
'text' => $msg->parse(),
|
|
|
|
|
'code' => $msg->getApiCode(),
|
|
|
|
|
'data' => $msg->getApiData(),
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$expectFormatted = $formatter->formatMessage( $msg );
|
|
|
|
|
$formatted = $formatter->formatException( $exception, $options );
|
|
|
|
|
$this->assertSame( $expectFormatted, $formatted );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetMessageFromException
|
|
|
|
|
* @covers ApiErrorFormatter_BackCompat::formatException
|
|
|
|
|
* @param Exception $exception
|
|
|
|
|
* @param array $options
|
|
|
|
|
* @param array $expect
|
|
|
|
|
*/
|
|
|
|
|
public function testGetMessageFromException_BC( $exception, $options, $expect ) {
|
|
|
|
|
$result = new ApiResult( 8388608 );
|
|
|
|
|
$formatter = new ApiErrorFormatter_BackCompat( $result );
|
|
|
|
|
|
|
|
|
|
$msg = $formatter->getMessageFromException( $exception, $options );
|
|
|
|
|
$this->assertInstanceOf( Message::class, $msg );
|
|
|
|
|
$this->assertInstanceOf( IApiMessage::class, $msg );
|
|
|
|
|
$this->assertSame( $expect, [
|
|
|
|
|
'text' => $msg->parse(),
|
|
|
|
|
'code' => $msg->getApiCode(),
|
|
|
|
|
'data' => $msg->getApiData(),
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$expectFormatted = $formatter->formatMessage( $msg );
|
|
|
|
|
$formatted = $formatter->formatException( $exception, $options );
|
|
|
|
|
$this->assertSame( $expectFormatted, $formatted );
|
|
|
|
|
$formatted = $formatter->formatException( $exception, $options + [ 'bc' => true ] );
|
|
|
|
|
$this->assertSame( $expectFormatted['info'], $formatted );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetMessageFromException() {
|
|
|
|
|
return [
|
|
|
|
|
'Normal exception' => [
|
|
|
|
|
new RuntimeException( '<b>Something broke!</b>' ),
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'text' => '<b>Something broke!</b>',
|
|
|
|
|
'code' => 'internal_api_error_RuntimeException',
|
|
|
|
|
'data' => [],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'Normal exception, wrapped' => [
|
|
|
|
|
new RuntimeException( '<b>Something broke!</b>' ),
|
|
|
|
|
[ 'wrap' => 'parentheses', 'code' => 'some-code', 'data' => [ 'foo' => 'bar', 'baz' => 42 ] ],
|
|
|
|
|
[
|
|
|
|
|
'text' => '(<b>Something broke!</b>)',
|
|
|
|
|
'code' => 'some-code',
|
|
|
|
|
'data' => [ 'foo' => 'bar', 'baz' => 42 ],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'UsageException' => [
|
|
|
|
|
new UsageException( '<b>Something broke!</b>', 'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ] ),
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'text' => '<b>Something broke!</b>',
|
|
|
|
|
'code' => 'ue-code',
|
|
|
|
|
'data' => [ 'xxx' => 'yyy', 'baz' => 23 ],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'UsageException, wrapped' => [
|
|
|
|
|
new UsageException( '<b>Something broke!</b>', 'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ] ),
|
|
|
|
|
[ 'wrap' => 'parentheses', 'code' => 'some-code', 'data' => [ 'foo' => 'bar', 'baz' => 42 ] ],
|
|
|
|
|
[
|
|
|
|
|
'text' => '(<b>Something broke!</b>)',
|
|
|
|
|
'code' => 'some-code',
|
|
|
|
|
'data' => [ 'xxx' => 'yyy', 'baz' => 42, 'foo' => 'bar' ],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'LocalizedException' => [
|
|
|
|
|
new LocalizedException( [ 'returnto', '<b>FooBar</b>' ] ),
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'text' => 'Return to <b>FooBar</b>.',
|
|
|
|
|
'code' => 'returnto',
|
|
|
|
|
'data' => [],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'LocalizedException, wrapped' => [
|
|
|
|
|
new LocalizedException( [ 'returnto', '<b>FooBar</b>' ] ),
|
|
|
|
|
[ 'wrap' => 'parentheses', 'code' => 'some-code', 'data' => [ 'foo' => 'bar', 'baz' => 42 ] ],
|
|
|
|
|
[
|
|
|
|
|
'text' => 'Return to <b>FooBar</b>.',
|
|
|
|
|
'code' => 'some-code',
|
|
|
|
|
'data' => [ 'foo' => 'bar', 'baz' => 42 ],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
}
|