From a26ea0bf8283c4fd9ecff990bef9bf2b63ec0d26 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Thu, 12 Mar 2015 22:28:28 +0100 Subject: [PATCH] LivePreview: Support section=new for preview Reproduce the new section behavior for the full submit preview. Diffing will require a bit more additional work in Api. Bug: T84877 Change-Id: Iec71fdc7ba09f91683214f3d65472ea2f72a06b1 --- resources/Resources.php | 1 + .../mediawiki.action.edit.preview.js | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index 2b12c7a6d3..69a6ff7149 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1095,6 +1095,7 @@ return array( 'otherlanguages', 'tooltip-p-lang', 'summary-preview', + 'subject-preview', 'parentheses', ), ), diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js index 4c6ca12ba1..c86f7c5255 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js @@ -11,14 +11,18 @@ var isDiff, api, request, postData, copySelectors, section, $wikiPreview, $wikiDiff, $editform, $copyElements, $spinner; - e.preventDefault(); - isDiff = ( e.target.name === 'wpDiff' ); $wikiPreview = $( '#wikiPreview' ); $wikiDiff = $( '#wikiDiff' ); $editform = $( '#editform' ); section = $editform.find( '[name="wpSection"]' ).val(); + // Show changes for a new section is not yet supported + if ( isDiff && section === 'new' ) { + return; + } + e.preventDefault(); + // Show #wikiPreview if it's hidden to be able to scroll to it // (if it is hidden, it's also empty, so nothing changes in the rendering) $wikiPreview.show(); @@ -65,6 +69,14 @@ summary: $editform.find( '#wpSummary' ).textSelection( 'getContents' ) }; + if ( section !== '' ) { + postData.sectionpreview = ''; + if ( section === 'new' ) { + postData.section = section; + postData.sectiontitle = postData.summary; + } + } + if ( isDiff ) { $wikiPreview.hide(); @@ -104,9 +116,6 @@ prop: 'text|displaytitle|modules|categorieshtml|templates|langlinks|limitreporthtml', disableeditsection: true } ); - if ( section !== '' ) { - postData.sectionpreview = ''; - } request = api.post( postData ); request.done( function ( response ) { var li, newList, $content, $parent, $list; @@ -186,12 +195,13 @@ } ); } request.done( function ( response ) { + var isSubject = ( section === 'new' ), + summaryMsg = isSubject ? 'subject-preview' : 'summary-preview'; if ( response.parse.parsedsummary ) { - // TODO implement special behavior for section === 'new' $editform.find( '.mw-summary-preview' ) .empty() .append( - mw.message( 'summary-preview' ).parse(), + mw.message( summaryMsg ).parse(), ' ', $( '' ).addClass( 'comment' ).html( // There is no equivalent to rawParams @@ -238,7 +248,7 @@ } if ( !$( '.mw-summary-preview' ).length ) { - $( '.editCheckboxes' ).before( + $( '#wpSummary' ).after( $( '
' ).addClass( 'mw-summary-preview' ) ); } -- 2.20.1