DLynch has uploaded a new change for review.
https://gerrit.wikimedia.org/r/299190
Change subject: Move internal-link detection into the
InternalLinkAnnotationWidget
......................................................................
Move internal-link detection into the InternalLinkAnnotationWidget
If internal link detection is in the LinkAnnotationInspector, it falls down
when a valid URL which isn't also a valid page title (e.g. percent-encoded
titles) is pasted into the input. This is fixed by moving the detection to the
input's change handler before any validation can occur.
Bug: T119431
Change-Id: I1eb2040dd918fdcc22c28594b5cbad835cf384a8
---
M modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
M modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js
2 files changed, 24 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/90/299190/1
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
index 193cb7e..9c6e9d2 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js
@@ -111,24 +111,7 @@
* @param {ve.dm.MWInternalLinkAnnotation} annotation Annotation
*/
ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChange = function (
annotation ) {
- var targetData,
- href = annotation ? annotation.getAttribute( 'title' ) : '',
- // Have to check that this.getFragment() is defined because
parent class's teardown
- // invokes setAnnotation( null ) which calls this code after
fragment is unset
- htmlDoc = this.getFragment() &&
this.getFragment().getDocument().getHtmlDocument();
-
- if ( htmlDoc &&
ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( href ) ) {
- // Check if the 'external' link is in fact a page on the same
wiki
- // e.g. http://en.wikipedia.org/wiki/Target -> Target
- targetData =
ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref(
- href,
- htmlDoc
- );
- if ( targetData.isInternal ) {
-
this.internalAnnotationInput.getTextInputWidget().setValue( targetData.title );
- return;
- }
- }
+ var href = annotation ? annotation.getAttribute( 'title' ) : '';
if (
!this.allowProtocolInInternal &&
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js
b/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js
index 2c80593..5e50dcb 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js
@@ -82,3 +82,26 @@
var title =
ve.ui.MWInternalLinkAnnotationWidget.super.prototype.getHref.call( this );
return mw.util.getUrl( title );
};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWInternalLinkAnnotationWidget.prototype.onTextChange = function ( value
) {
+ var targetData,
+ htmlDoc = this.getElementDocument();
+ // Specific thing we want to check: has a valid URL for an internal page
+ // been pasted into here, in which case we want to convert it to just
the
+ // page title. This has to happen /here/ because a URL can reference a
+ // valid page while not being a valid Title (e.g. if it contains a "%").
+ if ( ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( value )
) {
+ targetData =
ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref(
+ value,
+ htmlDoc
+ );
+ if ( targetData.isInternal ) {
+ value = targetData.title;
+ this.input.query.setValue( targetData.title );
+ }
+ }
+ return
ve.ui.MWInternalLinkAnnotationWidget.super.prototype.onTextChange.call( this,
value );
+};
--
To view, visit https://gerrit.wikimedia.org/r/299190
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1eb2040dd918fdcc22c28594b5cbad835cf384a8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits