Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/230972
Change subject: Autolink pasted URLs and bare autolinkable text
......................................................................
Autolink pasted URLs and bare autolinkable text
This partially addresses T107431 by autolinking pasted URLs,
including in the "manual" citation entry box.
Handling the text/uri-list, text/x-moz-url, and text/x-url types
requires Ie8c24b7391e9c2ab03cf20f1ceb86aa2b1e01b06 in `lib/ve`.
It's harmless to commit this first, you just won't get special
handling of those types. Some of them will eventually trigger
the heuristics associated with the text/plain type and autolink
anyway, but it's more reliable once VE recognizes the specific
URL mime types.
Task: T107431
Change-Id: I82281a11f63bb6a358b41c1348d7ead5d92c3f65
---
M
modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js
M modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js
2 files changed, 118 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/72/230972/1
diff --git
a/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js
b/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js
index 6e882a0..bcd6b36 100644
---
a/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js
+++
b/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js
@@ -121,3 +121,96 @@
{ type: '/internalList' }
] );
} );
+
+QUnit.test( 'simple external link', 1, function ( assert ) {
+ var a = {
+ type: 'link/mwExternal',
+ attributes: {
+ href: 'http://example.com',
+ rel: 'mw:ExtLink'
+ }
+ };
+ runHandlerTest( assert, this.server, 'http://example.com', 'text/plain',
+ '<body data-parsoid=\'{"dsr":[0,18,0,0]}\' lang="en"
class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki"
dir="ltr"><p data-parsoid=\'{"dsr":[0,18,0,0]}\'><a rel="mw:ExtLink"
href="http://example.com"
data-parsoid=\'{"stx":"url","dsr":[0,18,0,0]}\'>http://example.com</a></p></body>',
[
+ [ 'h', [ a ] ],
+ [ 't', [ a ] ],
+ [ 't', [ a ] ],
+ [ 'p', [ a ] ],
+ [ ':', [ a ] ],
+ [ '/', [ a ] ],
+ [ '/', [ a ] ],
+ [ 'e', [ a ] ],
+ [ 'x', [ a ] ],
+ [ 'a', [ a ] ],
+ [ 'm', [ a ] ],
+ [ 'p', [ a ] ],
+ [ 'l', [ a ] ],
+ [ 'e', [ a ] ],
+ [ '.', [ a ] ],
+ [ 'c', [ a ] ],
+ [ 'o', [ a ] ],
+ [ 'm', [ a ] ],
+ { type: 'internalList' },
+ { type: '/internalList' }
+ ] );
+} );
+
+QUnit.test( 'DnD standard URI list', 1, function ( assert ) {
+ var a = {
+ type: 'link/mwExternal',
+ attributes: {
+ href: 'http://example.com',
+ rel: 'mw:ExtLink'
+ }
+ };
+ runHandlerTest( assert, this.server, '#comment\nhttp://example.com\n',
'text/uri-list',
+ '<body data-parsoid=\'{"dsr":[0,18,0,0]}\' lang="en"
class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki"
dir="ltr"><p data-parsoid=\'{"dsr":[0,18,0,0]}\'><a rel="mw:ExtLink"
href="http://example.com"
data-parsoid=\'{"stx":"url","dsr":[0,18,0,0]}\'>http://example.com</a></p></body>',
[
+ [ 'h', [ a ] ],
+ [ 't', [ a ] ],
+ [ 't', [ a ] ],
+ [ 'p', [ a ] ],
+ [ ':', [ a ] ],
+ [ '/', [ a ] ],
+ [ '/', [ a ] ],
+ [ 'e', [ a ] ],
+ [ 'x', [ a ] ],
+ [ 'a', [ a ] ],
+ [ 'm', [ a ] ],
+ [ 'p', [ a ] ],
+ [ 'l', [ a ] ],
+ [ 'e', [ a ] ],
+ [ '.', [ a ] ],
+ [ 'c', [ a ] ],
+ [ 'o', [ a ] ],
+ [ 'm', [ a ] ],
+ { type: 'internalList' },
+ { type: '/internalList' }
+ ] );
+} );
+
+QUnit.test( 'Mozilla URI list', 1, function ( assert ) {
+ var a = [
+ {
+ type: 'link/mwExternal',
+ attributes: {
+ href: 'http://example.com',
+ rel: 'mw:ExtLink'
+ }
+ },
+ {
+ type: 'mwNowiki'
+ }
+ ];
+ runHandlerTest( assert, this.server, 'http://example.com\n[[Foo]]',
'text/x-moz-url',
+ '<body data-parsoid=\'{"dsr":[0,45,0,0]}\' lang="en"
class="mw-content-ltr sitedir-ltr ltr mw-body mw-body-content mediawiki"
dir="ltr"><p data-parsoid=\'{"dsr":[0,45,0,0]}\'><a rel="mw:ExtLink"
href="http://example.com"
data-parsoid=\'{"targetOff":20,"contentOffsets":[20,44],"dsr":[0,45,20,1]}\'><span
typeof="mw:Nowiki"
data-parsoid=\'{"dsr":[20,44,8,9]}\'>[[Foo]]</span></a></p></body>', [
+ [ '[', a ],
+ [ '[', a ],
+ [ 'F', a ],
+ [ 'o', a ],
+ [ 'o', a ],
+ [ ']', a ],
+ [ ']', a ],
+ { type: 'internalList' },
+ { type: '/internalList' }
+ ] );
+} );
diff --git
a/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js
b/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js
index 7bac9d2..0f65d5b 100644
---
a/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js
+++
b/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.js
@@ -30,7 +30,7 @@
ve.ui.MWWikitextStringTransferHandler.static.types =
ve.ui.PlainTextStringTransferHandler.static.types.concat(
- [ 'text/x-wiki' ]
+ [ 'text/x-wiki', 'text/x-uri', 'text/uri-list',
'text/x-moz-url' ]
);
ve.ui.MWWikitextStringTransferHandler.static.handlesPaste = true;
@@ -61,6 +61,18 @@
return true;
}
+ // If the mime type indicates a URL, always accept (in order to
autolink)
+ if ( /^text\/(x-uri|uri-list|x-moz-url)$/.test( item.type ) ) {
+ return true;
+ }
+
+ // Detect additional autolink opportunities.
+ // (The link should be the only contents of paste to match this
heuristic)
+ if ( this.linkRegExp.test( text ) ||
+ /^\s*(RFC|ISBN|PMID)[-\s0-9]+\s*$/.test( text ) ) {
+ return true;
+ }
+
// Use a heuristic regexp to find text likely to be wikitext.
// This test could be made more sophisticated in the future.
if ( this.matchRegExp.test( text ) ) {
@@ -86,6 +98,18 @@
handler.resolve( wikitext );
}
+ // text/uri-list has embedded comments; remove them before autolinking
+ if ( this.item.type === 'text/uri-list' ) {
+ // Use 'trim' to eliminate trailing newline, if present
+ wikitext = wikitext.replace( /^#.*(\r\n?|\n|$)/mg, '' ).trim();
+ }
+
+ // text/x-moz-url includes titles with the links
+ if ( this.item.type === 'text/x-moz-url' ) {
+ // Use 'trim' to eliminate trailing newline, if present
+ wikitext = wikitext.replace( /^(.*)(\r\n?|\n)(.*)$/mg, '[$1
<nowiki>$3</nowiki>]' ).trim();
+ }
+
singleLine = !/[\n\r]/.test( wikitext );
// Convert wikitext to html using Parsoid.
--
To view, visit https://gerrit.wikimedia.org/r/230972
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82281a11f63bb6a358b41c1348d7ead5d92c3f65
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