示例#1
0
 /**
  * Finish printing and output buffered data.
  */
 public function closePrinter()
 {
     if ($this->mDisabled) {
         return;
     }
     $mime = $this->getMimeType();
     if ($this->getIsHtml() && $mime !== null) {
         $format = $this->getFormat();
         $lcformat = strtolower($format);
         $result = $this->getBuffer();
         $context = new DerivativeContext($this->getMain());
         $context->setSkin(SkinFactory::getDefaultInstance()->makeSkin('apioutput'));
         $context->setTitle(SpecialPage::getTitleFor('ApiHelp'));
         $out = new OutputPage($context);
         $context->setOutput($out);
         $out->addModuleStyles('mediawiki.apipretty');
         $out->setPageTitle($context->msg('api-format-title'));
         if (!$this->getIsWrappedHtml()) {
             // When the format without suffix 'fm' is defined, there is a non-html version
             if ($this->getMain()->getModuleManager()->isDefined($lcformat, 'format')) {
                 $msg = $context->msg('api-format-prettyprint-header')->params($format, $lcformat);
             } else {
                 $msg = $context->msg('api-format-prettyprint-header-only-html')->params($format);
             }
             $header = $msg->parseAsBlock();
             $out->addHTML(Html::rawElement('div', ['class' => 'api-pretty-header'], ApiHelp::fixHelpLinks($header)));
         }
         if (Hooks::run('ApiFormatHighlight', [$context, $result, $mime, $format])) {
             $out->addHTML(Html::element('pre', ['class' => 'api-pretty-content'], $result));
         }
         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();
         }
     } else {
         // For non-HTML output, clear all errors that might have been
         // displayed if display_errors=On
         ob_clean();
         echo $this->getBuffer();
     }
 }
示例#2
0
 /**
  * Finish printing and output buffered data.
  */
 public function closePrinter()
 {
     if ($this->mDisabled) {
         return;
     }
     $mime = $this->getMimeType();
     if ($this->getIsHtml() && $mime !== null) {
         $format = $this->getFormat();
         $lcformat = strtolower($format);
         $result = $this->getBuffer();
         $context = new DerivativeContext($this->getMain());
         $context->setSkin(SkinFactory::getDefaultInstance()->makeSkin('apioutput'));
         $context->setTitle(SpecialPage::getTitleFor('ApiHelp'));
         $out = new OutputPage($context);
         $context->setOutput($out);
         $out->addModuleStyles('mediawiki.apipretty');
         $out->setPageTitle($context->msg('api-format-title'));
         // When the format without suffix 'fm' is defined, there is a non-html version
         if ($this->getMain()->getModuleManager()->isDefined($lcformat, 'format')) {
             $msg = $context->msg('api-format-prettyprint-header')->params($format, $lcformat);
         } else {
             $msg = $context->msg('api-format-prettyprint-header-only-html')->params($format);
         }
         $header = $msg->parseAsBlock();
         $out->addHTML(Html::rawElement('div', array('class' => 'api-pretty-header'), ApiHelp::fixHelpLinks($header)));
         if (Hooks::run('ApiFormatHighlight', array($context, $result, $mime, $format))) {
             $out->addHTML(Html::element('pre', array('class' => 'api-pretty-content'), $result));
         }
         // API handles its own clickjacking protection.
         // Note, that $wgBreakFrames will still override $wgApiFrameOptions for format mode.
         $out->allowClickJacking();
         $out->output();
     } else {
         // For non-HTML output, clear all errors that might have been
         // displayed if display_errors=On
         ob_clean();
         echo $this->getBuffer();
     }
 }