*/
const AS_IMAGE_REDIRECT_LOGGED = 234;
+ /**
+ * Status: can't parse content
+ */
+ const AS_PARSE_ERROR = 240;
+
+ /**
+ * HTML id and name for the beginning of the edit form.
+ */
+ const EDITFORM_ID = 'editform';
+
/**
* @var Article
*/
}
}
- $wgOut->addHTML( Html::openElement( 'form', array( 'id' => 'editform', 'name' => 'editform',
+ #FIXME: add EditForm plugin interface and use it here! #FIXME: search for textarea1 and textares2, and allow EditForm to override all uses.
+ $wgOut->addHTML( Html::openElement( 'form', array( 'id' => self::EDITFORM_ID, 'name' => self::EDITFORM_ID,
'method' => 'post', 'action' => $this->getActionURL( $this->getContextTitle() ),
'enctype' => 'multipart/form-data' ) ) );
function showDiff() {
global $wgUser, $wgContLang, $wgParser, $wgOut;
- $oldContent = $this->getOriginalContent();
+ $oldtitlemsg = 'currentrev';
+ # if message does not exist, show diff against the preloaded default
+ if( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists() ) {
+ $oldtext = $this->mTitle->getDefaultMessageText();
+ if( $oldtext !== false ) {
+ $oldtitlemsg = 'defaultmessagetext';
++ $oldContent = ContentHandler::makeContent( $oldtext, $this->mTitle );
++ } else {
++ $oldContent = null;
+ }
+ } else {
- $oldtext = $this->mArticle->getRawText();
++ $oldContent = $this->getOriginalContent();
++ }
+
+ $textboxContent = ContentHandler::makeContent( $this->textbox1, $this->getTitle(),
+ $this->content_model, $this->content_format ); #XXX: handle parse errors ?
+
+ $newContent = $this->mArticle->replaceSectionContent(
+ $this->section, $textboxContent,
+ $this->summary, $this->edittime );
+
+ # hanlde legacy text-based hook
+ $newtext_orig = $newContent->serialize( $this->content_format );
+ $newtext = $newtext_orig; #clone
+ wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
+
+ if ( $newtext != $newtext_orig ) {
+ #if the hook changed the text, create a new Content object accordingly.
+ $newContent = ContentHandler::makeContent( $newtext, $this->getTitle(), $newContent->getModelName() ); #XXX: handle parse errors ?
}
- $newtext = $this->mArticle->replaceSection(
- $this->section, $this->textbox1, $this->summary, $this->edittime );
- wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
+ wfRunHooks( 'EditPageGetDiffContent', array( $this, &$newContent ) ); #FIXME: document new hook
$popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
- $newtext = $wgParser->preSaveTransform( $newtext, $this->mTitle, $wgUser, $popts );
+ $newContent = $newContent->preSaveTransform( $this->mTitle, $wgUser, $popts );
- if ( $oldtext !== false || $newtext != '' ) {
+ if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) {
- $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
+ $oldtitle = wfMsgExt( $oldtitlemsg, array( 'parseinline' ) );
$newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
- $de = $oldContent->getContentHandler()->getDifferenceEngine( $this->mArticle->getContext() );
- $de = new DifferenceEngine( $this->mArticle->getContext() );
- $de->setText( $oldtext, $newtext );
++ $de = $oldContent->getContentHandler()->createDifferenceEngine( $this->mArticle->getContext() );
+ $de->setContent( $oldContent, $newContent );
+
$difftext = $de->getDiff( $oldtitle, $newtitle );
$de->showDiffStyle();
} else {
return $parsedNote;
}
- if ( $this->mTriedSave && !$this->mTokenOk ) {
- if ( $this->mTokenOkExceptSuffix ) {
- $note = wfMsg( 'token_suffix_mismatch' );
- } else {
- $note = wfMsg( 'session_fail_preview' );
- }
- } elseif ( $this->incompleteForm ) {
- $note = wfMsg( 'edit_form_incomplete' );
- } else {
- $note = wfMsg( 'previewnote' ) .
- ' [[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . wfMsg( 'continue-editing' ) . ']]';
- }
-
- $parserOptions = ParserOptions::newFromUser( $wgUser );
- $parserOptions->setEditSection( false );
- $parserOptions->setTidy( true );
- $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->isWikitextPage() ) {
- if ( $this->mTitle->isCssJsSubpage() ) {
- $level = 'user';
- } elseif ( $this->mTitle->isCssOrJsPage() ) {
- $level = 'site';
- } else {
- $level = false;
- }
++ $note = '';
++
+ try {
- $content = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), $this->content_model, $this->content_format );
++ $content = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), $this->content_model, $this->content_format );
- if ( $this->mTriedSave && !$this->mTokenOk ) {
- if ( $this->mTokenOkExceptSuffix ) {
- $note = wfMsg( 'token_suffix_mismatch' );
- } else {
- $note = wfMsg( 'session_fail_preview' );
- }
- } elseif ( $this->incompleteForm ) {
- $note = wfMsg( 'edit_form_incomplete' );
- } elseif ( $this->isCssJsSubpage || $this->mTitle->isCssOrJsPage() ) {
- # if this is a CSS or JS page used in the UI, show a special notice
- # XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
- # Used messages to make sure grep find them:
- # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
- $class = 'mw-code';
- if ( $level ) {
- if ( preg_match( "/\\.css$/", $this->mTitle->getText() ) ) {
- $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
- $class .= " mw-css";
- } elseif ( preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
- $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
- $class .= " mw-js";
++ if ( $this->mTriedSave && !$this->mTokenOk ) {
++ if ( $this->mTokenOkExceptSuffix ) {
++ $note = wfMsg( 'token_suffix_mismatch' );
+ } else {
- throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
++ $note = wfMsg( 'session_fail_preview' );
+ }
- $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
- $previewHTML = $parserOutput->getText();
++ } elseif ( $this->incompleteForm ) {
++ $note = wfMsg( 'edit_form_incomplete' );
+ } else {
- $previewHTML = '';
- }
-
- $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\n";
- } else {
- $toparse = $this->textbox1;
-
- # If we're adding a comment, we need to show the
- # summary as the headline
- if ( $this->section == "new" && $this->summary != "" ) {
- $toparse = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $toparse;
- }
-
- wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
-
- $parserOptions->enableLimitReport();
-
- $toparse = $wgParser->preSaveTransform( $toparse, $this->mTitle, $wgUser, $parserOptions );
- $parserOutput = $wgParser->parse( $toparse, $this->mTitle, $parserOptions );
-
- $rt = Title::newFromRedirectArray( $this->textbox1 );
- if ( $rt ) {
- $previewHTML = $this->mArticle->viewRedirect( $rt, false );
- } else {
- $previewHTML = $parserOutput->getText();
- }
-
- $this->mParserOutput = $parserOutput;
- $wgOut->addParserOutputNoText( $parserOutput );
-
- if ( count( $parserOutput->getWarnings() ) ) {
- $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
- }
- }
++ $note = wfMsg( 'previewnote' ) .
++ ' [[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . wfMsg( 'continue-editing' ) . ']]';
++ }
++
++ $parserOptions = ParserOptions::newFromUser( $wgUser );
++ $parserOptions->setEditSection( false );
++ $parserOptions->setTidy( true );
++ $parserOptions->setIsPreview( true );
++ $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
+
++ if ( $this->mTitle->isCssJsSubpage() || $this->mTitle->isCssOrJsPage() ) {
++ # don't parse non-wikitext pages, show message about preview
+ if( $this->mTitle->isCssJsSubpage() ) {
+ $level = 'user';
+ } elseif( $this->mTitle->isCssOrJsPage() ) {
+ $level = 'site';
+ } else {
+ $level = false;
+ }
+
+ if ( $content->getModelName() == CONTENT_MODEL_CSS ) {
+ $format = 'css';
+ } elseif ( $content->getModelName() == CONTENT_MODEL_JAVASCRIPT ) {
+ $format = 'js';
+ } 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'>" . wfMsg( "{$level}{$format}preview" ) . "</div>";
+ } else {
+ $note = wfMsg( 'previewnote' );
+ }
+ } else {
+ $note = wfMsg( 'previewnote' );
+ }
+
- $parserOptions = ParserOptions::newFromUser( $wgUser );
- $parserOptions->setEditSection( false );
- $parserOptions->setTidy( true );
- $parserOptions->setIsPreview( true );
- $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
-
+ $rt = $content->getRedirectChain();
+
+ if ( $rt ) {
+ $previewHTML = $this->mArticle->viewRedirect( $rt, false );
+ } else {
+
+ # 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 );
+ }
+
+ $toparse_orig = $content->serialize( $this->content_format );
+ $toparse = $toparse_orig;
+ wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
+
+ if ( $toparse !== $toparse_orig ) {
+ #hook changed the text, create new Content object
+ $content = ContentHandler::makeContent( $toparse, $this->getTitle(), $this->content_model, $this->content_format );
+ }
+
+ wfRunHooks( 'EditPageGetPreviewContent', array( $this, &$content ) ); # FIXME: document new hook
+
+ $parserOptions->enableLimitReport();
+
+ #XXX: For CSS/JS pages, we should have called the ShowRawCssJs hook here. But it's now deprecated, so never mind
+ $content = $content->preSaveTransform( $this->mTitle, $wgUser, $parserOptions );
+
+ // TODO: might be a saner way to get a meaningfull context here?
+ $parserOutput = $content->getParserOutput( $this->getArticle()->getContext(), null, $parserOptions );
+
+ $previewHTML = $parserOutput->getText();
+ $this->mParserOutput = $parserOutput;
+ $wgOut->addParserOutputNoText( $parserOutput );
+
+ if ( count( $parserOutput->getWarnings() ) ) {
+ $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
+ }
+ }
+ } catch (MWContentSerializationException $ex) {
+ $note .= "\n\n" . wfMsg('content-failed-to-parse', $this->content_model, $this->content_format, $ex->getMessage() );
+ $previewHTML = '';
+ }
if ( $this->isConflict ) {
$conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";