| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.MWInternalLinkAnnotationWidget = function VeUiMWInternalLinkAnnotationWidget() { |
| 18 |
|
| 19 |
ve.ui.MWInternalLinkAnnotationWidget.super.apply( this, arguments ); |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
OO.inheritClass( ve.ui.MWInternalLinkAnnotationWidget, ve.ui.LinkAnnotationWidget ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
ve.ui.MWInternalLinkAnnotationWidget.static.getAnnotationFromText = function ( value ) { |
| 32 |
const trimmed = value.trim(), |
| 33 |
title = mw.Title.newFromText( trimmed ); |
| 34 |
|
| 35 |
if ( !title ) { |
| 36 |
return null; |
| 37 |
} |
| 38 |
return ve.dm.MWInternalLinkAnnotation.static.newFromTitle( title ); |
| 39 |
}; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
ve.ui.MWInternalLinkAnnotationWidget.static.getTextFromAnnotation = function ( annotation ) { |
| 45 |
return annotation ? annotation.getAttribute( 'normalizedTitle' ) : ''; |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
ve.ui.MWInternalLinkAnnotationWidget.prototype.createInputWidget = function ( config ) { |
| 57 |
const input = new mw.widgets.TitleSearchWidget( ve.extendObject( { |
| 58 |
icon: 'search', |
| 59 |
excludeCurrentPage: true, |
| 60 |
showImages: mw.config.get( 'wgVisualEditorConfig' ).usePageImages, |
| 61 |
showDescriptions: mw.config.get( 'wgVisualEditorConfig' ).usePageDescriptions, |
| 62 |
showDisambigsLast: true, |
| 63 |
showInterwikis: true, |
| 64 |
searchFragments: true, |
| 65 |
addQueryInput: false, |
| 66 |
api: ve.init.target.getContentApi(), |
| 67 |
cache: ve.init.platform.linkCache |
| 68 |
}, config ) ); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
input.$element.prepend( input.$query ); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
input.getQuery().$input.removeAttr( 'maxlength' ); |
| 78 |
|
| 79 |
input.query.$input.attr( 'aria-label', mw.msg( 'visualeditor-linkinspector-button-link-internal' ) ); |
| 80 |
return input; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
ve.ui.MWInternalLinkAnnotationWidget.prototype.getTextInputWidget = function () { |
| 87 |
return this.input.query; |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
ve.ui.MWInternalLinkAnnotationWidget.prototype.onTextChange = function ( value ) { |
| 99 |
const htmlDoc = this.getElementDocument(), |
| 100 |
namespacesWithSubpages = mw.config.get( 'wgVisualEditorConfig' ).namespacesWithSubpages, |
| 101 |
basePageObj = mw.Title.newFromText( mw.config.get( 'wgRelevantPageName' ) ); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
if ( ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( value ) ) { |
| 107 |
const targetData = mw.libs.ve.getTargetDataFromHref( |
| 108 |
value, |
| 109 |
htmlDoc |
| 110 |
); |
| 111 |
if ( targetData.isInternal ) { |
| 112 |
value = targetData.title; |
| 113 |
this.input.query.setValue( targetData.title ); |
| 114 |
} |
| 115 |
} else if ( namespacesWithSubpages.indexOf( basePageObj.namespace ) !== -1 && value[ 0 ] === '/' ) { |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
value = basePageObj.getPrefixedText() + value; |
| 121 |
this.input.query.setValue( value ); |
| 122 |
} |
| 123 |
return ve.ui.MWInternalLinkAnnotationWidget.super.prototype.onTextChange.call( this, value ); |
| 124 |
}; |