Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/119436

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.

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


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/36/119436/1

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/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: newchange
Gerrit-Change-Id: I0e04f64c1bebeff84a0c17ef9b6c8dc06876f769
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>

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

Reply via email to