25 'emptyObject' =>
new stdClass,
27 'string' =>
'foobar\\',
34 '"7":["8",{"9":"10"}]',
36 "{\n\t\"emptyObject\": {\n\t},\n\t\"emptyArray\": [ ]\n}",
44 "string": "foobar\\\\",
50 "\"7\":[\"8\",{\"9\":\"10\"}]",
51 "{\n\t\"emptyObject\": {\n\t},\n\t\"emptyArray\": [ ]\n}"
55 $json = str_replace(
"\r",
'', $json );
56 $json = str_replace(
"\t", $expectedIndent, $json );
57 $this->assertSame( $json, FormatJson::encode( $obj, $pretty ) );
68 $this->assertSame( $to, FormatJson::encode( $from ) );
79 $this->assertSame( $to, FormatJson::encode( $from,
false, FormatJson::UTF8_OK ) );
90 $this->assertSame( $to, FormatJson::encode( $from,
false, FormatJson::XMLMETA_OK ) );
101 $this->assertSame( $to, FormatJson::encode( $from,
false, FormatJson::ALL_OK ) );
105 $this->assertNotEquals(
107 strtolower( FormatJson::encode(
"\xf0\xa0\x80\x80" ) ),
108 'Test encoding an broken json_encode character (U+20000)'
113 $this->assertInternalType(
115 FormatJson::decode(
'{"Name": "Cheeso", "Rank": 7}' ),
119 $this->assertInternalType(
121 FormatJson::decode(
'{"Name": "Cheeso", "Rank": 7}',
true ),
139 [ [
'a' =>
'b',
'x' => [
'c' =>
'd' ] ] ],
158 $json = FormatJson::encode( $expected,
false, FormatJson::ALL_OK );
159 $this->assertJson( $json );
161 $st = FormatJson::parse( $json );
162 $this->assertInstanceOf( Status::class, $st );
163 $this->assertTrue( $st->isGood() );
164 $this->assertEquals( $expected, $st->getValue() );
166 $st = FormatJson::parse( $json, FormatJson::FORCE_ASSOC );
167 $this->assertInstanceOf( Status::class, $st );
168 $this->assertTrue( $st->isGood() );
169 $this->assertEquals(
$value, $st->getValue() );
192 [
"[,]",
'[]',
false ],
193 [
"[ , ]",
'[]',
false ],
195 [
'[1],',
false,
true,
'[1]' ],
200 [
"[1\n,\n]\n",
'[1]' ],
201 [
'["a,",]',
'["a,"]' ],
202 [
"[[1,]\n,[2,\n],[3\n,]]",
'[[1],[2],[3]]' ],
204 [
'[[1,],[2,],[3,]]',
false,
true,
'[[1],[2],[3]]' ],
205 [
'[1,,]',
false,
false,
'[1]' ],
219 $jsoncParses =
true, $expectedJsonc =
null
222 $expectedGoodStatus =
false;
225 if ( json_decode(
'[1,]' ) !==
null ) {
227 $expected = ( $expectedJsonc === null ) ? $expected : $expectedJsonc;
229 $expectedGoodStatus = $jsoncParses;
232 $st = FormatJson::parse(
$value, FormatJson::TRY_FIXING );
233 $this->assertInstanceOf( Status::class, $st );
234 if ( $expected ===
false ) {
235 $this->assertFalse( $st->isOK(),
'Expected isOK() == false' );
237 $this->assertSame( $expectedGoodStatus, $st->isGood(),
238 'Expected isGood() == ' . ( $expectedGoodStatus ?
'true' :
'false' )
240 $this->assertTrue( $st->isOK(),
'Expected isOK == true' );
241 $val = FormatJson::encode( $st->getValue(),
false, FormatJson::ALL_OK );
242 $this->assertEquals( $expected, $val );
258 $st = FormatJson::parse(
$value );
259 $this->assertInstanceOf( Status::class, $st );
260 $this->assertFalse( $st->isOK() );
265 [
'{"a":"b"}',
'{"a":"b"}' ],
266 [
"{\"a\":\"b\"}\n",
"{\"a\":\"b\"}\n" ],
267 [
'/*c*/{"c":"b"}',
'{"c":"b"}' ],
268 [
'{"a":"c"}/*c*/',
'{"a":"c"}' ],
269 [
'/*c//d*/{"c":"b"}',
'{"c":"b"}' ],
270 [
'{/*c*/"c":"b"}',
'{"c":"b"}' ],
271 [
"/*\nc\r\n*/{\"c\":\"b\"}",
'{"c":"b"}' ],
272 [
"//c\n{\"c\":\"b\"}",
'{"c":"b"}' ],
273 [
"//c\r\n{\"c\":\"b\"}",
'{"c":"b"}' ],
274 [
'{"a":"c"}//c',
'{"a":"c"}' ],
275 [
"{\"a-c\"://c\n\"b\"}",
'{"a-c":"b"}' ],
276 [
'{"/*a":"b"}',
'{"/*a":"b"}' ],
277 [
'{"a":"//b"}',
'{"a":"//b"}' ],
278 [
'{"a":"b/*c*/"}',
'{"a":"b/*c*/"}' ],
279 [
"{\"\\\"/*a\":\"b\"}",
"{\"\\\"/*a\":\"b\"}" ],
283 [
'"http://example.com"',
'"http://example.com"' ],
285 [
'"Blåbærsyltetøy"',
'"Blåbærsyltetøy"' ],
296 $this->assertSame( $expect, FormatJson::stripComments( $json ) );
301 [
'/* blah */true',
true ],
302 [
"// blah \ntrue",
true ],
303 [
'[ "a" , /* blah */ "b" ]', [
'a',
'b' ] ],
315 $st = FormatJson::parse( $json, FormatJson::STRIP_COMMENTS );
316 $this->assertInstanceOf( Status::class, $st );
317 $this->assertTrue( $st->isGood() );
318 $this->assertEquals( $expect, $st->getValue() );
347 '\\\\' =>
'\\\\\\\\',
348 '\\u00e9' =>
'\\\u00e9',
351 "\xe2\x80\xa8" =>
'\u2028',
352 "\xe2\x80\xa9" =>
'\u2029',
355 "\xc3\xa9" =>
'\u00e9',
356 "\xf0\x9d\x92\x9e" =>
'\ud835\udc9e',
366 foreach ( $groups as $name => $rules ) {
367 $leaveUnescaped = in_array( $name, $unescapedGroups );
368 foreach ( $rules as $from => $to ) {
369 $cases[] = [ $from,
'"' . ( $leaveUnescaped ? $from : $to ) .
'"' ];
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
processing should stop and the error should be shown to the user * false
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object