/** * @desc Method for getting diff between actual Wikia.css file and text given in request parameter * @paramRequest string wikitext - request param in which you can provide text to create a diff */ public function getDiff() { $wikitext = $this->request->getVal('wikitext', ''); $model = new SpecialCssModel(); $editPageService = new EditPageService($model->getCssFileTitle()); $this->diff = $editPageService->getDiff($wikitext); }
/** * 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' => ''); }
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); }
public static function getTemplatesList() { global $wgTitle; $service = new EditPageService($wgTitle); $html = $service->getTemplatesList(); return array('templates' => $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]); }