2013-07-17 19:09:30 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MediaWiki MWReferenceDialog class.
|
|
|
|
*
|
2016-01-03 22:56:59 +00:00
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
2013-07-17 19:09:30 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog for editing MediaWiki references.
|
|
|
|
*
|
|
|
|
* @class
|
2014-04-24 00:22:45 +00:00
|
|
|
* @extends ve.ui.NodeDialog
|
2013-07-17 19:09:30 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-07-17 19:09:30 +00:00
|
|
|
*/
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWReferenceDialog = function VeUiMWReferenceDialog( config ) {
|
2013-07-17 19:09:30 +00:00
|
|
|
// Parent constructor
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWReferenceDialog.super.call( this, config );
|
2013-07-17 19:09:30 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-04-01 23:15:47 +00:00
|
|
|
this.referenceModel = null;
|
2015-04-09 23:22:45 +00:00
|
|
|
this.useExisting = false;
|
2013-07-17 19:09:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
OO.inheritClass( ve.ui.MWReferenceDialog, ve.ui.NodeDialog );
|
2013-07-17 19:09:30 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2013-08-27 23:28:29 +00:00
|
|
|
ve.ui.MWReferenceDialog.static.name = 'reference';
|
|
|
|
|
2014-02-12 21:45:37 +00:00
|
|
|
ve.ui.MWReferenceDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-dialog-reference-title' );
|
2013-07-17 19:09:30 +00:00
|
|
|
|
|
|
|
ve.ui.MWReferenceDialog.static.icon = 'reference';
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWReferenceDialog.static.actions = [
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'apply',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-apply' ),
|
2014-12-11 22:49:51 +00:00
|
|
|
flags: [ 'progressive', 'primary' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
modes: 'edit'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'insert',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-insert' ),
|
|
|
|
flags: [ 'primary', 'constructive' ],
|
|
|
|
modes: 'insert'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
|
2015-08-06 13:34:32 +00:00
|
|
|
flags: [ 'safe', 'back' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
modes: [ 'insert', 'edit', 'insert-select' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'select',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-reference-useexisting-label' ),
|
|
|
|
modes: [ 'insert', 'edit' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'back',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-goback' ),
|
|
|
|
flags: 'safe',
|
|
|
|
modes: 'select'
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
ve.ui.MWReferenceDialog.static.modelClasses = [ ve.dm.MWReferenceNode ];
|
|
|
|
|
2015-07-18 21:44:47 +00:00
|
|
|
ve.ui.MWReferenceDialog.static.includeCommands = null;
|
|
|
|
|
2014-11-24 17:43:16 +00:00
|
|
|
ve.ui.MWReferenceDialog.static.excludeCommands = [
|
2013-12-12 19:04:15 +00:00
|
|
|
// No formatting
|
2014-11-24 17:43:16 +00:00
|
|
|
'paragraph',
|
|
|
|
'heading1',
|
|
|
|
'heading2',
|
|
|
|
'heading3',
|
|
|
|
'heading4',
|
|
|
|
'heading5',
|
|
|
|
'heading6',
|
|
|
|
'preformatted',
|
2014-11-26 02:57:26 +00:00
|
|
|
'blockquote',
|
2014-11-24 17:43:16 +00:00
|
|
|
// No tables
|
|
|
|
'insertTable',
|
|
|
|
'deleteTable',
|
|
|
|
'mergeCells',
|
|
|
|
'tableCaption',
|
|
|
|
'tableCellHeader',
|
|
|
|
'tableCellData',
|
2014-03-25 00:13:59 +00:00
|
|
|
// No structure
|
2014-11-24 17:43:16 +00:00
|
|
|
'bullet',
|
2016-01-26 23:44:49 +00:00
|
|
|
'bulletWrapOnce',
|
2014-11-24 17:43:16 +00:00
|
|
|
'number',
|
2016-01-26 23:44:49 +00:00
|
|
|
'numberWrapOnce',
|
2014-11-24 17:43:16 +00:00
|
|
|
'indent',
|
|
|
|
'outdent',
|
|
|
|
// References
|
|
|
|
'reference',
|
|
|
|
'reference/existing',
|
2015-09-09 11:42:39 +00:00
|
|
|
'citefromid',
|
2014-11-24 17:43:16 +00:00
|
|
|
'referencesList'
|
2013-07-17 19:09:30 +00:00
|
|
|
];
|
|
|
|
|
2014-05-23 09:57:58 +00:00
|
|
|
/**
|
2015-07-13 15:06:01 +00:00
|
|
|
* Get the import rules for the surface widget in the dialog.
|
2014-05-23 09:57:58 +00:00
|
|
|
*
|
|
|
|
* @see ve.dm.ElementLinearData#sanitize
|
2014-11-24 11:27:25 +00:00
|
|
|
* @return {Object} Import rules
|
2014-05-23 09:57:58 +00:00
|
|
|
*/
|
2014-11-24 11:27:25 +00:00
|
|
|
ve.ui.MWReferenceDialog.static.getImportRules = function () {
|
2014-05-23 09:57:58 +00:00
|
|
|
return ve.extendObject(
|
2014-11-24 11:27:25 +00:00
|
|
|
ve.copy( ve.init.target.constructor.static.importRules ),
|
2014-05-23 09:57:58 +00:00
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
all: {
|
|
|
|
blacklist: OO.simpleArrayUnion(
|
2014-11-24 11:27:25 +00:00
|
|
|
ve.getProp( ve.init.target.constructor.static.importRules, 'all', 'blacklist' ) || [],
|
2014-05-23 09:57:58 +00:00
|
|
|
[
|
|
|
|
// Nested references are impossible
|
2014-08-19 18:32:46 +00:00
|
|
|
'mwReference', 'mwReferencesList',
|
2014-07-19 02:14:30 +00:00
|
|
|
// Lists and tables are actually possible in wikitext with a leading
|
2014-05-23 09:57:58 +00:00
|
|
|
// line break but we prevent creating these with the UI
|
|
|
|
'list', 'listItem', 'definitionList', 'definitionListItem',
|
|
|
|
'table', 'tableCaption', 'tableSection', 'tableRow', 'tableCell'
|
|
|
|
]
|
|
|
|
),
|
|
|
|
// Headings are not possible in wikitext without HTML
|
2014-08-22 20:50:48 +00:00
|
|
|
conversions: {
|
|
|
|
mwHeading: 'paragraph'
|
2014-05-23 09:57:58 +00:00
|
|
|
}
|
2014-02-03 15:08:52 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 09:57:58 +00:00
|
|
|
);
|
|
|
|
};
|
2014-02-03 15:08:52 +00:00
|
|
|
|
2013-07-17 19:09:30 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-12-02 01:25:19 +00:00
|
|
|
/**
|
|
|
|
* Determine whether the reference document we're editing has any content.
|
2015-07-13 15:06:01 +00:00
|
|
|
*
|
2014-12-02 01:25:19 +00:00
|
|
|
* @return {boolean} Document has content
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.documentHasContent = function () {
|
|
|
|
// TODO: Check for other types of empty, e.g. only whitespace?
|
2015-06-30 08:45:24 +00:00
|
|
|
return this.referenceModel.getDocument().data.hasContent();
|
2014-12-02 01:25:19 +00:00
|
|
|
};
|
|
|
|
|
2014-12-05 23:47:06 +00:00
|
|
|
/*
|
2015-07-13 15:06:01 +00:00
|
|
|
* Determine whether any changes have been made (and haven't been undone).
|
|
|
|
*
|
2014-12-05 23:47:06 +00:00
|
|
|
* @return {boolean} Dialog can be applied
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.canApply = function () {
|
|
|
|
return this.documentHasContent() &&
|
2015-07-18 21:42:09 +00:00
|
|
|
( this.referenceTarget.getSurface().getModel().hasBeenModified() ||
|
2014-12-05 23:47:06 +00:00
|
|
|
this.referenceGroupInput.input.getValue() !== this.originalGroup );
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* Handle reference surface change events
|
|
|
|
*/
|
2015-01-12 19:30:39 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.onSurfaceHistory = function () {
|
2014-12-02 01:25:19 +00:00
|
|
|
var hasContent = this.documentHasContent();
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setAbilities( {
|
2014-12-05 23:47:06 +00:00
|
|
|
apply: this.canApply(),
|
2014-08-22 20:50:48 +00:00
|
|
|
insert: hasContent,
|
|
|
|
select: !hasContent && !this.search.isIndexEmpty()
|
2014-07-14 21:32:49 +00:00
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
2014-12-02 01:25:19 +00:00
|
|
|
/**
|
2015-07-13 15:06:01 +00:00
|
|
|
* Handle reference group input change events.
|
2014-12-02 01:25:19 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.onReferenceGroupInputChange = function () {
|
|
|
|
this.actions.setAbilities( {
|
2014-12-05 23:47:06 +00:00
|
|
|
apply: this.canApply()
|
2014-12-02 01:25:19 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
2015-07-13 15:04:33 +00:00
|
|
|
* Handle search results choose events.
|
2013-11-05 00:29:50 +00:00
|
|
|
*
|
2015-07-13 15:04:33 +00:00
|
|
|
* @param {ve.ui.MWReferenceResultWidget} item Chosen item
|
2013-11-05 00:29:50 +00:00
|
|
|
*/
|
2015-07-13 15:04:33 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.onSearchResultsChoose = function ( item ) {
|
|
|
|
var ref = item.getData();
|
|
|
|
|
|
|
|
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
|
|
|
this.getFragment().removeContent();
|
|
|
|
this.selectedNode = null;
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
2015-07-13 15:04:33 +00:00
|
|
|
this.useReference( ref );
|
|
|
|
this.executeAction( 'insert' );
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
2014-04-01 23:15:47 +00:00
|
|
|
/**
|
2014-07-21 12:58:48 +00:00
|
|
|
* @inheritdoc
|
2014-04-01 23:15:47 +00:00
|
|
|
*/
|
2014-07-21 12:58:48 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.getReadyProcess.call( this, data )
|
|
|
|
.next( function () {
|
2015-04-09 23:22:45 +00:00
|
|
|
if ( this.useExisting ) {
|
|
|
|
this.search.getQuery().focus().select();
|
|
|
|
} else {
|
2015-07-18 21:42:09 +00:00
|
|
|
this.referenceTarget.focus();
|
2015-04-09 23:22:45 +00:00
|
|
|
}
|
2014-07-21 12:58:48 +00:00
|
|
|
}, this );
|
2014-04-01 23:15:47 +00:00
|
|
|
};
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.getBodyHeight = function () {
|
2014-07-23 01:57:39 +00:00
|
|
|
// Clamp value to between 300 and 400px height, preferring the actual height if available
|
|
|
|
return Math.min(
|
|
|
|
400,
|
|
|
|
Math.max(
|
|
|
|
300,
|
2015-08-19 17:33:02 +00:00
|
|
|
Math.ceil( this.panels.getCurrentItem().$element[ 0 ].scrollHeight )
|
2014-07-23 01:57:39 +00:00
|
|
|
)
|
|
|
|
);
|
2014-07-14 21:32:49 +00:00
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* Work on a specific reference.
|
|
|
|
*
|
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.dm.MWReferenceModel} [ref] Reference model, omit to work on a new reference
|
2013-11-05 00:29:50 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) {
|
2015-09-09 11:42:39 +00:00
|
|
|
var group, citeCommands;
|
|
|
|
|
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
|
|
|
// Properties
|
|
|
|
if ( ref instanceof ve.dm.MWReferenceModel ) {
|
2013-11-05 00:29:50 +00:00
|
|
|
// Use an existing reference
|
2014-04-01 23:15:47 +00:00
|
|
|
this.referenceModel = ref;
|
2013-11-05 00:29:50 +00:00
|
|
|
} else {
|
|
|
|
// Create a new reference
|
2015-08-27 06:27:14 +00:00
|
|
|
this.referenceModel = new ve.dm.MWReferenceModel( this.getFragment().getDocument() );
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
2015-07-18 21:42:09 +00:00
|
|
|
if ( this.referenceTarget ) {
|
|
|
|
this.referenceTarget.destroy();
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 11:42:39 +00:00
|
|
|
citeCommands = Object.keys( ve.init.target.commandRegistry.registry ).filter( function ( command ) {
|
|
|
|
return command.indexOf( 'cite-' ) !== -1;
|
|
|
|
} );
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Properties
|
2015-07-18 21:42:09 +00:00
|
|
|
this.referenceTarget = new ve.ui.MWTargetWidget(
|
2014-04-01 23:15:47 +00:00
|
|
|
this.referenceModel.getDocument(),
|
2013-11-05 00:29:50 +00:00
|
|
|
{
|
2015-12-10 16:07:50 +00:00
|
|
|
tools: ve.copy( ve.init.target.constructor.static.toolbarGroups ),
|
2015-07-18 21:44:47 +00:00
|
|
|
includeCommands: this.constructor.static.includeCommands,
|
2015-09-09 11:42:39 +00:00
|
|
|
excludeCommands: this.constructor.static.excludeCommands.concat( citeCommands ),
|
2015-04-07 01:28:22 +00:00
|
|
|
importRules: this.constructor.static.getImportRules(),
|
|
|
|
inDialog: this.constructor.static.name
|
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
|
|
|
// Events
|
2015-07-18 21:42:09 +00:00
|
|
|
this.referenceTarget.getSurface().getModel().connect( this, {
|
2015-01-12 19:30:39 +00:00
|
|
|
history: this.onSurfaceHistory.bind( this )
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-12-05 23:47:06 +00:00
|
|
|
this.originalGroup = this.referenceModel.getGroup();
|
|
|
|
this.referenceGroupInput.input.setValue( this.originalGroup );
|
2015-07-18 21:42:09 +00:00
|
|
|
this.contentFieldset.$element.append( this.referenceTarget.$element );
|
|
|
|
this.referenceTarget.initialize();
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2014-10-27 22:36:26 +00:00
|
|
|
group = this.getFragment().getDocument().getInternalList()
|
|
|
|
.getNodeGroup( this.referenceModel.getListGroup() );
|
2015-09-24 21:57:50 +00:00
|
|
|
if ( ve.getProp( group, 'keyedNodes', this.referenceModel.getListKey(), 'length' ) > 1 ) {
|
2015-01-29 23:09:47 +00:00
|
|
|
this.$reuseWarning.removeClass( 'oo-ui-element-hidden' );
|
2014-10-27 22:36:26 +00:00
|
|
|
this.$reuseWarningText.text( mw.msg(
|
|
|
|
'visualeditor-dialog-reference-editing-reused',
|
2015-08-19 17:33:02 +00:00
|
|
|
group.keyedNodes[ this.referenceModel.getListKey() ].length
|
2014-10-27 22:36:26 +00:00
|
|
|
) );
|
|
|
|
} else {
|
2015-01-29 23:09:47 +00:00
|
|
|
this.$reuseWarning.addClass( 'oo-ui-element-hidden' );
|
2014-10-27 22:36:26 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-07-17 19:09:30 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
2014-04-24 00:22:45 +00:00
|
|
|
ve.ui.MWReferenceDialog.super.prototype.initialize.call( this );
|
2013-07-17 19:09:30 +00:00
|
|
|
|
|
|
|
// Properties
|
2015-04-09 23:47:15 +00:00
|
|
|
this.panels = new OO.ui.StackLayout();
|
2013-10-09 20:09:59 +00:00
|
|
|
this.editPanel = new OO.ui.PanelLayout( {
|
2015-04-09 23:47:15 +00:00
|
|
|
scrollable: true, padded: true
|
2013-07-17 19:09:30 +00:00
|
|
|
} );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.searchPanel = new OO.ui.PanelLayout();
|
2014-10-27 22:36:26 +00:00
|
|
|
|
|
|
|
this.reuseWarningIcon = new OO.ui.IconWidget( { icon: 'alert' } );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$reuseWarningText = $( '<span>' );
|
|
|
|
this.$reuseWarning = $( '<span>' ).append( this.reuseWarningIcon.$element, this.$reuseWarningText );
|
2014-10-27 22:36:26 +00:00
|
|
|
|
2015-04-09 23:47:15 +00:00
|
|
|
this.contentFieldset = new OO.ui.FieldsetLayout();
|
2013-10-09 20:09:59 +00:00
|
|
|
this.optionsFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-reference-options-section' ),
|
|
|
|
icon: 'settings'
|
2013-07-17 19:09:30 +00:00
|
|
|
} );
|
2014-08-23 02:36:39 +00:00
|
|
|
this.referenceGroupInput = new ve.ui.MWReferenceGroupInputWidget( {
|
2014-10-30 21:50:10 +00:00
|
|
|
$overlay: this.$overlay,
|
2014-08-23 02:36:39 +00:00
|
|
|
emptyGroupName: ve.msg( 'visualeditor-dialog-reference-options-group-placeholder' )
|
2014-02-20 01:33:35 +00:00
|
|
|
} );
|
2014-12-02 01:25:19 +00:00
|
|
|
this.referenceGroupInput.input.connect( this, { change: 'onReferenceGroupInputChange' } );
|
2014-01-22 20:13:59 +00:00
|
|
|
this.referenceGroupField = new OO.ui.FieldLayout( this.referenceGroupInput, {
|
2014-08-22 20:50:48 +00:00
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-reference-options-group-label' )
|
2013-07-17 19:09:30 +00:00
|
|
|
} );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.search = new ve.ui.MWReferenceSearchWidget();
|
2013-07-17 19:09:30 +00:00
|
|
|
|
|
|
|
// Events
|
2015-07-13 15:04:33 +00:00
|
|
|
this.search.getResults().connect( this, { choose: 'onSearchResultsChoose' } );
|
2013-07-17 19:09:30 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.panels.addItems( [ this.editPanel, this.searchPanel ] );
|
2014-10-27 22:36:26 +00:00
|
|
|
this.editPanel.$element.append( this.$reuseWarning, this.contentFieldset.$element, this.optionsFieldset.$element );
|
2014-01-22 20:13:59 +00:00
|
|
|
this.optionsFieldset.addItems( [ this.referenceGroupField ] );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.searchPanel.$element.append( this.search.$element );
|
2014-07-14 21:32:49 +00:00
|
|
|
this.$body.append( this.panels.$element );
|
2013-07-17 19:09:30 +00:00
|
|
|
};
|
|
|
|
|
2014-05-30 21:28:41 +00:00
|
|
|
/**
|
2015-07-13 15:06:01 +00:00
|
|
|
* Switches dialog to use existing reference mode.
|
2014-07-03 20:42:54 +00:00
|
|
|
*
|
|
|
|
* @param {string} [action='select'] Symbolic name of action, either 'select' or 'insert-select'
|
2014-05-30 21:28:41 +00:00
|
|
|
*/
|
2014-07-03 20:42:54 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.useExistingReference = function ( action ) {
|
|
|
|
action = action || 'select';
|
|
|
|
if ( action === 'insert-select' || action === 'select' ) {
|
|
|
|
this.actions.setMode( action );
|
|
|
|
}
|
2014-07-21 14:27:25 +00:00
|
|
|
this.search.buildIndex();
|
2014-05-30 21:28:41 +00:00
|
|
|
this.panels.setItem( this.searchPanel );
|
|
|
|
this.search.getQuery().focus().select();
|
|
|
|
};
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.getActionProcess = function ( action ) {
|
|
|
|
if ( action === 'insert' || action === 'apply' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
var surfaceModel = this.getFragment().getSurface();
|
|
|
|
|
2014-08-23 02:36:39 +00:00
|
|
|
this.referenceModel.setGroup( this.referenceGroupInput.input.getValue() );
|
2014-07-14 21:32:49 +00:00
|
|
|
|
|
|
|
// Insert reference (will auto-create an internal item if needed)
|
|
|
|
if ( !( this.selectedNode instanceof ve.dm.MWReferenceNode ) ) {
|
|
|
|
if ( !this.referenceModel.findInternalItem( surfaceModel ) ) {
|
|
|
|
this.referenceModel.insertInternalItem( surfaceModel );
|
|
|
|
}
|
|
|
|
// Collapse returns a new fragment, so update this.fragment
|
2014-09-30 16:34:33 +00:00
|
|
|
this.fragment = this.getFragment().collapseToEnd();
|
2014-07-14 21:32:49 +00:00
|
|
|
this.referenceModel.insertReferenceNode( this.getFragment() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update internal item
|
|
|
|
this.referenceModel.updateInternalItem( surfaceModel );
|
|
|
|
|
2014-08-22 20:50:48 +00:00
|
|
|
this.close( { action: action } );
|
2014-07-14 21:32:49 +00:00
|
|
|
}, this );
|
|
|
|
} else if ( action === 'back' ) {
|
|
|
|
this.actions.setMode( this.selectedNode ? 'edit' : 'insert' );
|
|
|
|
this.panels.setItem( this.editPanel );
|
2015-08-19 17:33:02 +00:00
|
|
|
this.editPanel.$element.find( '.ve-ce-documentNode' )[ 0 ].focus();
|
2014-07-03 20:42:54 +00:00
|
|
|
} else if ( action === 'select' || action === 'insert-select' ) {
|
|
|
|
this.useExistingReference( action );
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.getActionProcess.call( this, action );
|
|
|
|
};
|
|
|
|
|
2013-07-17 19:09:30 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
2014-05-30 21:28:41 +00:00
|
|
|
* @param {Object} [data] Setup data
|
|
|
|
* @param {boolean} [data.useExistingReference] Open the dialog in "use existing reference" mode
|
2013-07-17 19:09:30 +00:00
|
|
|
*/
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.getSetupProcess = function ( data ) {
|
2014-07-15 22:49:51 +00:00
|
|
|
data = data || {};
|
2014-05-31 04:47:08 +00:00
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
|
|
|
this.panels.setItem( this.editPanel );
|
|
|
|
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
|
|
|
this.useReference(
|
|
|
|
ve.dm.MWReferenceModel.static.newFromReferenceNode( this.selectedNode )
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.useReference( null );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.actions.setAbilities( { apply: false, insert: false } );
|
2014-05-31 04:47:08 +00:00
|
|
|
}
|
2014-07-14 21:32:49 +00:00
|
|
|
|
|
|
|
this.actions.setMode( this.selectedNode ? 'edit' : 'insert' );
|
2014-07-21 14:27:25 +00:00
|
|
|
this.search.setInternalList( this.getFragment().getDocument().getInternalList() );
|
2014-05-30 21:28:41 +00:00
|
|
|
|
|
|
|
if ( data.useExisting ) {
|
2014-07-03 20:42:54 +00:00
|
|
|
this.useExistingReference( 'insert-select' );
|
2014-05-30 21:28:41 +00:00
|
|
|
}
|
2015-04-09 23:22:45 +00:00
|
|
|
this.useExisting = !!data.useExisting;
|
2014-05-31 19:09:07 +00:00
|
|
|
// If we're using an existing reference, start off disabled
|
|
|
|
// If not, set disabled based on whether or not there are any existing ones.
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setAbilities( {
|
2014-08-22 20:50:48 +00:00
|
|
|
select: !( this.selectedNode instanceof ve.dm.MWReferenceNode ) &&
|
2014-12-02 01:25:19 +00:00
|
|
|
!this.search.isIndexEmpty(),
|
|
|
|
apply: false
|
2014-07-14 21:32:49 +00:00
|
|
|
} );
|
2014-08-23 02:36:39 +00:00
|
|
|
|
|
|
|
this.referenceGroupInput.populateMenu( this.getFragment().getDocument().getInternalList() );
|
2014-05-31 04:47:08 +00:00
|
|
|
}, this );
|
2013-07-17 19:09:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.first( function () {
|
2015-07-25 18:23:13 +00:00
|
|
|
this.referenceTarget.getSurface().getModel().disconnect( this );
|
2014-05-31 04:47:08 +00:00
|
|
|
this.search.getQuery().setValue( '' );
|
2015-07-18 21:42:09 +00:00
|
|
|
this.referenceTarget.destroy();
|
|
|
|
this.referenceTarget = null;
|
2014-05-31 04:47:08 +00:00
|
|
|
this.referenceModel = null;
|
|
|
|
}, this );
|
2013-08-27 23:29:55 +00:00
|
|
|
};
|
|
|
|
|
2013-07-17 19:09:30 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2014-04-21 22:31:21 +00:00
|
|
|
ve.ui.windowFactory.register( ve.ui.MWReferenceDialog );
|