public function getPreview($wikitext) { // TODO: use wgParser here because some parser hooks initialize themselves on wgParser (should on provided parser instance) global $wgParser, $wgUser, $wgRequest; wfProfileIn(__METHOD__); $parserOptions = new ParserOptions($wgUser); // call preSaveTransform so signatures, {{subst:foo}}, etc. will work $wikitext = $wgParser->preSaveTransform($wikitext, $this->mTitle, $this->app->getGlobal('wgUser'), $parserOptions); // parse wikitext using MW parser $html = $wgParser->parse($wikitext, $this->mTitle, $parserOptions)->getText(); $html = EditPageService::wrapBodyText($this->mTitle, $wgRequest, $html); // we should also render categories and interlanguage links $parserOutput = $wgParser->getOutput(); $catbox = $this->renderCategoryBoxFromParserOutput($parserOutput); $interlanglinks = $this->renderInterlangBoxFromParserOutput($parserOutput); wfProfileOut(__METHOD__); return array($html, $catbox, $interlanglinks); }
public function getPreview($wikitext) { // TODO: use wgParser here because some parser hooks initialize themselves on wgParser (should on provided parser instance) global $wgParser, $wgUser, $wgRequest; wfProfileIn(__METHOD__); $wg = $this->app->wg; $parserOptions = new ParserOptions($wgUser); $originalWikitext = $wikitext; if (!empty($wg->EnableCategorySelectExt)) { // if CategorySelect is enabled, add categories to wikitext $categories = $wg->Request->getVal('categories', ''); $wikitext .= CategoryHelper::changeFormat($categories, 'json', 'wikitext'); } // call preSaveTransform so signatures, {{subst:foo}}, etc. will work $wikitext = $wgParser->preSaveTransform($wikitext, $this->mTitle, $this->app->getGlobal('wgUser'), $parserOptions); // parse wikitext using MW parser $parserOutput = $wgParser->parse($wikitext, $this->mTitle, $parserOptions); /** * Allow extensions to modify the ParserOutput */ wfRunHooks('ArticlePreviewAfterParse', [$parserOutput, $this->mTitle]); $html = $parserOutput->getText(); $html = EditPageService::wrapBodyText($this->mTitle, $wgRequest, $html); // we should also render categories and interlanguage links $catbox = $this->renderCategoryBoxFromParserOutput($parserOutput); $interlanglinks = $this->renderInterlangBoxFromParserOutput($parserOutput); /** * bugid: 47995 -- Treat JavaScript and CSS as raw text wrapped in <pre> tags * We still rely on the parser for other stuff */ if ($this->mTitle->isCssOrJsPage()) { $html = '<pre>' . htmlspecialchars($originalWikitext) . '</pre>'; } wfProfileOut(__METHOD__); return array($html, $catbox, $interlanglinks); }