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

Change subject: Add lookupTitle attribute
......................................................................


Add lookupTitle attribute

This is the normalized title without the fragment, which is what
should be used for existence check purposes. Also add a test for
an internal link to a page's section.

Change-Id: I0e04f64c1bebeff84a0c17ef9b6c8dc06876f769
---
M modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js
M modules/ve-mw/test/dm/ve.dm.mwExample.js
M modules/ve-mw/ui/inspectors/ve.ui.MWLinkInspector.js
M modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
4 files changed, 88 insertions(+), 8 deletions(-)

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



diff --git a/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js 
b/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js
index 8ddfc51..1cd1f57 100644
--- a/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js
+++ b/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js
@@ -40,7 +40,7 @@
                return str.replace( /([.?*+^$[\]\\(){}|-])/g, '\\$1' );
        }
 
-       var matches, normalizedTitle,
+       var matches, normalizedTitle, lookupTitle,
                doc = converter.getTargetHtmlDocument(),
                // Protocol relative base
                relativeBase = ve.resolveUrl( mw.config.get( 'wgArticlePath' ), 
doc ).toString().replace( /^https?:/, '' ),
@@ -61,7 +61,8 @@
        /*jshint regexp:false */
        matches = href.match( /^((?:\.\.?\/)*)(.*)$/ );
        // Normalize capitalisation and underscores
-       normalizedTitle = ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( 
matches[2] );
+       normalizedTitle = this.normalizeTitle( matches[2] );
+       lookupTitle = this.getLookupTitle( matches[2] );
 
        return {
                'type': this.name,
@@ -69,6 +70,7 @@
                        'hrefPrefix': matches[1],
                        'title': decodeURIComponent( matches[2] ).replace( 
/_/g, ' ' ),
                        'normalizedTitle': normalizedTitle,
+                       'lookupTitle': lookupTitle,
                        'origTitle': matches[2]
                }
        };
@@ -98,17 +100,29 @@
 };
 
 /**
- * Normalize title for comparison purposes
+ * Normalize title for comparison purposes.
  * @param {string} title Original title
  * @returns {string} Normalized title, or the original if it is invalid
  */
 ve.dm.MWInternalLinkAnnotation.static.normalizeTitle = function ( original ) {
        var title = mw.Title.newFromText( original );
-       if ( title ) {
-               return title.getPrefixedText() + ( title.getFragment() !== null 
? '#' + title.getFragment() : '' );
-       } else {
+       if ( !title ) {
                return original;
        }
+       return title.getPrefixedText() + ( title.getFragment() !== null ? '#' + 
title.getFragment() : '' );
+};
+
+/**
+ * Normalize title for lookup (search suggestion, existence) purposes.
+ * @param {string} title Original title
+ * @returns {string} Normalized title, or the original if it is invalid
+ */
+ve.dm.MWInternalLinkAnnotation.static.getLookupTitle = function ( original ) {
+       var title = mw.Title.newFromText( original );
+       if ( !title ) {
+               return original;
+       }
+       return title.getPrefixedText();
 };
 
 /* Methods */
diff --git a/modules/ve-mw/test/dm/ve.dm.mwExample.js 
b/modules/ve-mw/test/dm/ve.dm.mwExample.js
index d7422c0..6533f04 100644
--- a/modules/ve-mw/test/dm/ve.dm.mwExample.js
+++ b/modules/ve-mw/test/dm/ve.dm.mwExample.js
@@ -168,6 +168,7 @@
                'title': 'Foo/Bar',
                'origTitle': 'Foo/Bar',
                'normalizedTitle': 'Foo/Bar',
+               'lookupTitle': 'Foo/Bar',
                'hrefPrefix': ''
        },
        'htmlAttributes': [
@@ -178,6 +179,33 @@
                        },
                        'computed': {
                                'href': 
ve.dm.mwExample.MWInternalLink.absoluteHref
+                       }
+               }
+       ]
+};
+
+ve.dm.mwExample.MWInternalSectionLink = {
+       'absoluteHref': new mw.Uri( '/wiki/Foo#Bar' ).toString()
+};
+
+ve.dm.mwExample.MWInternalSectionLink.absoluteOpen = '<a rel="mw:WikiLink" 
href="' + ve.dm.mwExample.MWInternalSectionLink.absoluteHref + '">';
+ve.dm.mwExample.MWInternalSectionLink.absoluteData = {
+       'type': 'link/mwInternal',
+       'attributes': {
+               'title': 'Foo#Bar',
+               'origTitle': 'Foo#Bar',
+               'normalizedTitle': 'Foo#Bar',
+               'lookupTitle': 'Foo',
+               'hrefPrefix': ''
+       },
+       'htmlAttributes': [
+               {
+                       'values': {
+                               'href': 
ve.dm.mwExample.MWInternalSectionLink.absoluteHref,
+                               'rel': 'mw:WikiLink'
+                       },
+                       'computed': {
+                               'href': 
ve.dm.mwExample.MWInternalSectionLink.absoluteHref
                        }
                }
        ]
@@ -1296,6 +1324,7 @@
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
                                                'normalizedTitle': 'Bar',
+                                               'lookupTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [
@@ -1319,6 +1348,7 @@
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
                                                'normalizedTitle': 'Bar',
+                                               'lookupTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [
@@ -1342,6 +1372,7 @@
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
                                                'normalizedTitle': 'Bar',
+                                               'lookupTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [
@@ -1463,6 +1494,7 @@
                                                'title': 'Foo/Bar',
                                                'origTitle': 'Foo/Bar',
                                                'normalizedTitle': 'Foo/Bar',
+                                               'lookupTitle': 'Foo/Bar',
                                                'hrefPrefix': './../../../'
                                        },
                                        'htmlAttributes': [
@@ -1486,6 +1518,7 @@
                                                'title': 'Foo/Bar',
                                                'origTitle': 'Foo/Bar',
                                                'normalizedTitle': 'Foo/Bar',
+                                               'lookupTitle': 'Foo/Bar',
                                                'hrefPrefix': './../../../'
                                        },
                                        'htmlAttributes': [
@@ -1509,6 +1542,7 @@
                                                'title': 'Foo/Bar',
                                                'origTitle': 'Foo/Bar',
                                                'normalizedTitle': 'Foo/Bar',
+                                               'lookupTitle': 'Foo/Bar',
                                                'hrefPrefix': './../../../'
                                        },
                                        'htmlAttributes': [
@@ -1550,6 +1584,31 @@
                        { 'type': '/internalList' }
                ],
                'normalizedBody': '<p><a rel="mw:WikiLink" 
href="Foo/Bar">Foo</a></p>',
+               'mwConfig': {
+                       'wgArticlePath': '/wiki/$1'
+               }
+       },
+       'internal link with absolute path and section': {
+               'body': '<p>' + 
ve.dm.mwExample.MWInternalSectionLink.absoluteOpen + 'Foo</a></p>',
+               'data': [
+                       { 'type': 'paragraph' },
+                       [
+                               'F',
+                               [ 
ve.dm.mwExample.MWInternalSectionLink.absoluteData ]
+                       ],
+                       [
+                               'o',
+                               [ 
ve.dm.mwExample.MWInternalSectionLink.absoluteData ]
+                       ],
+                       [
+                               'o',
+                               [ 
ve.dm.mwExample.MWInternalSectionLink.absoluteData ]
+                       ],
+                       { 'type': '/paragraph' },
+                       { 'type': 'internalList' },
+                       { 'type': '/internalList' }
+               ],
+               'normalizedBody': '<p><a rel="mw:WikiLink" 
href="Foo#Bar">Foo</a></p>',
                'mwConfig': {
                        'wgArticlePath': '/wiki/$1'
                }
@@ -1892,6 +1951,7 @@
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
                                                'normalizedTitle': 'Bar',
+                                               'lookupTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [
@@ -1916,6 +1976,7 @@
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
                                                'normalizedTitle': 'Bar',
+                                               'lookupTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [
@@ -1940,6 +2001,7 @@
                                                'title': 'Bar',
                                                'origTitle': 'Bar',
                                                'normalizedTitle': 'Bar',
+                                               'lookupTitle': 'Bar',
                                                'hrefPrefix': './'
                                        },
                                        'htmlAttributes': [
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkInspector.js
index ae62b58..015c9b7 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkInspector.js
@@ -78,7 +78,9 @@
                        'type': 'link/mwInternal',
                        'attributes': {
                                'title': target,
-                               'normalizedTitle': 
ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( target )
+                               // bug 62816: we really need a builder for this 
stuff
+                               'normalizedTitle': 
ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( target ),
+                               'lookupTitle': 
ve.dm.MWInternalLinkAnnotation.static.getLookupTitle( target )
                        }
                } );
        } else {
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js 
b/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
index da32ec9..e2e3d3d 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js
@@ -275,7 +275,9 @@
                'type': 'link/mwInternal',
                'attributes': {
                        'title': target,
-                       'normalizedTitle': 
ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( target )
+                       // bug 62816: we really need a builder for this stuff
+                       'normalizedTitle': 
ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( target ),
+                       'lookupTitle': 
ve.dm.MWInternalLinkAnnotation.static.getLookupTitle( target )
                }
        } );
 };

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0e04f64c1bebeff84a0c17ef9b6c8dc06876f769
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
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