C. Scott Ananian has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358396 )

Change subject: Node inspector for LanguageConverter markup
......................................................................

Node inspector for LanguageConverter markup

Add an inspector giving more information on language converter markup.
A follow-up patch will add the edit dialog.

Bug: T49411
Change-Id: I3c91db84793a9a965dcb760253b24edee5d7bd23
---
M extension.json
M modules/ve-mw/i18n/en.json
M modules/ve-mw/i18n/qqq.json
A modules/ve-mw/ui/contextitems/ve.ui.MWLanguageVariantNodeContextItem.js
A modules/ve-mw/ui/dialogs/ve.ui.MWLanguageVariantDialog.js
A 
modules/ve-mw/ui/styles/contextitems/ve.ui.MWLanguageVariantNodeContextItem.css
6 files changed, 364 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/96/358396/1

diff --git a/extension.json b/extension.json
index 307cc61..ad3e883 100644
--- a/extension.json
+++ b/extension.json
@@ -1896,9 +1896,11 @@
                "ext.visualEditor.mwlanguage": {
                        "scripts": [
                                
"modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js",
-                               
"modules/ve-mw/ce/nodes/ve.ce.MWLanguageVariantNode.js"
+                               
"modules/ve-mw/ce/nodes/ve.ce.MWLanguageVariantNode.js",
+                               
"modules/ve-mw/ui/contextitems/ve.ui.MWLanguageVariantNodeContextItem.js"
                        ],
                        "styles": [
+                               
"modules/ve-mw/ui/styles/contextitems/ve.ui.MWLanguageVariantNodeContextItem.css",
                                
"modules/ve-mw/ce/styles/nodes/ve.ce.MWLanguageVariantNode.css"
                        ],
                        "dependencies": [
@@ -1910,7 +1912,17 @@
                                "visualeditor-mwlanguagevariant-disabled",
                                "visualeditor-mwlanguagevariant-filter",
                                "visualeditor-mwlanguagevariant-bidir",
-                               "visualeditor-mwlanguagevariant-unidir"
+                               "visualeditor-mwlanguagevariant-unidir",
+                               
"visualeditor-mwlanguagevariantnodeinspector-rule-name-label",
+                               
"visualeditor-mwlanguagevariantnodeinspector-rule-code-label",
+                               
"visualeditor-mwlanguagevariantnodeinspector-rule-text-label",
+                               
"visualeditor-mwlanguagevariantnodeinspector-rule-text-from-label",
+                               
"visualeditor-mwlanguagevariantnodeinspector-rule-text-to-label",
+                               
"visualeditor-mwlanguagevariantnodeinspector-title-unknown",
+                               
"visualeditor-mwlanguagevariantnodeinspector-title-disabled",
+                               
"visualeditor-mwlanguagevariantnodeinspector-title-filter",
+                               
"visualeditor-mwlanguagevariantnodeinspector-title-bidir",
+                               
"visualeditor-mwlanguagevariantnodeinspector-title-unidir"
                        ],
                        "targets": [
                                "desktop",
diff --git a/modules/ve-mw/i18n/en.json b/modules/ve-mw/i18n/en.json
index 8fdfceb..7ba6f53 100644
--- a/modules/ve-mw/i18n/en.json
+++ b/modules/ve-mw/i18n/en.json
@@ -324,6 +324,16 @@
        "visualeditor-mwlanguagevariant-filter": "Variants filtered to $1",
        "visualeditor-mwlanguagevariant-bidir": "Bidirectional conversion: $1",
        "visualeditor-mwlanguagevariant-unidir": "Unidirectional conversion: 
$1",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-name-label": 
"Language",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-code-label": 
"Language code",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-text-label": "Text",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-text-from-label": 
"Source",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-text-to-label": 
"Destination",
+       "visualeditor-mwlanguagevariantnodeinspector-title-unknown": "Language 
variant",
+       "visualeditor-mwlanguagevariantnodeinspector-title-disabled": "Variant 
conversion disabled",
+       "visualeditor-mwlanguagevariantnodeinspector-title-filter": "Variant 
filter",
+       "visualeditor-mwlanguagevariantnodeinspector-title-bidir": 
"Bidirectional conversion rule",
+       "visualeditor-mwlanguagevariantnodeinspector-title-unidir": 
"Unidirectional conversion rule",
        "visualeditor-mwpredialog-title": "Preformatted plain text",
        "visualeditor-mwpredialog-convert": "Allow text styling",
        "visualeditor-mwsignature-tool": "Your signature",
diff --git a/modules/ve-mw/i18n/qqq.json b/modules/ve-mw/i18n/qqq.json
index 1e27c0d..c486f6a 100644
--- a/modules/ve-mw/i18n/qqq.json
+++ b/modules/ve-mw/i18n/qqq.json
@@ -337,6 +337,16 @@
        "visualeditor-mwlanguagevariant-filter": "Description of a text where 
language variant conversion is filtered to a specific set of 
variants\n\nParameters:\n* $1 - the specific set of language variants",
        "visualeditor-mwlanguagevariant-bidir": "Description of a bidirectional 
language variant conversion rule\n\nParameters:\n* $1 - the language variants 
named in the rule",
        "visualeditor-mwlanguagevariant-unidir": "Description of a 
unidirectional language variant conversion rule\n\nParameters:\n* $1 - the 
language variants named in the rule",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-name-label": "Column 
header for language variant rule table, giving language name for a 
rule.\n{{Identical|Language}}",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-code-label": "Column 
header for language variant rule table, giving the language code for a 
rule.\n{{Identical|Language code}}",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-text-label": "Column 
header for language variant rule table, giving destination text for a 
bidirectional rule",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-text-from-label": 
"Column header for language variant rule table, giving source text for a 
unidirectional rule",
+       "visualeditor-mwlanguagevariantnodeinspector-rule-text-to-label": 
"Column header for language variant rule table, giving destination text for a 
unidirectional rule",
+       "visualeditor-mwlanguagevariantnodeinspector-title-unknown": "Title 
shown at top of node inspector for a language variant markup of unknown type",
+       "visualeditor-mwlanguagevariantnodeinspector-title-disabled": "Title 
shown at top of node inspector where language variant conversion is disabled",
+       "visualeditor-mwlanguagevariantnodeinspector-title-filter": "Title 
shown at top of node inspector where language variants are filtered for 
conversion",
+       "visualeditor-mwlanguagevariantnodeinspector-title-bidir": "Title shown 
at top of node inspector for a bidirectional language variant conversion rule",
+       "visualeditor-mwlanguagevariantnodeinspector-title-unidir": "Title 
shown at top of node inspector for a unidirectional language variant conversion 
rule",
        "visualeditor-mwpredialog-title": "Title for the preformatted text 
dialog",
        "visualeditor-mwpredialog-convert": "Label for a button which will 
convert the preformatted text block into a form which can have text styles 
applied (e.g. bold, italic, links).",
        "visualeditor-mwsignature-tool": "Used as name of the tool for 
inserting signatures.",
diff --git 
a/modules/ve-mw/ui/contextitems/ve.ui.MWLanguageVariantNodeContextItem.js 
b/modules/ve-mw/ui/contextitems/ve.ui.MWLanguageVariantNodeContextItem.js
new file mode 100644
index 0000000..6ad4d2e
--- /dev/null
+++ b/modules/ve-mw/ui/contextitems/ve.ui.MWLanguageVariantNodeContextItem.js
@@ -0,0 +1,172 @@
+/*!
+ * VisualEditor MWLanuageVariantNodeContextItem class.
+ *
+ * @copyright 2011-2017 VisualEditor Team and others; see 
http://ve.mit-license.org
+ */
+
+/**
+ * Context item for a MWLanguageVariantNode.
+ *
+ * @class
+ * @extends ve.ui.LinkContextItem
+ *
+ * @constructor
+ * @param {ve.ui.Context} context Context item is in
+ * @param {ve.dm.MWLanguageVariantNode} model Model item is related to
+ * @param {Object} config Configuration options
+ */
+ve.ui.MWLanguageVariantNodeContextItem = function 
VeUiMWLanguageVariantNodeContextItem() {
+       // Parent constructor
+       ve.ui.MWLanguageVariantNodeContextItem.super.apply( this, arguments );
+
+       // Initialization
+       this.$element.addClass( 've-ui-mwLanguageVariantNodeContextItem' );
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.ui.MWLanguageVariantNodeContextItem, 
ve.ui.LinearContextItem );
+
+/* Static Properties */
+
+ve.ui.MWLanguageVariantNodeContextItem.static.name = 'languageVariantNode';
+
+ve.ui.MWLanguageVariantNodeContextItem.static.icon = 'language';
+
+ve.ui.MWLanguageVariantNodeContextItem.static.label = null; // see #setup()
+
+ve.ui.MWLanguageVariantNodeContextItem.static.modelClasses = [
+       ve.dm.MWLanguageVariantBlockNode,
+       ve.dm.MWLanguageVariantInlineNode,
+       ve.dm.MWLanguageVariantHiddenNode
+];
+
+ve.ui.MWLanguageVariantNodeContextItem.static.commandName = 
'mwLanguageVariant';
+
+/* Methods */
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLanguageVariantNodeContextItem.prototype.setup = function () {
+       // Set up label
+       var msg = 'visualeditor-mwlanguagevariantnodeinspector-title-' +
+               this.model.getRuleType();
+       this.setLabel( OO.ui.deferMsg( msg ) );
+       // Invoke superclass method.
+       return 
ve.ui.MWLanguageVariantNodeContextItem.super.prototype.setup.call( this );
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLanguageVariantNodeContextItem.prototype.renderBody = function () {
+       var $table = $( '<table>' ),
+               $header = $( '<tr> ' ),
+               mwv = this.model.getVariantInfo(),
+               type = this.model.getRuleType();
+
+       $table.addClass(
+               've-ui-mwLanguageVariantNodeContextItem-rule-table'
+       );
+       $table.append( $header );
+
+       switch ( type ) {
+               case 'filter':
+                       $header
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-name-label' )
+                       ) )
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-code-label' )
+                       ) );
+
+                       mwv.filter.forEach( function ( code ) {
+                               var name = ve.init.platform.getLanguageName( 
code.toLowerCase() );
+                               $table
+                               .append( $( '<tr>' )
+                                       .append( $( '<td>' ).text( name ).attr( 
'lang', code ) )
+                                       .append( $( '<td>' ).text( code ) )
+                               );
+                       } );
+                       break;
+
+               case 'unidir':
+                       $header
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-name-label' )
+                       ) )
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-code-label' )
+                       ) )
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-text-from-label' )
+                       ) )
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-text-to-label' )
+                       ) );
+
+                       mwv.unidir.forEach( function ( item ) {
+                               var $fromText = $( '<td>' ).html( item.f ),
+                                       $toText = $( '<td>' ).html( item.t ),
+                                       code = item.l,
+                                       name = 
ve.init.platform.getLanguageName( code.toLowerCase() );
+                               $table
+                               .append( $( '<tr>' )
+                                       .append( $( '<td>' ).text( name ).attr( 
'lang', code ) )
+                                       .append( $( '<td>' ).text( code ) )
+                                       .append( $fromText )
+                                       .append( $toText )
+                               );
+                       } );
+                       break;
+
+               case 'bidir':
+                       $header
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-name-label' )
+                       ) )
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-code-label' )
+                       ) )
+                       .append( $( '<th>' ).append(
+                               ve.msg( 
'visualeditor-mwlanguagevariantnodeinspector-rule-text-label' )
+                       ) );
+
+                       mwv.bidir.forEach( function ( item ) {
+                               var code = item.l,
+                                       name = 
ve.init.platform.getLanguageName( code.toLowerCase() ),
+                                       $text = $( '<td>' ).html( item.t );
+                               
ve.dm.MWLanguageVariantNode.static.processVariants(
+                               $text, true, true
+                       );
+                               $table
+                               .append( $( '<tr>' )
+                                       .append( $( '<td>' ).text( name ).attr( 
'lang', code ) )
+                                       .append( $( '<td>' ).text( code ) )
+                                       .append( $text )
+                               );
+                       } );
+                       break;
+
+               default:
+               // Don't put $table in $body if the table is empty; this allows
+               // CSS :empty rules to have their proper effect.
+                       return;
+       }
+       ve.dm.MWLanguageVariantNode.static.processVariants(
+               $table, true, true
+       );
+       this.$body.append( $table );
+};
+
+/* Registration */
+
+ve.ui.contextItemFactory.register( ve.ui.MWLanguageVariantNodeContextItem );
+
+ve.ui.commandRegistry.register(
+       new ve.ui.Command(
+               'mwLanguageVariant', 'window', 'open',
+               { args: [ 'mwLanguageVariant' ], supportedSelections: [ 
'linear' ] }
+       )
+);
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWLanguageVariantDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWLanguageVariantDialog.js
new file mode 100644
index 0000000..ceea277
--- /dev/null
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWLanguageVariantDialog.js
@@ -0,0 +1,127 @@
+/*!
+ * VisualEditor user interface MWLanguageVariantDialog class.
+ *
+ * @copyright 2017 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+/**
+ * Dialog for editing MediaWiki LanguageConverter markup for language
+ * variants.
+ *
+ * @class
+ * @extends ve.ui.NodeDialog
+ *
+ * @constructor
+ * @param {Object} [config] Configuration options
+ */
+ve.ui.MWLanguageVariantDialog = function VeUiMWLanguageVariantDialog() {
+       // Parent constructor
+       ve.ui.MWLanguageVariantDialog.super.apply( this, arguments );
+
+       this.$element.addClass( 've-ui-mwLanguageVariantDialog' );
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.ui.MWLanguageVariantDialog, ve.ui.NodeDialog );
+
+/* Static properties */
+
+ve.ui.MWLanguageVariantDialog.static.name = 'mwLanguageVariant';
+
+ve.ui.MWLanguageVariantDialog.static.size = 'large';
+
+ve.ui.MWLanguageVariantDialog.static.title = OO.ui.deferMsg( 
'visualeditor-mwlanguagevariantdialog-title' );
+
+ve.ui.MWLanguageVariantDialog.static.modelClasses = [
+       ve.dm.MWLanguageVariantBlockNode,
+       ve.dm.MWLanguageVariantInlineNode,
+       ve.dm.MWLanguageVariantHiddenNode
+];
+
+/* Methods */
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLanguageVariantDialog.prototype.initialize = function () {
+       // Parent method
+       ve.ui.MWLanguageVariantDialog.super.prototype.initialize.call( this );
+
+       /*
+       // Properties
+       this.panel = new OO.ui.PanelLayout( {
+               padded: true
+       } );
+       // Note that this overrides this.input from ve.ui.MWExtensionWindow
+       this.input = new ve.ui.MWPreTextInputWidget( {
+               multiline: true,
+               // This number doesn't really matter, it just needs to be large.
+               // The real height is enforced by #getBodyHeight and max-height 
in CSS.
+               rows: 100,
+               classes: [ 've-ui-mwExtensionWindow-input' ]
+       } );
+       this.input.connect( this, { resize: 'updateSize' } );
+
+       // Initialization
+       this.panel.$element.append( this.input.$element );
+       this.$body.append( this.panel.$element );
+       */
+       this.$element.addClass( 've-ui-mwLanguageVariantDialog' );
+};
+
+/**
+ * @inheritdoc
+ */
+/*
+ve.ui.MWLanguageVariantDialog.prototype.getReadyProcess = function ( data ) {
+       return 
ve.ui.MWLanguageVariantDialog.super.prototype.getReadyProcess.call( this, data )
+               .next( function () {
+                       this.input.focus();
+               }, this );
+};
+*/
+
+/**
+ * @inheritdoc
+ */
+/*
+ve.ui.MWLanguageVariantDialog.prototype.getActionProcess = function ( action ) 
{
+       if ( action === 'convert' ) {
+               return new OO.ui.Process( function () {
+                       var
+                               value = this.input.getValue(),
+                               nodeRange = this.selectedNode.getOuterRange(),
+                               surfaceModel = this.getFragment().getSurface(),
+                               doc = surfaceModel.getDocument(),
+                               // Turn the text into content for insertion 
into document
+                               content = value.split( '' ),
+                               // Apply any annotations that were applied to 
the node also to the new content
+                               annotations = 
doc.data.getAnnotationsFromOffset( nodeRange.start );
+                       ve.dm.Document.static.addAnnotationsToData( content, 
annotations );
+                       // Make it use preformatted text
+                       content.unshift( { type: 'mwPreformatted' } );
+                       content.push( { type: '/mwPreformatted' } );
+                       // Replace
+                       surfaceModel.change(
+                               
ve.dm.TransactionBuilder.static.newFromReplacement( doc, nodeRange, content )
+                       );
+                       this.close();
+               }, this );
+       }
+       // Parent method
+       return 
ve.ui.MWLanguageVariantDialog.super.prototype.getActionProcess.call( this, 
action );
+};
+*/
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLanguageVariantDialog.prototype.getBodyHeight = function () {
+       return 500;
+};
+
+/* Registration */
+
+ve.ui.windowFactory.register( ve.ui.MWLanguageVariantDialog );
diff --git 
a/modules/ve-mw/ui/styles/contextitems/ve.ui.MWLanguageVariantNodeContextItem.css
 
