* Fixed and enhanced a little the Live Preview, which had been broken for some time
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 20 Feb 2006 21:18:11 +0000 (21:18 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 20 Feb 2006 21:18:11 +0000 (21:18 +0000)
RELEASE-NOTES
includes/EditPage.php
languages/Messages.php
skins/common/preview.js

index 9bced72..b435f02 100644 (file)
@@ -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 ===
index 128b0e4..f90e135 100644 (file)
@@ -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( '<div id="wikiPreview"></div>' );
+                       }
+
+                       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()
                        ? ""
                        : "<input type='hidden' name=\"safemode\" value='1' />\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 ) ) .
 "
 </textarea>
-
                " );
 
                $wgOut->addWikiText( $copywarn );
-
                $wgOut->addHTML( "
 {$metadata}
 {$editsummary}
@@ -924,16 +977,15 @@ END
 {$safemodehtml}
 ");
 
-               $wgOut->addHTML( "
+               $wgOut->addHTML("
 <div class='editButtons'>
-<input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
-" title=\"".wfMsg('tooltip-save')."\"/>
-<input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
-" title=\"".wfMsg('tooltip-preview')."\"/>
-<input tabindex='7' id='wpDiff' type='submit' value=\"{$diff}\" name=\"wpDiff\" accesskey=\"".wfMsg('accesskey-diff')."\"".
-" title=\"".wfMsg('tooltip-diff')."\"/> <span class='editHelp'>{$cancel} | {$edithelp}</span></div>
-</div>
-" );
+       {$buttons['save']}
+       {$buttons['preview']}
+       {$buttons['live']}
+       {$buttons['diff']}
+       <span class='editHelp'>{$cancel} | {$edithelp}</span>
+</div><!-- editButtons -->
+</div><!-- editOptions -->");
 
                $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
 
@@ -970,12 +1022,18 @@ END
                                . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2 ) ) . "\n</textarea>" );
                }
                $wgOut->addHTML( "</form>\n" );
-               if ( $this->formtype == 'preview' && !$wgUser->getOption( 'previewontop' ) ) {
-                       $this->showPreview();
-               }
-               if ( $this->formtype == 'diff' && !$wgUser->getOption( 'previewontop' ) ) {
-                       #$wgOut->addHTML( '<div id="wikiPreview">' . $difftext . '</div>' );
-                       $wgOut->addHTML( $this->getDiff() );
+               if ( !$wgUser->getOption( 'previewontop' ) ) {
+
+                       if ( $this->formtype == 'preview') {
+                               $this->showPreview();
+                       } else {
+                               $wgOut->addHTML( '<div id="wikiPreview"></div>' );
+                       }
+               
+                       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( '<script type="'.$wgJsMimeType.'" src="' .
                        htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
                        '"></script>' . "\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 "<br style=\"clear:both;\" />\n";
        }
 
 
index 78bd394..cd0e872 100644 (file)
@@ -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',
index 7695185..b117e85 100644 (file)
@@ -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'; }
 }