* @return array
*/
public function getEditButtons(&$tabindex) {
- global $wgLivePreview, $wgUser;
-
$buttons = array();
$temp = array(
$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(
'value' => wfMsg('showpreview'),
'accesskey' => '',
'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
- 'style' => 'display: none;',
);
$buttons['preview'] = Xml::element('input', $temp, '');
'value' => wfMsg('showlivepreview'),
'accesskey' => wfMsg('accesskey-preview'),
'title' => '',
+ 'style' => 'display: none;',
);
$buttons['live'] = Xml::element('input', $temp, '');
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
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();