Prepend a colon to internal links to Category: and File: pages

Change-Id: I77570ea6ec9f29b5d5eb06b518cb08a1b2cea0b2
This commit is contained in:
Catrope 2012-06-25 16:25:09 -07:00
parent 4eca804542
commit 1e62e9f64c
2 changed files with 15 additions and 1 deletions

View file

@ -220,7 +220,8 @@ $wgResourceModules += array(
'dependencies' => array( 'dependencies' => array(
'jquery', 'jquery',
'rangy', 'rangy',
'ext.visualEditor.base' 'ext.visualEditor.base',
'mediawiki.Title',
), ),
'messages' => array( 'messages' => array(
'visualeditor', 'visualeditor',

View file

@ -183,6 +183,7 @@ ve.ui.LinkInspector.prototype.onClose = function( accept ) {
}; };
ve.ui.LinkInspector.getAnnotationForTarget = function( target ) { ve.ui.LinkInspector.getAnnotationForTarget = function( target ) {
var title;
// Figure out if this is an internal or external link // Figure out if this is an internal or external link
if ( target.match( /^(https?:)?\/\// ) ) { if ( target.match( /^(https?:)?\/\// ) ) {
// External link // External link
@ -192,6 +193,18 @@ ve.ui.LinkInspector.getAnnotationForTarget = function( target ) {
}; };
} else { } else {
// Internal link // 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 { return {
'type': 'link/wikiLink', 'type': 'link/wikiLink',
'data': { 'title': target } 'data': { 'title': target }