2013-12-02 20:10:55 +00:00
|
|
|
/*
|
2013-06-11 19:16:04 +00:00
|
|
|
* VisualEditor user interface MWTransclusionDialog class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-11 19:16:04 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
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 inserting and editing MediaWiki transclusions.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-07-03 01:30:10 +00:00
|
|
|
* @extends ve.ui.MWDialog
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
* @param {ve.ui.Surface} surface Surface dialog is for
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-03-06 01:07:20 +00:00
|
|
|
ve.ui.MWTransclusionDialog = function VeUiMWTransclusionDialog( surface, config ) {
|
2013-06-11 19:16:04 +00:00
|
|
|
// Parent constructor
|
2014-03-06 01:07:20 +00:00
|
|
|
ve.ui.MWDialog.call( this, surface, config );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Properties
|
2014-04-01 23:15:47 +00:00
|
|
|
this.transclusionNode = null;
|
2013-06-11 19:16:04 +00:00
|
|
|
this.transclusion = null;
|
2013-12-02 20:10:55 +00:00
|
|
|
this.loaded = false;
|
2014-02-28 00:06:34 +00:00
|
|
|
this.preventReselection = false;
|
2014-03-04 22:56:14 +00:00
|
|
|
this.mode = null;
|
2014-03-06 23:39:40 +00:00
|
|
|
this.inserting = false;
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionDialog, ve.ui.MWDialog );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Static Properties */
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.name = 'transclusion';
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.icon = 'template';
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-dialog-transclusion-title' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map of symbolic mode names and CSS classes.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {Object}
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.static.modeCssClasses = {
|
|
|
|
'single': 've-ui-mwTransclusionDialog-single',
|
|
|
|
'multiple': 've-ui-mwTransclusionDialog-multiple'
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* Handle outline controls move events.
|
|
|
|
*
|
|
|
|
* @param {number} places Number of places to move the selected item
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsMove = function ( places ) {
|
|
|
|
var part, promise,
|
|
|
|
parts = this.transclusion.getParts(),
|
|
|
|
item = this.bookletLayout.getOutline().getSelectedItem();
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
part = this.transclusion.getPartFromId( item.getData() );
|
|
|
|
// Move part to new location, and if dialog is loaded switch to new part page
|
|
|
|
promise = this.transclusion.addPart( part, ve.indexOf( part, parts ) + places );
|
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
|
|
|
promise.done( ve.bind( this.setPageByName, this, part.getId() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle outline controls remove events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsRemove = function () {
|
|
|
|
var id, part, param,
|
|
|
|
item = this.bookletLayout.getOutline().getSelectedItem();
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
id = item.getData();
|
|
|
|
part = this.transclusion.getPartFromId( id );
|
|
|
|
// Check if the part is the actual template, or one of its parameters
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel && id !== part.getId() ) {
|
|
|
|
param = part.getParameterFromId( id );
|
|
|
|
if ( param instanceof ve.dm.MWParameterModel ) {
|
|
|
|
part.removeParameter( param );
|
|
|
|
}
|
|
|
|
} else if ( part instanceof ve.dm.MWTransclusionPartModel ) {
|
|
|
|
this.transclusion.removePart( part );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add template button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddTemplateButtonClick = function () {
|
|
|
|
this.addPart( new ve.dm.MWTemplatePlaceholderModel( this.transclusion ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add content button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddContentButtonClick = function () {
|
|
|
|
this.addPart( new ve.dm.MWTransclusionContentModel( this.transclusion, '' ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add parameter button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddParameterButtonClick = function () {
|
|
|
|
var part, param,
|
|
|
|
item = this.bookletLayout.getOutline().getSelectedItem();
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
part = this.transclusion.getPartFromId( item.getData() );
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
param = new ve.dm.MWParameterModel( part, '', null );
|
|
|
|
part.addParameter( param );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle mode button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onModeButtonClick = function () {
|
|
|
|
this.setMode( this.mode === 'single' ? 'multiple' : 'single' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle booklet layout page set events.
|
|
|
|
*
|
|
|
|
* @param {OO.ui.PageLayout} page Active page
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onBookletLayoutSet = function ( page ) {
|
|
|
|
this.addParameterButton.setDisabled(
|
|
|
|
!( page instanceof ve.ui.MWTemplatePage || page instanceof ve.ui.MWParameterPage )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2013-12-02 20:10:55 +00:00
|
|
|
* Handle parts being replaced.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2013-12-02 20:10:55 +00:00
|
|
|
* @param {ve.dm.MWTransclusionPartModel} removed Removed part
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} added Added part
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.onReplacePart = function ( removed, added ) {
|
2014-03-24 23:54:05 +00:00
|
|
|
var i, len, page, name, names, params, partPage, reselect,
|
2014-02-28 00:06:34 +00:00
|
|
|
removePages = [];
|
2013-06-11 19:16:04 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( removed ) {
|
|
|
|
// Remove parameter pages of removed templates
|
2014-02-28 00:06:34 +00:00
|
|
|
partPage = this.bookletLayout.getPage( removed.getId() );
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( removed instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
params = removed.getParameters();
|
|
|
|
for ( name in params ) {
|
|
|
|
removePages.push( this.bookletLayout.getPage( params[name].getId() ) );
|
2013-06-14 00:46:45 +00:00
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
removed.disconnect( this );
|
2013-06-14 00:46:45 +00:00
|
|
|
}
|
2014-02-28 00:06:34 +00:00
|
|
|
if ( this.loaded && !this.preventReselection && partPage.isActive() ) {
|
|
|
|
reselect = this.bookletLayout.getClosestPage( partPage );
|
2013-06-28 21:38:40 +00:00
|
|
|
}
|
2014-02-28 00:06:34 +00:00
|
|
|
removePages.push( partPage );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.bookletLayout.removePages( removePages );
|
2013-06-28 21:38:40 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( added ) {
|
|
|
|
if ( added instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
page = new ve.ui.MWTemplatePage( added, added.getId(), { '$': this.$ } );
|
|
|
|
} else if ( added instanceof ve.dm.MWTransclusionContentModel ) {
|
|
|
|
page = new ve.ui.MWTransclusionContentPage( added, added.getId(), { '$': this.$ } );
|
|
|
|
} else if ( added instanceof ve.dm.MWTemplatePlaceholderModel ) {
|
|
|
|
page = new ve.ui.MWTemplatePlaceholderPage( added, added.getId(), { '$': this.$ } );
|
|
|
|
}
|
|
|
|
if ( page ) {
|
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusion.getIndex( added ) );
|
2014-02-28 00:06:34 +00:00
|
|
|
if ( reselect ) {
|
|
|
|
// Use added page instead of closest page
|
2013-12-02 20:10:55 +00:00
|
|
|
this.setPageByName( added.getId() );
|
|
|
|
}
|
|
|
|
// Add existing params to templates (the template might be being moved)
|
|
|
|
if ( added instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
names = added.getParameterNames();
|
|
|
|
params = added.getParameters();
|
2014-02-28 00:06:34 +00:00
|
|
|
// Prevent selection changes
|
|
|
|
this.preventReselection = true;
|
2013-12-02 20:10:55 +00:00
|
|
|
for ( i = 0, len = names.length; i < len; i++ ) {
|
|
|
|
this.onAddParameter( params[names[i]] );
|
|
|
|
}
|
2014-02-28 00:06:34 +00:00
|
|
|
this.preventReselection = false;
|
2013-12-02 20:10:55 +00:00
|
|
|
added.connect( this, { 'add': 'onAddParameter', 'remove': 'onRemoveParameter' } );
|
2014-02-28 00:06:34 +00:00
|
|
|
if ( names.length ) {
|
|
|
|
this.setPageByName( params[names[0]].getId() );
|
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Add required params to user created templates
|
|
|
|
if ( added instanceof ve.dm.MWTemplateModel && this.loaded ) {
|
2014-02-28 00:06:34 +00:00
|
|
|
// Prevent selection changes
|
|
|
|
this.preventReselection = true;
|
2013-12-02 20:10:55 +00:00
|
|
|
added.addRequiredParameters();
|
2014-02-28 00:06:34 +00:00
|
|
|
this.preventReselection = false;
|
2014-02-05 19:11:41 +00:00
|
|
|
names = added.getParameterNames();
|
|
|
|
params = added.getParameters();
|
|
|
|
if ( names.length ) {
|
|
|
|
this.setPageByName( params[names[0]].getId() );
|
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2014-02-28 00:06:34 +00:00
|
|
|
} else if ( reselect ) {
|
|
|
|
this.setPageByName( reselect.getName() );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2014-03-06 23:39:40 +00:00
|
|
|
// Update widgets related to a transclusion being a single template or not
|
2014-03-24 23:54:05 +00:00
|
|
|
this.modeButton.setDisabled( !this.isSingleTemplateTransclusion() );
|
2014-03-06 23:39:40 +00:00
|
|
|
this.applyButton
|
2014-03-24 23:54:05 +00:00
|
|
|
.setLabel( this.getApplyButtonLabel() )
|
2014-03-06 23:39:40 +00:00
|
|
|
.setDisabled( !this.isInsertable() );
|
|
|
|
this.updateTitle();
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add param events.
|
|
|
|
*
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Added param
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddParameter = function ( param ) {
|
2014-02-27 23:58:37 +00:00
|
|
|
var page;
|
|
|
|
|
|
|
|
if ( param.getName() ) {
|
|
|
|
page = new ve.ui.MWParameterPage( param, param.getId(), { '$': this.$ } );
|
|
|
|
} else {
|
|
|
|
page = new ve.ui.MWParameterPlaceholderPage( param, param.getId(), { '$': this.$ } );
|
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusion.getIndex( param ) );
|
2014-02-28 00:06:34 +00:00
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
2013-12-02 20:10:55 +00:00
|
|
|
this.setPageByName( param.getId() );
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle remove param events.
|
|
|
|
*
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Removed param
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onRemoveParameter = function ( param ) {
|
2014-02-28 00:06:34 +00:00
|
|
|
var page = this.bookletLayout.getPage( param.getId() ),
|
|
|
|
reselect = this.bookletLayout.getClosestPage( page );
|
|
|
|
|
|
|
|
this.bookletLayout.removePages( [ page ] );
|
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
|
|
|
this.setPageByName( reselect.getName() );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
/**
|
2014-03-04 22:56:14 +00:00
|
|
|
* Checks if transclusion only contains a single template or template placeholder.
|
2013-06-18 21:24:16 +00:00
|
|
|
*
|
2014-03-06 23:39:40 +00:00
|
|
|
* @returns {boolean} Transclusion only contains a single template or template placeholder
|
2013-06-18 21:24:16 +00:00
|
|
|
*/
|
2014-03-06 23:39:40 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.isSingleTemplateTransclusion = function () {
|
|
|
|
var parts = this.transclusion && this.transclusion.getParts();
|
2014-03-04 22:56:14 +00:00
|
|
|
|
|
|
|
return parts && parts.length === 1 && (
|
|
|
|
parts[0] instanceof ve.dm.MWTemplateModel ||
|
|
|
|
parts[0] instanceof ve.dm.MWTemplatePlaceholderModel
|
2014-02-26 00:22:26 +00:00
|
|
|
);
|
2013-06-18 21:24:16 +00:00
|
|
|
};
|
|
|
|
|
2014-03-06 23:39:40 +00:00
|
|
|
/**
|
|
|
|
* Checks if transclusion is in a valid state for inserting into the document
|
|
|
|
*
|
|
|
|
* If the transclusion is empty or only contains a placeholder it will not be insertable.
|
|
|
|
*
|
|
|
|
* @returns {boolean} Transclusion can be inserted
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.isInsertable = function () {
|
|
|
|
var parts = this.transclusion && this.transclusion.getParts();
|
|
|
|
|
|
|
|
return !this.loading &&
|
|
|
|
parts.length &&
|
|
|
|
( parts.length > 1 || !( parts[0] instanceof ve.dm.MWTemplatePlaceholderModel ) );
|
|
|
|
};
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* Get the label of a template or template placeholder.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTemplateModel|ve.dm.MWTemplatePlaceholderModel} part Part to check
|
2014-03-06 23:39:40 +00:00
|
|
|
* @returns {string} Label of template or template placeholder
|
2014-03-04 22:56:14 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getTemplatePartLabel = function ( part ) {
|
|
|
|
return part instanceof ve.dm.MWTemplateModel ?
|
|
|
|
part.getSpec().getLabel() : ve.msg( 'visualeditor-dialog-transclusion-placeholder' );
|
|
|
|
};
|
|
|
|
|
2014-03-24 23:54:05 +00:00
|
|
|
/**
|
|
|
|
* Get a label for the apply button.
|
|
|
|
*
|
|
|
|
* @returns {string} Apply button label
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getApplyButtonLabel = function () {
|
|
|
|
var single = this.isSingleTemplateTransclusion();
|
|
|
|
return ve.msg(
|
|
|
|
this.inserting ?
|
|
|
|
(
|
|
|
|
single ?
|
|
|
|
'visualeditor-dialog-transclusion-insert-template' :
|
|
|
|
'visualeditor-dialog-transclusion-insert-transclusion'
|
|
|
|
) : 'visualeditor-dialog-action-apply'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* Set the page by name.
|
|
|
|
*
|
|
|
|
* Page names are always the ID of the part or param they represent.
|
|
|
|
*
|
|
|
|
* @param {string} name Page name
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.setPageByName = function ( name ) {
|
2013-12-06 20:24:36 +00:00
|
|
|
if ( this.bookletLayout.isOutlined() ) {
|
2013-12-02 20:10:55 +00:00
|
|
|
this.bookletLayout.getOutline().selectItem(
|
|
|
|
this.bookletLayout.getOutline().getItemFromData( name )
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.bookletLayout.setPage( name );
|
|
|
|
}
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* Set dialog mode.
|
|
|
|
*
|
|
|
|
* Auto mode will choose single if possible.
|
|
|
|
*
|
|
|
|
* @param {string} [mode='multiple'] Symbolic name of dialog mode, `multiple`, `single` or 'auto'
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.setMode = function ( mode ) {
|
|
|
|
var name, parts, part, single,
|
|
|
|
modeCssClasses = ve.ui.MWTransclusionDialog.static.modeCssClasses;
|
|
|
|
|
|
|
|
if ( this.transclusion ) {
|
|
|
|
parts = this.transclusion.getParts();
|
|
|
|
part = parts.length && parts[0];
|
|
|
|
if ( mode === 'auto' ) {
|
2014-03-06 23:39:40 +00:00
|
|
|
mode = this.isSingleTemplateTransclusion() ? 'single' : 'multiple';
|
2014-03-04 22:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !modeCssClasses[mode] ) {
|
|
|
|
mode = 'multiple';
|
|
|
|
}
|
|
|
|
this.mode = mode;
|
|
|
|
single = mode === 'single';
|
|
|
|
if ( this.frame.$content ) {
|
|
|
|
for ( name in modeCssClasses ) {
|
|
|
|
this.frame.$content.toggleClass( modeCssClasses[name], name === mode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setSize( single ? 'medium' : 'large' );
|
|
|
|
this.bookletLayout.toggleOutline( !single );
|
|
|
|
this.modeButton.setLabel( ve.msg(
|
|
|
|
single ?
|
|
|
|
'visualeditor-dialog-transclusion-multiple-mode' :
|
|
|
|
'visualeditor-dialog-transclusion-single-mode'
|
|
|
|
) );
|
2014-03-06 23:39:40 +00:00
|
|
|
this.updateTitle();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the dialog title.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.updateTitle = function () {
|
|
|
|
var parts = this.transclusion && this.transclusion.getParts();
|
|
|
|
|
|
|
|
this.setTitle(
|
|
|
|
this.mode === 'single' && parts && parts.length && parts[0] ?
|
|
|
|
this.getTemplatePartLabel( parts[0] ) :
|
|
|
|
this.constructor.static.title
|
|
|
|
);
|
2014-03-04 22:56:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a part to the transclusion.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} part Part to add
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.addPart = function ( part ) {
|
|
|
|
var index, promise,
|
|
|
|
parts = this.transclusion.getParts(),
|
|
|
|
item = this.bookletLayout.getOutline().getSelectedItem();
|
|
|
|
|
|
|
|
if ( part ) {
|
|
|
|
// Insert after selected part, or at the end if nothing is selected
|
|
|
|
index = item ?
|
|
|
|
ve.indexOf( this.transclusion.getPartFromId( item.getData() ), parts ) + 1 :
|
|
|
|
parts.length;
|
|
|
|
// Add the part, and if dialog is loaded switch to part page
|
|
|
|
promise = this.transclusion.addPart( part, index );
|
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
|
|
|
promise.done( ve.bind( this.setPageByName, this, part.getId() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWDialog.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
2014-01-17 14:24:12 +00:00
|
|
|
this.applyButton = new OO.ui.ButtonWidget( {
|
2013-11-05 00:29:50 +00:00
|
|
|
'$': this.$,
|
2013-12-02 20:10:55 +00:00
|
|
|
'flags': ['primary']
|
2013-11-05 00:29:50 +00:00
|
|
|
} );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.modeButton = new OO.ui.ButtonWidget( { '$': this.$ } );
|
|
|
|
this.bookletLayout = new OO.ui.BookletLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'continuous': true,
|
|
|
|
'autoFocus': true,
|
|
|
|
'outlined': true,
|
|
|
|
'editable': true
|
|
|
|
} );
|
|
|
|
this.addTemplateButton = new OO.ui.ButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'template',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-template' )
|
|
|
|
} );
|
|
|
|
this.addContentButton = new OO.ui.ButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'source',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-content' )
|
|
|
|
} );
|
|
|
|
this.addParameterButton = new OO.ui.ButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'parameter',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-param' )
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.applyButton.connect( this, { 'click': [ 'close', { 'action': 'apply' } ] } );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.modeButton.connect( this, { 'click': 'onModeButtonClick' } );
|
|
|
|
this.bookletLayout.connect( this, { 'set': 'onBookletLayoutSet' } );
|
|
|
|
this.addTemplateButton.connect( this, { 'click': 'onAddTemplateButtonClick' } );
|
|
|
|
this.addContentButton.connect( this, { 'click': 'onAddContentButtonClick' } );
|
|
|
|
this.addParameterButton.connect( this, { 'click': 'onAddParameterButtonClick' } );
|
|
|
|
this.bookletLayout.getOutlineControls()
|
|
|
|
.addItems( [ this.addTemplateButton, this.addContentButton, this.addParameterButton ] )
|
|
|
|
.connect( this, {
|
|
|
|
'move': 'onOutlineControlsMove',
|
|
|
|
'remove': 'onOutlineControlsRemove'
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-03-04 22:56:14 +00:00
|
|
|
this.frame.$content.addClass( 've-ui-mwTransclusionDialog' );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.$body.append( this.bookletLayout.$element );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.$foot.append( this.applyButton.$element, this.modeButton.$element );
|
|
|
|
this.setMode( 'single' );
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
/**
|
2014-04-01 23:15:47 +00:00
|
|
|
* Get the transclusion node to be edited.
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
*
|
2014-04-01 23:15:47 +00:00
|
|
|
* @returns {ve.dm.MWTransclusionNode|null} Transclusion node to be edited, null if none exists
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
*/
|
2014-04-01 23:15:47 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.getTransclusionNode = function () {
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
var focusedNode = this.surface.getView().getFocusedNode();
|
2014-04-01 23:15:47 +00:00
|
|
|
return focusedNode instanceof ve.ce.MWTransclusionNode ? focusedNode.getModel() : null;
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save changes.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.saveChanges = function () {
|
|
|
|
var surfaceModel = this.surface.getModel(),
|
|
|
|
obj = this.transclusion.getPlainObject();
|
|
|
|
|
2014-04-01 23:15:47 +00:00
|
|
|
if ( this.transclusionNode instanceof ve.dm.MWTransclusionNode ) {
|
|
|
|
this.transclusion.updateTransclusionNode( surfaceModel, this.transclusionNode );
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
} else if ( obj !== null ) {
|
|
|
|
this.transclusion.insertTransclusionNode( surfaceModel );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.setup = function ( data ) {
|
2014-04-01 23:15:47 +00:00
|
|
|
var template, promise,
|
|
|
|
transclusionNode = this.getTransclusionNode( data );
|
2014-03-04 22:56:14 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.MWDialog.prototype.setup.call( this, data );
|
|
|
|
|
2014-04-02 23:29:04 +00:00
|
|
|
// Data initialization
|
|
|
|
data = data || {};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Properties
|
2013-12-02 20:10:55 +00:00
|
|
|
this.loaded = false;
|
2014-04-01 23:15:47 +00:00
|
|
|
this.transclusion = new ve.dm.MWTransclusionModel();
|
|
|
|
this.transclusionNode = transclusionNode instanceof ve.dm.MWTransclusionNode &&
|
|
|
|
( !data.template || transclusionNode.isSingleTemplate( data.template ) ) ?
|
|
|
|
transclusionNode : null;
|
|
|
|
this.inserting = !this.transclusionNode;
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Events
|
2013-12-02 20:10:55 +00:00
|
|
|
this.transclusion.connect( this, { 'replace': 'onReplacePart' } );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-03-06 23:39:40 +00:00
|
|
|
this.applyButton
|
|
|
|
.setDisabled( true )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-transclusion-loading' ) );
|
|
|
|
if ( this.inserting ) {
|
2014-03-26 22:40:35 +00:00
|
|
|
if ( data.template ) {
|
|
|
|
template = ve.dm.MWTemplateModel.newFromName( this.transclusion, data.template );
|
|
|
|
promise = this.transclusion.addPart( template ).done( function () {
|
|
|
|
template.addRequiredParameters();
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
promise = this.transclusion.addPart(
|
|
|
|
new ve.dm.MWTemplatePlaceholderModel( this.transclusion )
|
|
|
|
);
|
|
|
|
}
|
2013-11-05 00:29:50 +00:00
|
|
|
} else {
|
2014-03-04 22:56:14 +00:00
|
|
|
promise = this.transclusion
|
2014-04-01 23:15:47 +00:00
|
|
|
.load( ve.copy( this.transclusionNode.getAttribute( 'mw' ) ) );
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
2014-03-04 22:56:14 +00:00
|
|
|
promise.always( ve.bind( function () {
|
|
|
|
this.loaded = true;
|
|
|
|
this.setMode( 'auto' );
|
|
|
|
}, this ) );
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.teardown = function ( data ) {
|
|
|
|
// Data initialization
|
|
|
|
data = data || {};
|
|
|
|
|
|
|
|
// Save changes
|
|
|
|
if ( data.action === 'apply' ) {
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
this.saveChanges();
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.transclusion.disconnect( this );
|
|
|
|
this.transclusion.abortRequests();
|
|
|
|
this.transclusion = null;
|
2013-12-02 20:10:55 +00:00
|
|
|
this.bookletLayout.clearPages();
|
2014-04-01 23:15:47 +00:00
|
|
|
this.transclusionNode = null;
|
2013-11-05 00:29:50 +00:00
|
|
|
this.content = null;
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
this.setMode( 'single' );
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.MWDialog.prototype.teardown.call( this, data );
|
|
|
|
};
|
2014-03-04 22:56:14 +00:00
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.dialogFactory.register( ve.ui.MWTransclusionDialog );
|