From 724d89054198be2f0e6388946e90d74d2063d5d0 Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Wed, 27 Apr 2016 21:03:49 +0100 Subject: [PATCH] Make it possible to send VE cite toolbar items to the 'insert' (other) group To be merged with Ifd688ae6 Bug: T133727 Change-Id: Ic87f996f2a95ffe89999384c48f11745f251db0e --- CiteHooks.php | 9 +++++++ extension.json | 9 +++++-- modules/ve-cite/i18n/en.json | 3 ++- modules/ve-cite/i18n/qqq.json | 5 ++-- modules/ve-cite/ve.ui.MWReference.init.js | 18 +++++++++++++- .../ve-cite/ve.ui.MWReferenceDialogTool.js | 24 +++++++++++++++---- 6 files changed, 58 insertions(+), 10 deletions(-) diff --git a/CiteHooks.php b/CiteHooks.php index b71b28bcb..1b927c4b3 100644 --- a/CiteHooks.php +++ b/CiteHooks.php @@ -135,4 +135,13 @@ class CiteHooks { // delete with reduced hold off period (LinksUpdate uses a master connection) $cache->delete( $key, WANObjectCache::MAX_COMMIT_DELAY ); } + + /** + * Adds extra variables to the global config + */ + public static function onResourceLoaderGetConfigVars( array &$vars ) { + $config = ConfigFactory::getDefaultInstance()->makeConfig( 'cite' ); + $vars['wgCiteVisualEditorOtherGroup'] = $config->get( 'CiteVisualEditorOtherGroup' ); + return true; + } } diff --git a/extension.json b/extension.json index b010e1c2a..afd93c488 100644 --- a/extension.json +++ b/extension.json @@ -38,6 +38,9 @@ ], "LinksUpdateComplete": [ "CiteHooks::onLinksUpdateComplete" + ], + "ResourceLoaderGetConfigVars": [ + "CiteHooks::onResourceLoaderGetConfigVars" ] }, "ResourceModules": { @@ -148,7 +151,8 @@ "cite-ve-dialogbutton-reference-title", "cite-ve-dialogbutton-referenceslist-tooltip", "cite-ve-reference-input-placeholder", - "cite-ve-toolbar-group-label" + "cite-ve-toolbar-group-label", + "cite-ve-othergroup-item" ], "targets": [ "desktop", @@ -170,7 +174,8 @@ "AllowCiteGroups": true, "CiteCacheReferences": false, "CiteStoreReferencesData": false, - "CiteCacheReferencesDataOnParse": false + "CiteCacheReferencesDataOnParse": false, + "CiteVisualEditorOtherGroup": false }, "AutoloadClasses": { "ApiQueryReferences": "ApiQueryReferences.php", diff --git a/modules/ve-cite/i18n/en.json b/modules/ve-cite/i18n/en.json index a96588915..f3a57bda1 100644 --- a/modules/ve-cite/i18n/en.json +++ b/modules/ve-cite/i18n/en.json @@ -44,5 +44,6 @@ "cite-ve-referenceslist-isempty": "There are no references with the group \"$1\" on this page to include in this list.", "cite-ve-referenceslist-isempty-default": "There are no references on this page to include in this list.", "cite-ve-referenceslist-missingref": "This reference is defined in a template or other generated block, and for now can only be edited in source mode.", - "cite-ve-toolbar-group-label": "Cite" + "cite-ve-toolbar-group-label": "Cite", + "cite-ve-othergroup-item": "$1 reference" } \ No newline at end of file diff --git a/modules/ve-cite/i18n/qqq.json b/modules/ve-cite/i18n/qqq.json index 71468abfc..fad98b953 100644 --- a/modules/ve-cite/i18n/qqq.json +++ b/modules/ve-cite/i18n/qqq.json @@ -54,5 +54,6 @@ "cite-ve-referenceslist-isempty": "Message that appears in the references list when there are no references on the page of that group.\n\nParameters:\n* $1 - reference-group name", "cite-ve-referenceslist-isempty-default": "Message that appears in the references list when there are no references on the page in the default group.", "cite-ve-referenceslist-missingref": "Message that appears in the references list, and as a tooltip on the reference itself, for references that are generated by a template or are otherwise uneditable.\n\nSee also:\n* {{msg-mw|visualeditor-dialog-meta-languages-readonlynote}}", - "cite-ve-toolbar-group-label": "Label text for the toolbar button for inserting customized references.\n{{Identical|Cite}}" -} + "cite-ve-toolbar-group-label": "Label text for the toolbar button for inserting customized references.\n{{Identical|Cite}}", + "cite-ve-othergroup-item": "Label text for the toolbar items under the 'Insert' (other) group if VisualEditor is configured that way.\n\nParameters:\n* $1 - citation type label" +} \ No newline at end of file diff --git a/modules/ve-cite/ve.ui.MWReference.init.js b/modules/ve-cite/ve.ui.MWReference.init.js index e2bca2fac..c36ad21a9 100644 --- a/modules/ve-cite/ve.ui.MWReference.init.js +++ b/modules/ve-cite/ve.ui.MWReference.init.js @@ -12,6 +12,18 @@ } toolGroups = target.static.toolbarGroups; linkIndex = toolGroups.length; + + if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) { + for ( j = 0; j < linkIndex; j++ ) { + if ( toolGroups[ j ].include === '*' ) { + toolGroups[ j ].type = 'list'; + toolGroups[ j ].include = [ '*', { group: 'cite' }, 'reference', 'reference/existing' ]; + toolGroups[ j ].demote = [ 'reference', 'reference/existing' ]; + } + } + continue; + } + for ( j = 0, jLen = toolGroups.length; j < jLen; j++ ) { if ( ve.getProp( toolGroups[ j ], 'include', 0, 'group' ) === 'cite' ) { // Skip if the cite group exists already @@ -99,7 +111,11 @@ tool.static.group = 'cite'; tool.static.name = name; tool.static.icon = item.icon; - tool.static.title = item.title; + if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) { + tool.static.title = mw.msg( 'cite-ve-othergroup-item', item.title ); + } else { + tool.static.title = item.title; + } tool.static.commandName = name; tool.static.template = item.template; tool.static.autoAddToCatchall = false; diff --git a/modules/ve-cite/ve.ui.MWReferenceDialogTool.js b/modules/ve-cite/ve.ui.MWReferenceDialogTool.js index 5e6b95437..f034b880c 100644 --- a/modules/ve-cite/ve.ui.MWReferenceDialogTool.js +++ b/modules/ve-cite/ve.ui.MWReferenceDialogTool.js @@ -21,8 +21,16 @@ OO.inheritClass( ve.ui.MWReferenceDialogTool, ve.ui.FragmentWindowTool ); ve.ui.MWReferenceDialogTool.static.name = 'reference'; ve.ui.MWReferenceDialogTool.static.group = 'object'; ve.ui.MWReferenceDialogTool.static.icon = 'reference'; -ve.ui.MWReferenceDialogTool.static.title = - OO.ui.deferMsg( 'cite-ve-dialogbutton-reference-tooltip' ); +if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) { + ve.ui.MWReferenceDialogTool.static.title = OO.ui.deferMsg( + 'cite-ve-othergroup-item', + OO.ui.msg( 'cite-ve-dialogbutton-reference-tooltip' ) + ); +} else { + ve.ui.MWReferenceDialogTool.static.title = OO.ui.deferMsg( + 'cite-ve-dialogbutton-reference-tooltip' + ); +} ve.ui.MWReferenceDialogTool.static.modelClasses = [ ve.dm.MWReferenceNode ]; ve.ui.MWReferenceDialogTool.static.commandName = 'reference'; ve.ui.MWReferenceDialogTool.static.autoAddToCatchall = false; @@ -44,8 +52,16 @@ OO.inheritClass( ve.ui.MWUseExistingReferenceDialogTool, ve.ui.WindowTool ); ve.ui.MWUseExistingReferenceDialogTool.static.name = 'reference/existing'; ve.ui.MWUseExistingReferenceDialogTool.static.group = 'object'; ve.ui.MWUseExistingReferenceDialogTool.static.icon = 'reference-existing'; -ve.ui.MWUseExistingReferenceDialogTool.static.title = - OO.ui.deferMsg( 'cite-ve-dialog-reference-useexisting-tool' ); +if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) { + ve.ui.MWUseExistingReferenceDialogTool.static.title = OO.ui.deferMsg( + 'cite-ve-othergroup-item', + OO.ui.msg( 'cite-ve-dialog-reference-useexisting-tool' ) + ); +} else { + ve.ui.MWUseExistingReferenceDialogTool.static.title = OO.ui.deferMsg( + 'cite-ve-dialog-reference-useexisting-tool' + ); +} ve.ui.MWUseExistingReferenceDialogTool.static.commandName = 'reference/existing'; ve.ui.MWUseExistingReferenceDialogTool.static.autoAddToGroup = false; ve.ui.MWUseExistingReferenceDialogTool.static.autoAddToCatchall = false;