예제 #1
0
파일: ApiHelp.php 프로젝트: paladox/2
 public function execute()
 {
     $params = $this->extractRequestParams();
     $modules = array();
     foreach ($params['modules'] as $path) {
         $modules[] = $this->getModuleFromPath($path);
     }
     // Get the help
     $context = new DerivativeContext($this->getMain()->getContext());
     $context->setSkin(SkinFactory::getDefaultInstance()->makeSkin('apioutput'));
     $context->setLanguage($this->getMain()->getLanguage());
     $context->setTitle(SpecialPage::getTitleFor('ApiHelp'));
     $out = new OutputPage($context);
     $out->setCopyrightUrl('https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright');
     $context->setOutput($out);
     self::getHelp($context, $modules, $params);
     // Grab the output from the skin
     ob_start();
     $context->getOutput()->output();
     $html = ob_get_clean();
     $result = $this->getResult();
     if ($params['wrap']) {
         $data = array('mime' => 'text/html', 'help' => $html);
         ApiResult::setSubelementsList($data, 'help');
         $result->addValue(null, $this->getModuleName(), $data);
     } else {
         $result->reset();
         $result->addValue(null, 'text', $html, ApiResult::NO_SIZE_CHECK);
         $result->addValue(null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK);
     }
 }
 /**
  * @param string $url
  * @param array $cookies
  * @return MobileContext
  */
 private function makeContext($url = '/', $cookies = array())
 {
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest(new MFFauxRequest($url, $cookies));
     $context->setOutput(new OutputPage($context));
     $instance = unserialize('O:13:"MobileContext":0:{}');
     $instance->setContext($context);
     return $instance;
 }
 /**
  * @param string $url
  * @param array $cookies
  * @return MobileContext
  */
 private function makeContext($url = '/', $cookies = array())
 {
     $query = array();
     if ($url) {
         $params = wfParseUrl(wfExpandUrl($url));
         if (isset($params['query'])) {
             $query = wfCgiToArray($params['query']);
         }
     }
     $request = new FauxRequest($query);
     $request->setRequestURL($url);
     $request->setCookies($cookies, '');
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest($request);
     $context->setOutput(new OutputPage($context));
     $instance = unserialize('O:13:"MobileContext":0:{}');
     $instance->setContext($context);
     return $instance;
 }
예제 #4
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();
     }
 }
예제 #5
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();
     }
 }
 /**
  * Get a Filepage as parsed HTML
  * @param Title $title
  * @return string
  */
 private function getFilePage(Title $title)
 {
     //HACK: HACK: HACK:
     $context = new DerivativeContext($this->getContext());
     $context->setTitle($title);
     $context->setOutput(new OutputPage($context));
     $page = new ImagePage($title);
     $page->setContext($context);
     $page->view();
     $html = $context->getOutput()->getHTML();
     return $html;
 }
 /**
  * Get a Filepage as parsed HTML
  * @param Title $title
  * @return string
  */
 private function getFilePage(Title $title)
 {
     // HACK: HACK: HACK:
     $context = new DerivativeContext($this->getContext());
     $context->setTitle($title);
     $context->setOutput(new OutputPage($context));
     $page = new ImagePage($title);
     $page->setContext($context);
     // T123821: Without setting the wiki page on the derivative context,
     // DerivativeContext#getWikiPage will (eventually) fall back to
     // RequestContext#getWikiPage. Here, the request context is distinct from the
     // derivative context and deliberately constructed with a bad title in the prelude
     // of api.php.
     $context->setWikiPage($page->getPage());
     $page->view();
     $html = $context->getOutput()->getHTML();
     return $html;
 }