mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-26 19:56:49 +00:00
Show wikitext warnings in the reference and media caption dialogs
Bug: 56213 Change-Id: I9da0ae627a990864cc8b9466d97c4419f315f65e
This commit is contained in:
parent
4be0218bbb
commit
046979ae80
|
@ -388,7 +388,12 @@ ve.init.mw.ViewPageTarget.prototype.onLoadError = function ( jqXHR, status ) {
|
|||
ve.init.mw.ViewPageTarget.prototype.onSurfaceReady = function () {
|
||||
this.activating = false;
|
||||
this.surface.getModel().connect( this, {
|
||||
'documentUpdate': 'checkForWikitextWarning',
|
||||
'documentUpdate': function () {
|
||||
this.wikitextWarning = ve.init.mw.ViewPageTarget.static.checkForWikitextWarning(
|
||||
this.surface,
|
||||
this.wikitextWarning
|
||||
);
|
||||
},
|
||||
'history': 'updateToolbarSaveButtonState'
|
||||
} );
|
||||
this.surface.setPasteRules( this.constructor.static.pasteRules );
|
||||
|
@ -774,13 +779,13 @@ ve.init.mw.ViewPageTarget.prototype.onToolbarMetaButtonClick = function () {
|
|||
* This method is bound to the 'documentUpdate' event on the surface model, and unbinds itself when
|
||||
* the wikitext notification is displayed.
|
||||
*
|
||||
* @param {ve.dm.Transaction} transaction
|
||||
* @param {ve.ui.Surface} surface
|
||||
* @param {Object} [wikitextWarning] MediaWiki notification object
|
||||
*/
|
||||
ve.init.mw.ViewPageTarget.prototype.checkForWikitextWarning = function () {
|
||||
var text, node, doc = this.surface.getView().getDocument(),
|
||||
selection = this.surface.getModel().getSelection(),
|
||||
textMatches,
|
||||
viewPageTarget = this;
|
||||
ve.init.mw.ViewPageTarget.static.checkForWikitextWarning = function ( surface, wikitextWarning ) {
|
||||
var text, node, doc = surface.getView().getDocument(),
|
||||
selection = surface.getModel().getSelection(),
|
||||
textMatches;
|
||||
if ( !selection ) {
|
||||
return;
|
||||
}
|
||||
|
@ -791,7 +796,7 @@ ve.init.mw.ViewPageTarget.prototype.checkForWikitextWarning = function () {
|
|||
text = ve.ce.getDomText( node.$element[0] );
|
||||
textMatches = text.match( /\[\[|\{\{|''|<nowiki|<ref|~~~|^==|^\*|^\#/ );
|
||||
|
||||
if ( textMatches && !this.wikitextWarning ) {
|
||||
if ( textMatches && !wikitextWarning ) {
|
||||
mw.notify(
|
||||
$( $.parseHTML( ve.init.platform.getParsedMessage( 'visualeditor-wikitext-warning' ) ) )
|
||||
.filter( 'a' ).attr( 'target', '_blank' ).end(),
|
||||
|
@ -801,12 +806,13 @@ ve.init.mw.ViewPageTarget.prototype.checkForWikitextWarning = function () {
|
|||
'autoHide': false
|
||||
}
|
||||
).done( function ( notif ) {
|
||||
viewPageTarget.wikitextWarning = notif;
|
||||
wikitextWarning = notif;
|
||||
} );
|
||||
} else if ( !textMatches && this.wikitextWarning ) {
|
||||
this.wikitextWarning.close();
|
||||
this.wikitextWarning = undefined;
|
||||
} else if ( !textMatches && wikitextWarning ) {
|
||||
wikitextWarning.close();
|
||||
wikitextWarning = undefined;
|
||||
}
|
||||
return wikitextWarning;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -463,6 +463,14 @@ ve.ui.MWMediaEditDialog.prototype.getSetupProcess = function ( data ) {
|
|||
'pasteRules': this.constructor.static.pasteRules
|
||||
}
|
||||
);
|
||||
this.captionSurface.getSurface().getModel().connect( this, {
|
||||
'documentUpdate': function () {
|
||||
this.wikitextWarning = ve.init.mw.ViewPageTarget.static.checkForWikitextWarning(
|
||||
this.captionSurface.getSurface(),
|
||||
this.wikitextWarning
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
// Size widget
|
||||
this.$spinner.hide();
|
||||
|
@ -536,6 +544,9 @@ ve.ui.MWMediaEditDialog.prototype.getTeardownProcess = function ( data ) {
|
|||
.first( function () {
|
||||
// Cleanup
|
||||
this.imageModel.disconnect( this );
|
||||
if ( this.wikitextWarning ) {
|
||||
this.wikitextWarning.close();
|
||||
}
|
||||
this.captionSurface.destroy();
|
||||
this.captionSurface = null;
|
||||
this.captionNode = null;
|
||||
|
|
|
@ -205,6 +205,14 @@ ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) {
|
|||
|
||||
// Events
|
||||
this.referenceModel.getDocument().connect( this, { 'transact': 'onDocumentTransact' } );
|
||||
this.referenceSurface.getSurface().getModel().connect( this, {
|
||||
'documentUpdate': function () {
|
||||
this.wikitextWarning = ve.init.mw.ViewPageTarget.static.checkForWikitextWarning(
|
||||
this.referenceSurface.getSurface(),
|
||||
this.wikitextWarning
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
// Initialization
|
||||
this.referenceGroupInput.setValue( this.referenceModel.getGroup() );
|
||||
|
@ -361,6 +369,9 @@ ve.ui.MWReferenceDialog.prototype.getTeardownProcess = function ( data ) {
|
|||
return ve.ui.MWReferenceDialog.super.prototype.getTeardownProcess.call( this, data )
|
||||
.first( function () {
|
||||
this.search.getQuery().setValue( '' );
|
||||
if ( this.wikitextWarning ) {
|
||||
this.wikitextWarning.close();
|
||||
}
|
||||
this.referenceSurface.destroy();
|
||||
this.referenceSurface = null;
|
||||
this.referenceModel = null;
|
||||
|
|
Loading…
Reference in a new issue