From d5fbf478a871618004dcbef2fe12ff04452fb943 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 26 Sep 2009 08:57:18 +0000 Subject: [PATCH] Fixes for live preview: * (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 | 1 + includes/EditPage.php | 21 +++++++++++++++++---- skins/common/preview.js | 12 ++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f2935ec53a..d631789517 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/EditPage.php b/includes/EditPage.php index 794072ca73..4366a37952 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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 diff --git a/skins/common/preview.js b/skins/common/preview.js index ea88cdc389..0ba416d8ac 100644 --- a/skins/common/preview.js +++ b/skins/common/preview.js @@ -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(); -- 2.20.1