LivePreview: Support section=new for preview
authorDerk-Jan Hartman <hartman.wiki@gmail.com>
Thu, 12 Mar 2015 21:28:28 +0000 (22:28 +0100)
committerTheDJ <hartman.wiki@gmail.com>
Wed, 25 Mar 2015 19:51:38 +0000 (19:51 +0000)
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
resources/src/mediawiki.action/mediawiki.action.edit.preview.js

index 2b12c7a..69a6ff7 100644 (file)
@@ -1095,6 +1095,7 @@ return array(
                        'otherlanguages',
                        'tooltip-p-lang',
                        'summary-preview',
+                       'subject-preview',
                        'parentheses',
                ),
        ),
index 4c6ca12..c86f7c5 100644 (file)
                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();
                        summary: $editform.find( '#wpSummary' ).textSelection( 'getContents' )
                };
 
+               if ( section !== '' ) {
+                       postData.sectionpreview = '';
+                       if ( section === 'new' ) {
+                               postData.section = section;
+                               postData.sectiontitle = postData.summary;
+                       }
+               }
+
                if ( isDiff ) {
                        $wikiPreview.hide();
 
                                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;
                        } );
                }
                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(),
                                                ' ',
                                                $( '<span>' ).addClass( 'comment' ).html(
                                                        // There is no equivalent to rawParams
                }
 
                if ( !$( '.mw-summary-preview' ).length ) {
-                       $( '.editCheckboxes' ).before(
+                       $( '#wpSummary' ).after(
                                $( '<div>' ).addClass( 'mw-summary-preview' )
                        );
                }