From 1e62e9f64c08e1e92303235846ec6a37e431d0bd Mon Sep 17 00:00:00 2001 From: Catrope Date: Mon, 25 Jun 2012 16:25:09 -0700 Subject: [PATCH] Prepend a colon to internal links to Category: and File: pages Change-Id: I77570ea6ec9f29b5d5eb06b518cb08a1b2cea0b2 --- VisualEditor.php | 3 ++- modules/ve/ui/inspectors/ve.ui.LinkInspector.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/VisualEditor.php b/VisualEditor.php index dbd959b5fe..b69c4e6911 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -220,7 +220,8 @@ $wgResourceModules += array( 'dependencies' => array( 'jquery', 'rangy', - 'ext.visualEditor.base' + 'ext.visualEditor.base', + 'mediawiki.Title', ), 'messages' => array( 'visualeditor', diff --git a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js index c8d0a95ed1..7812910d8f 100644 --- a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js +++ b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js @@ -183,6 +183,7 @@ ve.ui.LinkInspector.prototype.onClose = function( accept ) { }; ve.ui.LinkInspector.getAnnotationForTarget = function( target ) { + var title; // Figure out if this is an internal or external link if ( target.match( /^(https?:)?\/\// ) ) { // External link @@ -192,6 +193,18 @@ ve.ui.LinkInspector.getAnnotationForTarget = function( target ) { }; } else { // Internal link + // TODO in the longer term we'll want to have autocompletion and existence&validity + // checks using AJAX + try { + title = new mw.Title( target ); + if ( title.getNamespaceId() === 6 || title.getNamespaceId() === 14 ) { + // File: or Category: link + // We have to prepend a colon so this is interpreted as a link + // rather than an image inclusion or categorization + target = ':' + target; + } + } catch ( e ) { } + return { 'type': 'link/wikiLink', 'data': { 'title': target }