From 0d1617a627a01162fbdea14114203512b6b8c1c3 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Sat, 3 Aug 2013 15:41:22 +0100 Subject: [PATCH] Hieroglyphics support Mostly as a demonstration of how easy this is with MWExtensionNode. The icon was chosen with the following criteria: 1. Recognisable (the ankh is quite common in popular culture, right?) 2. Doesn't look idiotic to academics (I've consulted an Egyptology PhD and they can confirm it's not the glyph for penis) 3. Renders well at <16x16 That said it does look a little like a stick man... Bug: 43118 Change-Id: I9f9e8af501401866bfeecf0eec3690a705fbd4db --- VisualEditor.i18n.php | 2 + VisualEditor.php | 5 ++ modules/ve-mw/ce/nodes/ve.ce.MWHieroNode.js | 50 ++++++++++++++++++ modules/ve-mw/ce/styles/ve.ce.Node.css | 6 +++ modules/ve-mw/dm/nodes/ve.dm.MWHieroNode.js | 35 ++++++++++++ .../init/targets/ve.init.mw.ViewPageTarget.js | 2 +- .../ui/inspectors/ve.ui.MWHieroInspector.js | 49 +++++++++++++++++ .../ve-mw/ui/styles/images/icons/hiero.png | Bin 0 -> 340 bytes .../ve-mw/ui/styles/images/icons/hiero.svg | 8 +++ .../ve-mw/ui/styles/ve.ui.Icons-raster.css | 5 ++ .../ve-mw/ui/styles/ve.ui.Icons-vector.css | 5 ++ .../tools/buttons/ve.ui.MWHieroButtonTool.js | 40 ++++++++++++++ 12 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 modules/ve-mw/ce/nodes/ve.ce.MWHieroNode.js create mode 100644 modules/ve-mw/dm/nodes/ve.dm.MWHieroNode.js create mode 100644 modules/ve-mw/ui/inspectors/ve.ui.MWHieroInspector.js create mode 100644 modules/ve-mw/ui/styles/images/icons/hiero.png create mode 100644 modules/ve-mw/ui/styles/images/icons/hiero.svg create mode 100644 modules/ve-mw/ui/tools/buttons/ve.ui.MWHieroButtonTool.js diff --git a/VisualEditor.i18n.php b/VisualEditor.i18n.php index 20fd99f9d6..fde772b61d 100644 --- a/VisualEditor.i18n.php +++ b/VisualEditor.i18n.php @@ -132,6 +132,7 @@ $messages['en'] = array( 'visualeditor-linkinspector-suggest-matching-page' => 'Matching page', 'visualeditor-linkinspector-suggest-new-page' => 'New page', 'visualeditor-linkinspector-title' => 'Hyperlink', + 'visualeditor-mwhieroinspector-title' => 'Hieroglyphics', 'visualeditor-mwmathinspector-title' => 'LaTeX', 'visualeditor-languageinspector-title' => 'Language', 'visualeditor-languageinspector-block-tooltip' => 'Language block: $1', @@ -427,6 +428,7 @@ Parameters: {{Identical|New page}}', 'visualeditor-linkinspector-title' => 'Title of the link inspector dialog. {{Identical|Hyperlink}}', + 'visualeditor-mwhieroinspector-title' => 'Used as title for hieroglyphics inspector.', 'visualeditor-mwmathinspector-title' => 'Used as title for MathInspector. See [[w:LaTeX]].', diff --git a/VisualEditor.php b/VisualEditor.php index 822b4fc929..6da386e425 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -713,9 +713,13 @@ $wgResourceModules += array( 'scripts' => array( 've-mw/dm/nodes/ve.dm.MWExtensionNode.js', 've-mw/ce/nodes/ve.ce.MWExtensionNode.js', + 've-mw/dm/nodes/ve.dm.MWHieroNode.js', + 've-mw/ce/nodes/ve.ce.MWHieroNode.js', 've-mw/dm/nodes/ve.dm.MWMathNode.js', 've-mw/ce/nodes/ve.ce.MWMathNode.js', 've-mw/ui/inspectors/ve.ui.MWExtensionInspector.js', + 've-mw/ui/inspectors/ve.ui.MWHieroInspector.js', + 've-mw/ui/tools/buttons/ve.ui.MWHieroButtonTool.js', 've-mw/ui/inspectors/ve.ui.MWMathInspector.js', 've-mw/ui/tools/buttons/ve.ui.MWMathButtonTool.js', 've/dm/annotations/ve.dm.LanguageAnnotation.js', @@ -732,6 +736,7 @@ $wgResourceModules += array( ), 'messages' => array( // VE messages needed by code that is only in experimental mode + 'visualeditor-mwhieroinspector-title', 'visualeditor-mwmathinspector-title', 'visualeditor-annotationbutton-language-tooltip', 'visualeditor-annotationbutton-strikethrough-tooltip', diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWHieroNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWHieroNode.js new file mode 100644 index 0000000000..b0d041e176 --- /dev/null +++ b/modules/ve-mw/ce/nodes/ve.ce.MWHieroNode.js @@ -0,0 +1,50 @@ +/*! + * VisualEditor ContentEditable MWHieroNode class. + * + * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * ContentEditable MediaWiki hieroglyphics node. + * + * @class + * @extends ve.ce.MWExtensionNode + * + * @constructor + * @param {ve.dm.MWHieroNode} model Model to observe + * @param {Object} [config] Config options + */ +ve.ce.MWHieroNode = function VeCeMWHieroNode( model, config ) { + // Parent constructor + ve.ce.MWExtensionNode.call( this, model, config ); + + // DOM Changes + this.$.addClass( 've-ce-mwHieroNode' ); +}; + +/* Inheritance */ + +ve.inheritClass( ve.ce.MWHieroNode, ve.ce.MWExtensionNode ); + +/* Static Properties */ + +ve.ce.MWHieroNode.static.name = 'mwHiero'; + +ve.ce.MWHieroNode.static.tagName = 'div'; + +/* Methods */ + +/** */ +ve.ce.MWHieroNode.prototype.onParseSuccess = function ( deferred, response ) { + var data = response.visualeditor, contentNodes = $( data.content ).get(); + deferred.resolve( contentNodes ); + // Rerender after image load + this.$.find( 'img' ).on( 'load', ve.bind( function () { + this.emit( 'rerender' ); + }, this ) ); +}; + +/* Registration */ + +ve.ce.nodeFactory.register( ve.ce.MWHieroNode ); diff --git a/modules/ve-mw/ce/styles/ve.ce.Node.css b/modules/ve-mw/ce/styles/ve.ce.Node.css index cca422b761..32226eadfa 100644 --- a/modules/ve-mw/ce/styles/ve.ce.Node.css +++ b/modules/ve-mw/ce/styles/ve.ce.Node.css @@ -50,3 +50,9 @@ .ve-ce-mwMathNode { display: inline-block; } + +/* ve.ce.MWHieroNode */ + +.ve-ce-mwHieroNode { + display: table; +} diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWHieroNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWHieroNode.js new file mode 100644 index 0000000000..f588a7af87 --- /dev/null +++ b/modules/ve-mw/dm/nodes/ve.dm.MWHieroNode.js @@ -0,0 +1,35 @@ +/*! + * VisualEditor DataModel MWHieroNode class. + * + * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * DataModel MediaWiki hieroglyphics node. + * + * @class + * @extends ve.dm.MWExtensionNode + * + * @constructor + */ +ve.dm.MWHieroNode = function VeDmMWHieroNode( length, element ) { + // Parent constructor + ve.dm.MWExtensionNode.call( this, 0, element ); +}; + +/* Inheritance */ + +ve.inheritClass( ve.dm.MWHieroNode, ve.dm.MWExtensionNode ); + +/* Static members */ + +ve.dm.MWHieroNode.static.name = 'mwHiero'; + +ve.dm.MWHieroNode.static.tagName = 'table'; + +ve.dm.MWHieroNode.static.extensionName = 'hiero'; + +/* Registration */ + +ve.dm.modelRegistry.register( ve.dm.MWHieroNode ); diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js index 3bfa364a9d..16b7d418cb 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -172,7 +172,7 @@ ve.init.mw.ViewPageTarget.static.toolbarTools = [ { 'items': [ 'mwFormat' ] }, { 'items': [ 'bold', 'italic', 'mwLink', 'language', 'code', 'strikethrough', 'clear' ] }, { 'items': [ 'number', 'bullet', 'outdent', 'indent' ] }, - { 'items': [ 'mwMediaInsert', 'mwReference', 'mwReferenceList', 'mwTransclusion', 'mwMath' ] } + { 'items': [ 'mwMediaInsert', 'mwReference', 'mwReferenceList', 'mwTransclusion', 'mwMath', 'mwHiero' ] } ]; ve.init.mw.ViewPageTarget.static.surfaceCommands = [ diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWHieroInspector.js b/modules/ve-mw/ui/inspectors/ve.ui.MWHieroInspector.js new file mode 100644 index 0000000000..571098d8fa --- /dev/null +++ b/modules/ve-mw/ui/inspectors/ve.ui.MWHieroInspector.js @@ -0,0 +1,49 @@ +/*! + * VisualEditor UserInterface MWHieroInspector class. + * + * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * MediaWiki hieroglyphics inspector. + * + * @class + * @extends ve.ui.MWExtensionInspector + * + * @constructor + * @param {ve.ui.Surface} surface + * @param {Object} [config] Config options + */ +ve.ui.MWHieroInspector = function VeUiMWHieroInspector( surface, config ) { + // Parent constructor + ve.ui.MWExtensionInspector.call( this, surface, config ); +}; + +/* Inheritance */ + +ve.inheritClass( ve.ui.MWHieroInspector, ve.ui.MWExtensionInspector ); + +/* Static properties */ + +ve.ui.MWHieroInspector.static.icon = 'hiero'; + +ve.ui.MWHieroInspector.static.titleMessage = 'visualeditor-mwhieroinspector-title'; + +ve.ui.MWHieroInspector.static.nodeView = ve.ce.MWHieroNode; + +ve.ui.MWHieroInspector.static.nodeModel = ve.dm.MWHieroNode; + + +/* Methods */ + +ve.ui.MWHieroInspector.prototype.initialize = function () { + // Parent method + ve.ui.MWExtensionInspector.prototype.initialize.call( this ); + + this.input.$.addClass( 've-ui-mwHieroInspector-input' ); +}; + +/* Registration */ + +ve.ui.inspectorFactory.register( 'mwHieroInspector', ve.ui.MWHieroInspector ); diff --git a/modules/ve-mw/ui/styles/images/icons/hiero.png b/modules/ve-mw/ui/styles/images/icons/hiero.png new file mode 100644 index 0000000000000000000000000000000000000000..0822cab658c05dde91ba70fda349adbbb28d350a GIT binary patch literal 340 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjEX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4p-6gDtCQd79ca^!NO#k?#r21b5?eD+5=3Sult@(TC(kL0mu&G0<}ip00i_>zopr0HeWiPXGV_ literal 0 HcmV?d00001 diff --git a/modules/ve-mw/ui/styles/images/icons/hiero.svg b/modules/ve-mw/ui/styles/images/icons/hiero.svg new file mode 100644 index 0000000000..61507950df --- /dev/null +++ b/modules/ve-mw/ui/styles/images/icons/hiero.svg @@ -0,0 +1,8 @@ + + + + + + + diff --git a/modules/ve-mw/ui/styles/ve.ui.Icons-raster.css b/modules/ve-mw/ui/styles/ve.ui.Icons-raster.css index e204f753c7..730d3b1db7 100644 --- a/modules/ve-mw/ui/styles/ve.ui.Icons-raster.css +++ b/modules/ve-mw/ui/styles/ve.ui.Icons-raster.css @@ -5,6 +5,11 @@ * @license The MIT License (MIT); see LICENSE.txt */ +.ve-ui-icon-hiero { + /* @embed */ + background-image: url(images/icons/hiero.png); +} + .ve-ui-icon-language { /* @embed */ background-image: url(images/icons/language.png); diff --git a/modules/ve-mw/ui/styles/ve.ui.Icons-vector.css b/modules/ve-mw/ui/styles/ve.ui.Icons-vector.css index 8467ed8f91..fe3b058e93 100644 --- a/modules/ve-mw/ui/styles/ve.ui.Icons-vector.css +++ b/modules/ve-mw/ui/styles/ve.ui.Icons-vector.css @@ -5,6 +5,11 @@ * @license The MIT License (MIT); see LICENSE.txt */ +.ve-ui-icon-hiero { + /* @embed */ + background-image: url(images/icons/hiero.svg); +} + .ve-ui-icon-language { /* @embed */ background-image: url(images/icons/language.svg); diff --git a/modules/ve-mw/ui/tools/buttons/ve.ui.MWHieroButtonTool.js b/modules/ve-mw/ui/tools/buttons/ve.ui.MWHieroButtonTool.js new file mode 100644 index 0000000000..5f7b6cd153 --- /dev/null +++ b/modules/ve-mw/ui/tools/buttons/ve.ui.MWHieroButtonTool.js @@ -0,0 +1,40 @@ +/*! + * VisualEditor UserInterface MWHieroButtonTool class. + * + * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * UserInterface MediaWiki hieroglyphics button tool. + * + * @class + * @extends ve.ui.InspectorButtonTool + * @constructor + * @param {ve.ui.Toolbar} toolbar + * @param {Object} [config] Config options + */ +ve.ui.MWHieroButtonTool = function VeUiMWHieroButtonTool( toolbar, config ) { + // Parent constructor + ve.ui.InspectorButtonTool.call( this, toolbar, config ); +}; + +/* Inheritance */ + +ve.inheritClass( ve.ui.MWHieroButtonTool, ve.ui.InspectorButtonTool ); + +/* Static Properties */ + +ve.ui.MWHieroButtonTool.static.name = 'mwHiero'; + +ve.ui.MWHieroButtonTool.static.icon = 'hiero'; + +ve.ui.MWHieroButtonTool.static.titleMessage = 'visualeditor-mwhieroinspector-title'; + +ve.ui.MWHieroButtonTool.static.inspector = 'mwHieroInspector'; + +ve.ui.MWHieroButtonTool.static.modelClasses = [ ve.dm.MWHieroNode ]; + +/* Registration */ + +ve.ui.toolFactory.register( 'mwHiero', ve.ui.MWHieroButtonTool );