r56939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56938‎ | r56939 | r56940 >
Date:08:57, 26 September 2009
Author:ialex
Status:deferred
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/skins/common/preview.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/preview.js
@@ -4,15 +4,23 @@
55
66 function setupLivePreview() {
77 var livePreviewButton = $j('#wpLivePreview');
8 -
 8+
 9+ $j('#wpPreview').hide();
 10+ livePreviewButton.show();
 11+
912 livePreviewButton.click( doLivePreview );
1013 }
1114
1215 function doLivePreview( e ) {
1316 e.preventDefault();
1417 var previewText = $j('#wpTextbox1').val();
 18+
 19+ var editToken = $j( '[name="wpEditToken"]' ).attr( 'value' );
 20+ var editTime = $j( '[name="wpEdittime"]' ).attr( 'value' );
 21+ var startTime = $j( '[name="wpStarttime"]' ).attr( 'value' );
 22+
1523 var postData = { 'action' : 'submit', 'wpTextbox1' : previewText, 'wpPreview' : true,
16 - 'title' : wgPageName };
 24+ 'wpEditToken' : editToken, 'wpEdittime': editTime, 'wpStarttime': startTime, 'title' : wgPageName };
1725
1826 // Hide active diff, used templates, old preview if shown
1927 $j('#wikiDiff').slideUp();
Index: trunk/phase3/includes/EditPage.php
@@ -2299,8 +2299,6 @@
23002300 * @return array
23012301 */
23022302 public function getEditButtons(&$tabindex) {
2303 - global $wgLivePreview, $wgUser;
2304 -
23052303 $buttons = array();
23062304
23072305 $temp = array(
@@ -2315,7 +2313,7 @@
23162314 $buttons['save'] = Xml::element('input', $temp, '');
23172315
23182316 ++$tabindex; // use the same for preview and live preview
2319 - if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
 2317+ if ( $this->useLivePreview() ) {
23202318 $this->doLivePreviewScript(); // Add to output
23212319
23222320 $temp = array(
@@ -2326,7 +2324,6 @@
23272325 'value' => wfMsg('showpreview'),
23282326 'accesskey' => '',
23292327 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2330 - 'style' => 'display: none;',
23312328 );
23322329 $buttons['preview'] = Xml::element('input', $temp, '');
23332330
@@ -2338,6 +2335,7 @@
23392336 'value' => wfMsg('showlivepreview'),
23402337 'accesskey' => wfMsg('accesskey-preview'),
23412338 'title' => '',
 2339+ 'style' => 'display: none;',
23422340 );
23432341
23442342 $buttons['live'] = Xml::element('input', $temp, '');
@@ -2371,6 +2369,21 @@
23722370 }
23732371
23742372 /**
 2373+ * Whether to use live preview for this page
 2374+ * This disables live preview when editing css/js user subpages so that the
 2375+ * user can preview them (bug 3421)
 2376+ *
 2377+ * @return Boolean
 2378+ */
 2379+ public function useLivePreview() {
 2380+ global $wgLivePreview, $wgUser;
 2381+
 2382+ return $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) &&
 2383+ !( ( $this->mTitle->isCssSubpage() && $this->mTitle->userCanEditCssSubpage() ) ||
 2384+ ( $this->mTitle->isJsSubpage() && $this->mTitle->userCanEditCssSubpage() ) );
 2385+ }
 2386+
 2387+ /**
23752388 * Output preview text only. This can be sucked into the edit page
23762389 * via JavaScript, and saves the server time rendering the skin as
23772390 * well as theoretically being more robust on the client (doesn't
Index: trunk/phase3/RELEASE-NOTES
@@ -535,6 +535,7 @@
536536 * (bug 20802) Fixed thumb.php redirect handling
537537 * (bug 17747) Only display thumbnail column in file history if the image can
538538 be rendered.
 539+* (bug 3421) Live preview no longer breaks user CSS/JS previews
539540
540541 == API changes in 1.16 ==
541542

Status & tagging log