2017-04-20 16:08:44 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki Cite initialisation code.
|
|
|
|
*
|
2018-01-03 01:05:45 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
|
2017-12-29 12:12:35 +00:00
|
|
|
* @license MIT
|
2017-04-20 16:08:44 +00:00
|
|
|
*/
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2018-05-12 15:40:34 +00:00
|
|
|
( function () {
|
|
|
|
function fixTarget( target ) {
|
2021-11-03 12:28:17 +00:00
|
|
|
var toolGroups = target.static.toolbarGroups;
|
2016-04-27 20:03:49 +00:00
|
|
|
|
2021-11-03 12:28:17 +00:00
|
|
|
var i, iLen;
|
2016-04-27 20:03:49 +00:00
|
|
|
if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) {
|
2018-05-12 15:40:34 +00:00
|
|
|
for ( i = 0, iLen = toolGroups.length; i < iLen; i++ ) {
|
2021-11-03 12:28:17 +00:00
|
|
|
var toolGroup = toolGroups[ i ];
|
2018-05-12 15:40:34 +00:00
|
|
|
if ( toolGroup.name === 'insert' && ( !toolGroup.demote || toolGroup.demote.indexOf( 'reference' ) === -1 ) ) {
|
2016-07-09 18:22:14 +00:00
|
|
|
toolGroup.demote = toolGroup.demote || [];
|
|
|
|
toolGroup.demote.push( { group: 'cite' }, 'reference', 'reference/existing' );
|
2016-04-27 20:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-03 21:03:41 +00:00
|
|
|
} else {
|
2018-05-12 15:40:34 +00:00
|
|
|
// Find the reference placeholder group and replace it
|
|
|
|
for ( i = 0, iLen = toolGroups.length; i < iLen; i++ ) {
|
|
|
|
if ( toolGroups[ i ].name === 'reference' ) {
|
2021-11-03 12:28:17 +00:00
|
|
|
var group = {
|
2018-05-12 15:40:34 +00:00
|
|
|
// Change the name so it isn't replaced twice
|
|
|
|
name: 'cite',
|
|
|
|
type: 'list',
|
|
|
|
indicator: 'down',
|
|
|
|
include: [ { group: 'cite' }, 'reference', 'reference/existing' ],
|
|
|
|
demote: [ 'reference', 'reference/existing' ]
|
|
|
|
};
|
2021-11-03 12:28:17 +00:00
|
|
|
var label = OO.ui.deferMsg( 'cite-ve-toolbar-group-label' );
|
2018-05-12 15:40:34 +00:00
|
|
|
// Treat mobile targets differently
|
2019-09-18 02:11:32 +00:00
|
|
|
if ( target === ve.init.mw.MobileArticleTarget ) {
|
2018-05-12 15:40:34 +00:00
|
|
|
group.header = label;
|
|
|
|
group.title = label;
|
|
|
|
group.icon = 'reference';
|
|
|
|
} else {
|
|
|
|
group.label = label;
|
|
|
|
}
|
2021-11-03 12:28:17 +00:00
|
|
|
toolGroups[ i ] = group;
|
2018-05-12 15:40:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
2018-05-12 15:40:34 +00:00
|
|
|
}
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2021-11-03 12:28:17 +00:00
|
|
|
for ( var n in ve.init.mw.targetFactory.registry ) {
|
2020-09-12 23:12:43 +00:00
|
|
|
fixTarget( ve.init.mw.targetFactory.lookup( n ) );
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 15:40:34 +00:00
|
|
|
ve.init.mw.targetFactory.on( 'register', function ( name, target ) {
|
|
|
|
fixTarget( target );
|
|
|
|
} );
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/**
|
|
|
|
* Add reference insertion tools from on-wiki data.
|
|
|
|
*
|
|
|
|
* By adding a definition in JSON to MediaWiki:Visualeditor-cite-tool-definition, the cite menu can
|
|
|
|
* be populated with tools that create refrences containing a specific templates. The content of the
|
|
|
|
* definition should be an array containing a series of objects, one for each tool. Each object must
|
|
|
|
* contain a `name`, `icon` and `template` property. An optional `title` property can also be used
|
|
|
|
* to define the tool title in plain text. The `name` property is a unique identifier for the tool,
|
|
|
|
* and also provides a fallback title for the tool by being transformed into a message key. The name
|
|
|
|
* is prefixed with `visualeditor-cite-tool-name-`, and messages can be defined on Wiki. Some common
|
|
|
|
* messages are pre-defined for tool names such as `web`, `book`, `news` and `journal`.
|
|
|
|
*
|
|
|
|
* Example:
|
2019-04-12 13:11:47 +00:00
|
|
|
* [ { "name": "web", "icon": "browser", "template": "Cite web" }, ... ]
|
2016-02-03 21:03:41 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
( function () {
|
2021-11-10 20:56:35 +00:00
|
|
|
var deprecatedIcons = {
|
2019-04-12 13:11:47 +00:00
|
|
|
'ref-cite-book': 'book',
|
|
|
|
'ref-cite-journal': 'journal',
|
|
|
|
'ref-cite-news': 'newspaper',
|
|
|
|
'ref-cite-web': 'browser',
|
|
|
|
'reference-existing': 'referenceExisting'
|
2019-04-12 14:00:02 +00:00
|
|
|
},
|
|
|
|
defaultIcons = {
|
|
|
|
book: 'book',
|
|
|
|
journal: 'journal',
|
|
|
|
news: 'newspaper',
|
|
|
|
web: 'browser'
|
2019-04-12 13:11:47 +00:00
|
|
|
};
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2021-11-10 20:56:35 +00:00
|
|
|
// This is assigned server-side by CiteVisualEditorModule.php, before this file runs.
|
|
|
|
// Ensure it has a fallback, just in case.
|
|
|
|
ve.ui.mwCitationTools = ve.ui.mwCitationTools || [];
|
2019-03-28 15:47:46 +00:00
|
|
|
|
|
|
|
ve.ui.mwCitationTools.forEach( function ( item ) {
|
2021-11-03 12:28:17 +00:00
|
|
|
var hasOwn = Object.prototype.hasOwnProperty,
|
2019-02-15 14:57:44 +00:00
|
|
|
data = { template: item.template, title: item.title };
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2019-04-12 14:00:02 +00:00
|
|
|
if ( !item.icon && hasOwn.call( defaultIcons, item.name ) ) {
|
|
|
|
item.icon = defaultIcons[ item.name ];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hasOwn.call( deprecatedIcons, item.icon ) ) {
|
2019-04-12 13:11:47 +00:00
|
|
|
item.icon = deprecatedIcons[ item.icon ];
|
|
|
|
}
|
|
|
|
|
2019-03-28 15:47:46 +00:00
|
|
|
// Generate citation tool
|
2021-11-03 12:28:17 +00:00
|
|
|
var name = 'cite-' + item.name;
|
2019-03-28 15:47:46 +00:00
|
|
|
if ( !ve.ui.toolFactory.lookup( name ) ) {
|
2021-11-03 12:28:17 +00:00
|
|
|
var tool = function GeneratedMWCitationDialogTool() {
|
2019-03-28 15:47:46 +00:00
|
|
|
ve.ui.MWCitationDialogTool.apply( this, arguments );
|
|
|
|
};
|
|
|
|
OO.inheritClass( tool, ve.ui.MWCitationDialogTool );
|
|
|
|
tool.static.group = 'cite';
|
|
|
|
tool.static.name = name;
|
|
|
|
tool.static.icon = item.icon;
|
|
|
|
if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) {
|
|
|
|
tool.static.title = mw.msg( 'cite-ve-othergroup-item', item.title );
|
|
|
|
} else {
|
|
|
|
tool.static.title = item.title;
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
2019-03-28 15:47:46 +00:00
|
|
|
tool.static.commandName = name;
|
|
|
|
tool.static.template = item.template;
|
|
|
|
tool.static.autoAddToCatchall = false;
|
|
|
|
tool.static.autoAddToGroup = true;
|
|
|
|
tool.static.associatedWindows = [ name ];
|
|
|
|
ve.ui.toolFactory.register( tool );
|
|
|
|
ve.ui.commandRegistry.register(
|
|
|
|
new ve.ui.Command(
|
|
|
|
name, 'mwcite', 'open', { args: [ data ], supportedSelections: [ 'linear' ] }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2019-03-28 15:47:46 +00:00
|
|
|
// Generate citation context item
|
|
|
|
if ( !ve.ui.contextItemFactory.lookup( name ) ) {
|
2021-11-03 12:28:17 +00:00
|
|
|
var contextItem = function GeneratedMWCitationContextItem() {
|
2019-03-28 15:47:46 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWCitationContextItem.apply( this, arguments );
|
|
|
|
};
|
|
|
|
OO.inheritClass( contextItem, ve.ui.MWCitationContextItem );
|
|
|
|
contextItem.static.name = name;
|
|
|
|
contextItem.static.icon = item.icon;
|
|
|
|
contextItem.static.label = item.title;
|
|
|
|
contextItem.static.commandName = name;
|
|
|
|
contextItem.static.template = item.template;
|
|
|
|
ve.ui.contextItemFactory.register( contextItem );
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
2019-03-28 15:47:46 +00:00
|
|
|
} );
|
2016-11-15 12:59:21 +00:00
|
|
|
}() );
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
}() );
|