Ejemplo n.º 1
0
	/**
	 * Get parser options suitable for rendering the primary article wikitext
	 * @return ParserOptions
	 */
	public function getParserOptions() {
		if ( !$this->mParserOptions ) {
			$this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext() );
		}
		// Clone to allow modifications of the return value without affecting cache
		return clone $this->mParserOptions;
	}
Ejemplo n.º 2
0
 /**
  * Get parser options suitable for rendering the primary article wikitext
  * @return ParserOptions|false
  */
 public function getParserOptions()
 {
     global $wgUser;
     if (!$this->mParserOptions) {
         $this->mParserOptions = $this->mPage->makeParserOptions($wgUser);
     }
     // Clone to allow modifications of the return value without affecting cache
     return clone $this->mParserOptions;
 }
Ejemplo n.º 3
0
 protected function getParserOutput(WikiPage $page, Revision $rev)
 {
     $parserOptions = $page->makeParserOptions($this->getContext());
     if (!$rev->isCurrent() || !$rev->getTitle()->quickUserCan('edit', $this->getUser())) {
         $parserOptions->setEditSection(false);
     }
     $parserOutput = $page->getParserOutput($parserOptions, $rev->getId());
     return $parserOutput;
 }
Ejemplo n.º 4
0
 /**
  * Constructs a ParserOptions object
  *
  * @param WikiPage $pageObj
  * @param array $params
  *
  * @return ParserOptions
  */
 protected function makeParserOptions(WikiPage $pageObj, array $params)
 {
     $popts = $pageObj->makeParserOptions($this->getContext());
     $popts->enableLimitReport(!$params['disablepp'] && !$params['disablelimitreport']);
     $popts->setIsPreview($params['preview'] || $params['sectionpreview']);
     $popts->setIsSectionPreview($params['sectionpreview']);
     $popts->setEditSection(!$params['disableeditsection']);
     if ($params['disabletidy']) {
         $popts->setTidy(false);
     }
     return $popts;
 }
Ejemplo n.º 5
0
 /**
  * Constructs a ParserOptions object
  *
  * @param WikiPage $pageObj
  * @param array $params
  *
  * @return ParserOptions
  */
 protected function makeParserOptions(WikiPage $pageObj, array $params)
 {
     wfProfileIn(__METHOD__);
     $popts = $pageObj->makeParserOptions($this->getContext());
     $popts->enableLimitReport(!$params['disablepp']);
     $popts->setIsPreview($params['preview'] || $params['sectionpreview']);
     $popts->setIsSectionPreview($params['sectionpreview']);
     wfProfileOut(__METHOD__);
     return $popts;
 }
Ejemplo n.º 6
0
 /**
  * Constructs a ParserOptions object
  *
  * @param WikiPage $pageObj
  * @param array $params
  *
  * @return array [ ParserOptions, ScopedCallback, bool $suppressCache ]
  */
 protected function makeParserOptions(WikiPage $pageObj, array $params)
 {
     $popts = $pageObj->makeParserOptions($this->getContext());
     $popts->enableLimitReport(!$params['disablepp'] && !$params['disablelimitreport']);
     $popts->setIsPreview($params['preview'] || $params['sectionpreview']);
     $popts->setIsSectionPreview($params['sectionpreview']);
     $popts->setEditSection(!$params['disableeditsection']);
     if ($params['disabletidy']) {
         $popts->setTidy(false);
     }
     $reset = null;
     $suppressCache = false;
     Hooks::run('ApiMakeParserOptions', [$popts, $pageObj->getTitle(), $params, $this, &$reset, &$suppressCache]);
     return [$popts, $reset, $suppressCache];
 }
