From 83d7e6137329d24cb1f895865d83151d60313f17 Mon Sep 17 00:00:00 2001
From: Andrew Garrett
Date: Tue, 9 Feb 2010 07:39:09 +0000
Subject: [PATCH] Reverse removal of Live Preview in r59446, with the following
changes: * Make Live Preview entirely JS-based. It requires no modification
of the HTML. * Replace annoying slideDown with less annoying fadeIn(). *
Ensure that elements not supposed to be shown are not, in fact, shown by
fadeIn(). * Remove some redundant lines of code. * Make compatible with the
current jQuery usage in MediaWiki.
---
includes/EditPage.php | 7 +++++-
includes/Preferences.php | 10 +++++++-
skins/common/preview.js | 52 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 2 deletions(-)
create mode 100644 skins/common/preview.js
diff --git a/includes/EditPage.php b/includes/EditPage.php
index b0f90fe70c..e3bd3a4fbd 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -364,7 +364,7 @@ class EditPage {
* the newly-edited page.
*/
function edit() {
- global $wgOut, $wgRequest;
+ global $wgOut, $wgRequest, $wgUser;
// Allow extensions to modify/prevent this form or submission
if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
return;
@@ -392,6 +392,11 @@ class EditPage {
}
$wgOut->addScriptFile( 'edit.js' );
+
+ if ( $wgUser->getOption( 'uselivepreview', false ) ) {
+ $wgOut->includeJQuery();
+ $wgOut->addScriptFile( 'preview.js' );
+ }
$permErrors = $this->getEditPermissionErrors();
if ( $permErrors ) {
diff --git a/includes/Preferences.php b/includes/Preferences.php
index a701125720..2137f9d861 100644
--- a/includes/Preferences.php
+++ b/includes/Preferences.php
@@ -637,7 +637,7 @@ class Preferences {
}
static function editingPreferences( $user, &$defaultPreferences ) {
- global $wgUseExternalEditor;
+ global $wgUseExternalEditor, $wgLivePreview;
## Editing #####################################
$defaultPreferences['cols'] =
@@ -739,6 +739,14 @@ class Preferences {
'section' => 'editing/advancedediting',
'label-message' => 'tog-forceeditsummary',
);
+ if ( $wgLivePreview ) {
+ $defaultPreferences['uselivepreview'] =
+ array(
+ 'type' => 'toggle',
+ 'section' => 'editing/advancedediting',
+ 'label-message' => 'tog-uselivepreview',
+ );
+ }
}
static function rcPreferences( $user, &$defaultPreferences ) {
diff --git a/skins/common/preview.js b/skins/common/preview.js
new file mode 100644
index 0000000000..44769033f4
--- /dev/null
+++ b/skins/common/preview.js
@@ -0,0 +1,52 @@
+/**
+ * Live preview script for MediaWiki
+ */
+
+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,
+ 'wpEditToken' : editToken, 'wpEdittime': editTime, 'wpStarttime': startTime, 'title' : wgPageName };
+
+ // Hide active diff, used templates, old preview if shown
+ var copyElements = ['#wikiPreview', '.templatesUsed', '.hiddencats',
+ '#catlinks'];
+
+ $j.each( copyElements, function(k,v) { $j(v).fadeOut(); } );
+
+ // Display a loading graphic
+ var loadSpinner = $j('');
+ $j('#wikiPreview').before( loadSpinner );
+
+ var page = $j('');
+ page.load( wgScript+'?action=submit',
+ postData,
+ function() {
+
+ for( var i=0; i