Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/232066

Change subject: [PULL-THROUGH] Add MW-specific trailing punctuation rules for 
autolinking
......................................................................

[PULL-THROUGH] Add MW-specific trailing punctuation rules for autolinking

Depends on If21fb4aac13fe3ca9a0253b272a848894f325cf3.

Change-Id: Iaa620142222f47e9fde2d03b935f38c24d38800b
---
M VisualEditor.hooks.php
A modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js
M modules/ve-mw/ui/actions/ve.ui.MWLinkAction.js
3 files changed, 73 insertions(+), 0 deletions(-)


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

diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index 6744e25..6d7eefc 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -606,6 +606,7 @@
                                
'modules/ve-mw/tests/ui/actions/ve.ui.FormatAction.test.js',
                                
'lib/ve/tests/ui/actions/ve.ui.IndentationAction.test.js',
                                
'lib/ve/tests/ui/actions/ve.ui.LinkAction.test.js',
+                               
'modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js',
                                
'lib/ve/tests/ui/actions/ve.ui.ListAction.test.js',
                                // VisualEditor initialization Tests
                                'lib/ve/tests/init/ve.init.Platform.test.js',
diff --git a/modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js 
b/modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js
new file mode 100644
index 0000000..7de1f5e
--- /dev/null
+++ b/modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js
@@ -0,0 +1,60 @@
+/*!
+ * VisualEditor UserInterface Actions MWLinkAction tests.
+ *
+ * @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+QUnit.module( 've.ui.MWLinkAction' );
+
+/* Tests */
+
+function runMWAutolinkTest( assert, html, method, range, expectedRange, 
expectedData, expectedOriginalData, msg ) {
+       var status,
+               expectFail = /^Don't/.test( msg ),
+               surface = ve.test.utils.createModelOnlySurfaceFromHtml( html || 
ve.dm.example.html ),
+               linkAction = new ve.ui.MWLinkAction( surface ),
+               data = ve.copy( surface.getModel().getDocument().getFullData() 
),
+               originalData = ve.copy( data );
+
+       expectedData( data );
+       if ( expectedOriginalData ) {
+               expectedOriginalData( originalData );
+       }
+       surface.getModel().setLinearSelection( range );
+       status = linkAction[method]();
+       assert.equal( status, !expectFail, msg + ': action return value' );
+
+       assert.equalLinearData( surface.getModel().getDocument().getFullData(), 
data, msg + ': data models match' );
+       assert.equalRange( surface.getModel().getSelection().getRange(), 
expectedRange, msg + ': ranges match' );
+
+       if ( status ) {
+               surface.getModel().undo();
+       }
+
+       assert.equalLinearData( surface.getModel().getDocument().getFullData(), 
originalData, msg + ' (undo): data models match' );
+       assert.equalRange( surface.getModel().getSelection().getRange(), 
expectedRange, msg + ' (undo): ranges match' );
+}
+
+QUnit.test( 'MW autolink', function ( assert ) {
+       var i,
+               cases = [
+                       {
+                               html: 
'<p>https://en.wikipedia.org/wiki/Red_(disambiguation) xyz</p>',
+                               range: new ve.Range( 1, 52 ),
+                               method: 'autolinkUrl',
+                               expectedRange: new ve.Range( 52, 52 ),
+                               expectedData: function ( data ) {
+                                       for ( var i = 1; i < 51; i++ ) {
+                                               data[i] = [ data[i], [ 0 ] ];
+                                       }
+                               },
+                               msg: 'Strip trailing punctuation (but not 
matched parens)'
+                       }
+               ];
+
+       QUnit.expect( cases.length * 5 );
+       for ( i = 0; i < cases.length; i++ ) {
+               runMWAutolinkTest( assert, cases[i].html, cases[i].method, 
cases[i].range, cases[i].expectedRange, cases[i].expectedData, 
cases[i].expectedOriginalData, cases[i].msg );
+       }
+} );
diff --git a/modules/ve-mw/ui/actions/ve.ui.MWLinkAction.js 
b/modules/ve-mw/ui/actions/ve.ui.MWLinkAction.js
index 53405ff..107c177 100644
--- a/modules/ve-mw/ui/actions/ve.ui.MWLinkAction.js
+++ b/modules/ve-mw/ui/actions/ve.ui.MWLinkAction.js
@@ -36,6 +36,18 @@
 /* Methods */
 
 /**
+ * Match the trailing punctuation set used for autolinks in wikitext.
+ * Closing parens are only stripped if open parens are missing from the
+ * candidate text, so that URLs with embedded matched parentheses (like
+ * wiki articles with disambiguation text) autolink nicely.
+ * @method
+ * @inheritdoc
+ */
+ve.ui.MWLinkAction.prototype.getTrailingPunctuation = function ( candidate ) {
+       return /\(/.test( candidate ) ? /[,;.:!?]+$/ : /[,;.:!?)]+$/;
+};
+
+/**
  * @method
  * @inheritdoc
  * @return {ve.dm.MWExternalLinkAnnotation} The annotation to use.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa620142222f47e9fde2d03b935f38c24d38800b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to