2013-06-18 22:58:10 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWMediaEditDialog class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-18 22:58:10 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
/*global mw */
|
|
|
|
|
2013-06-18 22:58:10 +00:00
|
|
|
/**
|
Single-click insertion
Objectives:
* Reduce the number of clicks and mouse maneuvers required to insert
media, references or template parameters
* Make use of highlighting with mouse movement or arrow key presses,
similar to menus, to suggest action when clicked
* Improve the way media search results look and feel
Changes:
ve.ui.SelectWidget.js
* Add mouseleave handler to un-highlight when the mouse exits the widget
* Document highlight events (already being emitted)
ve.ui.SearchWidget.js
* Propagate both select and highlight events from results widget
* Make arrow keys change highlight instead of selection
* Get rid of enter event, make enter key select highlighted item instead
* Provide direct access to results widget through getResults method
ve.ui.MenuWidget.js
* Use the selected item as a starting point if nothing is currently
highlighted when adjusting the highlight position
ve.ui.Dialog.js
* Add footless option to hide the foot element and make the body extend
all the way down to the bottom
* Remove applyButton, which only some dialogs need, and should be creating
themselves, along with other buttons as needed
ve.ui.Widget.css
* Change highlight and selected colors of option widgets to match other
selection colors used elsewhere
* Leave selected and highlighted widget looking selected
ve.ui.Frame.css
* Add background color to combat any color that might have been applied to
the frame body in the imported CSS from the parent frame
ve.ui.Dialog.css
* Add rules for footless mode
ve.ui.MWReferenceResultWidget.js,
ve.ui.MWParameterResultWidget.js,
ve.ui.MWMediaResultWidget.js
* Allow highlighting
ve.ui.MWParamterSearchWidget.js
* Switch from selecting the first item when filtering to highlighting
ve-mw/ve.ui.Widget.js
* Adjust media result widget styling to better match other elements
ve.ui.MWTransclusionDialog.js,
ve.ui.MWReferenceListDialog.js,
ve.ui.MWReferenceEditDialog.js,
ve.ui.MWMetaDialog.js
ve.ui.MWMediaEditDialog.js
* Add apply button, as per it being removed from parent class
ve.ui.MWTransclusionDialog.js,
ve.ui.MWReferenceInsertDialog.js,
ve.ui.MWMediaInsertDialog.js
* Insert parameter/reference/media on select, instead of clicking an
insert button
* Use 'insert' instead of 'apply' as argument for close method
Bug: 50774
Bug: 51143
Change-Id: Ia18e79f1f8df2540f465468edb01f5ce989bf843
2013-07-15 21:07:53 +00:00
|
|
|
* Dialog for editing MediaWiki media objects.
|
2013-06-18 22:58:10 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-07-03 01:30:10 +00:00
|
|
|
* @extends ve.ui.MWDialog
|
2013-06-18 22:58:10 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-11-05 00:29:50 +00:00
|
|
|
* @param {ve.ui.WindowSet} windowSet Window set this dialog is part of
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-18 22:58:10 +00:00
|
|
|
*/
|
2013-10-09 19:59:03 +00:00
|
|
|
ve.ui.MWMediaEditDialog = function VeUiMWMediaEditDialog( windowSet, config ) {
|
2013-06-18 22:58:10 +00:00
|
|
|
// Parent constructor
|
2013-10-09 19:59:03 +00:00
|
|
|
ve.ui.MWDialog.call( this, windowSet, config );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Properties
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
this.mediaNode = null;
|
2013-06-18 22:58:10 +00:00
|
|
|
this.captionNode = null;
|
2013-12-21 22:37:54 +00:00
|
|
|
// Cache for image original size, if requested
|
|
|
|
this.mediaSize = {};
|
|
|
|
this.filename = null;
|
|
|
|
// GUI properties
|
|
|
|
this.inputs = {};
|
|
|
|
this.fieldsets = {};
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ui.MWMediaEditDialog, ve.ui.MWDialog );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2013-08-27 23:28:29 +00:00
|
|
|
ve.ui.MWMediaEditDialog.static.name = 'mediaEdit';
|
|
|
|
|
2013-06-18 22:58:10 +00:00
|
|
|
ve.ui.MWMediaEditDialog.static.titleMessage = 'visualeditor-dialog-media-title';
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.icon = 'picture';
|
|
|
|
|
2013-08-09 18:29:09 +00:00
|
|
|
ve.ui.MWMediaEditDialog.static.toolbarGroups = [
|
2013-12-12 19:04:15 +00:00
|
|
|
// History
|
2013-08-27 23:28:29 +00:00
|
|
|
{ 'include': [ 'undo', 'redo' ] },
|
2013-12-12 19:04:15 +00:00
|
|
|
// No formatting
|
|
|
|
/* {
|
|
|
|
'type': 'menu',
|
2014-01-13 22:46:15 +00:00
|
|
|
'indicator': 'down',
|
2013-12-12 19:04:15 +00:00
|
|
|
'include': [ { 'group': 'format' } ],
|
|
|
|
'promote': [ 'paragraph' ],
|
|
|
|
'demote': [ 'preformatted', 'heading1' ]
|
|
|
|
},*/
|
|
|
|
// Style
|
|
|
|
{
|
|
|
|
'type': 'list',
|
|
|
|
'icon': 'text-style',
|
2014-01-13 22:46:15 +00:00
|
|
|
'indicator': 'down',
|
2013-12-12 19:04:15 +00:00
|
|
|
'include': [ { 'group': 'textStyle' }, 'clear' ],
|
|
|
|
'promote': [ 'bold', 'italic' ],
|
|
|
|
'demote': [ 'strikethrough', 'code', 'underline', 'clear' ]
|
|
|
|
},
|
|
|
|
// Link
|
|
|
|
{ 'include': [ 'link' ] },
|
|
|
|
// No structure
|
|
|
|
/* {
|
|
|
|
'type': 'bar',
|
|
|
|
'include': [ 'number', 'bullet', 'outdent', 'indent' ]
|
|
|
|
},*/
|
|
|
|
// Insert
|
2013-09-05 00:32:50 +00:00
|
|
|
{
|
2014-01-13 22:46:15 +00:00
|
|
|
'label': 'visualeditor-toolbar-insert',
|
|
|
|
'indicator': 'down',
|
2013-09-05 00:32:50 +00:00
|
|
|
'include': '*',
|
2013-12-12 19:04:15 +00:00
|
|
|
'exclude': [ { 'group': 'format' }, { 'group': 'structure' }, 'referenceList' ],
|
|
|
|
'demote': [ 'specialcharacter' ]
|
2013-09-05 00:32:50 +00:00
|
|
|
}
|
2013-06-18 22:58:10 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.surfaceCommands = [
|
2013-12-12 19:04:15 +00:00
|
|
|
'undo',
|
|
|
|
'redo',
|
|
|
|
'bold',
|
|
|
|
'italic',
|
|
|
|
'link',
|
|
|
|
'clear',
|
|
|
|
'underline',
|
|
|
|
'subscript',
|
|
|
|
'superscript',
|
|
|
|
'pasteSpecial'
|
2013-06-18 22:58:10 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2013-06-18 22:58:10 +00:00
|
|
|
ve.ui.MWMediaEditDialog.prototype.initialize = function () {
|
2013-06-21 02:47:10 +00:00
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.initialize.call( this );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
// TODO: Create a ve-wide spinner class instead of the local
|
|
|
|
// classes using spinners
|
|
|
|
this.$spinner = this.$( '<div>' ).addClass( 've-specialchar-spinner' );
|
|
|
|
|
|
|
|
// Set up the booklet layout
|
|
|
|
this.bookletLayout = new OO.ui.BookletLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'outlined': true
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.generalSettingsPage = new OO.ui.PageLayout( 'general', {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-page-general' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.advancedSettingsPage = new OO.ui.PageLayout( 'advanced', {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2013-12-21 22:37:54 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-page-advanced' ),
|
|
|
|
'icon': 'parameter'
|
2013-07-18 18:36:43 +00:00
|
|
|
} );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
|
|
|
this.bookletLayout.addPages( [
|
|
|
|
this.generalSettingsPage, this.advancedSettingsPage
|
|
|
|
] );
|
|
|
|
|
|
|
|
// Define fieldsets for image settings
|
|
|
|
|
|
|
|
// Caption
|
|
|
|
this.fieldsets.caption = new OO.ui.FieldsetLayout( {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2013-06-18 22:58:10 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-content-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
2013-12-21 22:37:54 +00:00
|
|
|
|
|
|
|
// Size
|
|
|
|
this.fieldsets.size = new OO.ui.FieldsetLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-size-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.sizeErrorLabel = new OO.ui.InputLabelWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-size-originalsize-error' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.inputs.size = new ve.ui.MediaSizeWidget( {
|
|
|
|
'$': this.$
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.fieldsets.size.$element.append( [
|
|
|
|
this.inputs.size.$element,
|
|
|
|
this.sizeErrorLabel.$element,
|
|
|
|
this.$spinner
|
|
|
|
] );
|
|
|
|
this.sizeErrorLabel.$element.hide();
|
|
|
|
this.$spinner.hide();
|
|
|
|
|
2014-01-17 14:24:12 +00:00
|
|
|
this.applyButton = new OO.ui.ButtonWidget( {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2013-07-18 18:36:43 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-action-apply' ),
|
|
|
|
'flags': ['primary']
|
Single-click insertion
Objectives:
* Reduce the number of clicks and mouse maneuvers required to insert
media, references or template parameters
* Make use of highlighting with mouse movement or arrow key presses,
similar to menus, to suggest action when clicked
* Improve the way media search results look and feel
Changes:
ve.ui.SelectWidget.js
* Add mouseleave handler to un-highlight when the mouse exits the widget
* Document highlight events (already being emitted)
ve.ui.SearchWidget.js
* Propagate both select and highlight events from results widget
* Make arrow keys change highlight instead of selection
* Get rid of enter event, make enter key select highlighted item instead
* Provide direct access to results widget through getResults method
ve.ui.MenuWidget.js
* Use the selected item as a starting point if nothing is currently
highlighted when adjusting the highlight position
ve.ui.Dialog.js
* Add footless option to hide the foot element and make the body extend
all the way down to the bottom
* Remove applyButton, which only some dialogs need, and should be creating
themselves, along with other buttons as needed
ve.ui.Widget.css
* Change highlight and selected colors of option widgets to match other
selection colors used elsewhere
* Leave selected and highlighted widget looking selected
ve.ui.Frame.css
* Add background color to combat any color that might have been applied to
the frame body in the imported CSS from the parent frame
ve.ui.Dialog.css
* Add rules for footless mode
ve.ui.MWReferenceResultWidget.js,
ve.ui.MWParameterResultWidget.js,
ve.ui.MWMediaResultWidget.js
* Allow highlighting
ve.ui.MWParamterSearchWidget.js
* Switch from selecting the first item when filtering to highlighting
ve-mw/ve.ui.Widget.js
* Adjust media result widget styling to better match other elements
ve.ui.MWTransclusionDialog.js,
ve.ui.MWReferenceListDialog.js,
ve.ui.MWReferenceEditDialog.js,
ve.ui.MWMetaDialog.js
ve.ui.MWMediaEditDialog.js
* Add apply button, as per it being removed from parent class
ve.ui.MWTransclusionDialog.js,
ve.ui.MWReferenceInsertDialog.js,
ve.ui.MWMediaInsertDialog.js
* Insert parameter/reference/media on select, instead of clicking an
insert button
* Use 'insert' instead of 'apply' as argument for close method
Bug: 50774
Bug: 51143
Change-Id: Ia18e79f1f8df2540f465468edb01f5ce989bf843
2013-07-15 21:07:53 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Events
|
2013-11-05 00:29:50 +00:00
|
|
|
this.applyButton.connect( this, { 'click': [ 'close', { 'action': 'apply' } ] } );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Initialization
|
2013-12-21 22:37:54 +00:00
|
|
|
this.generalSettingsPage.$element.append( this.fieldsets.caption.$element );
|
|
|
|
this.advancedSettingsPage.$element.append( this.fieldsets.size.$element );
|
|
|
|
|
|
|
|
this.$body.append( this.bookletLayout.$element );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$foot.append( this.applyButton.$element );
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
/**
|
|
|
|
* Get the original size of the media object from the API, if it exists
|
|
|
|
* @returns {jQuery.Promise}
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaEditDialog.prototype.getMediaSize = function () {
|
|
|
|
var rawfilename = this.mediaNode.getAttribute( 'resource' ),
|
|
|
|
deferred = $.Deferred();
|
|
|
|
|
|
|
|
// Strip the raw filename up to the 'File:' namespage
|
|
|
|
this.filename = rawfilename.substring( rawfilename.indexOf( 'File:' ) );
|
|
|
|
|
|
|
|
if ( this.mediaSize && !$.isEmptyObject( this.mediaSize[this.filename] ) ) {
|
|
|
|
// The image size is already cached
|
|
|
|
deferred.resolve( this.mediaSize[this.filename] );
|
|
|
|
} else {
|
|
|
|
// Look for the media size through the API
|
|
|
|
$.ajax( {
|
|
|
|
'url': mw.util.wikiScript( 'api' ),
|
|
|
|
'data': {
|
|
|
|
'action': 'query',
|
|
|
|
'prop': 'imageinfo',
|
|
|
|
'indexpageids': '1',
|
|
|
|
'iiprop': 'size|mediatype',
|
|
|
|
'format': 'json',
|
|
|
|
'titles': this.filename
|
|
|
|
},
|
|
|
|
'dataType': 'json',
|
|
|
|
'type': 'POST',
|
|
|
|
// Wait up to 100 seconds before giving up
|
|
|
|
'timeout': 100000,
|
|
|
|
'cache': false
|
|
|
|
} )
|
|
|
|
.done( function ( resp ) {
|
|
|
|
var imginfo = resp.query.pages[ resp.query.pageids[0] ];
|
|
|
|
|
|
|
|
// Resolve with the size parameters
|
|
|
|
deferred.resolve( {
|
|
|
|
'height': imginfo.imageinfo[0].height,
|
|
|
|
'width': imginfo.imageinfo[0].width,
|
|
|
|
'mediatype': imginfo.imageinfo[0].mediatype
|
|
|
|
} );
|
|
|
|
} )
|
|
|
|
.fail( function () {
|
|
|
|
deferred.resolve( false );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
return deferred.promise();
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaEditDialog.prototype.setup = function ( data ) {
|
2013-12-21 22:37:54 +00:00
|
|
|
var attrs, newDoc,
|
|
|
|
dimensions = {},
|
|
|
|
doc = this.surface.getModel().getDocument();
|
|
|
|
|
2013-06-18 22:58:10 +00:00
|
|
|
// Parent method
|
2013-11-05 00:29:50 +00:00
|
|
|
ve.ui.MWDialog.prototype.setup.call( this, data );
|
|
|
|
|
2013-07-18 18:36:43 +00:00
|
|
|
// Properties
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
this.mediaNode = this.surface.getView().getFocusedNode().getModel();
|
|
|
|
this.captionNode = this.mediaNode.getCaptionNode();
|
2013-06-18 22:58:10 +00:00
|
|
|
if ( this.captionNode && this.captionNode.getLength() > 0 ) {
|
2013-10-03 09:52:21 +00:00
|
|
|
newDoc = doc.cloneFromRange( this.captionNode.getRange() );
|
2013-06-18 22:58:10 +00:00
|
|
|
} else {
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
newDoc = [
|
2013-06-18 22:58:10 +00:00
|
|
|
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': 'internalList' },
|
|
|
|
{ 'type': '/internalList' }
|
2013-06-18 22:58:10 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2013-07-18 18:36:43 +00:00
|
|
|
this.captionSurface = new ve.ui.SurfaceWidget(
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
newDoc,
|
2013-07-18 18:36:43 +00:00
|
|
|
{
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2013-08-09 18:29:09 +00:00
|
|
|
'tools': this.constructor.static.toolbarGroups,
|
2013-07-18 18:36:43 +00:00
|
|
|
'commands': this.constructor.static.surfaceCommands
|
|
|
|
}
|
2013-06-18 22:58:10 +00:00
|
|
|
);
|
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
attrs = this.mediaNode.getAttributes();
|
|
|
|
|
|
|
|
// Show the spinner
|
|
|
|
this.$spinner.show();
|
|
|
|
|
|
|
|
// Save original size for later calculations
|
|
|
|
this.getMediaSize().done( ve.bind( function ( sizeObj ) {
|
|
|
|
if ( sizeObj && sizeObj.width && sizeObj.height ) {
|
|
|
|
// Set the original dimensions in the widget
|
|
|
|
this.inputs.size.setOriginalDimensions( {
|
|
|
|
'width': sizeObj.width,
|
|
|
|
'height': sizeObj.height
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Check if we need to limit the size
|
|
|
|
if ( sizeObj.mediatype === 'BITMAP' ) {
|
|
|
|
// Set the max dimensions
|
|
|
|
this.inputs.size.setMaxDimensions( {
|
|
|
|
'width': sizeObj.width,
|
|
|
|
'height': sizeObj.height
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache the size and mediatype
|
|
|
|
this.mediaSize[this.filename] = {
|
|
|
|
'height': sizeObj.height,
|
|
|
|
'width': sizeObj.width,
|
|
|
|
'mediatype': sizeObj.mediatype
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Original dimensions couldn't be fetched. Display an error message
|
|
|
|
this.sizeErrorLabel.$element.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set initial size in inputs
|
|
|
|
dimensions = {};
|
|
|
|
if ( attrs.height !== undefined && Number( attrs.height ) > 0 ) {
|
|
|
|
dimensions.height = attrs.height;
|
|
|
|
}
|
|
|
|
if ( attrs.width !== undefined && Number( attrs.width ) > 0 ) {
|
|
|
|
dimensions.width = attrs.width;
|
|
|
|
}
|
|
|
|
this.inputs.size.setDimensions( dimensions );
|
|
|
|
|
|
|
|
this.$spinner.hide();
|
|
|
|
}, this ) );
|
|
|
|
|
2013-07-18 18:36:43 +00:00
|
|
|
// Initialization
|
2013-12-21 22:37:54 +00:00
|
|
|
this.fieldsets.caption.$element.append( this.captionSurface.$element );
|
2013-06-18 22:58:10 +00:00
|
|
|
this.captionSurface.initialize();
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaEditDialog.prototype.teardown = function ( data ) {
|
2013-12-21 22:37:54 +00:00
|
|
|
var newDoc, doc, attrs = {},
|
2013-11-05 00:29:50 +00:00
|
|
|
surfaceModel = this.surface.getModel();
|
2013-06-18 22:58:10 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Data initialization
|
|
|
|
data = data || {};
|
2013-06-18 22:58:10 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
if ( data.action === 'apply' ) {
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
newDoc = this.captionSurface.getSurface().getModel().getDocument();
|
2013-06-18 22:58:10 +00:00
|
|
|
doc = surfaceModel.getDocument();
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
if ( !this.captionNode ) {
|
2013-06-18 22:58:10 +00:00
|
|
|
// Insert a new caption at the beginning of the image node
|
|
|
|
surfaceModel.getFragment()
|
|
|
|
.adjustRange( 1 )
|
|
|
|
.collapseRangeToStart()
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
.insertContent( [ { 'type': 'mwImageCaption' }, { 'type': '/mwImageCaption' } ] );
|
|
|
|
this.captionNode = this.mediaNode.getCaptionNode();
|
2013-06-18 22:58:10 +00:00
|
|
|
}
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
// Replace the contents of the caption
|
|
|
|
surfaceModel.change(
|
2013-09-30 13:25:28 +00:00
|
|
|
ve.dm.Transaction.newFromRemoval( doc, this.captionNode.getRange(), true )
|
|
|
|
);
|
|
|
|
surfaceModel.change(
|
|
|
|
ve.dm.Transaction.newFromDocumentInsertion( doc, this.captionNode.getRange().start, newDoc )
|
Introduce newFromDocumentReplace() transaction builder
Replaces newFromNodeReplacement(). newFromNodeReplacement was very
simplistic and didn't support metadata or internal list items, so
if you had comments or references inside of the data you were editing
(reference contents or an image caption), they'd get mangled.
With this, you can do:
newDoc = doc.getDocumentSlice( node );
// Edit newDoc
tx = ve.dm.Transaction.newFromDocumentReplace( doc, node, newDoc );
surface.change( newDoc );
and that takes care of metadata, internal list items, and things like
references that reference internal list items.
ve.dm.Document.js:
* In getDocumentSlice(), store a reference to the original document
and the number of items in its InternalList at the time of slicing
in the created slice. This is used for reconciliation when the
modified slice is injected back into the parent document with
newFromDocumentReplace().
ve.dm.InternalList.js:
* Add a method for merging in another InternalList. This provides a
mapping from old to new InternalList indexes so the linear model data
being injected by newFromDocumentReplace() can have its InternalList
indexes remapped.
ve.dm.Transaction.js:
* Replace newFromNodeReplacement() with newFromDocumentReplace()
ve.ui.MWMediaEditDialog.js, ve.ui.MWReferenceDialog.js:
* Use getDocumentSlice/newFromDocumentReplace for editing captions/refs
* Change insertion code path to insert an empty internalItem/caption, then
newFromDocumentReplace into that
* Add empty internalList to new mini-documents
ve/test/dm/ve.dm.Transaction.test.js:
* Replace newFromNodeReplacement tests with newFromDocumentReplace tests
ve-mw/test/dm/ve.dm.Transaction.test.js (new):
* Add tests for newFromDocumentReplace with mwReference nodes
ve.dm.mwExample.js:
* Add data for newFromDocumentReplace with mwReference tests
VisualEditor.hooks.php:
* Add new test file
Bug: 52102
Change-Id: I4aa980780114b391924f04df588e81c990c32983
2013-09-05 01:05:07 +00:00
|
|
|
);
|
2013-12-21 22:37:54 +00:00
|
|
|
|
|
|
|
// Change attributes only if the values are valid
|
|
|
|
if ( this.inputs.size.isValid() ) {
|
|
|
|
attrs = this.inputs.size.getDimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
surfaceModel.change(
|
|
|
|
ve.dm.Transaction.newFromAttributeChanges( doc, this.mediaNode.getOffset(), attrs )
|
|
|
|
);
|
2013-06-18 22:58:10 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 22:37:54 +00:00
|
|
|
// Clean size values
|
|
|
|
this.inputs.size.clear();
|
|
|
|
|
2013-06-18 22:58:10 +00:00
|
|
|
// Cleanup
|
|
|
|
this.captionSurface.destroy();
|
2013-07-18 18:36:43 +00:00
|
|
|
this.captionSurface = null;
|
|
|
|
this.captionNode = null;
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWDialog.prototype.teardown.call( this, data );
|
2013-06-18 22:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
2013-08-27 23:28:29 +00:00
|
|
|
ve.ui.dialogFactory.register( ve.ui.MWMediaEditDialog );
|