Show wikitext warnings in the reference and media caption dialogs

Bug: 56213
Change-Id: I9da0ae627a990864cc8b9466d97c4419f315f65e
This commit is contained in:
Krenair 2014-06-10 22:19:03 +01:00 committed by Alex Monk
parent 4be0218bbb
commit 046979ae80
3 changed files with 40 additions and 12 deletions

View file

@ -388,7 +388,12 @@ ve.init.mw.ViewPageTarget.prototype.onLoadError = function ( jqXHR, status ) {
ve.init.mw.ViewPageTarget.prototype.onSurfaceReady = function () { ve.init.mw.ViewPageTarget.prototype.onSurfaceReady = function () {
this.activating = false; this.activating = false;
this.surface.getModel().connect( this, { this.surface.getModel().connect( this, {
'documentUpdate': 'checkForWikitextWarning', 'documentUpdate': function () {
this.wikitextWarning = ve.init.mw.ViewPageTarget.static.checkForWikitextWarning(
this.surface,
this.wikitextWarning
);
},
'history': 'updateToolbarSaveButtonState' 'history': 'updateToolbarSaveButtonState'
} ); } );
this.surface.setPasteRules( this.constructor.static.pasteRules ); 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 * This method is bound to the 'documentUpdate' event on the surface model, and unbinds itself when
* the wikitext notification is displayed. * 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 () { ve.init.mw.ViewPageTarget.static.checkForWikitextWarning = function ( surface, wikitextWarning ) {
var text, node, doc = this.surface.getView().getDocument(), var text, node, doc = surface.getView().getDocument(),
selection = this.surface.getModel().getSelection(), selection = surface.getModel().getSelection(),
textMatches, textMatches;
viewPageTarget = this;
if ( !selection ) { if ( !selection ) {
return; return;
} }
@ -791,7 +796,7 @@ ve.init.mw.ViewPageTarget.prototype.checkForWikitextWarning = function () {
text = ve.ce.getDomText( node.$element[0] ); text = ve.ce.getDomText( node.$element[0] );
textMatches = text.match( /\[\[|\{\{|''|<nowiki|<ref|~~~|^==|^\*|^\#/ ); textMatches = text.match( /\[\[|\{\{|''|<nowiki|<ref|~~~|^==|^\*|^\#/ );
if ( textMatches && !this.wikitextWarning ) { if ( textMatches && !wikitextWarning ) {
mw.notify( mw.notify(
$( $.parseHTML( ve.init.platform.getParsedMessage( 'visualeditor-wikitext-warning' ) ) ) $( $.parseHTML( ve.init.platform.getParsedMessage( 'visualeditor-wikitext-warning' ) ) )
.filter( 'a' ).attr( 'target', '_blank' ).end(), .filter( 'a' ).attr( 'target', '_blank' ).end(),
@ -801,12 +806,13 @@ ve.init.mw.ViewPageTarget.prototype.checkForWikitextWarning = function () {
'autoHide': false 'autoHide': false
} }
).done( function ( notif ) { ).done( function ( notif ) {
viewPageTarget.wikitextWarning = notif; wikitextWarning = notif;
} ); } );
} else if ( !textMatches && this.wikitextWarning ) { } else if ( !textMatches && wikitextWarning ) {
this.wikitextWarning.close(); wikitextWarning.close();
this.wikitextWarning = undefined; wikitextWarning = undefined;
} }
return wikitextWarning;
}; };
/** /**

View file

@ -463,6 +463,14 @@ ve.ui.MWMediaEditDialog.prototype.getSetupProcess = function ( data ) {
'pasteRules': this.constructor.static.pasteRules '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 // Size widget
this.$spinner.hide(); this.$spinner.hide();
@ -536,6 +544,9 @@ ve.ui.MWMediaEditDialog.prototype.getTeardownProcess = function ( data ) {
.first( function () { .first( function () {
// Cleanup // Cleanup
this.imageModel.disconnect( this ); this.imageModel.disconnect( this );
if ( this.wikitextWarning ) {
this.wikitextWarning.close();
}
this.captionSurface.destroy(); this.captionSurface.destroy();
this.captionSurface = null; this.captionSurface = null;
this.captionNode = null; this.captionNode = null;

View file

@ -205,6 +205,14 @@ ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) {
// Events // Events
this.referenceModel.getDocument().connect( this, { 'transact': 'onDocumentTransact' } ); 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 // Initialization
this.referenceGroupInput.setValue( this.referenceModel.getGroup() ); 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 ) return ve.ui.MWReferenceDialog.super.prototype.getTeardownProcess.call( this, data )
.first( function () { .first( function () {
this.search.getQuery().setValue( '' ); this.search.getQuery().setValue( '' );
if ( this.wikitextWarning ) {
this.wikitextWarning.close();
}
this.referenceSurface.destroy(); this.referenceSurface.destroy();
this.referenceSurface = null; this.referenceSurface = null;
this.referenceModel = null; this.referenceModel = null;