mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-24 02:38:40 +00:00
Merge "Update VE core submodule to master (2c0224d)"
This commit is contained in:
commit
db741011b8
|
@ -39,7 +39,6 @@
|
|||
<link rel=stylesheet href="lib/ve/src/ui/styles/widgets/ve.ui.MediaSizeWidget.css" class="stylesheet-ve">
|
||||
<link rel=stylesheet href="lib/ve/src/ui/styles/inspectors/ve.ui.CommentInspector.css" class="stylesheet-ve">
|
||||
<link rel=stylesheet href="lib/ve/src/ui/styles/inspectors/ve.ui.FragmentInspector.css" class="stylesheet-ve">
|
||||
<link rel=stylesheet href="lib/ve/src/ui/styles/inspectors/ve.ui.LinkInspector.css" class="stylesheet-ve">
|
||||
<link rel=stylesheet href="lib/ve/src/ui/styles/ve.ui.ContextItem.css" class="stylesheet-ve">
|
||||
<link rel=stylesheet href="lib/ve/src/ui/styles/contextitems/ve.ui.AlignableContextItem.css" class="stylesheet-ve">
|
||||
<link rel=stylesheet href="lib/ve/src/ui/styles/contextitems/ve.ui.CommentContextItem.css" class="stylesheet-ve">
|
||||
|
@ -367,7 +366,7 @@
|
|||
<script src="lib/ve/src/ui/dialogs/ve.ui.LanguageSearchDialog.js"></script>
|
||||
<script src="lib/ve/src/ui/widgets/ve.ui.LanguageInputWidget.js"></script>
|
||||
<script src="lib/ve/src/ui/widgets/ve.ui.SurfaceWidget.js"></script>
|
||||
<script src="lib/ve/src/ui/widgets/ve.ui.LinkTargetInputWidget.js"></script>
|
||||
<script src="lib/ve/src/ui/widgets/ve.ui.LinkAnnotationWidget.js"></script>
|
||||
<script src="lib/ve/src/ui/widgets/ve.ui.ContextSelectWidget.js"></script>
|
||||
<script src="lib/ve/src/ui/widgets/ve.ui.ContextOptionWidget.js"></script>
|
||||
<script src="lib/ve/src/ui/widgets/ve.ui.DimensionsWidget.js"></script>
|
||||
|
@ -388,7 +387,7 @@
|
|||
<script src="lib/ve/src/ui/inspectors/ve.ui.FragmentInspector.js"></script>
|
||||
<script src="lib/ve/src/ui/inspectors/ve.ui.AnnotationInspector.js"></script>
|
||||
<script src="lib/ve/src/ui/inspectors/ve.ui.NodeInspector.js"></script>
|
||||
<script src="lib/ve/src/ui/inspectors/ve.ui.LinkInspector.js"></script>
|
||||
<script src="lib/ve/src/ui/inspectors/ve.ui.LinkAnnotationInspector.js"></script>
|
||||
<script src="lib/ve/src/ui/inspectors/ve.ui.CommentInspector.js"></script>
|
||||
<script src="lib/ve/src/ui/inspectors/ve.ui.LanguageInspector.js"></script>
|
||||
<script src="lib/ve/src/ui/pages/ve.ui.SpecialCharacterPage.js"></script>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* VisualEditor extension
|
||||
*
|
||||
|
@ -613,7 +614,7 @@ $wgResourceModules += array(
|
|||
|
||||
'lib/ve/src/ui/widgets/ve.ui.AlignWidget.js',
|
||||
'lib/ve/src/ui/widgets/ve.ui.SurfaceWidget.js',
|
||||
'lib/ve/src/ui/widgets/ve.ui.LinkTargetInputWidget.js',
|
||||
'lib/ve/src/ui/widgets/ve.ui.LinkAnnotationWidget.js',
|
||||
'lib/ve/src/ui/widgets/ve.ui.ContextSelectWidget.js',
|
||||
'lib/ve/src/ui/widgets/ve.ui.ContextOptionWidget.js',
|
||||
'lib/ve/src/ui/widgets/ve.ui.DimensionsWidget.js',
|
||||
|
@ -636,7 +637,7 @@ $wgResourceModules += array(
|
|||
'lib/ve/src/ui/inspectors/ve.ui.AnnotationInspector.js',
|
||||
'lib/ve/src/ui/inspectors/ve.ui.NodeInspector.js',
|
||||
'lib/ve/src/ui/inspectors/ve.ui.CommentInspector.js',
|
||||
'lib/ve/src/ui/inspectors/ve.ui.LinkInspector.js',
|
||||
'lib/ve/src/ui/inspectors/ve.ui.LinkAnnotationInspector.js',
|
||||
|
||||
'lib/ve/src/ui/pages/ve.ui.SpecialCharacterPage.js',
|
||||
),
|
||||
|
@ -672,7 +673,6 @@ $wgResourceModules += array(
|
|||
'lib/ve/src/ui/styles/widgets/ve.ui.MediaSizeWidget.css',
|
||||
'lib/ve/src/ui/styles/inspectors/ve.ui.CommentInspector.css',
|
||||
'lib/ve/src/ui/styles/inspectors/ve.ui.FragmentInspector.css',
|
||||
'lib/ve/src/ui/styles/inspectors/ve.ui.LinkInspector.css',
|
||||
'lib/ve/src/ui/styles/widgets/ve.ui.SurfaceWidget.css',
|
||||
'lib/ve/src/ui/styles/ve.ui.ContextItem.css',
|
||||
'lib/ve/src/ui/styles/contextitems/ve.ui.AlignableContextItem.css',
|
||||
|
@ -1125,6 +1125,8 @@ $wgResourceModules += array(
|
|||
'modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js',
|
||||
'modules/ve-mw/ui/widgets/ve.ui.MWLinkMenuOptionWidget.js',
|
||||
'modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkMenuOptionWidget.js',
|
||||
'modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js',
|
||||
'modules/ve-mw/ui/widgets/ve.ui.MWExternalLinkAnnotationWidget.js',
|
||||
|
||||
'modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js',
|
||||
'modules/ve-mw/ui/inspectors/ve.ui.MWLinkNodeInspector.js',
|
||||
|
@ -1136,7 +1138,8 @@ $wgResourceModules += array(
|
|||
'styles' => array(
|
||||
'modules/ve-mw/ui/styles/contextitems/ve.ui.MWInternalLinkContextItem.css',
|
||||
'modules/ve-mw/ui/styles/widgets/ve.ui.MWLinkTargetInputWidget.css',
|
||||
'modules/ve-mw/ui/styles/widgets/ve.ui.MWInternalLinkMenuOptionWidget.css'
|
||||
'modules/ve-mw/ui/styles/widgets/ve.ui.MWInternalLinkMenuOptionWidget.css',
|
||||
'modules/ve-mw/ui/styles/inspectors/ve.ui.MWLinkAnnotationInspector.css',
|
||||
),
|
||||
'skinStyles' => array(
|
||||
'apex' => array(
|
||||
|
|
|
@ -673,7 +673,7 @@
|
|||
"lib/ve/src/ui/windowmanagers/ve.ui.ToolbarDialogWindowManager.js",
|
||||
"lib/ve/src/ui/widgets/ve.ui.AlignWidget.js",
|
||||
"lib/ve/src/ui/widgets/ve.ui.SurfaceWidget.js",
|
||||
"lib/ve/src/ui/widgets/ve.ui.LinkTargetInputWidget.js",
|
||||
"lib/ve/src/ui/widgets/ve.ui.LinkAnnotationWidget.js",
|
||||
"lib/ve/src/ui/widgets/ve.ui.ContextSelectWidget.js",
|
||||
"lib/ve/src/ui/widgets/ve.ui.ContextOptionWidget.js",
|
||||
"lib/ve/src/ui/widgets/ve.ui.DimensionsWidget.js",
|
||||
|
@ -694,7 +694,7 @@
|
|||
"lib/ve/src/ui/inspectors/ve.ui.AnnotationInspector.js",
|
||||
"lib/ve/src/ui/inspectors/ve.ui.NodeInspector.js",
|
||||
"lib/ve/src/ui/inspectors/ve.ui.CommentInspector.js",
|
||||
"lib/ve/src/ui/inspectors/ve.ui.LinkInspector.js",
|
||||
"lib/ve/src/ui/inspectors/ve.ui.LinkAnnotationInspector.js",
|
||||
"lib/ve/src/ui/pages/ve.ui.SpecialCharacterPage.js"
|
||||
],
|
||||
"debugScripts": [
|
||||
|
@ -726,7 +726,6 @@
|
|||
"lib/ve/src/ui/styles/widgets/ve.ui.MediaSizeWidget.css",
|
||||
"lib/ve/src/ui/styles/inspectors/ve.ui.CommentInspector.css",
|
||||
"lib/ve/src/ui/styles/inspectors/ve.ui.FragmentInspector.css",
|
||||
"lib/ve/src/ui/styles/inspectors/ve.ui.LinkInspector.css",
|
||||
"lib/ve/src/ui/styles/widgets/ve.ui.SurfaceWidget.css",
|
||||
"lib/ve/src/ui/styles/ve.ui.ContextItem.css",
|
||||
"lib/ve/src/ui/styles/contextitems/ve.ui.AlignableContextItem.css",
|
||||
|
@ -1154,6 +1153,8 @@
|
|||
"modules/ve-mw/ui/widgets/ve.ui.MWLinkTargetInputWidget.js",
|
||||
"modules/ve-mw/ui/widgets/ve.ui.MWLinkMenuOptionWidget.js",
|
||||
"modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkMenuOptionWidget.js",
|
||||
"modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js",
|
||||
"modules/ve-mw/ui/widgets/ve.ui.MWExternalLinkAnnotationWidget.js",
|
||||
"modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js",
|
||||
"modules/ve-mw/ui/inspectors/ve.ui.MWLinkNodeInspector.js",
|
||||
"modules/ve-mw/ui/tools/ve.ui.MWLinkInspectorTool.js",
|
||||
|
@ -1162,7 +1163,8 @@
|
|||
"styles": [
|
||||
"modules/ve-mw/ui/styles/contextitems/ve.ui.MWInternalLinkContextItem.css",
|
||||
"modules/ve-mw/ui/styles/widgets/ve.ui.MWLinkTargetInputWidget.css",
|
||||
"modules/ve-mw/ui/styles/widgets/ve.ui.MWInternalLinkMenuOptionWidget.css"
|
||||
"modules/ve-mw/ui/styles/widgets/ve.ui.MWInternalLinkMenuOptionWidget.css",
|
||||
"modules/ve-mw/ui/styles/inspectors/ve.ui.MWLinkAnnotationInspector.css"
|
||||
],
|
||||
"skinStyles": {
|
||||
"apex": [
|
||||
|
|
2
lib/ve
2
lib/ve
|
@ -1 +1 @@
|
|||
Subproject commit 7c4bbb1bb4ea11b51075e19be0eb17fa22dd63ba
|
||||
Subproject commit f81eefa3d5ce28ae39331c2a214560b3fd6f9624
|
|
@ -1,5 +1,5 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface LinkInspector class.
|
||||
* VisualEditor UserInterface LinkAnnotationInspector class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
|
@ -9,19 +9,19 @@
|
|||
* Inspector for applying and editing labeled MediaWiki internal and external links.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.LinkInspector
|
||||
* @extends ve.ui.LinkAnnotationInspector
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector = function VeUiMWLinkAnnotationInspector( config ) {
|
||||
// Parent constructor
|
||||
ve.ui.LinkInspector.call( this, config );
|
||||
ve.ui.MWLinkAnnotationInspector.super.call( this, config );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWLinkAnnotationInspector, ve.ui.LinkInspector );
|
||||
OO.inheritClass( ve.ui.MWLinkAnnotationInspector, ve.ui.LinkAnnotationInspector );
|
||||
|
||||
/* Static properties */
|
||||
|
||||
|
@ -32,10 +32,142 @@ ve.ui.MWLinkAnnotationInspector.static.modelClasses = [
|
|||
ve.dm.MWInternalLinkAnnotation
|
||||
];
|
||||
|
||||
ve.ui.MWLinkAnnotationInspector.static.linkTargetInputWidget = ve.ui.MWLinkTargetInputWidget;
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.initialize = function () {
|
||||
var overlay = this.manager.getOverlay();
|
||||
|
||||
// Properties
|
||||
this.allowProtocolInInternal = false;
|
||||
this.internalAnnotationInput = new ve.ui.MWInternalLinkAnnotationWidget( {
|
||||
// Sub-classes may want to know where to position overlays
|
||||
$overlay: overlay ? overlay.$element : this.$frame
|
||||
} );
|
||||
this.externalAnnotationInput = new ve.ui.MWExternalLinkAnnotationWidget();
|
||||
|
||||
this.linkTypeSelect = new OO.ui.ButtonSelectWidget( {
|
||||
classes: [ 've-ui-mwLinkAnnotationInspector-linkTypeSelect' ],
|
||||
items: [
|
||||
new OO.ui.ButtonOptionWidget( { framed: false, data: 'internal', label: ve.msg( 'visualeditor-linkinspector-button-link-internal' ) } ),
|
||||
new OO.ui.ButtonOptionWidget( { framed: false, data: 'external', label: ve.msg( 'visualeditor-linkinspector-button-link-external' ) } )
|
||||
]
|
||||
} );
|
||||
|
||||
// Events
|
||||
this.linkTypeSelect.connect( this, { select: 'onLinkTypeSelectSelect' } );
|
||||
this.internalAnnotationInput.connect( this, { change: 'onInternalLinkChange' } );
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWLinkAnnotationInspector.super.prototype.initialize.call( this );
|
||||
|
||||
// Initialization
|
||||
this.form.$element.prepend( this.linkTypeSelect.$element );
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the current input mode is for external links
|
||||
*
|
||||
* @return {boolean} Input mode is for external links
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.isExternal = function () {
|
||||
var item = this.linkTypeSelect.getSelectedItem();
|
||||
return item && item.getData() === 'external';
|
||||
};
|
||||
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChange = function ( annotation ) {
|
||||
var title,
|
||||
href = annotation ? annotation.getAttribute( 'title' ) : '';
|
||||
|
||||
if ( ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( href ) ) {
|
||||
// Check if the 'external' link is in fact a page on the same wiki
|
||||
// e.g. http://en.wikipedia.org/wiki/Target -> Target
|
||||
title = ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref(
|
||||
href,
|
||||
ve.init.target.doc
|
||||
).title;
|
||||
if ( title !== href ) {
|
||||
this.internalAnnotationInput.text.setValue( title );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!this.allowProtocolInInternal &&
|
||||
ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( href )
|
||||
) {
|
||||
this.linkTypeSelect.selectItem( this.linkTypeSelect.getItemFromData( 'external' ) );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.createAnnotationInput = function () {
|
||||
return this.isExternal() ? this.externalAnnotationInput : this.internalAnnotationInput;
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.getSetupProcess = function ( data ) {
|
||||
return ve.ui.MWLinkAnnotationInspector.super.prototype.getSetupProcess.call( this, data )
|
||||
.next( function () {
|
||||
this.linkTypeSelect.selectItem(
|
||||
this.linkTypeSelect.getItemFromData(
|
||||
this.initialAnnotation instanceof ve.dm.MWExternalLinkAnnotation ? 'external' : 'internal'
|
||||
)
|
||||
);
|
||||
this.annotationInput.setAnnotation( this.initialAnnotation );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.getTeardownProcess = function ( data ) {
|
||||
return ve.ui.MWLinkAnnotationInspector.super.prototype.getTeardownProcess.call( this, data )
|
||||
.next( function () {
|
||||
this.allowProtocolInInternal = false;
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle select events from the linkTypeSelect widget
|
||||
*
|
||||
* @param {OO.ui.MenuOptionWidget} item Selected item
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.onLinkTypeSelectSelect = function () {
|
||||
var text = this.annotationInput.text.getValue(),
|
||||
isExternal = this.isExternal(),
|
||||
inputHasProtocol = ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( text );
|
||||
|
||||
this.annotationInput.$element.detach();
|
||||
|
||||
this.annotationInput = this.createAnnotationInput();
|
||||
this.form.$element.append( this.annotationInput.$element );
|
||||
|
||||
if ( isExternal ) {
|
||||
// If the user switches to external links clear the input, unless the input is URL-like
|
||||
if ( !inputHasProtocol ) {
|
||||
text = '';
|
||||
}
|
||||
} else {
|
||||
// If the user manually switches to internal links with an external link in the input, remember this
|
||||
if ( inputHasProtocol ) {
|
||||
this.allowProtocolInInternal = true;
|
||||
}
|
||||
}
|
||||
|
||||
this.annotationInput.text.setValue( text ).focus();
|
||||
|
||||
if ( !isExternal ) {
|
||||
this.annotationInput.text.populateLookupMenu();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets an annotation object from a fragment.
|
||||
*
|
||||
|
@ -88,18 +220,15 @@ ve.ui.MWLinkAnnotationInspector.prototype.getAnnotationFromFragment = function (
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.getInsertionData = function () {
|
||||
var target = this.targetInput.getValue(),
|
||||
inserting = this.initialSelection.isCollapsed();
|
||||
|
||||
// If this is a new external link, insert an autonumbered link instead of a link annotation (in
|
||||
// #getAnnotation we have the same condition to skip the annotating). Otherwise call parent method
|
||||
// to figure out the text to insert and annotate.
|
||||
if ( inserting && ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( target ) ) {
|
||||
if ( this.isExternal() ) {
|
||||
return [
|
||||
{
|
||||
type: 'link/mwNumberedExternal',
|
||||
attributes: {
|
||||
href: target
|
||||
href: this.annotationInput.getHref()
|
||||
}
|
||||
},
|
||||
{ type: '/link/mwNumberedExternal' }
|
||||
|
@ -109,22 +238,6 @@ ve.ui.MWLinkAnnotationInspector.prototype.getInsertionData = function () {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.getAnnotation = function () {
|
||||
var target = this.targetInput.getValue(),
|
||||
inserting = this.initialSelection.isCollapsed();
|
||||
|
||||
// If this is a new external link, we've just inserted an autonumbered link node (see
|
||||
// #getInsertionData). Do not place any annotations of top of it.
|
||||
if ( inserting && ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( target ) ) {
|
||||
return null;
|
||||
} else {
|
||||
return ve.ui.MWLinkAnnotationInspector.super.prototype.getAnnotation.call( this );
|
||||
}
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.windowFactory.register( ve.ui.MWLinkAnnotationInspector );
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/*!
|
||||
* VisualEditor MediaWiki UserInterface MWLinkAnnotationInspector styles.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
.ve-ui-mwLinkAnnotationInspector-linkTypeSelect .oo-ui-buttonOptionWidget .oo-ui-buttonElement-button {
|
||||
height: auto;
|
||||
margin: 0;
|
||||
padding: 0 0.5em;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.ve-ui-mwLinkAnnotationInspector-linkTypeSelect .oo-ui-optionWidget-selected .oo-ui-buttonElement-button {
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
.ve-ui-mwLinkAnnotationInspector .oo-ui-iconElement-icon {
|
||||
opacity: 0.4;
|
||||
}
|
|
@ -5,31 +5,6 @@
|
|||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
.ve-ui-mwLinkTargetInputWidget {
|
||||
margin-top: 2.75em;
|
||||
}
|
||||
|
||||
|
||||
.ve-ui-mwLinkTargetInputWidget-linkTypeSelect {
|
||||
position: absolute;
|
||||
top: -1.75em;
|
||||
}
|
||||
|
||||
.ve-ui-mwLinkTargetInputWidget-linkTypeSelect .oo-ui-buttonOptionWidget .oo-ui-buttonElement-button {
|
||||
height: auto;
|
||||
margin: 0;
|
||||
padding: 0 0.5em;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.ve-ui-mwLinkTargetInputWidget-linkTypeSelect .oo-ui-optionWidget-selected .oo-ui-buttonElement-button {
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
.ve-ui-mwLinkTargetInputWidget .oo-ui-iconElement-icon {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
/* Warning text for invalid titles (bug 62761) */
|
||||
|
||||
.ve-ui-mwLinkTargetInputWidget-warning {
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWExternalLinkAnnotationWidget class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates an ve.ui.MWExternalLinkAnnotationWidget object.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.LinkAnnotationWidget
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ui.MWExternalLinkAnnotationWidget = function VeUiMWExternalLinkAnnotationWidget() {
|
||||
// Parent constructor
|
||||
ve.ui.MWExternalLinkAnnotationWidget.super.apply( this, arguments );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWExternalLinkAnnotationWidget, ve.ui.LinkAnnotationWidget );
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* Create a text input widget to be used by the annotation widget
|
||||
*
|
||||
* @param {Object} [config] Configuration options
|
||||
* @return {OO.ui.TextInputWidget} Text input widget
|
||||
*/
|
||||
ve.ui.MWExternalLinkAnnotationWidget.prototype.createInputWidget = function () {
|
||||
return new OO.ui.TextInputWidget( {
|
||||
icon: 'linkExternal',
|
||||
validate: ve.init.platform.getExternalLinkUrlProtocolsRegExp()
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWExternalLinkAnnotationWidget.prototype.getAnnotationFromText = function ( value ) {
|
||||
var href = value.trim();
|
||||
|
||||
// Keep annotation in sync with value
|
||||
if ( href === '' ) {
|
||||
return null;
|
||||
} else {
|
||||
return new ve.dm.MWExternalLinkAnnotation( {
|
||||
type: 'link/mwExternal',
|
||||
attributes: {
|
||||
href: href
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
|
@ -0,0 +1,80 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWInternalLinkAnnotationWidget class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates an ve.ui.MWInternalLinkAnnotationWidget object.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.LinkAnnotationWidget
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ui.MWInternalLinkAnnotationWidget = function VeUiMWInternalLinkAnnotationWidget() {
|
||||
// Parent constructor
|
||||
ve.ui.MWInternalLinkAnnotationWidget.super.apply( this, arguments );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWInternalLinkAnnotationWidget, ve.ui.LinkAnnotationWidget );
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* Create a text input widget to be used by the annotation widget
|
||||
*
|
||||
* @param {Object} [config] Configuration options
|
||||
* @return {OO.ui.TextInputWidget} Text input widget
|
||||
*/
|
||||
ve.ui.MWInternalLinkAnnotationWidget.prototype.createInputWidget = function ( config ) {
|
||||
return new ve.ui.MWLinkTargetInputWidget( {
|
||||
icon: 'search',
|
||||
$overlay: config.$overlay
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWInternalLinkAnnotationWidget.prototype.getAnnotationFromText = function ( value ) {
|
||||
var title,
|
||||
target = value.trim();
|
||||
|
||||
// Keep annotation in sync with value
|
||||
if ( target === '' ) {
|
||||
return null;
|
||||
} else {
|
||||
title = mw.Title.newFromText( target );
|
||||
|
||||
if (
|
||||
title &&
|
||||
( title.getNamespaceId() === 6 || title.getNamespaceId() === 14 ) &&
|
||||
target[0] !== ':'
|
||||
) {
|
||||
// Prepend links to File and Category namespace with a colon
|
||||
target = ':' + target;
|
||||
}
|
||||
|
||||
return new ve.dm.MWInternalLinkAnnotation( {
|
||||
type: 'link/mwInternal',
|
||||
attributes: {
|
||||
title: 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 )
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWInternalLinkAnnotationWidget.prototype.getTextFromAnnotation = function ( annotation ) {
|
||||
return annotation ? annotation.getAttribute( 'title' ) : '';
|
||||
};
|
|
@ -13,22 +13,30 @@
|
|||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
* @cfg {string} [pagename] Pagename to return the names of internal pages
|
||||
* @cfg {string} [data] Page title
|
||||
* @cfg {string} [imageUrl] Thumbnail image URL with URL encoding
|
||||
* @cfg {string} [description] Page description
|
||||
* @cfg {string} [query] Matching query string
|
||||
*/
|
||||
ve.ui.MWInternalLinkMenuOptionWidget = function VeUiMWInternalLinkMenuOptionWidget( config ) {
|
||||
// Config initialization
|
||||
config = ve.extendObject( { icon: 'page-existing' }, config );
|
||||
var title = config.data;
|
||||
|
||||
// Properties
|
||||
this.pagename = config.pagename;
|
||||
// Config initialization
|
||||
config = ve.extendObject( {
|
||||
icon: 'page-existing',
|
||||
label: title,
|
||||
href: mw.util.getUrl( title ),
|
||||
autoFitLabel: false
|
||||
}, config );
|
||||
|
||||
// Parent constructor
|
||||
ve.ui.MWLinkMenuOptionWidget.call( this, $.extend( { label: this.pagename, href: mw.util.getUrl( this.pagename ), autoFitLabel: false }, config ) );
|
||||
ve.ui.MWInternalLinkMenuOptionWidget.super.call( this, config );
|
||||
|
||||
// Highlight matching parts of link suggestion
|
||||
this.$label.autoEllipsis( { hasSpan: false, tooltip: true, matchText: config.query } );
|
||||
|
||||
// Style based on link cache information
|
||||
ve.init.platform.linkCache.styleElement( this.pagename, this.$link );
|
||||
ve.init.platform.linkCache.styleElement( title, this.$link );
|
||||
|
||||
// Intialization
|
||||
this.$element.addClass( 've-ui-mwInternalLinkMenuOptionWidget' );
|
||||
|
@ -46,9 +54,6 @@ ve.ui.MWInternalLinkMenuOptionWidget = function VeUiMWInternalLinkMenuOptionWidg
|
|||
.text( config.description )
|
||||
);
|
||||
}
|
||||
|
||||
// Highlight matching parts of link suggestion
|
||||
this.$label.autoEllipsis( { hasSpan: false, tooltip: true, matchText: config.query } );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* Creates an ve.ui.MWLinkTargetInputWidget object.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.LinkTargetInputWidget
|
||||
* @extends OO.ui.TextInputWidget
|
||||
* @mixins OO.ui.LookupElement
|
||||
*
|
||||
* @constructor
|
||||
|
@ -22,27 +22,12 @@ ve.ui.MWLinkTargetInputWidget = function VeUiMWLinkTargetInputWidget( config ) {
|
|||
config = config || {};
|
||||
|
||||
// Parent constructor
|
||||
ve.ui.LinkTargetInputWidget.call( this, config );
|
||||
ve.ui.MWLinkTargetInputWidget.super.call( this, config );
|
||||
|
||||
// Mixin constructors
|
||||
OO.ui.LookupElement.call( this, config );
|
||||
|
||||
// Properties
|
||||
this.annotation = null;
|
||||
this.allowProtocolInInternal = false;
|
||||
|
||||
this.linkTypeSelect = new OO.ui.ButtonSelectWidget( {
|
||||
classes: [ 've-ui-mwLinkTargetInputWidget-linkTypeSelect' ]
|
||||
} ).addItems( [
|
||||
new OO.ui.ButtonOptionWidget( { framed: false, data: 'internal', label: ve.msg( 'visualeditor-linkinspector-button-link-internal' ) } ),
|
||||
new OO.ui.ButtonOptionWidget( { framed: false, data: 'external', label: ve.msg( 'visualeditor-linkinspector-button-link-external' ) } )
|
||||
] ).connect( this, {
|
||||
select: 'onLinkTypeSelectSelect',
|
||||
choose: 'onLinkTypeSelectChoose'
|
||||
} );
|
||||
|
||||
// Initialization
|
||||
this.$element.prepend( this.linkTypeSelect.$element );
|
||||
this.$element.addClass( 've-ui-mwLinkTargetInputWidget' );
|
||||
this.lookupMenu.$element.addClass( 've-ui-mwLinkTargetInputWidget-menu' );
|
||||
if ( mw.config.get( 'wgVisualEditor' ).usePageImages ) {
|
||||
|
@ -66,67 +51,19 @@ ve.ui.MWLinkTargetInputWidget = function VeUiMWLinkTargetInputWidget( config ) {
|
|||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWLinkTargetInputWidget, ve.ui.LinkTargetInputWidget );
|
||||
OO.inheritClass( ve.ui.MWLinkTargetInputWidget, OO.ui.TextInputWidget );
|
||||
|
||||
OO.mixinClass( ve.ui.MWLinkTargetInputWidget, OO.ui.LookupElement );
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* Check if the current input mode is for external links
|
||||
*
|
||||
* @return {boolean} Input mode is for external links
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.isExternal = function () {
|
||||
var item = this.linkTypeSelect.getSelectedItem();
|
||||
return item && item.getData() === 'external';
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle select events from the linkTypeSelect widget
|
||||
*
|
||||
* @param {OO.ui.MenuOptionWidget} item Selected item
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.onLinkTypeSelectSelect = function () {
|
||||
this.setIcon( this.isExternal() ? 'linkExternal' : 'search' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle choose events from the linkTypeSelect widget
|
||||
*
|
||||
* Choose events are only generated by the user
|
||||
*
|
||||
* @param {OO.ui.MenuOptionWidget} item Chosen item
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.onLinkTypeSelectChoose = function () {
|
||||
var isExternal = this.isExternal(),
|
||||
inputHasProtocol = ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( this.value );
|
||||
|
||||
if ( isExternal ) {
|
||||
// If the user switches to external links clear the input, unless the input is URL-like
|
||||
if ( !inputHasProtocol ) {
|
||||
this.setValue( '' );
|
||||
}
|
||||
this.closeLookupMenu();
|
||||
} else {
|
||||
// If the user manually switches to internal links with an external link in the input, remember this
|
||||
if ( inputHasProtocol ) {
|
||||
this.allowProtocolInInternal = true;
|
||||
}
|
||||
if ( this.lookupInputFocused ) {
|
||||
this.onLookupInputChange();
|
||||
this.populateLookupMenu();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.onLookupMenuItemChoose = function ( item ) {
|
||||
this.closeLookupMenu();
|
||||
this.setLookupsDisabled( true );
|
||||
this.setAnnotation( item.getData() );
|
||||
this.setValue( item.getData() );
|
||||
this.setLookupsDisabled( false );
|
||||
};
|
||||
|
||||
|
@ -149,13 +86,7 @@ ve.ui.MWLinkTargetInputWidget.prototype.focus = function () {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.isValid = function () {
|
||||
var valid;
|
||||
if ( this.annotation instanceof ve.dm.MWExternalLinkAnnotation ) {
|
||||
valid = this.annotation.getAttribute( 'href' )
|
||||
.match( /(^|\s)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi );
|
||||
} else {
|
||||
valid = !!mw.Title.newFromText( this.getValue() );
|
||||
}
|
||||
var valid = !!mw.Title.newFromText( this.getValue() );
|
||||
return $.Deferred().resolve( valid ).promise();
|
||||
};
|
||||
|
||||
|
@ -172,7 +103,7 @@ ve.ui.MWLinkTargetInputWidget.prototype.getLookupRequest = function () {
|
|||
// Do nothing. This is just so OOUI doesn't break due to abort being undefined.
|
||||
} };
|
||||
|
||||
if ( !this.isExternal() && mw.Title.newFromText( this.value ) ) {
|
||||
if ( mw.Title.newFromText( this.value ) ) {
|
||||
return this.interwikiPrefixesPromise.then( function () {
|
||||
var interwiki = widget.value.substring( 0, widget.value.indexOf( ':' ) );
|
||||
if (
|
||||
|
@ -219,37 +150,6 @@ ve.ui.MWLinkTargetInputWidget.prototype.getLookupCacheDataFromResponse = functio
|
|||
return data.query || {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc OO.ui.LookupElement
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.onLookupInputChange = function () {
|
||||
var title;
|
||||
if ( !this.isExternal() && ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( this.value ) ) {
|
||||
// Check if the 'external' link is in fact a page on the same wiki
|
||||
// e.g. http://en.wikipedia.org/wiki/Target -> Target
|
||||
title = ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref(
|
||||
this.value,
|
||||
ve.init.target.doc
|
||||
).title;
|
||||
if ( title !== this.value ) {
|
||||
this.setValue( title );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If the user types http:// in an internal search switch them to external (unless
|
||||
// they have previously explicitly switched back to internal)
|
||||
if (
|
||||
!this.isExternal() && !this.allowProtocolInInternal &&
|
||||
ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( this.value )
|
||||
) {
|
||||
this.linkTypeSelect.selectItem( this.linkTypeSelect.getItemFromData( 'external' ) );
|
||||
}
|
||||
|
||||
// Mixin method
|
||||
OO.ui.LookupElement.prototype.onLookupInputChange.apply( this, arguments );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get list of menu items from a server response.
|
||||
*
|
||||
|
@ -306,179 +206,25 @@ ve.ui.MWLinkTargetInputWidget.prototype.getLookupMenuOptionsFromData = function
|
|||
|
||||
ve.init.platform.linkCache.set( links );
|
||||
|
||||
if ( this.isExternal() ) {
|
||||
|
||||
// External link
|
||||
if ( ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( this.value ) ) {
|
||||
// Set annotation directly, bypassing re-setting the value of the input
|
||||
this.annotation = this.getExternalLinkAnnotationFromUrl( this.value );
|
||||
} else {
|
||||
// No protocol was found, assume 'http'
|
||||
this.annotation = this.getExternalLinkAnnotationFromUrl( 'http://' + this.value );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Internal Link
|
||||
// Offer the exact text as a suggestion if the page exists
|
||||
if ( pageExists && !pageExistsExact ) {
|
||||
suggestionPages.unshift( this.value );
|
||||
}
|
||||
// Offer the exact text as a new page if the title is valid
|
||||
if ( !pageExists && titleObj ) {
|
||||
suggestionPages.push( this.value );
|
||||
}
|
||||
for ( i = 0, len = suggestionPages.length; i < len; i++ ) {
|
||||
linkData = links[suggestionPages[i]] || {};
|
||||
items.push( new ve.ui.MWInternalLinkMenuOptionWidget( {
|
||||
data: this.getInternalLinkAnnotationFromTitle( suggestionPages[i] ),
|
||||
pagename: suggestionPages[i],
|
||||
imageUrl: linkData.imageUrl,
|
||||
description: linkData.description,
|
||||
icon: ve.init.platform.linkCache.constructor.static.getIconForLink( linkData ),
|
||||
query: this.value
|
||||
} ) );
|
||||
}
|
||||
|
||||
// Internal Link
|
||||
// Offer the exact text as a suggestion if the page exists
|
||||
if ( pageExists && !pageExistsExact ) {
|
||||
suggestionPages.unshift( this.value );
|
||||
}
|
||||
// Offer the exact text as a new page if the title is valid
|
||||
if ( !pageExists && titleObj ) {
|
||||
suggestionPages.push( this.value );
|
||||
}
|
||||
for ( i = 0, len = suggestionPages.length; i < len; i++ ) {
|
||||
linkData = links[suggestionPages[i]] || {};
|
||||
items.push( new ve.ui.MWInternalLinkMenuOptionWidget( {
|
||||
data: suggestionPages[i],
|
||||
imageUrl: linkData.imageUrl,
|
||||
description: linkData.description,
|
||||
icon: ve.init.platform.linkCache.constructor.static.getIconForLink( linkData ),
|
||||
query: this.value
|
||||
} ) );
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.initializeLookupMenuSelection = function () {
|
||||
var item;
|
||||
|
||||
if ( this.annotation ) {
|
||||
this.lookupMenu.selectItem( this.lookupMenu.getItemFromData( this.annotation ) );
|
||||
}
|
||||
|
||||
item = this.lookupMenu.getSelectedItem();
|
||||
if ( !item ) {
|
||||
// Parent method
|
||||
OO.ui.LookupElement.prototype.initializeLookupMenuSelection.call( this );
|
||||
}
|
||||
|
||||
// Update annotation to match selected item
|
||||
item = this.lookupMenu.getSelectedItem();
|
||||
if ( item ) {
|
||||
// Set annotation directly, bypassing re-setting the value of the input
|
||||
this.annotation = item.getData();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the value of the input.
|
||||
*
|
||||
* Overrides setValue to keep annotations in sync.
|
||||
*
|
||||
* @method
|
||||
* @param {string} value New value
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.setValue = function ( value ) {
|
||||
// Keep annotation in sync with value by skipping parent and calling grandparent method
|
||||
OO.ui.TextInputWidget.prototype.setValue.call( this, value );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.setAnnotation = function ( annotation ) {
|
||||
// Keep annotation in sync with value by skipping parent and calling grandparent method
|
||||
ve.ui.MWLinkTargetInputWidget.super.prototype.setAnnotation.apply( this, arguments );
|
||||
|
||||
var isExternal = this.getAnnotation() instanceof ve.dm.MWExternalLinkAnnotation;
|
||||
this.linkTypeSelect.selectItem(
|
||||
this.linkTypeSelect.getItemFromData(
|
||||
isExternal ? 'external' : 'internal'
|
||||
)
|
||||
);
|
||||
if ( annotation === null ) {
|
||||
// When the widget is 'reset', reset this state variable.
|
||||
this.allowProtocolInInternal = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets an internal link annotation.
|
||||
*
|
||||
* File: or Category: links will be prepended with a colon so they are interpreted as a links rather
|
||||
* than image inclusions or categorizations.
|
||||
*
|
||||
* @method
|
||||
* @param {string} target Page title
|
||||
* @returns {ve.dm.MWInternalLinkAnnotation}
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.getInternalLinkAnnotationFromTitle = function ( target ) {
|
||||
var title = mw.Title.newFromText( target );
|
||||
|
||||
if (
|
||||
title &&
|
||||
( title.getNamespaceId() === 6 || title.getNamespaceId() === 14 ) &&
|
||||
target[0] !== ':'
|
||||
) {
|
||||
// Prepend links to File and Category namespace with a colon
|
||||
target = ':' + target;
|
||||
}
|
||||
|
||||
return new ve.dm.MWInternalLinkAnnotation( {
|
||||
type: 'link/mwInternal',
|
||||
attributes: {
|
||||
title: 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 )
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets an external link annotation.
|
||||
*
|
||||
* @method
|
||||
* @param {string} target Web address
|
||||
* @returns {ve.dm.MWExternalLinkAnnotation}
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.getExternalLinkAnnotationFromUrl = function ( target ) {
|
||||
return new ve.dm.MWExternalLinkAnnotation( {
|
||||
type: 'link/mwExternal',
|
||||
attributes: {
|
||||
href: target
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a target from an annotation.
|
||||
*
|
||||
* @method
|
||||
* @param {ve.dm.MWExternalLinkAnnotation|ve.dm.MWInternalLinkAnnotation} annotation Annotation
|
||||
* @returns {string} Target
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.getTargetFromAnnotation = function ( annotation ) {
|
||||
if ( annotation instanceof ve.dm.MWExternalLinkAnnotation ) {
|
||||
return annotation.getAttribute( 'href' );
|
||||
} else if ( annotation instanceof ve.dm.MWInternalLinkAnnotation ) {
|
||||
return annotation.getAttribute( 'title' );
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLinkTargetInputWidget.prototype.getHref = function () {
|
||||
var title;
|
||||
|
||||
if ( this.annotation instanceof ve.dm.MWExternalLinkAnnotation ) {
|
||||
return this.annotation.getAttribute( 'href' );
|
||||
} else if ( this.annotation instanceof ve.dm.MWInternalLinkAnnotation ) {
|
||||
title = mw.Title.newFromText( this.annotation.getAttribute( 'title' ) );
|
||||
return title.getUrl();
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue