mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-24 00:06:49 +00:00
Small side-by-side preview improvements
- load jsconfigvars - trigger the hooks for wikipage.content and wikipage.diff - rvdifftotextpst for diffs - improve section support This module is not used within WMF, but has some users amongst 3rd parties. Change-Id: I7f0b2de4a984d811ccd94149670390929a6182f6
This commit is contained in:
parent
e2cf07f2f3
commit
6627f2cd94
|
@ -60,26 +60,36 @@ $.wikiEditor.modules.preview = {
|
|||
action: 'parse',
|
||||
title: mw.config.get( 'wgPageName' ),
|
||||
text: wikitext,
|
||||
prop: 'text|modules',
|
||||
pst: ''
|
||||
pst: '',
|
||||
prop: 'text|modules|jsconfigvars',
|
||||
preview: true,
|
||||
disableeditsection: true,
|
||||
uselang: mw.config.get( 'wgUserLanguage' )
|
||||
} ).done( function ( data ) {
|
||||
if ( !data.parse || !data.parse.text ) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.modules.preview.previewText = wikitext;
|
||||
context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide();
|
||||
context.modules.preview.$preview.find( '.wikiEditor-preview-contents' )
|
||||
.html( data.parse.text )
|
||||
.append( '<div class="visualClear"></div>' )
|
||||
.find( 'a:not([href^=#])' )
|
||||
.click( false );
|
||||
|
||||
if ( data.parse.jsconfigvars ) {
|
||||
mw.config.set( data.parse.jsconfigvars );
|
||||
}
|
||||
var loadmodules = data.parse.modules.concat(
|
||||
data.parse.modulescripts,
|
||||
data.parse.modulestyles
|
||||
);
|
||||
mw.loader.load( loadmodules );
|
||||
|
||||
context.modules.preview.previewText = wikitext;
|
||||
context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide();
|
||||
var $content = context.modules.preview.$preview.find( '.wikiEditor-preview-contents' )
|
||||
.detach()
|
||||
.html( data.parse.text );
|
||||
$content.append( '<div class="visualClear"></div>' )
|
||||
.find( 'a:not([href^=#])' )
|
||||
.click( false );
|
||||
|
||||
mw.hook( 'wikipage.content' ).fire( $content );
|
||||
context.modules.preview.$preview.append( $content );
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
@ -97,48 +107,34 @@ $.wikiEditor.modules.preview = {
|
|||
context.$changesTab.find( 'table.diff tbody' ).empty();
|
||||
context.$changesTab.find( '.wikiEditor-preview-loading' ).show();
|
||||
|
||||
// Call the API. First PST the input, then diff it
|
||||
api.post( {
|
||||
var section = $( '[name="wpSection"]' ).val();
|
||||
var postdata = {
|
||||
formatversion: 2,
|
||||
action: 'parse',
|
||||
title: mw.config.get( 'wgPageName' ),
|
||||
onlypst: '',
|
||||
text: wikitext
|
||||
} ).done( function ( data ) {
|
||||
action: 'query',
|
||||
prop: 'revisions',
|
||||
titles: mw.config.get( 'wgPageName' ),
|
||||
rvdifftotext: wikitext,
|
||||
rvdifftotextpst: true,
|
||||
rvprop: '',
|
||||
rvsection: section === '' ? undefined : section
|
||||
};
|
||||
|
||||
api.post( postdata )
|
||||
.done( function ( data ) {
|
||||
try {
|
||||
var postdata2 = {
|
||||
formatversion: 2,
|
||||
action: 'query',
|
||||
prop: 'revisions',
|
||||
titles: mw.config.get( 'wgPageName' ),
|
||||
rvdifftotext: data.parse.text,
|
||||
rvprop: ''
|
||||
};
|
||||
var section = $( '[name="wpSection"]' ).val();
|
||||
if ( section !== '' ) {
|
||||
postdata2.rvsection = section;
|
||||
}
|
||||
var diff = data.query.pages[ 0 ]
|
||||
.revisions[ 0 ].diff.body;
|
||||
|
||||
api.post( postdata2 )
|
||||
.done( function ( data ) {
|
||||
// Add diff CSS
|
||||
mw.loader.load( 'mediawiki.action.history.diff' );
|
||||
try {
|
||||
var diff = data.query.pages[ 0 ]
|
||||
.revisions[ 0 ].diff.body;
|
||||
|
||||
context.$changesTab.find( 'table.diff tbody' )
|
||||
.html( diff )
|
||||
.append( '<div class="visualClear"></div>' );
|
||||
context.modules.preview.changesText = wikitext;
|
||||
} catch ( e ) {
|
||||
// "data.blah is undefined" error, ignore
|
||||
}
|
||||
context.$changesTab.find( '.wikiEditor-preview-loading' ).hide();
|
||||
} );
|
||||
context.$changesTab.find( 'table.diff tbody' )
|
||||
.html( diff )
|
||||
.append( '<div class="visualClear"></div>' );
|
||||
mw.hook( 'wikipage.diff' )
|
||||
.fire( context.$changesTab.find( 'table.diff' ) );
|
||||
context.modules.preview.changesText = wikitext;
|
||||
} catch ( e ) {
|
||||
// "data.blah is undefined" error, ignore
|
||||
}
|
||||
context.$changesTab.find( '.wikiEditor-preview-loading' ).hide();
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue