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

Change subject: Fix comparison of MW internal links
......................................................................


Fix comparison of MW internal links

We need to normalise titles so 'user:foo_bar' == 'User:Foo bar', and
we also need to some HTML attribute removal as links from Parsoid
will have href and rel set (again, this should be fixed in by Parsoid
when the do the merging at their end).

Bug: 49985
Change-Id: I5fb5bfc69c344ca4ce4803d7b6116074648a8d7e
---
M modules/ve/dm/annotations/ve.dm.MWInternalLinkAnnotation.js
M modules/ve/test/dm/ve.dm.mwExample.js
M modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js
M modules/ve/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
4 files changed, 40 insertions(+), 4 deletions(-)

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



diff --git a/modules/ve/dm/annotations/ve.dm.MWInternalLinkAnnotation.js 
b/modules/ve/dm/annotations/ve.dm.MWInternalLinkAnnotation.js
index 9715fd6..f0368dc 100644
--- a/modules/ve/dm/annotations/ve.dm.MWInternalLinkAnnotation.js
+++ b/modules/ve/dm/annotations/ve.dm.MWInternalLinkAnnotation.js
@@ -5,6 +5,8 @@
  * @license The MIT License (MIT); see LICENSE.txt
  */
 
+/*global mw */
+
 /**
  * DataModel MediaWiki internal link annotation.
  *
@@ -36,12 +38,15 @@
        // The href is simply the title, unless we're dealing with a page that 
has slashes in its name
        // in which case it's preceded by one or more instances of "./" or 
"../", so strip those
        /*jshint regexp:false */
-       var matches = domElements[0].getAttribute( 'href' ).match( 
/^((?:\.\.?\/)*)(.*)$/ );
+       var matches = domElements[0].getAttribute( 'href' ).match( 
/^((?:\.\.?\/)*)(.*)$/ ),
+               // Normalize capitalisation and underscores
+               normalizedTitle = 
ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( matches[2] );
        return {
                'type': 'link/mwInternal',
                'attributes': {
                        'hrefPrefix': matches[1],
                        'title': decodeURIComponent( matches[2] ).replace( 
/_/g, ' ' ),
+                       'normalizedTitle': normalizedTitle,
                        'origTitle': matches[2]
                }
        };
@@ -67,15 +72,35 @@
        return [ domElement ];
 };
 
+/**
+ * Normalize title for comparison purposes
+ * @param {string} title Original title
+ * @returns {string} Normalized title
+ */
+ve.dm.MWInternalLinkAnnotation.static.normalizeTitle = function ( title ) {
+       var normalizedTitle = title;
+       try {
+               normalizedTitle = new mw.Title( title ).getPrefixedText();
+       } catch ( e ) {}
+       return normalizedTitle;
+};
+
 /* Methods */
 
 ve.dm.MWInternalLinkAnnotation.prototype.getComparableObject = function () {
        return {
                'type': this.getType(),
-               'title': this.getAttribute( 'title' )
+               'normalizedTitle': this.getAttribute( 'normalizedTitle' )
        };
 };
 
+ve.dm.MWInternalLinkAnnotation.prototype.getComparableHtmlAttributes = 
function () {
+       var attributes = 
ve.dm.Annotation.prototype.getComparableHtmlAttributes.call( this );
+       delete attributes.href;
+       delete attributes.rel;
+       return attributes;
+};
+
 /* Registration */
 
 ve.dm.modelRegistry.register( ve.dm.MWInternalLinkAnnotation );
diff --git a/modules/ve/test/dm/ve.dm.mwExample.js 
b/modules/ve/test/dm/ve.dm.mwExample.js
index b06db96..480d968 100644
--- a/modules/ve/test/dm/ve.dm.mwExample.js
+++ b/modules/ve/test/dm/ve.dm.mwExample.js
@@ -497,6 +497,7 @@
                                        'attributes': {
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
+                                               'normalizedTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [ { 'values': {
@@ -512,6 +513,7 @@
                                        'attributes': {
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
+                                               'normalizedTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [ { 'values': {
@@ -527,6 +529,7 @@
                                        'attributes': {
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
+                                               'normalizedTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [ { 'values': {
@@ -626,6 +629,7 @@
                                        'attributes': {
                                                'title': 'Foo/Bar',
                                                'origTitle': 'Foo/Bar',
+                                               'normalizedTitle': 'Foo/Bar',
                                                'hrefPrefix': './../../../'
                                        },
                                        'htmlAttributes': [ { 'values': {
@@ -641,6 +645,7 @@
                                        'attributes': {
                                                'title': 'Foo/Bar',
                                                'origTitle': 'Foo/Bar',
+                                               'normalizedTitle': 'Foo/Bar',
                                                'hrefPrefix': './../../../'
                                        },
                                        'htmlAttributes': [ { 'values': {
@@ -656,6 +661,7 @@
                                        'attributes': {
                                                'title': 'Foo/Bar',
                                                'origTitle': 'Foo/Bar',
+                                               'normalizedTitle': 'Foo/Bar',
                                                'hrefPrefix': './../../../'
                                        },
                                        'htmlAttributes': [ { 'values': {
@@ -1008,6 +1014,7 @@
                                        'attributes': {
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
+                                               'normalizedTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [ { 'values': { 
'href': './Bar', 'rel': 'mw:WikiLink', 'data-parsoid': '{}' } } ]
@@ -1020,6 +1027,7 @@
                                        'attributes': {
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
+                                               'normalizedTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [ { 'values': { 
'href': './Bar', 'rel': 'mw:WikiLink', 'data-parsoid': '{}' } } ]
@@ -1032,6 +1040,7 @@
                                        'attributes': {
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
+                                               'normalizedTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [ { 'values': { 
'href': './Bar', 'rel': 'mw:WikiLink', 'data-parsoid': '{}' } } ]
diff --git a/modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js 
b/modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js
index 6c683e7..6e9b683 100644
--- a/modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js
@@ -73,7 +73,8 @@
                return new ve.dm.MWInternalLinkAnnotation( {
                        'type': 'link/mwInternal',
                        'attributes': {
-                               'title': target
+                               'title': target,
+                               'normalizedTitle': 
ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( target )
                        }
                } );
        }
diff --git a/modules/ve/ui/widgets/ve.ui.MWLinkTargetInputWidget.js 
b/modules/ve/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
index 8cacd62..cb72a3b 100644
--- a/modules/ve/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
+++ b/modules/ve/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
@@ -190,7 +190,8 @@
        return new ve.dm.MWInternalLinkAnnotation( {
                'type': 'link/mwInternal',
                'attributes': {
-                       'title': target
+                       'title': target,
+                       'normalizedTitle': 
ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( target )
                }
        } );
 };

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5fb5bfc69c344ca4ce4803d7b6116074648a8d7e
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to