From f17362f93b6a8ead77cb0d94cbcb67cef29f74fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Mon, 20 Feb 2006 21:18:11 +0000 Subject: [PATCH] * Fixed and enhanced a little the Live Preview, which had been broken for some time --- RELEASE-NOTES | 1 + includes/EditPage.php | 138 ++++++++++++++++++++++++++++------------ languages/Messages.php | 1 + skins/common/preview.js | 10 ++- 4 files changed, 110 insertions(+), 40 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 9bced72022..b435f02311 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -644,6 +644,7 @@ fully support the editing toolbar, but was found to be too confusing. generated stylesheets... hopefully... * (bug 4685) More fixes for Slovenian project namespace * Fix --report interval option for dumpTextPass +* Fixed and enhanced a little the Live Preview, which had been broken for some time === Caveats === diff --git a/includes/EditPage.php b/includes/EditPage.php index 128b0e4ba4..f90e13522e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -345,7 +345,8 @@ class EditPage { wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" ); $this->preview = true; } else { - $this->preview = $request->getCheck( 'wpPreview' ); + /* Fallback for live preview */ + $this->preview = $request->getCheck( 'wpPreview' ) || $request->getCheck( 'wpLivePreview' ); $this->diff = $request->getCheck( 'wpDiff' ); if( !$this->preview ) { @@ -765,9 +766,6 @@ class EditPage { $subject = wfMsg('subject'); $minor = wfMsg('minoredit'); $watchthis = wfMsg ('watchthis'); - $save = wfMsg('savearticle'); - $prev = wfMsg('showpreview'); - $diff = wfMsg('showdiff'); $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedText(), wfMsg('cancel') ); @@ -821,11 +819,15 @@ class EditPage { $checkboxhtml = $minoredithtml . $watchhtml; - if ( 'preview' == $this->formtype && $wgUser->getOption( 'previewontop' ) ) { - $this->showPreview(); - } - if ( 'diff' == $this->formtype ) { - if ( $wgUser->getOption('previewontop' ) ) { + if ( $wgUser->getOption( 'previewontop' ) ) { + + if ( 'preview' == $this->formtype ) { + $this->showPreview(); + } else { + $wgOut->addHTML( '
' ); + } + + if ( 'diff' == $this->formtype ) { $wgOut->addHTML( $this->getDiff() ); } } @@ -848,13 +850,6 @@ class EditPage { } $templates = $this->formatTemplates(); - global $wgLivePreview; - if ( $wgLivePreview ) { - $liveOnclick = $this->doLivePreviewScript(); - } else { - $liveOnclick = ''; - } - global $wgUseMetadataEdit ; if ( $wgUseMetadataEdit ) { $metadata = $this->mMetaData ; @@ -882,6 +877,65 @@ class EditPage { } } + $temp = array( + 'id' => 'wpSave', + 'name' => 'wpSave', + 'type' => 'submit', + 'tabindex' => '5', + 'value' => wfMsg('savearticle'), + 'accesskey' => wfMsg('accesskey-save'), + 'title' => wfMsg('tooltip-save'), + ); + $buttons['save'] = wfElement('input', $temp, ''); + $temp = array( + 'id' => 'wpDiff', + 'name' => 'wpDiff', + 'type' => 'submit', + 'tabindex' => '7', + 'value' => wfMsg('showdiff'), + 'accesskey' => wfMsg('accesskey-diff'), + 'title' => wfMsg('tooltip-diff'), + ); + $buttons['diff'] = wfElement('input', $temp, ''); + + global $wgLivePreview; + if ( $wgLivePreview ) { + $temp = array( + 'id' => 'wpPreview', + 'name' => 'wpPreview', + 'type' => 'submit', + 'tabindex' => '6', + 'value' => wfMsg('showpreview'), + 'accesskey' => '', + 'title' => wfMsg('tooltip-preview'), + 'style' => 'display: none;', + ); + $buttons['preview'] = wfElement('input', $temp, ''); + $temp = array( + 'id' => 'wpLivePreview', + 'name' => 'wpLivePreview', + 'type' => 'submit', + 'tabindex' => '6', + 'value' => wfMsg('showlivepreview'), + 'accesskey' => wfMsg('accesskey-preview'), + 'title' => '', + 'onclick' => $this->doLivePreviewScript(), + ); + $buttons['live'] = wfElement('input', $temp, ''); + } else { + $temp = array( + 'id' => 'wpPreview', + 'name' => 'wpPreview', + 'type' => 'submit', + 'tabindex' => '6', + 'value' => wfMsg('showpreview'), + 'accesskey' => wfMsg('accesskey-preview'), + 'title' => wfMsg('tooltip-preview'), + ); + $buttons['preview'] = wfElement('input', $temp, ''); + $buttons['live'] = ''; + } + $safemodehtml = $this->checkUnicodeCompliantBrowser() ? "" : "\n"; @@ -892,6 +946,7 @@ class EditPage { enctype="multipart/form-data"> END ); + if( is_callable( $formCallback ) ) { call_user_func_array( $formCallback, array( &$wgOut ) ); } @@ -912,11 +967,9 @@ END . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) ) . " - " ); $wgOut->addWikiText( $copywarn ); - $wgOut->addHTML( " {$metadata} {$editsummary} @@ -924,16 +977,15 @@ END {$safemodehtml} "); - $wgOut->addHTML( " + $wgOut->addHTML("
- - - {$cancel} | {$edithelp}
- -" ); + {$buttons['save']} + {$buttons['preview']} + {$buttons['live']} + {$buttons['diff']} + {$cancel} | {$edithelp} + +"); $wgOut->addWikiText( wfMsgForContent( 'edittools' ) ); @@ -970,12 +1022,18 @@ END . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2 ) ) . "\n" ); } $wgOut->addHTML( "\n" ); - if ( $this->formtype == 'preview' && !$wgUser->getOption( 'previewontop' ) ) { - $this->showPreview(); - } - if ( $this->formtype == 'diff' && !$wgUser->getOption( 'previewontop' ) ) { - #$wgOut->addHTML( '
' . $difftext . '
' ); - $wgOut->addHTML( $this->getDiff() ); + if ( !$wgUser->getOption( 'previewontop' ) ) { + + if ( $this->formtype == 'preview') { + $this->showPreview(); + } else { + $wgOut->addHTML( '
' ); + } + + if ( $this->formtype == 'diff') { + $wgOut->addHTML( $this->getDiff() ); + } + } wfProfileOut( $fname ); @@ -1044,15 +1102,15 @@ END * of the preview button */ function doLivePreviewScript() { - global $wgStylePath, $wgJsMimeType, $wgOut; + global $wgStylePath, $wgJsMimeType, $wgOut, $wgTitle; $wgOut->addHTML( '' . "\n" ); $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' ); - return 'onclick="return !livePreview('. - 'getElementById(\'wikiPreview\'),' . - 'editform.wpTextbox1.value,' . - htmlspecialchars( '"' . $liveAction . '"' ) . ')"'; + return "return !livePreview(" . + "getElementById('wikiPreview')," . + "editform.wpTextbox1.value," . + '"' . $liveAction . '"' . ")"; } function getLastDelete() { @@ -1430,7 +1488,9 @@ END header( 'Content-type: text/xml' ); header( 'Cache-control: no-cache' ); # FIXME - echo $this->getPreviewText( false, false ); + echo $this->getPreviewText( ); + /* To not shake screen up and down between preview and live-preview */ + echo "
\n"; } diff --git a/languages/Messages.php b/languages/Messages.php index 78bd394dab..cd0e8727ec 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -449,6 +449,7 @@ format. Please enter a well-formatted address or empty that field.', 'savearticle' => 'Save page', 'preview' => 'Preview', 'showpreview' => 'Show preview', +'showlivepreview' => 'Live preview', 'showdiff' => 'Show changes', 'anoneditwarning' => 'You are not logged in. Your IP address will be recorded in this page\'s edit history.', 'blockedtitle' => 'User is blocked', diff --git a/skins/common/preview.js b/skins/common/preview.js index 76951856e2..b117e85b7b 100644 --- a/skins/common/preview.js +++ b/skins/common/preview.js @@ -18,7 +18,9 @@ function openXMLHttpRequest() { function livePreview(target, text, postUrl) { prevTarget = target; if( !target ) { - window.alert('crash and burn'); + window.alert('Live preview failed!\nTry normal preview.'); + var fallback = document.getElementById('wpPreview'); + if ( fallback ) { fallback.style.display = 'inline'; } } prevReq = openXMLHttpRequest(); if( !prevReq ) return false; @@ -39,7 +41,13 @@ function updatePreviewText() { if( prevReq.status != 200 ) { window.alert('Failed to connect: ' + prevReq.status + ' "' + prevReq.statusText + '"'); + var fallback = document.getElementById('wpPreview'); + if ( fallback ) { fallback.style.display = 'inline'; } return; } prevTarget.innerHTML = prevReq.responseText; + + /* Hide the active diff if it exists */ + var diff = document.getElementById('wikiDiff'); + if ( diff ) { diff.style.display = 'none'; } } -- 2.20.1