b/modules/ve-mw/ui/styles/contextitems/ve.ui.MWLanguageVariantNodeContextItem.css
new file mode 100644
index 0000000..bb5cfb8
--- /dev/null
+++ 
b/modules/ve-mw/ui/styles/contextitems/ve.ui.MWLanguageVariantNodeContextItem.css
@@ -0,0 +1,31 @@
+/*!
+ * VisualEditor MediaWiki UserInterface alien extension inspector styles.
+ *
+ * @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+.ve-ui-mwLanguageVariantNodeContextItem-rule-table {
+       width: 100%;
+       border: 0;
+       border-collapse: collapse;
+}
+
+.ve-ui-mwLanguageVariantNodeContextItem-rule-table th {
+       border-bottom: solid 1px #ddd;
+       text-align: left;
+}
+
+.ve-ui-mwLanguageVariantNodeContextItem-rule-table th,
+.ve-ui-mwLanguageVariantNodeContextItem-rule-table td {
+       padding: 0.75em 1em;
+       border-bottom: 1px solid #fff;
+}
+
+.ve-ui-mwLanguageVariantNodeContextItem-rule-table tr:nth-child( odd ) td {
+       background: #f0f0f0;
+}
+
+.ve-ui-mwLanguageVariantNodeContextItem-rule-table tr:nth-child( even ) td {
+       background: #f8f8f8;
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/358396
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c91db84793a9a965dcb760253b24edee5d7bd23
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian <canan...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to