Ejemplo n.º 7
0
 /**
  * Get the rendered text for previewing.
  * @throws MWException
  * @return string
  */
 function getPreviewText()
 {
     global $wgOut, $wgUser, $wgRawHtml, $wgLang;
     global $wgAllowUserCss, $wgAllowUserJs;
     $stats = $wgOut->getContext()->getStats();
     if ($wgRawHtml && !$this->mTokenOk) {
         // Could be an offsite preview attempt. This is very unsafe if
         // HTML is enabled, as it could be an attack.
         $parsedNote = '';
         if ($this->textbox1 !== '') {
             // Do not put big scary notice, if previewing the empty
             // string, which happens when you initially edit
             // a category page, due to automatic preview-on-open.
             $parsedNote = $wgOut->parse("<div class='previewnote'>" . wfMessage('session_fail_preview_html')->text() . "</div>", true, true);
         }
         $stats->increment('edit.failures.session_loss');
         return $parsedNote;
     }
     $note = '';
     try {
         $content = $this->toEditContent($this->textbox1);
         $previewHTML = '';
         if (!Hooks::run('AlternateEditPreview', array($this, &$content, &$previewHTML, &$this->mParserOutput))) {
             return $previewHTML;
         }
         # provide a anchor link to the editform
         $continueEditing = '<span class="mw-continue-editing">' . '[[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . wfMessage('continue-editing')->text() . ']]</span>';
         if ($this->mTriedSave && !$this->mTokenOk) {
             if ($this->mTokenOkExceptSuffix) {
                 $note = wfMessage('token_suffix_mismatch')->plain();
                 $stats->increment('edit.failures.bad_token');
             } else {
                 $note = wfMessage('session_fail_preview')->plain();
                 $stats->increment('edit.failures.session_loss');
             }
         } elseif ($this->incompleteForm) {
             $note = wfMessage('edit_form_incomplete')->plain();
             if ($this->mTriedSave) {
                 $stats->increment('edit.failures.incomplete_form');
             }
         } else {
             $note = wfMessage('previewnote')->plain() . ' ' . $continueEditing;
         }
         $parserOptions = $this->page->makeParserOptions($this->mArticle->getContext());
         $parserOptions->setIsPreview(true);
         $parserOptions->setIsSectionPreview(!is_null($this->section) && $this->section !== '');
         # don't parse non-wikitext pages, show message about preview
         if ($this->mTitle->isCssJsSubpage() || $this->mTitle->isCssOrJsPage()) {
             if ($this->mTitle->isCssJsSubpage()) {
                 $level = 'user';
             } elseif ($this->mTitle->isCssOrJsPage()) {
                 $level = 'site';
             } else {
                 $level = false;
             }
             if ($content->getModel() == CONTENT_MODEL_CSS) {
                 $format = 'css';
                 if ($level === 'user' && !$wgAllowUserCss) {
                     $format = false;
                 }
             } elseif ($content->getModel() == CONTENT_MODEL_JAVASCRIPT) {
                 $format = 'js';
                 if ($level === 'user' && !$wgAllowUserJs) {
                     $format = false;
                 }
             } else {
                 $format = false;
             }
             # Used messages to make sure grep find them:
             # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
             if ($level && $format) {
                 $note = "<div id='mw-{$level}{$format}preview'>" . wfMessage("{$level}{$format}preview")->text() . ' ' . $continueEditing . "</div>";
             }
         }
         # If we're adding a comment, we need to show the
         # summary as the headline
         if ($this->section === "new" && $this->summary !== "") {
             $content = $content->addSectionHeader($this->summary);
         }
         $hook_args = array($this, &$content);
         ContentHandler::runLegacyHooks('EditPageGetPreviewText', $hook_args);
         Hooks::run('EditPageGetPreviewContent', $hook_args);
         $parserOptions->enableLimitReport();
         # For CSS/JS pages, we should have called the ShowRawCssJs hook here.
         # But it's now deprecated, so never mind
         $pstContent = $content->preSaveTransform($this->mTitle, $wgUser, $parserOptions);
         $scopedCallback = $parserOptions->setupFakeRevision($this->mTitle, $pstContent, $wgUser);
         $parserOutput = $pstContent->getParserOutput($this->mTitle, null, $parserOptions);
         # Try to stash the edit for the final submission step
         # @todo: different date format preferences cause cache misses
         ApiStashEdit::stashEditFromPreview($this->getArticle(), $content, $pstContent, $parserOutput, $parserOptions, $parserOptions, wfTimestampNow());
         $parserOutput->setEditSectionTokens(false);
         // no section edit links
         $previewHTML = $parserOutput->getText();
         $this->mParserOutput = $parserOutput;
         $wgOut->addParserOutputMetadata($parserOutput);
         if (count($parserOutput->getWarnings())) {
             $note .= "\n\n" . implode("\n\n", $parserOutput->getWarnings());
         }
         ScopedCallback::consume($scopedCallback);
     } catch (MWContentSerializationException $ex) {
         $m = wfMessage('content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage());
         $note .= "\n\n" . $m->parse();
         $previewHTML = '';
     }
     if ($this->isConflict) {
         $conflict = '<h2 id="mw-previewconflict">' . wfMessage('previewconflict')->escaped() . "</h2>\n";
     } else {
         $conflict = '<hr />';
     }
     $previewhead = "<div class='previewnote'>\n" . '<h2 id="mw-previewheader">' . wfMessage('preview')->escaped() . "</h2>" . $wgOut->parse($note, true, true) . $conflict . "</div>\n";
     $pageViewLang = $this->mTitle->getPageViewLanguage();
     $attribs = array('lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(), 'class' => 'mw-content-' . $pageViewLang->getDir());
     $previewHTML = Html::rawElement('div', $attribs, $previewHTML);
     return $previewhead . $previewHTML . $this->previewTextAfterContent;
 }
 /**
  * Creates a ParserOptions instance
  * @param WikiPage $wp
  * @return ParserOptions
  */
 protected function makeParserOptions(WikiPage $wp)
 {
     return $wp->makeParserOptions($this);
 }
Ejemplo n.º 9
0
 /**
  * Get parser options for a preview
  * @return ParserOptions
  */
 protected function getPreviewParserOptions()
 {
     $parserOptions = $this->page->makeParserOptions($this->mArticle->getContext());
     $parserOptions->setIsPreview(true);
     $parserOptions->setIsSectionPreview(!is_null($this->section) && $this->section !== '');
     $parserOptions->enableLimitReport();
     return $parserOptions;
 }
Ejemplo n.º 10
0
 /**
  * Produce page output suitable for indexing.
  *
  * Specific content handlers may override it if they need different content handling.
  *
  * @param WikiPage    $page
  * @param ParserCache $cache
  * @return ParserOutput
  */
 public function getParserOutputForIndexing(WikiPage $page, ParserCache $cache = null)
 {
     $parserOptions = $page->makeParserOptions('canonical');
     $revId = $page->getRevision()->getId();
     if ($cache) {
         $parserOutput = $cache->get($page, $parserOptions);
     }
     if (empty($parserOutput)) {
         $parserOutput = $page->getContent()->getParserOutput($page->getTitle(), $revId, $parserOptions);
         if ($cache) {
             $cache->save($parserOutput, $page, $parserOptions);
         }
     }
     return $parserOutput;
 }