jenkins-bot has submitted this change and it was merged.

Change subject: Make it possible to create autonumbered external links from 
link inspector
......................................................................


Make it possible to create autonumbered external links from link inspector

Inserting a new external link from the link inspector when nothing is
selected (collapsed selection) will now produce an autonumbered external
link ('link/mwNumberedExternal' node, corresponding to wikitext
"[http://example.com]";). It used to produce annotated link text
('link/mwExternal' annotation, corresponding to wikitext
"[http://example.com http://example.com]"; or "http://example.com";).

Depends on two commits in VisualEditor/VisualEditor:
* Icc2e368a to insert unannotated content from the inspector.
* I40cd4d5a to insert non-text content from the inspector.

Bug: 51309
Change-Id: Ie4a633ed42907551337a62d96d0abd59e208d49d
---
M modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
1 file changed, 41 insertions(+), 0 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
index baa0700..239eb11 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
@@ -86,6 +86,47 @@
        }
 };
 
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLinkAnnotationInspector.prototype.getInsertionData = function () {
+       var target = this.targetInput.getValue(),
+               inserting = this.initialSelection.isCollapsed();
+
+       // If this is a new external link, insert an autonumbered link instead 
of a link annotation (in
+       // #getAnnotation we have the same condition to skip the annotating). 
Otherwise call parent method
+       // to figure out the text to insert and annotate.
+       if ( inserting && 
ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( target ) ) {
+               return [
+                       {
+                               type: 'link/mwNumberedExternal',
+                               attributes: {
+                                       href: target
+                               }
+                       },
+                       { type: '/link/mwNumberedExternal' }
+               ];
+       } else {
+               return 
ve.ui.MWLinkAnnotationInspector.super.prototype.getInsertionData.call( this );
+       }
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLinkAnnotationInspector.prototype.getAnnotation = function () {
+       var target = this.targetInput.getValue(),
+               inserting = this.initialSelection.isCollapsed();
+
+       // If this is a new external link, we've just inserted an autonumbered 
link node (see
+       // #getInsertionData). Do not place any annotations of top of it.
+       if ( inserting && 
ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( target ) ) {
+               return null;
+       } else {
+               return 
ve.ui.MWLinkAnnotationInspector.super.prototype.getAnnotation.call( this );
+       }
+};
+
 /* Registration */
 
 ve.ui.windowFactory.register( ve.ui.MWLinkAnnotationInspector );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie4a633ed42907551337a62d96d0abd59e208d49d
Gerrit-PatchSet: 13
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Mooeypoo <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to