From d23d09628122881bf4bcc91d2bc56c169019dbf8 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 20 Jul 2019 01:09:04 -0700 Subject: [PATCH] Convert ext.wikiEditor module to packageFiles This allows us to bundle the wgWikiEditorMagicWords and mw.msg.wikiEditor(?!) config vars that were previously exported globally in the startup module. This code is old and crufty, so this is a somewhat minimal conversion: * Use require() for jquery.wikiEditor.{dialogs,toolbar}.config.js, and for jquery.wikiEditor.{dialogs,toolbar}.js * Don't attempt to convert jquery.wikiEditor.js to something require-based, instead just run it and let it set the $.wikiEditor and $.fn.wikiEditor globals * Consolidate ext.wikiEditor.{dialogs,toolbars}.js into ext.wikiEditor.js Bug: T222828 Change-Id: Ia75d685cbde786e8fceb6db36f2436b2beea1499 --- extension.json | 14 +- includes/WikiEditorHooks.php | 35 +- modules/ext.wikiEditor.dialogs.js | 10 - modules/ext.wikiEditor.js | 19 +- modules/ext.wikiEditor.toolbar.js | 12 - modules/jquery.wikiEditor.dialogs.config.js | 16 +- modules/jquery.wikiEditor.dialogs.js | 28 +- modules/jquery.wikiEditor.js | 5 +- modules/jquery.wikiEditor.toolbar.config.js | 1210 +++++++++---------- modules/jquery.wikiEditor.toolbar.js | 66 +- 10 files changed, 717 insertions(+), 698 deletions(-) delete mode 100644 modules/ext.wikiEditor.dialogs.js delete mode 100644 modules/ext.wikiEditor.toolbar.js diff --git a/extension.json b/extension.json index d1e55c97..0c10ac42 100644 --- a/extension.json +++ b/extension.json @@ -27,9 +27,6 @@ "GetPreferences": [ "WikiEditorHooks::getPreferences" ], - "ResourceLoaderGetConfigVars": [ - "WikiEditorHooks::resourceLoaderGetConfigVars" - ], "EditPageBeforeEditToolbar": [ "WikiEditorHooks::EditPageBeforeEditToolbar" ], @@ -46,15 +43,18 @@ "ResourceModules": { "ext.wikiEditor": { "group": "ext.wikiEditor", - "scripts": [ + "packageFiles": [ + "ext.wikiEditor.js", "jquery.wikiEditor.js", "jquery.wikiEditor.toolbar.js", "jquery.wikiEditor.toolbar.config.js", "jquery.wikiEditor.dialogs.js", "jquery.wikiEditor.dialogs.config.js", - "ext.wikiEditor.js", - "ext.wikiEditor.toolbar.js", - "ext.wikiEditor.dialogs.js" + { + "name": "data.json", + "callback": "WikiEditorHooks::getModuleData", + "versionCallback": "WikiEditorHooks::getModuleDataSummary" + } ], "styles": [ "jquery.wikiEditor.less", diff --git a/includes/WikiEditorHooks.php b/includes/WikiEditorHooks.php index d462b015..f1b78fe6 100644 --- a/includes/WikiEditorHooks.php +++ b/includes/WikiEditorHooks.php @@ -185,20 +185,39 @@ class WikiEditorHooks { } /** - * @param array &$vars + * @param ResourceLoaderContext $context + * @param Config $config + * @return array */ - public static function resourceLoaderGetConfigVars( &$vars ) { - // expose magic words for use by the wikieditor toolbar - self::getMagicWords( $vars ); + public static function getModuleData( ResourceLoaderContext $context, Config $config ) { + return [ + // expose magic words for use by the wikieditor toolbar + 'magicWords' => self::getMagicWords(), + 'signature' => self::getSignatureMessage( $context ) + ]; + } - $vars['mw.msg.wikieditor'] = wfMessage( 'sig-text', '~~~~' )->inContentLanguage()->text(); + /** + * @param ResourceLoaderContext $context + * @param Config $config + * @return array + */ + public static function getModuleDataSummary( ResourceLoaderContext $context, Config $config ) { + return [ + 'magicWords' => self::getMagicWords(), + 'signature' => self::getSignatureMessage( $context, true ) + ]; + } + + private static function getSignatureMessage( MessageLocalizer $ml, $raw = false ) { + $msg = $ml->msg( 'sig-text' )->params( '~~~~' )->inContentLanguage(); + return $raw ? $msg->plain() : $msg->text(); } /** * Expose useful magic words which are used by the wikieditor toolbar - * @param array &$vars */ - private static function getMagicWords( &$vars ) { + private static function getMagicWords() { $requiredMagicWords = [ 'redirect', 'img_right', @@ -220,7 +239,7 @@ class WikiEditorHooks { $magicWords[$name] = MagicWord::get( $name )->getSynonym( 0 ); } } - $vars['wgWikiEditorMagicWords'] = $magicWords; + return $magicWords; } /** diff --git a/modules/ext.wikiEditor.dialogs.js b/modules/ext.wikiEditor.dialogs.js deleted file mode 100644 index f34694ce..00000000 --- a/modules/ext.wikiEditor.dialogs.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * JavaScript for WikiEditor Dialogs - */ -$( function () { - // Replace icons - $.wikiEditor.modules.dialogs.config.replaceIcons( $( '#wpTextbox1' ) ); - - // Add dialogs module - $( '#wpTextbox1' ).wikiEditor( 'addModule', $.wikiEditor.modules.dialogs.config.getDefaultConfig() ); -} ); diff --git a/modules/ext.wikiEditor.js b/modules/ext.wikiEditor.js index de240f7b..77c5f08b 100644 --- a/modules/ext.wikiEditor.js +++ b/modules/ext.wikiEditor.js @@ -12,6 +12,9 @@ }, trackdebug = !!mw.util.getParamValue( 'trackdebug' ); + // This sets $.wikiEditor and $.fn.wikiEditor + require( './jquery.wikiEditor.js' ); + function log() { // mw.log is a no-op unless resource loader is in debug mode, so // this allows trackdebug to work independently (T211698) @@ -127,7 +130,7 @@ var $textarea = $( '#wpTextbox1' ), $editingSessionIdInput = $( '#editingStatsId' ), origText = $textarea.val(), - submitting, onUnloadFallback; + submitting, onUnloadFallback, dialogsConfig; if ( $editingSessionIdInput.length ) { editingSessionId = $editingSessionIdInput.val(); @@ -189,5 +192,19 @@ logAbort( true, unmodified ); } ); } + + // The old toolbar is still in place and needs to be removed so there aren't two toolbars + $( '#toolbar' ).remove(); + // Add toolbar module + // TODO: Implement .wikiEditor( 'remove' ) + $textarea.wikiEditor( + 'addModule', require( './jquery.wikiEditor.toolbar.config.js' ) + ); + + dialogsConfig = require( './jquery.wikiEditor.dialogs.config.js' ); + // Replace icons + dialogsConfig.replaceIcons( $textarea ); + // Add dialogs module + $textarea.wikiEditor( 'addModule', dialogsConfig.getDefaultConfig() ); } ); }() ); diff --git a/modules/ext.wikiEditor.toolbar.js b/modules/ext.wikiEditor.toolbar.js deleted file mode 100644 index f9eb064c..00000000 --- a/modules/ext.wikiEditor.toolbar.js +++ /dev/null @@ -1,12 +0,0 @@ -/* - * JavaScript for WikiEditor Toolbar - */ -$( function () { - // The old toolbar is still in place and needs to be removed so there aren't two toolbars - $( '#toolbar' ).remove(); - // Add toolbar module - // TODO: Implement .wikiEditor( 'remove' ) - $( '#wpTextbox1' ).wikiEditor( - 'addModule', $.wikiEditor.modules.toolbar.config.getDefaultConfig() - ); -} ); diff --git a/modules/jquery.wikiEditor.dialogs.config.js b/modules/jquery.wikiEditor.dialogs.config.js index 68f43716..fb1855ba 100644 --- a/modules/jquery.wikiEditor.dialogs.config.js +++ b/modules/jquery.wikiEditor.dialogs.config.js @@ -3,9 +3,11 @@ */ ( function () { - var hasOwn = Object.prototype.hasOwnProperty; + var hasOwn = Object.prototype.hasOwnProperty, + toolbarModule = require( './jquery.wikiEditor.toolbar.js' ), + configData = require( './data.json' ); - $.wikiEditor.modules.dialogs.config = { + module.exports = { replaceIcons: function ( $textarea ) { $textarea @@ -428,7 +430,7 @@ insertText = whitespace[ 0 ] + insertText + whitespace[ 1 ]; } $( this ).dialog( 'close' ); - $.wikiEditor.modules.toolbar.fn.doAction( $( this ).data( 'context' ), { + toolbarModule.fn.doAction( $( this ).data( 'context' ), { type: 'replace', options: { pre: insertText @@ -539,7 +541,7 @@ id: 'wikieditor-toolbar-file-dialog', htmlTemplate: 'dialogInsertFile.html', init: function () { - var magicWordsI18N = mw.config.get( 'wgWikiEditorMagicWords' ), + var magicWordsI18N = configData.magicWords, defaultMsg = mw.msg( 'wikieditor-toolbar-file-default' ); $( this ).find( '[data-i18n-magic]' ) .text( function () { @@ -565,7 +567,7 @@ var fileName, caption, fileFloat, fileFormat, fileSize, whitespace, fileTitle, options, fileUse, hasPxRgx = /.+px$/, - magicWordsI18N = mw.config.get( 'wgWikiEditorMagicWords' ); + magicWordsI18N = configData.magicWords; fileName = $( '#wikieditor-toolbar-file-target' ).val(); caption = $( '#wikieditor-toolbar-file-caption' ).val(); fileFloat = $( '#wikieditor-toolbar-file-float' ).val(); @@ -594,7 +596,7 @@ } fileUse = options.length === 0 ? fileName : ( fileName + '|' + options.join( '|' ) ); $( this ).dialog( 'close' ); - $.wikiEditor.modules.toolbar.fn.doAction( + toolbarModule.fn.doAction( $( this ).data( 'context' ), { type: 'replace', @@ -863,7 +865,7 @@ } classStr = classes.length > 0 ? ' class="' + classes.join( ' ' ) + '"' : ''; $( this ).dialog( 'close' ); - $.wikiEditor.modules.toolbar.fn.doAction( + toolbarModule.fn.doAction( $( this ).data( 'context' ), { type: 'replace', diff --git a/modules/jquery.wikiEditor.dialogs.js b/modules/jquery.wikiEditor.dialogs.js index 7f182c36..b77f112a 100644 --- a/modules/jquery.wikiEditor.dialogs.js +++ b/modules/jquery.wikiEditor.dialogs.js @@ -3,22 +3,22 @@ */ ( function () { - $.wikiEditor.modules.dialogs = { + var dialogsModule = { /** * API accessible functions */ api: { addDialog: function ( context, data ) { - $.wikiEditor.modules.dialogs.fn.create( context, data ); + dialogsModule.fn.create( context, data ); }, openDialog: function ( context, module ) { var mod, $dialog; - if ( module in $.wikiEditor.modules.dialogs.modules ) { - mod = $.wikiEditor.modules.dialogs.modules[ module ]; + if ( module in dialogsModule.modules ) { + mod = dialogsModule.modules[ module ]; $dialog = $( '#' + mod.id ); if ( $dialog.length === 0 ) { - $.wikiEditor.modules.dialogs.fn.reallyCreate( context, mod, module ); + dialogsModule.fn.reallyCreate( context, mod, module ); $dialog = $( '#' + mod.id ); } @@ -31,8 +31,8 @@ } }, closeDialog: function ( context, module ) { - if ( module in $.wikiEditor.modules.dialogs.modules ) { - $( '#' + $.wikiEditor.modules.dialogs.modules[ module ].id ).dialog( 'close' ); + if ( module in dialogsModule.modules ) { + $( '#' + dialogsModule.modules[ module ].id ).dialog( 'close' ); } } }, @@ -71,11 +71,11 @@ // Re-select from the DOM, we might have removed the dialog just now $existingDialog = $( '#' + module.id ); if ( !filtered && $existingDialog.length === 0 ) { - $.wikiEditor.modules.dialogs.modules[ mod ] = module; + dialogsModule.modules[ mod ] = module; context.$textarea.trigger( 'wikiEditor-dialogs-setup-' + mod ); // If this dialog requires immediate creation, create it now if ( typeof module.immediateCreate !== 'undefined' && module.immediateCreate ) { - $.wikiEditor.modules.dialogs.fn.reallyCreate( context, module, mod ); + dialogsModule.fn.reallyCreate( context, module, mod ); } } } @@ -86,7 +86,7 @@ * * @param {Object} context Context object of editor dialog belongs to * @param {Object} module Dialog module object - * @param {string} name Dialog name (key in $.wikiEditor.modules.dialogs.modules) + * @param {string} name Dialog name (key in dialogsModule.modules) */ reallyCreate: function ( context, module, name ) { var msg, $dialogDiv, $content, @@ -123,14 +123,14 @@ .each( module.init ) .dialog( configuration ); // Set tabindexes on buttons added by .dialog() - $.wikiEditor.modules.dialogs.fn.setTabindexes( $dialogDiv.closest( '.ui-dialog' ) + dialogsModule.fn.setTabindexes( $dialogDiv.closest( '.ui-dialog' ) .find( 'button' ).not( '[tabindex]' ) ); if ( !( 'resizeme' in module ) || module.resizeme ) { $dialogDiv - .on( 'dialogopen', $.wikiEditor.modules.dialogs.fn.resize ) + .on( 'dialogopen', dialogsModule.fn.resize ) .find( '.ui-tabs' ).on( 'tabsshow', function () { $( this ).closest( '.ui-dialog-content' ).each( - $.wikiEditor.modules.dialogs.fn.resize ); + dialogsModule.fn.resize ); } ); } $dialogDiv.on( 'dialogclose', function () { @@ -212,4 +212,6 @@ }; + module.exports = dialogsModule; + }() ); diff --git a/modules/jquery.wikiEditor.js b/modules/jquery.wikiEditor.js index cb5814fc..b346ad42 100644 --- a/modules/jquery.wikiEditor.js +++ b/modules/jquery.wikiEditor.js @@ -39,7 +39,10 @@ * module name. The existence of a module in this object only indicates the module is available. To check if a * module is in use by a specific context check the context.modules object. */ - modules: {}, + modules: { + toolbar: require( './jquery.wikiEditor.toolbar.js' ), + dialogs: require( './jquery.wikiEditor.dialogs.js' ) + }, /** * A context can be extended, such as adding iframe support, on a per-wikiEditor instance basis. diff --git a/modules/jquery.wikiEditor.toolbar.config.js b/modules/jquery.wikiEditor.toolbar.config.js index 4128e6b4..daa868b2 100644 --- a/modules/jquery.wikiEditor.toolbar.config.js +++ b/modules/jquery.wikiEditor.toolbar.config.js @@ -3,630 +3,626 @@ */ ( function () { - $.wikiEditor.modules.toolbar.config = { + var configData = require( './data.json' ), + fileNamespace = mw.config.get( 'wgFormattedNamespaces' )[ 6 ], + specialCharacterGroups = require( 'mediawiki.language.specialCharacters' ), + toolbarConfig; - getDefaultConfig: function () { - var result, - fileNamespace = mw.config.get( 'wgFormattedNamespaces' )[ 6 ], - specialCharacterGroups = require( 'mediawiki.language.specialCharacters' ); - result = { - toolbar: { - // Main section - main: { - type: 'toolbar', - groups: { - format: { - tools: { - bold: { - labelMsg: 'wikieditor-toolbar-tool-bold', - type: 'button', - oouiIcon: 'bold', - action: { - type: 'encapsulate', - options: { - pre: "'''", - periMsg: 'wikieditor-toolbar-tool-bold-example', - post: "'''" - } - } - }, - italic: { - section: 'main', - group: 'format', - id: 'italic', - labelMsg: 'wikieditor-toolbar-tool-italic', - type: 'button', - oouiIcon: 'italic', - action: { - type: 'encapsulate', - options: { - pre: "''", - periMsg: 'wikieditor-toolbar-tool-italic-example', - post: "''" - } - } + toolbarConfig = { + toolbar: { + // Main section + main: { + type: 'toolbar', + groups: { + format: { + tools: { + bold: { + labelMsg: 'wikieditor-toolbar-tool-bold', + type: 'button', + oouiIcon: 'bold', + action: { + type: 'encapsulate', + options: { + pre: "'''", + periMsg: 'wikieditor-toolbar-tool-bold-example', + post: "'''" } } }, - insert: { - tools: { - signature: { - labelMsg: 'wikieditor-toolbar-tool-signature', - type: 'button', - oouiIcon: 'signature', - action: { - type: 'encapsulate', - options: { - pre: mw.config.get( 'mw.msg.wikieditor' ) - } - } + italic: { + section: 'main', + group: 'format', + id: 'italic', + labelMsg: 'wikieditor-toolbar-tool-italic', + type: 'button', + oouiIcon: 'italic', + action: { + type: 'encapsulate', + options: { + pre: "''", + periMsg: 'wikieditor-toolbar-tool-italic-example', + post: "''" } } } } }, - // Format section - advanced: { - labelMsg: 'wikieditor-toolbar-section-advanced', - type: 'toolbar', - groups: { - heading: { - tools: { - heading: { - labelMsg: 'wikieditor-toolbar-tool-heading', - type: 'select', - list: { - 'heading-2': { - labelMsg: 'wikieditor-toolbar-tool-heading-2', - action: { - type: 'encapsulate', - options: { - pre: '== ', - periMsg: 'wikieditor-toolbar-tool-heading-example', - post: ' ==', - regex: /^(\s*)(={1,6})(.*?)\2(\s*)$/, - regexReplace: '$1==$3==$4', - ownline: true - } - } - }, - 'heading-3': { - labelMsg: 'wikieditor-toolbar-tool-heading-3', - action: { - type: 'encapsulate', - options: { - pre: '=== ', - periMsg: 'wikieditor-toolbar-tool-heading-example', - post: ' ===', - regex: /^(\s*)(={1,6})(.*?)\2(\s*)$/, - regexReplace: '$1===$3===$4', - ownline: true - } - } - }, - 'heading-4': { - labelMsg: 'wikieditor-toolbar-tool-heading-4', - action: { - type: 'encapsulate', - options: { - pre: '==== ', - periMsg: 'wikieditor-toolbar-tool-heading-example', - post: ' ====', - regex: /^(\s*)(={1,6})(.*?)\2(\s*)$/, - regexReplace: '$1====$3====$4', - ownline: true - } - } - }, - 'heading-5': { - labelMsg: 'wikieditor-toolbar-tool-heading-5', - action: { - type: 'encapsulate', - options: { - pre: '===== ', - periMsg: 'wikieditor-toolbar-tool-heading-example', - post: ' =====', - regex: /^(\s*)(={1,6})(.*?)\2(\s*)$/, - regexReplace: '$1=====$3=====$4', - ownline: true - } - } - } - } + insert: { + tools: { + signature: { + labelMsg: 'wikieditor-toolbar-tool-signature', + type: 'button', + oouiIcon: 'signature', + action: { + type: 'encapsulate', + options: { + pre: configData.signature } } - }, - format: { - labelMsg: 'wikieditor-toolbar-group-format', - tools: { - ulist: { - labelMsg: 'wikieditor-toolbar-tool-ulist', - type: 'button', - oouiIcon: 'listBullet', - action: { - type: 'encapsulate', - options: { - pre: '* ', - periMsg: 'wikieditor-toolbar-tool-ulist-example', - post: '', - ownline: true, - splitlines: true - } - } - }, - olist: { - labelMsg: 'wikieditor-toolbar-tool-olist', - type: 'button', - oouiIcon: 'listNumbered', - action: { - type: 'encapsulate', - options: { - pre: '# ', - periMsg: 'wikieditor-toolbar-tool-olist-example', - post: '', - ownline: true, - splitlines: true - } - } - }, - nowiki: { - labelMsg: 'wikieditor-toolbar-tool-nowiki', - type: 'button', - oouiIcon: 'noWikiText', - action: { - type: 'encapsulate', - options: { - pre: '', - periMsg: 'wikieditor-toolbar-tool-nowiki-example', - post: '' - } - } - }, - newline: { - labelMsg: 'wikieditor-toolbar-tool-newline', - type: 'button', - oouiIcon: 'newline', - action: { - type: 'encapsulate', - options: { - pre: '
\n' - } - } - } - } - }, - size: { - tools: { - big: { - labelMsg: 'wikieditor-toolbar-tool-big', - type: 'button', - oouiIcon: 'bigger', - action: { - type: 'encapsulate', - options: { - pre: '', - periMsg: 'wikieditor-toolbar-tool-big-example', - post: '' - } - } - }, - small: { - labelMsg: 'wikieditor-toolbar-tool-small', - type: 'button', - oouiIcon: 'smaller', - action: { - type: 'encapsulate', - options: { - pre: '', - periMsg: 'wikieditor-toolbar-tool-small-example', - post: '' - } - } - }, - superscript: { - labelMsg: 'wikieditor-toolbar-tool-superscript', - type: 'button', - oouiIcon: 'superscript', - action: { - type: 'encapsulate', - options: { - pre: '', - periMsg: 'wikieditor-toolbar-tool-superscript-example', - post: '' - } - } - }, - subscript: { - labelMsg: 'wikieditor-toolbar-tool-subscript', - type: 'button', - oouiIcon: 'subscript', - action: { - type: 'encapsulate', - options: { - pre: '', - periMsg: 'wikieditor-toolbar-tool-subscript-example', - post: '' - } - } - } - } - }, - insert: { - labelMsg: 'wikieditor-toolbar-group-insert', - tools: { - gallery: { - labelMsg: 'wikieditor-toolbar-tool-gallery', - type: 'button', - oouiIcon: 'imageGallery', - action: { - type: 'encapsulate', - options: { - pre: '\n', - periMsg: [ - 'wikieditor-toolbar-tool-gallery-example', - fileNamespace - ], - post: '\n', - ownline: true - } - } - }, - redirect: { - labelMsg: 'wikieditor-toolbar-tool-redirect', - type: 'button', - oouiIcon: 'articleRedirect', - action: { - type: 'encapsulate', - options: { - pre: mw.config.get( 'wgWikiEditorMagicWords' ).redirect + ' [[', - periMsg: 'wikieditor-toolbar-tool-redirect-example', - post: ']]', - ownline: true - } - } - } - } - } - } - }, - characters: { - labelMsg: 'wikieditor-toolbar-section-characters', - type: 'booklet', - deferLoad: true, - pages: { - latin: { - labelMsg: 'special-characters-group-latin', - layout: 'characters', - characters: specialCharacterGroups.latin - }, - latinextended: { - labelMsg: 'special-characters-group-latinextended', - layout: 'characters', - characters: specialCharacterGroups.latinextended - }, - ipa: { - labelMsg: 'special-characters-group-ipa', - layout: 'characters', - characters: specialCharacterGroups.ipa - }, - symbols: { - labelMsg: 'special-characters-group-symbols', - layout: 'characters', - characters: specialCharacterGroups.symbols - }, - greek: { - labelMsg: 'special-characters-group-greek', - layout: 'characters', - language: 'el', - characters: specialCharacterGroups.greek - }, - greekextended: { - labelMsg: 'special-characters-group-greekextended', - layout: 'characters', - characters: specialCharacterGroups.greekextended - }, - cyrillic: { - labelMsg: 'special-characters-group-cyrillic', - layout: 'characters', - characters: specialCharacterGroups.cyrillic - }, - // The core 28-letter alphabet, special letters for the Arabic language, - // vowels, punctuation, digits. - // Names of letters are written as in the Unicode charts. - arabic: { - labelMsg: 'special-characters-group-arabic', - layout: 'characters', - language: 'ar', - direction: 'rtl', - characters: specialCharacterGroups.arabic - }, - // Characters for languages other than Arabic. - arabicextended: { - labelMsg: 'special-characters-group-arabicextended', - layout: 'characters', - language: 'ar', - direction: 'rtl', - characters: specialCharacterGroups.arabicextended - }, - hebrew: { - labelMsg: 'special-characters-group-hebrew', - layout: 'characters', - direction: 'rtl', - characters: specialCharacterGroups.hebrew - }, - bangla: { - labelMsg: 'special-characters-group-bangla', - language: 'bn', - layout: 'characters', - characters: specialCharacterGroups.bangla - }, - tamil: { - labelMsg: 'special-characters-group-tamil', - language: 'ta', - layout: 'characters', - characters: specialCharacterGroups.tamil - }, - telugu: { - labelMsg: 'special-characters-group-telugu', - language: 'te', - layout: 'characters', - characters: specialCharacterGroups.telugu - }, - sinhala: { - labelMsg: 'special-characters-group-sinhala', - language: 'si', - layout: 'characters', - characters: specialCharacterGroups.sinhala - }, - devanagari: { - labelMsg: 'special-characters-group-devanagari', - layout: 'characters', - characters: specialCharacterGroups.devanagari - }, - gujarati: { - labelMsg: 'special-characters-group-gujarati', - language: 'gu', - layout: 'characters', - characters: specialCharacterGroups.gujarati - }, - thai: { - labelMsg: 'special-characters-group-thai', - language: 'th', - layout: 'characters', - characters: specialCharacterGroups.thai - }, - lao: { - labelMsg: 'special-characters-group-lao', - language: 'lo', - layout: 'characters', - characters: specialCharacterGroups.lao - }, - khmer: { - labelMsg: 'special-characters-group-khmer', - language: 'km', - layout: 'characters', - characters: specialCharacterGroups.khmer - }, - canadianaboriginal: { - labelMsg: 'special-characters-group-canadianaboriginal', - language: 'cr', - layout: 'characters', - characters: specialCharacterGroups.canadianaboriginal - } - } - }, - help: { - labelMsg: 'wikieditor-toolbar-section-help', - type: 'booklet', - deferLoad: true, - pages: { - format: { - labelMsg: 'wikieditor-toolbar-help-page-format', - layout: 'table', - headings: [ - { textMsg: 'wikieditor-toolbar-help-heading-description' }, - { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, - { textMsg: 'wikieditor-toolbar-help-heading-result' } - ], - rows: [ - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-italic-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-italic-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-italic-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-bold-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-bold-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-bold-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-bolditalic-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-bolditalic-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-bolditalic-result' } - } - ] - }, - link: { - labelMsg: 'wikieditor-toolbar-help-page-link', - layout: 'table', - headings: [ - { textMsg: 'wikieditor-toolbar-help-heading-description' }, - { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, - { textMsg: 'wikieditor-toolbar-help-heading-result' } - ], - rows: [ - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-ilink-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-ilink-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-ilink-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-xlink-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-xlink-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-xlink-result' } - } - ] - }, - heading: { - labelMsg: 'wikieditor-toolbar-help-page-heading', - layout: 'table', - headings: [ - { textMsg: 'wikieditor-toolbar-help-heading-description' }, - { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, - { textMsg: 'wikieditor-toolbar-help-heading-result' } - ], - rows: [ - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-heading2-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-heading2-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-heading2-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-heading3-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-heading3-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-heading3-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-heading4-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-heading4-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-heading4-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-heading5-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-heading5-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-heading5-result' } - } - ] - }, - list: { - labelMsg: 'wikieditor-toolbar-help-page-list', - layout: 'table', - headings: [ - { textMsg: 'wikieditor-toolbar-help-heading-description' }, - { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, - { textMsg: 'wikieditor-toolbar-help-heading-result' } - ], - rows: [ - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-ulist-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-ulist-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-ulist-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-olist-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-olist-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-olist-result' } - } - ] - }, - file: { - labelMsg: 'wikieditor-toolbar-help-page-file', - layout: 'table', - headings: [ - { textMsg: 'wikieditor-toolbar-help-heading-description' }, - { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, - { textMsg: 'wikieditor-toolbar-help-heading-result' } - ], - rows: [ - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-file-description' }, - syntax: { htmlMsg: [ - 'wikieditor-toolbar-help-content-file-syntax', - fileNamespace, - mw.config.get( 'wgWikiEditorMagicWords' ).img_thumbnail, - mw.message( 'wikieditor-toolbar-help-content-file-caption' ).text() - ] }, - result: { html: '
' + - '' + - '' + - '' + - '
' + - '' + - '
' + mw.message( 'wikieditor-toolbar-help-content-file-caption' ).escaped() + '
' + - '
' - } - } - ] - }, - reference: { - labelMsg: 'wikieditor-toolbar-help-page-reference', - layout: 'table', - headings: [ - { textMsg: 'wikieditor-toolbar-help-heading-description' }, - { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, - { textMsg: 'wikieditor-toolbar-help-heading-result' } - ], - rows: [ - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-reference-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-reference-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-reference-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-named-reference-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-named-reference-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-named-reference-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-rereference-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-rereference-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-rereference-result' } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-showreferences-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-showreferences-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-showreferences-result' } - } - ] - }, - discussion: { - labelMsg: 'wikieditor-toolbar-help-page-discussion', - layout: 'table', - headings: [ - { textMsg: 'wikieditor-toolbar-help-heading-description' }, - { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, - { textMsg: 'wikieditor-toolbar-help-heading-result' } - ], - rows: [ - { - description: { - htmlMsg: 'wikieditor-toolbar-help-content-signaturetimestamp-description' - }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-signaturetimestamp-syntax' }, - result: { htmlMsg: [ 'wikieditor-toolbar-help-content-signaturetimestamp-result', - mw.config.get( 'wgFormattedNamespaces' )[ 2 ], - mw.config.get( 'wgFormattedNamespaces' )[ 3 ] - ] } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-signature-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-signature-syntax' }, - result: { htmlMsg: [ - 'wikieditor-toolbar-help-content-signature-result', - mw.config.get( 'wgFormattedNamespaces' )[ 2 ], - mw.config.get( 'wgFormattedNamespaces' )[ 3 ] - ] } - }, - { - description: { htmlMsg: 'wikieditor-toolbar-help-content-indent-description' }, - syntax: { htmlMsg: 'wikieditor-toolbar-help-content-indent-syntax' }, - result: { htmlMsg: 'wikieditor-toolbar-help-content-indent-result' } - } - ] } } } } - }; - - // Remove the signature button on non-signature namespaces - if ( !mw.Title.wantSignaturesNamespace( mw.config.get( 'wgNamespaceNumber' ) ) ) { - delete result.toolbar.main.groups.insert.tools.signature; + }, + // Format section + advanced: { + labelMsg: 'wikieditor-toolbar-section-advanced', + type: 'toolbar', + groups: { + heading: { + tools: { + heading: { + labelMsg: 'wikieditor-toolbar-tool-heading', + type: 'select', + list: { + 'heading-2': { + labelMsg: 'wikieditor-toolbar-tool-heading-2', + action: { + type: 'encapsulate', + options: { + pre: '== ', + periMsg: 'wikieditor-toolbar-tool-heading-example', + post: ' ==', + regex: /^(\s*)(={1,6})(.*?)\2(\s*)$/, + regexReplace: '$1==$3==$4', + ownline: true + } + } + }, + 'heading-3': { + labelMsg: 'wikieditor-toolbar-tool-heading-3', + action: { + type: 'encapsulate', + options: { + pre: '=== ', + periMsg: 'wikieditor-toolbar-tool-heading-example', + post: ' ===', + regex: /^(\s*)(={1,6})(.*?)\2(\s*)$/, + regexReplace: '$1===$3===$4', + ownline: true + } + } + }, + 'heading-4': { + labelMsg: 'wikieditor-toolbar-tool-heading-4', + action: { + type: 'encapsulate', + options: { + pre: '==== ', + periMsg: 'wikieditor-toolbar-tool-heading-example', + post: ' ====', + regex: /^(\s*)(={1,6})(.*?)\2(\s*)$/, + regexReplace: '$1====$3====$4', + ownline: true + } + } + }, + 'heading-5': { + labelMsg: 'wikieditor-toolbar-tool-heading-5', + action: { + type: 'encapsulate', + options: { + pre: '===== ', + periMsg: 'wikieditor-toolbar-tool-heading-example', + post: ' =====', + regex: /^(\s*)(={1,6})(.*?)\2(\s*)$/, + regexReplace: '$1=====$3=====$4', + ownline: true + } + } + } + } + } + } + }, + format: { + labelMsg: 'wikieditor-toolbar-group-format', + tools: { + ulist: { + labelMsg: 'wikieditor-toolbar-tool-ulist', + type: 'button', + oouiIcon: 'listBullet', + action: { + type: 'encapsulate', + options: { + pre: '* ', + periMsg: 'wikieditor-toolbar-tool-ulist-example', + post: '', + ownline: true, + splitlines: true + } + } + }, + olist: { + labelMsg: 'wikieditor-toolbar-tool-olist', + type: 'button', + oouiIcon: 'listNumbered', + action: { + type: 'encapsulate', + options: { + pre: '# ', + periMsg: 'wikieditor-toolbar-tool-olist-example', + post: '', + ownline: true, + splitlines: true + } + } + }, + nowiki: { + labelMsg: 'wikieditor-toolbar-tool-nowiki', + type: 'button', + oouiIcon: 'noWikiText', + action: { + type: 'encapsulate', + options: { + pre: '', + periMsg: 'wikieditor-toolbar-tool-nowiki-example', + post: '' + } + } + }, + newline: { + labelMsg: 'wikieditor-toolbar-tool-newline', + type: 'button', + oouiIcon: 'newline', + action: { + type: 'encapsulate', + options: { + pre: '
\n' + } + } + } + } + }, + size: { + tools: { + big: { + labelMsg: 'wikieditor-toolbar-tool-big', + type: 'button', + oouiIcon: 'bigger', + action: { + type: 'encapsulate', + options: { + pre: '', + periMsg: 'wikieditor-toolbar-tool-big-example', + post: '' + } + } + }, + small: { + labelMsg: 'wikieditor-toolbar-tool-small', + type: 'button', + oouiIcon: 'smaller', + action: { + type: 'encapsulate', + options: { + pre: '', + periMsg: 'wikieditor-toolbar-tool-small-example', + post: '' + } + } + }, + superscript: { + labelMsg: 'wikieditor-toolbar-tool-superscript', + type: 'button', + oouiIcon: 'superscript', + action: { + type: 'encapsulate', + options: { + pre: '', + periMsg: 'wikieditor-toolbar-tool-superscript-example', + post: '' + } + } + }, + subscript: { + labelMsg: 'wikieditor-toolbar-tool-subscript', + type: 'button', + oouiIcon: 'subscript', + action: { + type: 'encapsulate', + options: { + pre: '', + periMsg: 'wikieditor-toolbar-tool-subscript-example', + post: '' + } + } + } + } + }, + insert: { + labelMsg: 'wikieditor-toolbar-group-insert', + tools: { + gallery: { + labelMsg: 'wikieditor-toolbar-tool-gallery', + type: 'button', + oouiIcon: 'imageGallery', + action: { + type: 'encapsulate', + options: { + pre: '\n', + periMsg: [ + 'wikieditor-toolbar-tool-gallery-example', + fileNamespace + ], + post: '\n', + ownline: true + } + } + }, + redirect: { + labelMsg: 'wikieditor-toolbar-tool-redirect', + type: 'button', + oouiIcon: 'articleRedirect', + action: { + type: 'encapsulate', + options: { + pre: configData.magicWords.redirect + ' [[', + periMsg: 'wikieditor-toolbar-tool-redirect-example', + post: ']]', + ownline: true + } + } + } + } + } + } + }, + characters: { + labelMsg: 'wikieditor-toolbar-section-characters', + type: 'booklet', + deferLoad: true, + pages: { + latin: { + labelMsg: 'special-characters-group-latin', + layout: 'characters', + characters: specialCharacterGroups.latin + }, + latinextended: { + labelMsg: 'special-characters-group-latinextended', + layout: 'characters', + characters: specialCharacterGroups.latinextended + }, + ipa: { + labelMsg: 'special-characters-group-ipa', + layout: 'characters', + characters: specialCharacterGroups.ipa + }, + symbols: { + labelMsg: 'special-characters-group-symbols', + layout: 'characters', + characters: specialCharacterGroups.symbols + }, + greek: { + labelMsg: 'special-characters-group-greek', + layout: 'characters', + language: 'el', + characters: specialCharacterGroups.greek + }, + greekextended: { + labelMsg: 'special-characters-group-greekextended', + layout: 'characters', + characters: specialCharacterGroups.greekextended + }, + cyrillic: { + labelMsg: 'special-characters-group-cyrillic', + layout: 'characters', + characters: specialCharacterGroups.cyrillic + }, + // The core 28-letter alphabet, special letters for the Arabic language, + // vowels, punctuation, digits. + // Names of letters are written as in the Unicode charts. + arabic: { + labelMsg: 'special-characters-group-arabic', + layout: 'characters', + language: 'ar', + direction: 'rtl', + characters: specialCharacterGroups.arabic + }, + // Characters for languages other than Arabic. + arabicextended: { + labelMsg: 'special-characters-group-arabicextended', + layout: 'characters', + language: 'ar', + direction: 'rtl', + characters: specialCharacterGroups.arabicextended + }, + hebrew: { + labelMsg: 'special-characters-group-hebrew', + layout: 'characters', + direction: 'rtl', + characters: specialCharacterGroups.hebrew + }, + bangla: { + labelMsg: 'special-characters-group-bangla', + language: 'bn', + layout: 'characters', + characters: specialCharacterGroups.bangla + }, + tamil: { + labelMsg: 'special-characters-group-tamil', + language: 'ta', + layout: 'characters', + characters: specialCharacterGroups.tamil + }, + telugu: { + labelMsg: 'special-characters-group-telugu', + language: 'te', + layout: 'characters', + characters: specialCharacterGroups.telugu + }, + sinhala: { + labelMsg: 'special-characters-group-sinhala', + language: 'si', + layout: 'characters', + characters: specialCharacterGroups.sinhala + }, + devanagari: { + labelMsg: 'special-characters-group-devanagari', + layout: 'characters', + characters: specialCharacterGroups.devanagari + }, + gujarati: { + labelMsg: 'special-characters-group-gujarati', + language: 'gu', + layout: 'characters', + characters: specialCharacterGroups.gujarati + }, + thai: { + labelMsg: 'special-characters-group-thai', + language: 'th', + layout: 'characters', + characters: specialCharacterGroups.thai + }, + lao: { + labelMsg: 'special-characters-group-lao', + language: 'lo', + layout: 'characters', + characters: specialCharacterGroups.lao + }, + khmer: { + labelMsg: 'special-characters-group-khmer', + language: 'km', + layout: 'characters', + characters: specialCharacterGroups.khmer + }, + canadianaboriginal: { + labelMsg: 'special-characters-group-canadianaboriginal', + language: 'cr', + layout: 'characters', + characters: specialCharacterGroups.canadianaboriginal + } + } + }, + help: { + labelMsg: 'wikieditor-toolbar-section-help', + type: 'booklet', + deferLoad: true, + pages: { + format: { + labelMsg: 'wikieditor-toolbar-help-page-format', + layout: 'table', + headings: [ + { textMsg: 'wikieditor-toolbar-help-heading-description' }, + { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, + { textMsg: 'wikieditor-toolbar-help-heading-result' } + ], + rows: [ + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-italic-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-italic-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-italic-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-bold-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-bold-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-bold-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-bolditalic-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-bolditalic-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-bolditalic-result' } + } + ] + }, + link: { + labelMsg: 'wikieditor-toolbar-help-page-link', + layout: 'table', + headings: [ + { textMsg: 'wikieditor-toolbar-help-heading-description' }, + { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, + { textMsg: 'wikieditor-toolbar-help-heading-result' } + ], + rows: [ + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-ilink-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-ilink-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-ilink-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-xlink-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-xlink-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-xlink-result' } + } + ] + }, + heading: { + labelMsg: 'wikieditor-toolbar-help-page-heading', + layout: 'table', + headings: [ + { textMsg: 'wikieditor-toolbar-help-heading-description' }, + { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, + { textMsg: 'wikieditor-toolbar-help-heading-result' } + ], + rows: [ + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-heading2-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-heading2-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-heading2-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-heading3-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-heading3-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-heading3-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-heading4-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-heading4-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-heading4-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-heading5-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-heading5-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-heading5-result' } + } + ] + }, + list: { + labelMsg: 'wikieditor-toolbar-help-page-list', + layout: 'table', + headings: [ + { textMsg: 'wikieditor-toolbar-help-heading-description' }, + { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, + { textMsg: 'wikieditor-toolbar-help-heading-result' } + ], + rows: [ + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-ulist-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-ulist-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-ulist-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-olist-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-olist-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-olist-result' } + } + ] + }, + file: { + labelMsg: 'wikieditor-toolbar-help-page-file', + layout: 'table', + headings: [ + { textMsg: 'wikieditor-toolbar-help-heading-description' }, + { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, + { textMsg: 'wikieditor-toolbar-help-heading-result' } + ], + rows: [ + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-file-description' }, + syntax: { htmlMsg: [ + 'wikieditor-toolbar-help-content-file-syntax', + fileNamespace, + configData.magicWords.img_thumbnail, + mw.message( 'wikieditor-toolbar-help-content-file-caption' ).text() + ] }, + result: { html: '
' + + '' + + '' + + '' + + '
' + + '' + + '
' + mw.message( 'wikieditor-toolbar-help-content-file-caption' ).escaped() + '
' + + '
' + } + } + ] + }, + reference: { + labelMsg: 'wikieditor-toolbar-help-page-reference', + layout: 'table', + headings: [ + { textMsg: 'wikieditor-toolbar-help-heading-description' }, + { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, + { textMsg: 'wikieditor-toolbar-help-heading-result' } + ], + rows: [ + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-reference-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-reference-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-reference-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-named-reference-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-named-reference-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-named-reference-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-rereference-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-rereference-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-rereference-result' } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-showreferences-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-showreferences-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-showreferences-result' } + } + ] + }, + discussion: { + labelMsg: 'wikieditor-toolbar-help-page-discussion', + layout: 'table', + headings: [ + { textMsg: 'wikieditor-toolbar-help-heading-description' }, + { textMsg: 'wikieditor-toolbar-help-heading-syntax' }, + { textMsg: 'wikieditor-toolbar-help-heading-result' } + ], + rows: [ + { + description: { + htmlMsg: 'wikieditor-toolbar-help-content-signaturetimestamp-description' + }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-signaturetimestamp-syntax' }, + result: { htmlMsg: [ 'wikieditor-toolbar-help-content-signaturetimestamp-result', + mw.config.get( 'wgFormattedNamespaces' )[ 2 ], + mw.config.get( 'wgFormattedNamespaces' )[ 3 ] + ] } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-signature-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-signature-syntax' }, + result: { htmlMsg: [ + 'wikieditor-toolbar-help-content-signature-result', + mw.config.get( 'wgFormattedNamespaces' )[ 2 ], + mw.config.get( 'wgFormattedNamespaces' )[ 3 ] + ] } + }, + { + description: { htmlMsg: 'wikieditor-toolbar-help-content-indent-description' }, + syntax: { htmlMsg: 'wikieditor-toolbar-help-content-indent-syntax' }, + result: { htmlMsg: 'wikieditor-toolbar-help-content-indent-result' } + } + ] + } + } } - - return result; } - }; + // Remove the signature button on non-signature namespaces + if ( !mw.Title.wantSignaturesNamespace( mw.config.get( 'wgNamespaceNumber' ) ) ) { + delete toolbarConfig.toolbar.main.groups.insert.tools.signature; + } + + module.exports = toolbarConfig; + }() ); diff --git a/modules/jquery.wikiEditor.toolbar.js b/modules/jquery.wikiEditor.toolbar.js index f4570f0b..80499a3c 100644 --- a/modules/jquery.wikiEditor.toolbar.js +++ b/modules/jquery.wikiEditor.toolbar.js @@ -3,7 +3,7 @@ */ ( function () { - $.wikiEditor.modules.toolbar = { + var toolbarModule = { /** * API accessible functions @@ -23,7 +23,7 @@ if ( section === 'main' ) { // Section context.modules.toolbar.$toolbar.prepend( - $.wikiEditor.modules.toolbar.fn.buildSection( + toolbarModule.fn.buildSection( context, section, data[ type ][ section ] ) ); @@ -31,11 +31,11 @@ } // Section $sections.append( - $.wikiEditor.modules.toolbar.fn.buildSection( context, section, data[ type ][ section ] ) + toolbarModule.fn.buildSection( context, section, data[ type ][ section ] ) ); // Tab $tabs.append( - $.wikiEditor.modules.toolbar.fn.buildTab( context, section, data[ type ][ section ] ) + toolbarModule.fn.buildTab( context, section, data[ type ][ section ] ) ); } break; @@ -47,7 +47,7 @@ for ( group in data[ type ] ) { // Group $section.append( - $.wikiEditor.modules.toolbar.fn.buildGroup( context, group, data[ type ][ group ] ) + toolbarModule.fn.buildGroup( context, group, data[ type ][ group ] ) ); } break; @@ -61,7 +61,7 @@ ); for ( tool in data[ type ] ) { // Tool - $group.append( $.wikiEditor.modules.toolbar.fn.buildTool( context, tool, data[ type ][ tool ] ) ); + $group.append( toolbarModule.fn.buildTool( context, tool, data[ type ][ tool ] ) ); } if ( $group.children().length ) { $group.removeClass( 'empty' ); @@ -79,13 +79,13 @@ ); for ( page in data[ type ] ) { // Page - $pages.append( $.wikiEditor.modules.toolbar.fn.buildPage( context, page, data[ type ][ page ] ) ); + $pages.append( toolbarModule.fn.buildPage( context, page, data[ type ][ page ] ) ); // Index $index.append( - $.wikiEditor.modules.toolbar.fn.buildBookmark( context, page, data[ type ][ page ] ) + toolbarModule.fn.buildBookmark( context, page, data[ type ][ page ] ) ); } - $.wikiEditor.modules.toolbar.fn.updateBookletSelection( context, data.section, $pages, $index ); + toolbarModule.fn.updateBookletSelection( context, data.section, $pages, $index ); break; case 'rows': if ( !( 'section' in data && 'page' in data ) ) { @@ -97,7 +97,7 @@ ); for ( i = 0; i < data.rows.length; i++ ) { // Row - $table.append( $.wikiEditor.modules.toolbar.fn.buildRow( context, data.rows[ i ] ) ); + $table.append( toolbarModule.fn.buildRow( context, data.rows[ i ] ) ); } break; case 'characters': @@ -112,14 +112,14 @@ for ( i = 0; i < data.characters.length; i++ ) { // Character $characters.append( - $( $.wikiEditor.modules.toolbar.fn.buildCharacter( data.characters[ i ], actions ) ) + $( toolbarModule.fn.buildCharacter( data.characters[ i ], actions ) ) .on( 'mousedown', function ( e ) { // No dragging! e.preventDefault(); return false; } ) .on( 'click', function ( e ) { - $.wikiEditor.modules.toolbar.fn.doAction( $( this ).parent().data( 'context' ), + toolbarModule.fn.doAction( $( this ).parent().data( 'context' ), $( this ).parent().data( 'actions' )[ $( this ).attr( 'rel' ) ] ); e.preventDefault(); return false; @@ -160,7 +160,7 @@ } else { // Just a page, remove the index too! context.modules.toolbar.$toolbar.find( index ).remove(); - $.wikiEditor.modules.toolbar.fn.updateBookletSelection( + toolbarModule.fn.updateBookletSelection( context, data.section, context.modules.toolbar.$toolbar.find( target ), @@ -200,7 +200,7 @@ context.modules.toolbar.$toolbar = $( '
' ) .addClass( 'wikiEditor-ui-toolbar' ) .attr( 'id', 'wikiEditor-ui-toolbar' ); - $.wikiEditor.modules.toolbar.fn.build( context, config ); + toolbarModule.fn.build( context, config ); context.$ui.find( '.wikiEditor-ui-top' ).append( context.modules.toolbar.$toolbar ); }, /** @@ -262,7 +262,7 @@ empty = true; if ( 'tools' in group ) { for ( tool in group.tools ) { - tool = $.wikiEditor.modules.toolbar.fn.buildTool( context, tool, group.tools[ tool ] ); + tool = toolbarModule.fn.buildTool( context, tool, group.tools[ tool ] ); if ( tool ) { // Consider a group with only hidden tools empty as well // .is( ':visible' ) always returns false because tool is not attached to the DOM yet @@ -342,13 +342,13 @@ } ); if ( $button.data( 'ooui' ) ) { $button.data( 'ooui' ).on( 'click', function () { - $.wikiEditor.modules.toolbar.fn.doAction( + toolbarModule.fn.doAction( context, tool.action ); } ); } else { $button.on( 'click', function ( e ) { - $.wikiEditor.modules.toolbar.fn.doAction( + toolbarModule.fn.doAction( context, tool.action ); e.preventDefault(); @@ -374,7 +374,7 @@ return false; } ) .on( 'click', function ( e ) { - $.wikiEditor.modules.toolbar.fn.doAction( + toolbarModule.fn.doAction( $( this ).data( 'context' ), $( this ).data( 'action' ), $( this ) ); // Hide the dropdown @@ -445,10 +445,10 @@ } ); if ( deferLoad ) { $page.one( 'loadPage', function () { - $.wikiEditor.modules.toolbar.fn.reallyBuildPage( context, id, page, $page ); + toolbarModule.fn.reallyBuildPage( context, id, page, $page ); } ); } else { - $.wikiEditor.modules.toolbar.fn.reallyBuildPage( context, id, page, $page ); + toolbarModule.fn.reallyBuildPage( context, id, page, $page ); } return $page; }, @@ -460,11 +460,11 @@ html = ''; if ( 'headings' in page ) { - html += $.wikiEditor.modules.toolbar.fn.buildHeading( context, page.headings ); + html += toolbarModule.fn.buildHeading( context, page.headings ); } if ( 'rows' in page ) { for ( i = 0; i < page.rows.length; i++ ) { - html += $.wikiEditor.modules.toolbar.fn.buildRow( context, page.rows[ i ] ); + html += toolbarModule.fn.buildRow( context, page.rows[ i ] ); } } $page.html( html + '
' ); @@ -487,7 +487,7 @@ if ( 'characters' in page ) { html = ''; for ( i = 0; i < page.characters.length; i++ ) { - html += $.wikiEditor.modules.toolbar.fn.buildCharacter( page.characters[ i ], actions ); + html += toolbarModule.fn.buildCharacter( page.characters[ i ], actions ); } $characters .html( html ) @@ -498,7 +498,7 @@ return false; } ) .on( 'click', function ( e ) { - $.wikiEditor.modules.toolbar.fn.doAction( + toolbarModule.fn.doAction( $( this ).parent().data( 'context' ), $( this ).parent().data( 'actions' )[ $( this ).attr( 'rel' ) ], $( this ) @@ -650,7 +650,7 @@ selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' ); show = selected === id; - $.wikiEditor.modules.toolbar.fn.reallyBuildSection( context, id, section, $section, section.deferLoad ); + toolbarModule.fn.reallyBuildSection( context, id, section, $section, section.deferLoad ); // Show or hide section if ( id !== 'main' ) { @@ -672,7 +672,7 @@ if ( 'groups' in section ) { for ( group in section.groups ) { $section.append( - $.wikiEditor.modules.toolbar.fn.buildGroup( context, group, section.groups[ group ] ) + toolbarModule.fn.buildGroup( context, group, section.groups[ group ] ) ); } } @@ -683,15 +683,15 @@ if ( 'pages' in section ) { for ( page in section.pages ) { $pages.append( - $.wikiEditor.modules.toolbar.fn.buildPage( context, page, section.pages[ page ], deferLoad ) + toolbarModule.fn.buildPage( context, page, section.pages[ page ], deferLoad ) ); $index.append( - $.wikiEditor.modules.toolbar.fn.buildBookmark( context, page, section.pages[ page ] ) + toolbarModule.fn.buildBookmark( context, page, section.pages[ page ] ) ); } } $section.append( $index ).append( $pages ); - $.wikiEditor.modules.toolbar.fn.updateBookletSelection( context, id, $pages, $index ); + toolbarModule.fn.updateBookletSelection( context, id, $pages, $index ); break; } }, @@ -721,11 +721,11 @@ for ( section in config ) { if ( section === 'main' ) { context.modules.toolbar.$toolbar.prepend( - $.wikiEditor.modules.toolbar.fn.buildSection( context, section, config[ section ] ) + toolbarModule.fn.buildSection( context, section, config[ section ] ) ); } else { - $sections.append( $.wikiEditor.modules.toolbar.fn.buildSection( context, section, config[ section ] ) ); - $tabs.append( $.wikiEditor.modules.toolbar.fn.buildTab( context, section, config[ section ] ) ); + $sections.append( toolbarModule.fn.buildSection( context, section, config[ section ] ) ); + $tabs.append( toolbarModule.fn.buildTab( context, section, config[ section ] ) ); } } setTimeout( function () { @@ -736,4 +736,6 @@ }; + module.exports = toolbarModule; + }() );