/**
  * Perform reverse parsing on given HTML (when needed)
  */
 private static function resolveWikitext($content, $mode, $page, $method, $section)
 {
     global $wgRequest, $wgTitle, $wgOut;
     wfProfileIn(__METHOD__);
     if ($wgTitle && class_exists($page)) {
         $pageObj = new $page();
         if (is_a($pageObj, 'SpecialCustomEditPage')) {
             $wikitext = $pageObj->getWikitextFromRequestForPreview($wgRequest->getVal('title', 'empty'));
             $service = new EditPageService($wgTitle);
             $html = $pageObj->getOwnPreviewDiff($wikitext, $method);
             $catbox = null;
             $interlanglinks = null;
             if ($html === false) {
                 $html = '';
                 if ($method == 'preview') {
                     list($html, $catbox, $interlanglinks) = $service->getPreview($wikitext);
                     // allow extensions to modify preview (BugId:8354) - this hook should only be run on article's content
                     wfRunHooks('OutputPageBeforeHTML', array(&$wgOut, &$html));
                     // add page title when not in section edit mode
                     if ($section === '') {
                         $html = '<h1 class="pagetitle">' . $wgTitle->getPrefixedText() . '</h1>' . $html;
                     }
                     // allow extensions to modify preview (BugId:6721)
                     wfRunHooks('EditPageLayoutModifyPreview', array($wgTitle, &$html, $wikitext));
                 } elseif ($method == 'diff') {
                     $html = $service->getDiff($wikitext, intval($section));
                 }
             }
             $html = '<div class="WikiaArticle">' . $html . '</div>';
             $res = array('html' => $html, 'catbox' => $catbox, 'interlanglinks' => $interlanglinks);
             wfProfileOut(__METHOD__);
             return $res;
         }
     }
     wfProfileOut(__METHOD__);
     return array('html' => '');
 }
 /**
  * Perform reverse parsing on given HTML (when needed)
  */
 private static function resolveWikitext($content, $mode, $page, $method, $section)
 {
     global $wgRequest, $wgTitle, $wgOut, $wgEnableSlowPagesBlacklistExt;
     wfProfileIn(__METHOD__);
     if (!empty($wgEnableSlowPagesBlacklistExt)) {
         global $wgSlowPagesBlacklist;
         if (in_array($wgTitle->getFullURL(), $wgSlowPagesBlacklist)) {
             wfProfileOut(__METHOD__);
             return ['html' => wfMessage('slowpagesblacklist-preview-unavailable')->plain(), 'catbox' => '', 'interlanglinks' => ''];
         }
     }
     if ($wgTitle && class_exists($page)) {
         $pageObj = new $page();
         if (is_a($pageObj, 'SpecialCustomEditPage')) {
             $wikitext = $pageObj->getWikitextFromRequestForPreview($wgRequest->getVal('title', 'empty'));
             $service = new EditPageService($wgTitle);
             $html = $pageObj->getOwnPreviewDiff($wikitext, $method);
             /**
              * @val String $type - partial or full - whether to return full skin along with css and js or just a content
              */
             $type = $wgRequest->getVal('type', 'partial');
             $res = [];
             if ($html === false) {
                 $html = '';
                 if ($method == 'preview') {
                     list($html, $catbox, $interlanglinks) = $service->getPreview($wikitext);
                     // allow extensions to modify preview (BugId:8354) - this hook should only be run on article's content
                     wfRunHooks('OutputPageBeforeHTML', array(&$wgOut, &$html));
                     if (F::app()->checkSkin('wikiamobile')) {
                         if ($type === 'full') {
                             $res['html'] = F::app()->renderView('WikiaMobileService', 'preview', ['content' => $html, 'section' => $section]);
                         } else {
                             $res['html'] = $html;
                         }
                     } elseif (F::app()->checkSkin('venus')) {
                         if ($type === 'full') {
                             $res['html'] = F::app()->renderView('VenusController', 'preview', ['content' => $html, 'section' => $section]);
                         } else {
                             $res['html'] = $html;
                         }
                     } else {
                         // add page title when not in section edit mode
                         if ($section === '') {
                             $html = '<h1 class="pagetitle">' . $wgTitle->getPrefixedText() . '</h1>' . $html;
                         }
                         // allow extensions to modify preview (BugId:6721)
                         wfRunHooks('EditPageLayoutModifyPreview', array($wgTitle, &$html, $wikitext));
                         /**
                          * bugid: 11407
                          * Provide an appropriate preview for a redirect, based on wikitext, not revision.
                          */
                         if (preg_match('/^#REDIRECT /m', $wikitext)) {
                             $article = Article::newFromTitle($wgTitle, RequestContext::getMain());
                             $matches = array();
                             if (preg_match_all('/^#REDIRECT \\[\\[([^\\]]+)\\]\\]/Um', $wikitext, $matches)) {
                                 $redirectTitle = Title::newFromText($matches[1][0]);
                                 if ($redirectTitle) {
                                     $html = $article->viewRedirect(array($redirectTitle));
                                 } else {
                                     \Wikia\Logger\WikiaLogger::instance()->info('No redirect title', ['titleText' => $matches[1][0]]);
                                     $html = '';
                                 }
                             }
                         }
                         $html = '<div class="WikiaArticle">' . $html . '</div>';
                         $res = ['html' => $html, 'catbox' => $catbox, 'interlanglinks' => $interlanglinks];
                     }
                 } elseif ($method == 'diff') {
                     $res['html'] = $service->getDiff($wikitext, intval($section));
                 }
             }
             wfProfileOut(__METHOD__);
             return $res;
         }
     }
     wfProfileOut(__METHOD__);
     return ['html' => ''];
 }
 public function preview()
 {
     $body = $this->getConvertedContent($this->request->getVal('body', ''));
     $service = new EditPageService($this->wg->Title);
     $out = $service->getPreview($body);
     $metatitle = $this->request->getVal('metatitle', '');
     if (!empty($metatitle)) {
         $metatitle = '<div class="msg-title"><span>' . htmlspecialchars($metatitle) . '</span></div>';
     }
     $this->response->setVal('body', $metatitle . $out[0]);
 }