2013-07-17 19:09:30 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MediaWiki MWReferenceDialog class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 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-04-04 17:42:13 +00:00
|
|
|
ve.ui.MWReferenceDialog = function VeUiMWReferenceDialog( config ) {
|
2013-07-17 19:09:30 +00:00
|
|
|
// Parent constructor
|
2014-04-24 00:22:45 +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;
|
2014-04-14 23:27:27 +00:00
|
|
|
|
|
|
|
// Events
|
2014-04-28 23:34:58 +00:00
|
|
|
this.connect( this, { 'ready': 'onReady' } );
|
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-04-24 00:22:45 +00:00
|
|
|
ve.ui.MWReferenceDialog.static.modelClasses = [ ve.dm.MWReferenceNode ];
|
|
|
|
|
2013-08-09 18:29:09 +00:00
|
|
|
ve.ui.MWReferenceDialog.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',
|
2014-03-15 00:01:44 +00:00
|
|
|
'title': OO.ui.deferMsg( 'visualeditor-toolbar-format-tooltip' ),
|
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',
|
2014-03-15 00:01:44 +00:00
|
|
|
'title': OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ),
|
2013-12-12 19:04:15 +00:00
|
|
|
'include': [ { 'group': 'textStyle' }, 'clear' ],
|
|
|
|
'promote': [ 'bold', 'italic' ],
|
2014-03-15 00:01:44 +00:00
|
|
|
'demote': [ 'strikethrough', 'code', 'underline', 'clear' ]
|
2013-12-12 19:04:15 +00:00
|
|
|
},
|
|
|
|
// Link
|
|
|
|
{ 'include': [ 'link' ] },
|
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
|
|
|
// Cite
|
|
|
|
{
|
|
|
|
'type': 'list',
|
2014-06-02 16:44:52 +00:00
|
|
|
'label': OO.ui.deferMsg( 'visualeditor-toolbar-cite-label' ),
|
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
|
|
|
'indicator': 'down',
|
|
|
|
'include': [ { 'group': 'cite-transclusion' } ]
|
|
|
|
},
|
2014-03-25 00:13:59 +00:00
|
|
|
// No structure
|
|
|
|
/* {
|
2014-05-23 00:47:29 +00:00
|
|
|
'type': 'list',
|
|
|
|
'icon': 'bullet-list',
|
|
|
|
'indicator': 'down',
|
|
|
|
'include': [ { 'group': 'structure' } ],
|
|
|
|
'demote': [ 'outdent', 'indent' ]
|
2014-03-25 00:13:59 +00:00
|
|
|
},*/
|
2013-12-12 19:04:15 +00:00
|
|
|
// Insert
|
|
|
|
{
|
2014-02-12 23:04:28 +00:00
|
|
|
'label': OO.ui.deferMsg( 'visualeditor-toolbar-insert' ),
|
2014-01-13 22:46:15 +00:00
|
|
|
'indicator': 'down',
|
2013-12-12 19:04:15 +00:00
|
|
|
'include': '*',
|
2014-02-05 19:45:56 +00:00
|
|
|
'exclude': [
|
2014-03-15 00:01:44 +00:00
|
|
|
{ 'group': 'format' },
|
|
|
|
{ 'group': 'structure' },
|
|
|
|
'reference',
|
|
|
|
'referenceList',
|
2014-02-05 19:45:56 +00:00
|
|
|
'gallery'
|
|
|
|
],
|
2014-03-20 05:58:35 +00:00
|
|
|
'promote': [ 'mediaInsert' ],
|
2014-03-05 22:49:52 +00:00
|
|
|
'demote': [ 'language', 'specialcharacter' ]
|
2013-12-12 19:04:15 +00:00
|
|
|
}
|
2013-07-17 19:09:30 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
ve.ui.MWReferenceDialog.static.surfaceCommands = [
|
2013-12-12 19:04:15 +00:00
|
|
|
'undo',
|
|
|
|
'redo',
|
|
|
|
'bold',
|
|
|
|
'italic',
|
|
|
|
'link',
|
|
|
|
'clear',
|
|
|
|
'underline',
|
|
|
|
'subscript',
|
|
|
|
'superscript',
|
|
|
|
'pasteSpecial'
|
2013-07-17 19:09:30 +00:00
|
|
|
];
|
|
|
|
|
2014-05-23 09:57:58 +00:00
|
|
|
/**
|
|
|
|
* Get the paste rules for the surface widget in the dialog
|
|
|
|
*
|
|
|
|
* @see ve.dm.ElementLinearData#sanitize
|
|
|
|
* @return {Object} Paste rules
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.static.getPasteRules = function () {
|
|
|
|
return ve.extendObject(
|
|
|
|
ve.copy( ve.init.target.constructor.static.pasteRules ),
|
|
|
|
{
|
|
|
|
'all': {
|
|
|
|
'blacklist': OO.simpleArrayUnion(
|
|
|
|
ve.getProp( ve.init.target.constructor.static.pasteRules, 'all', 'blacklist' ) || [],
|
|
|
|
[
|
|
|
|
// Nested references are impossible
|
|
|
|
'mwReference', 'mwReferenceList',
|
|
|
|
// Lists are tables are actually possible in wikitext with a leading
|
|
|
|
// 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
|
|
|
|
'conversions': {
|
|
|
|
'mwHeading': 'paragraph'
|
|
|
|
}
|
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 */
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* Handle reference surface change events
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.onDocumentTransact = function () {
|
2014-05-31 00:05:04 +00:00
|
|
|
var data = this.referenceModel.getDocument().data,
|
2013-11-05 00:29:50 +00:00
|
|
|
// TODO: Check for other types of empty, e.g. only whitespace?
|
2014-05-31 00:05:04 +00:00
|
|
|
applyDisabled = data.countNoninternalElements() <= 2;
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2014-05-30 20:04:51 +00:00
|
|
|
this.applyButton.setDisabled( applyDisabled );
|
2014-05-31 19:09:07 +00:00
|
|
|
this.selectButton.setDisabled( !applyDisabled || this.search.isIndexEmpty() );
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle search select events.
|
|
|
|
*
|
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|null} ref Reference model or null if no item is selected
|
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
|
|
|
ve.ui.MWReferenceDialog.prototype.onSearchSelect = function ( ref ) {
|
|
|
|
if ( ref instanceof ve.dm.MWReferenceModel ) {
|
2014-05-31 19:09:07 +00:00
|
|
|
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
|
|
|
this.getFragment().removeContent();
|
|
|
|
this.selectedNode = 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
|
|
|
this.useReference( ref );
|
2014-04-30 21:06:38 +00:00
|
|
|
// HACK - This proves that the interface for ActionDialog is screwed up
|
|
|
|
this.onApplyButtonClick();
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-01 23:15:47 +00:00
|
|
|
/**
|
2014-04-28 23:34:58 +00:00
|
|
|
* Handle window ready events
|
2014-04-01 23:15:47 +00:00
|
|
|
*/
|
2014-04-28 23:34:58 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.onReady = function () {
|
2014-04-24 00:22:45 +00:00
|
|
|
// Focus the reference surface
|
|
|
|
this.referenceSurface.focus();
|
2014-04-01 23:15:47 +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 ) {
|
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
|
2014-04-01 23:15:47 +00:00
|
|
|
this.referenceModel = new ve.dm.MWReferenceModel();
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
if ( this.referenceSurface ) {
|
|
|
|
this.referenceSurface.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.referenceSurface = new ve.ui.SurfaceWidget(
|
2014-04-01 23:15:47 +00:00
|
|
|
this.referenceModel.getDocument(),
|
2013-11-05 00:29:50 +00:00
|
|
|
{
|
|
|
|
'$': this.$,
|
|
|
|
'tools': this.constructor.static.toolbarGroups,
|
2014-02-03 15:08:52 +00:00
|
|
|
'commands': this.constructor.static.surfaceCommands,
|
2014-05-23 09:57:58 +00:00
|
|
|
'pasteRules': this.constructor.static.getPasteRules()
|
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
|
2014-04-01 23:15:47 +00:00
|
|
|
this.referenceModel.getDocument().connect( this, { 'transact': 'onDocumentTransact' } );
|
2014-06-10 21:19:03 +00:00
|
|
|
this.referenceSurface.getSurface().getModel().connect( this, {
|
|
|
|
'documentUpdate': function () {
|
|
|
|
this.wikitextWarning = ve.init.mw.ViewPageTarget.static.checkForWikitextWarning(
|
|
|
|
this.referenceSurface.getSurface(),
|
|
|
|
this.wikitextWarning
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-04-01 23:15:47 +00:00
|
|
|
this.referenceGroupInput.setValue( this.referenceModel.getGroup() );
|
2013-11-05 00:29:50 +00:00
|
|
|
this.contentFieldset.$element.append( this.referenceSurface.$element );
|
|
|
|
this.referenceSurface.initialize();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.getApplyButtonLabel = function () {
|
|
|
|
return this.selectedNode instanceof ve.dm.MWReferenceNode ?
|
|
|
|
ve.ui.MWReferenceDialog.super.prototype.getApplyButtonLabel.call( this ) :
|
|
|
|
ve.msg( 'visualeditor-dialog-reference-insert-button' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.applyChanges = function () {
|
2014-06-16 13:28:54 +00:00
|
|
|
var surfaceModel = this.getFragment().getSurface();
|
2014-04-24 00:22:45 +00:00
|
|
|
|
|
|
|
this.referenceModel.setGroup( this.referenceGroupInput.getValue() );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|
2014-06-16 13:28:54 +00:00
|
|
|
// Collapse returns a new fragment, so update this.fragment
|
|
|
|
this.fragment = this.getFragment().collapseRangeToEnd();
|
|
|
|
this.referenceModel.insertReferenceNode( this.getFragment() );
|
2014-04-24 00:22:45 +00:00
|
|
|
}
|
2014-05-31 19:09:07 +00:00
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
// Update internal item
|
|
|
|
this.referenceModel.updateInternalItem( surfaceModel );
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.applyChanges.call( 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
|
2013-10-09 20:09:59 +00:00
|
|
|
this.editPanel = new OO.ui.PanelLayout( {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$, 'scrollable': true, 'padded': true
|
2013-07-17 19:09:30 +00:00
|
|
|
} );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.searchPanel = new OO.ui.PanelLayout( { '$': this.$ } );
|
2014-01-17 14:24:12 +00:00
|
|
|
this.selectButton = new OO.ui.ButtonWidget( {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2013-07-17 19:09:30 +00:00
|
|
|
'label': ve.msg ( 'visualeditor-dialog-reference-useexisting-label' )
|
|
|
|
} );
|
2014-01-17 14:24:12 +00:00
|
|
|
this.backButton = new OO.ui.ButtonWidget( {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2013-07-17 19:09:30 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-action-goback' )
|
|
|
|
} );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.contentFieldset = new OO.ui.FieldsetLayout( { '$': this.$ } );
|
2013-10-09 20:09:59 +00:00
|
|
|
this.optionsFieldset = new OO.ui.FieldsetLayout( {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2013-07-17 19:09:30 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-reference-options-section' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
// TODO: Use a drop-down or something, and populate with existing groups instead of free-text
|
2014-02-20 01:33:35 +00:00
|
|
|
this.referenceGroupInput = new OO.ui.TextInputWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'placeholder': ve.msg( 'visualeditor-dialog-reference-options-group-placeholder' )
|
|
|
|
} );
|
2014-01-22 20:13:59 +00:00
|
|
|
this.referenceGroupField = new OO.ui.FieldLayout( this.referenceGroupInput, {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$,
|
2014-01-22 20:13:59 +00:00
|
|
|
'align': 'top',
|
2013-07-17 19:09:30 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-reference-options-group-label' )
|
|
|
|
} );
|
2014-04-04 17:42:13 +00:00
|
|
|
this.search = new ve.ui.MWReferenceSearchWidget( { '$': this.$ } );
|
2013-07-17 19:09:30 +00:00
|
|
|
|
|
|
|
// Events
|
2014-05-30 21:28:41 +00:00
|
|
|
this.selectButton.connect( this, { 'click': 'useExistingReference' } );
|
2013-07-17 19:09:30 +00:00
|
|
|
this.backButton.connect( this, { 'click': function () {
|
2013-11-01 19:45:59 +00:00
|
|
|
this.backButton.$element.hide();
|
2014-04-24 00:22:45 +00:00
|
|
|
this.applyButton.$element.show();
|
2013-11-01 19:45:59 +00:00
|
|
|
this.selectButton.$element.show();
|
2013-12-02 20:10:55 +00:00
|
|
|
this.panels.setItem( this.editPanel );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.editPanel.$element.find( '.ve-ce-documentNode' ).focus();
|
2013-07-17 19:09:30 +00:00
|
|
|
} } );
|
|
|
|
this.search.connect( this, { 'select': 'onSearchSelect' } );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.panels.addItems( [ this.editPanel, this.searchPanel ] );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.editPanel.$element.append( 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 );
|
2013-07-17 19:09:30 +00:00
|
|
|
this.$foot.append(
|
2013-11-01 19:45:59 +00:00
|
|
|
this.applyButton.$element,
|
|
|
|
this.selectButton.$element,
|
|
|
|
this.backButton.$element
|
2013-07-17 19:09:30 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-05-30 21:28:41 +00:00
|
|
|
/**
|
|
|
|
* Switches dialog to use existing reference mode
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.useExistingReference = function () {
|
|
|
|
this.backButton.$element.show();
|
|
|
|
this.applyButton.$element.hide();
|
|
|
|
this.selectButton.$element.hide();
|
|
|
|
this.panels.setItem( this.searchPanel );
|
|
|
|
this.search.getQuery().focus().select();
|
|
|
|
};
|
|
|
|
|
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 ) {
|
|
|
|
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 );
|
|
|
|
this.applyButton.setDisabled( true );
|
|
|
|
}
|
2014-05-31 19:09:07 +00:00
|
|
|
this.selectButton.$element.show();
|
2014-05-31 04:47:08 +00:00
|
|
|
this.applyButton.$element.show();
|
|
|
|
this.backButton.$element.hide();
|
|
|
|
this.search.buildIndex( this.getFragment().getDocument().getInternalList() );
|
2014-05-30 21:28:41 +00:00
|
|
|
|
|
|
|
if ( data.useExisting ) {
|
|
|
|
this.useExistingReference();
|
|
|
|
}
|
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.
|
|
|
|
this.selectButton.setDisabled(
|
|
|
|
this.selectedNode instanceof ve.dm.MWReferenceNode ||
|
|
|
|
this.search.isIndexEmpty()
|
|
|
|
);
|
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 () {
|
|
|
|
this.search.getQuery().setValue( '' );
|
2014-06-10 21:19:03 +00:00
|
|
|
if ( this.wikitextWarning ) {
|
|
|
|
this.wikitextWarning.close();
|
|
|
|
}
|
2014-05-31 04:47:08 +00:00
|
|
|
this.referenceSurface.destroy();
|
|
|
|
this.referenceSurface = null;
|
|
|
|
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 );
|