Fixes for live preview:
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 26 Sep 2009 08:57:18 +0000 (08:57 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 26 Sep 2009 08:57:18 +0000 (08:57 +0000)
* (bug 3421) Live preview is now disabled on user CSS/JS subpages so that it doesn't break script/style previewing
* The "Live preview" button is now hidden by default rather than "Show preview", this will be switched by JavaScript to not confuse users with JavaScript disabled
* Pass wpEditToken, wpStarttime, wpEdittime in the request so that you don't get "Session lost" when $wgRawHtml is enabled

RELEASE-NOTES
includes/EditPage.php
skins/common/preview.js

index f2935ec..d631789 100644 (file)
@@ -535,6 +535,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 20802) Fixed thumb.php redirect handling
 * (bug 17747) Only display thumbnail column in file history if the image can 
   be rendered.
+* (bug 3421) Live preview no longer breaks user CSS/JS previews
 
 == API changes in 1.16 ==
 
index 794072c..4366a37 100644 (file)
@@ -2299,8 +2299,6 @@ END
         * @return array
         */
        public function getEditButtons(&$tabindex) {
-               global $wgLivePreview, $wgUser;
-
                $buttons = array();
 
                $temp = array(
@@ -2315,7 +2313,7 @@ END
                $buttons['save'] = Xml::element('input', $temp, '');
 
                ++$tabindex; // use the same for preview and live preview
-               if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
+               if ( $this->useLivePreview() ) {
                        $this->doLivePreviewScript(); // Add to output
                        
                        $temp = array(
@@ -2326,7 +2324,6 @@ END
                                'value'     => wfMsg('showpreview'),
                                'accesskey' => '',
                                'title'     => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
-                               'style'     => 'display: none;',
                        );
                        $buttons['preview'] = Xml::element('input', $temp, '');
 
@@ -2338,6 +2335,7 @@ END
                                'value'     => wfMsg('showlivepreview'),
                                'accesskey' => wfMsg('accesskey-preview'),
                                'title'     => '',
+                               'style'     => 'display: none;',
                        );
                        
                        $buttons['live'] = Xml::element('input', $temp, '');
@@ -2370,6 +2368,21 @@ END
                return $buttons;
        }
 
+       /**
+        * Whether to use live preview for this page
+        * This disables live preview when editing css/js user subpages so that the
+        * user can preview them (bug 3421)
+        *
+        * @return Boolean
+        */
+       public function useLivePreview() {
+               global $wgLivePreview, $wgUser;
+
+               return $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) &&
+                       !( ( $this->mTitle->isCssSubpage() && $this->mTitle->userCanEditCssSubpage() ) ||
+                       ( $this->mTitle->isJsSubpage() && $this->mTitle->userCanEditCssSubpage() ) );
+       }
+
        /**
         * Output preview text only. This can be sucked into the edit page
         * via JavaScript, and saves the server time rendering the skin as
index ea88cdc..0ba416d 100644 (file)
@@ -4,15 +4,23 @@
 
 function setupLivePreview() {
        var livePreviewButton = $j('#wpLivePreview');
-       
+
+       $j('#wpPreview').hide();
+       livePreviewButton.show();
+
        livePreviewButton.click( doLivePreview );
 }
 
 function doLivePreview( e ) {
        e.preventDefault();
        var previewText = $j('#wpTextbox1').val();
+
+       var editToken = $j( '[name="wpEditToken"]' ).attr( 'value' );
+       var editTime = $j( '[name="wpEdittime"]' ).attr( 'value' );
+       var startTime = $j( '[name="wpStarttime"]' ).attr( 'value' );
+
        var postData = { 'action' : 'submit', 'wpTextbox1' : previewText, 'wpPreview' : true,
-                                               'title' : wgPageName };
+               'wpEditToken' : editToken, 'wpEdittime': editTime, 'wpStarttime': startTime, 'title' : wgPageName };
        
        // Hide active diff, used templates, old preview if shown
        $j('#wikiDiff').slideUp();