Merge "Revert "mediawiki.action.edit.preview: Disable if there is no #wpTextbox1""
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 26 Mar 2015 23:26:14 +0000 (23:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 26 Mar 2015 23:26:14 +0000 (23:26 +0000)
1  2 
resources/src/mediawiki.action/mediawiki.action.edit.preview.js

@@@ -9,23 -9,16 +9,23 @@@
         */
        function doLivePreview( e ) {
                var isDiff, api, request, postData, copySelectors, section,
 -                      $wikiPreview, $wikiDiff, $editform, $copyElements, $spinner;
 -
 -              e.preventDefault();
 +                      $wikiPreview, $wikiDiff, $editform, $copyElements, $spinner, $errorBox;
  
                isDiff = ( e.target.name === 'wpDiff' );
                $wikiPreview = $( '#wikiPreview' );
                $wikiDiff = $( '#wikiDiff' );
                $editform = $( '#editform' );
 +              $errorBox = $( '.errorbox' );
                section = $editform.find( '[name="wpSection"]' ).val();
  
 +              // Show changes for a new section is not yet supported
 +              if ( isDiff && section === 'new' ) {
 +                      return;
 +              }
 +              e.preventDefault();
 +
 +              // Remove any previously displayed errors
 +              $errorBox.remove();
                // 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;
 +                              var li, newList, $displaytitle, $content, $parent, $list;
                                if ( response.parse.modules ) {
                                        mw.loader.load( response.parse.modules.concat(
                                                response.parse.modulescripts,
                                                response.parse.modulemessages ) );
                                }
                                if ( response.parse.displaytitle ) {
 -                                      $( '#firstHeading' ).html( response.parse.displaytitle );
 +                                      $displaytitle = $( $.parseHTML( response.parse.displaytitle ) );
 +                                      $( '#firstHeading' ).msg(
 +                                              mw.config.get( 'wgEditMessage', 'editing' ),
 +                                              $displaytitle
 +                                      );
 +                                      document.title = mw.msg(
 +                                              'pagetitle',
 +                                              mw.msg(
 +                                                      mw.config.get( 'wgEditMessage', 'editing' ),
 +                                                      $displaytitle.text()
 +                                              )
 +                                      );
                                }
                                if ( response.parse.categorieshtml ) {
                                        $( '#catlinks' ).replaceWith( response.parse.categorieshtml['*'] );
                                                newList.push( li );
                                        } );
  
 -                                      $editform.find( '.mw-editfooter-list' ).detach().empty().append( newList ).appendTo( '.templatesUsed' );
 +                                      $editform.find( '.templatesUsed .mw-editfooter-list' ).detach().empty().append( newList ).appendTo( '.templatesUsed' );
                                }
                                if ( response.parse.limitreporthtml ) {
                                        $( '.limitreport' ).html( response.parse.limitreporthtml['*'] );
                        } );
                }
                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
                                opacity: 1
                        }, 'fast' );
                } );
 +              request.fail( function ( code, result ) {
 +                      var errorMsg = 'API error: ' +  code;
 +                      if ( code === 'http' ) {
 +                              errorMsg = 'HTTP error: ';
 +                              if ( result.exception ) {
 +                                      errorMsg += result.exception;
 +                              } else {
 +                                      errorMsg += result.textStatus;
 +                              }
 +                      }
 +                      $errorBox = $( '<div>' )
 +                              .addClass( 'errorbox' )
 +                              .html( '<strong>' + mw.message( 'previewerrortext' ).escaped() + '</strong><br>' )
 +                              .append( document.createTextNode( errorMsg ) );
 +                      $wikiDiff.hide();
 +                      $wikiPreview.hide().before( $errorBox );
 +              } );
        }
  
        $( function () {
                // Do not enable on user .js/.css pages, as there's no sane way of "previewing"
                // the scripts or styles without reloading the page.
-               // Do not enable for ProofreadPage Index page editors, which have no textbox
-               if ( $( '#mw-userjsyoucanpreview' ).length || $( '#mw-usercssyoucanpreview' ).length || $( '#wpTextbox1' ).length === 0 ) {
+               if ( $( '#mw-userjsyoucanpreview' ).length || $( '#mw-usercssyoucanpreview' ).length ) {
                        return;
                }
  
                }
  
                if ( !$( '.mw-summary-preview' ).length ) {
 -                      $( '.editCheckboxes' ).before(
 +                      $( '#wpSummary' ).after(
                                $( '<div>' ).addClass( 'mw-summary-preview' )
                        );
                }