- // API handles its own clickjacking protection.
- // Note, that $wgBreakFrames will still override $wgApiFrameOptions for format mode.
- $out->allowClickJacking();
- $out->output();
+ if ( $this->getIsWrappedHtml() ) {
+ // This is a special output mode mainly intended for ApiSandbox use
+ $time = microtime( true ) - $this->getConfig()->get( 'RequestTime' );
+ $json = FormatJson::encode(
+ [
+ 'html' => $out->getHTML(),
+ 'modules' => array_values( array_unique( array_merge(
+ $out->getModules(),
+ $out->getModuleScripts(),
+ $out->getModuleStyles()
+ ) ) ),
+ 'time' => round( $time * 1000 ),
+ ],
+ false, FormatJson::ALL_OK
+ );
+
+ // Bug 66776: wfMangleFlashPolicy() is needed to avoid a nasty bug in
+ // Flash, but what it does isn't friendly for the API, so we need to
+ // work around it.
+ if ( preg_match( '/\<\s*cross-domain-policy\s*\>/i', $json ) ) {
+ $json = preg_replace(
+ '/\<(\s*cross-domain-policy\s*)\>/i', '\\u003C$1\\u003E', $json
+ );
+ }
+
+ echo $json;
+ } else {
+ // API handles its own clickjacking protection.
+ // Note, that $wgBreakFrames will still override $wgApiFrameOptions for format mode.
+ $out->allowClickjacking();
+ $out->output();
+ }