X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.action%2Fmediawiki.action.edit.preview.js;h=5074d942b735adf4feeef9099d99fd5c5081d87b;hb=23f56a62ea76890325a2bfa85859372c884780a2;hp=3bf8e32b7a43d22e700920addd888dd959d34075;hpb=05dd02d5f9e8063469867a43ae55193ad27bdc69;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js index 3bf8e32b7a..5074d942b7 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js @@ -9,16 +9,28 @@ */ function doLivePreview( e ) { var isDiff, api, request, postData, copySelectors, section, - $wikiPreview, $wikiDiff, $editform, $copyElements, $spinner; - - e.preventDefault(); + $wikiPreview, $wikiDiff, $editform, $textbox, $summary, $copyElements, $spinner, $errorBox; isDiff = ( e.target.name === 'wpDiff' ); $wikiPreview = $( '#wikiPreview' ); $wikiDiff = $( '#wikiDiff' ); $editform = $( '#editform' ); + $textbox = $editform.find( '#wpTextbox1' ); + $summary = $editform.find( '#wpSummary' ); + $errorBox = $( '.errorbox' ); section = $editform.find( '[name="wpSection"]' ).val(); + if ( $textbox.length === 0 ) { + return; + } + // 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(); @@ -61,10 +73,18 @@ action: 'parse', uselang: mw.config.get( 'wgUserLanguage' ), title: mw.config.get( 'wgPageName' ), - text: $editform.find( '#wpTextbox1' ).textSelection( 'getContents' ), - summary: $editform.find( '#wpSummary' ).textSelection( 'getContents' ) + text: $textbox.textSelection( 'getContents' ), + summary: $summary.textSelection( 'getContents' ) }; + if ( section !== '' ) { + postData.sectionpreview = ''; + if ( section === 'new' ) { + postData.section = section; + postData.sectiontitle = postData.summary; + } + } + if ( isDiff ) { $wikiPreview.hide(); @@ -101,15 +121,15 @@ $.extend( postData, { pst: '', preview: '', - prop: 'text|displaytitle|modules|categorieshtml|templates|langlinks|limitreporthtml', + prop: 'text|displaytitle|modules|jsconfigvars|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.jsconfigvars ) { + mw.config.set( response.parse.jsconfigvars ); + } if ( response.parse.modules ) { mw.loader.load( response.parse.modules.concat( response.parse.modulescripts, @@ -117,7 +137,18 @@ 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['*'] ); @@ -136,7 +167,7 @@ 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['*'] ); @@ -179,12 +210,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 @@ -200,6 +232,23 @@ 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 = $( '
' ) + .addClass( 'errorbox' ) + .html( '' + mw.message( 'previewerrortext' ).escaped() + '
' ) + .append( document.createTextNode( errorMsg ) ); + $wikiDiff.hide(); + $wikiPreview.hide().before( $errorBox ); + } ); } $( function () { @@ -230,7 +279,7 @@ } if ( !$( '.mw-summary-preview' ).length ) { - $( '.editCheckboxes' ).before( + $( '#wpSummary' ).after( $( '
' ).addClass( 'mw-summary-preview' ) ); }