| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.MWLinkAction = function VeUiMWLinkAction( surface ) { |
| 18 |
|
| 19 |
ve.ui.MWLinkAction.super.call( this, surface ); |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
OO.inheritClass( ve.ui.MWLinkAction, ve.ui.LinkAction ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
ve.ui.MWLinkAction.static.methods = [ |
| 29 |
...ve.ui.MWLinkAction.super.static.methods, |
| 30 |
'open', 'autolinkMagicLink' |
| 31 |
]; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
ve.ui.MWLinkAction.static.getLinkAnnotation = function ( linktext, doc ) { |
| 46 |
const href = linktext; |
| 47 |
|
| 48 |
|
| 49 |
if ( ve.dm.MWMagicLinkNode.static.validateContent( linktext ) ) { |
| 50 |
return ve.dm.MWMagicLinkNode.static.annotationFromContent( linktext ); |
| 51 |
} |
| 52 |
|
| 53 |
const targetData = mw.libs.ve.getTargetDataFromHref( href, doc ); |
| 54 |
if ( targetData.isInternal ) { |
| 55 |
const title = mw.Title.newFromText( targetData.title ); |
| 56 |
return ve.dm.MWInternalLinkAnnotation.static.newFromTitle( title ); |
| 57 |
} |
| 58 |
|
| 59 |
return new ve.dm.MWExternalLinkAnnotation( { |
| 60 |
type: 'link/mwExternal', |
| 61 |
attributes: { href: href } |
| 62 |
} ); |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
ve.ui.MWLinkAction.prototype.getTrailingPunctuation = function ( candidate ) { |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
»“‘‹«」』 |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
return /\(/.test( candidate ) ? |
| 86 |
/[,;.:!?\[\]<>"'”’›»“‘‹«」』]+$/ : |
| 87 |
/[,;.:!?\[\]<>"'”’›»“‘‹«」』)]+$/; |
| 88 |
|
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ve.ui.MWLinkAction.prototype.getLinkAnnotation = function ( linktext ) { |
| 96 |
return this.constructor.static.getLinkAnnotation( linktext, this.surface.getModel().getDocument().getHtmlDocument() ); |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.ui.MWLinkAction.prototype.autolinkMagicLink = function () { |
| 109 |
return this.autolink( ( linktext ) => ve.dm.MWMagicLinkNode.static.validateContent( linktext ), ( doc, range, linktext ) => { |
| 110 |
const annotations = doc.data.getAnnotationsFromRange( range ), |
| 111 |
data = new ve.dm.ElementLinearData( annotations.store, [ |
| 112 |
{ |
| 113 |
type: 'link/mwMagic', |
| 114 |
attributes: { |
| 115 |
content: linktext |
| 116 |
} |
| 117 |
}, |
| 118 |
{ |
| 119 |
type: '/link/mwMagic' |
| 120 |
} |
| 121 |
] ); |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
data.setAnnotationsAtOffset( 0, annotations ); |
| 126 |
return ve.dm.TransactionBuilder.static.newFromReplacement( |
| 127 |
doc, range, data.getData() |
| 128 |
); |
| 129 |
} ); |
| 130 |
}; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
ve.ui.MWLinkAction.prototype.open = function () { |
| 138 |
const fragment = this.surface.getModel().getFragment(), |
| 139 |
selectedNode = fragment.getSelectedNode(); |
| 140 |
|
| 141 |
let windowName = 'link'; |
| 142 |
if ( selectedNode instanceof ve.dm.MWNumberedExternalLinkNode ) { |
| 143 |
windowName = 'linkNode'; |
| 144 |
} else if ( selectedNode instanceof ve.dm.MWMagicLinkNode ) { |
| 145 |
windowName = 'linkMagicNode'; |
| 146 |
} |
| 147 |
this.surface.executeWithSource( 'window', 'open', this.source, windowName ); |
| 148 |
return true; |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
ve.ui.actionFactory.register( ve.ui.MWLinkAction ); |
| 154 |
|
| 155 |
ve.ui.commandRegistry.register( |
| 156 |
new ve.ui.Command( |
| 157 |
'autolinkMagicLink', ve.ui.MWLinkAction.static.name, 'autolinkMagicLink', |
| 158 |
{ supportedSelections: [ 'linear' ] } |
| 159 |
) |
| 160 |
); |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
ve.ui.sequenceRegistry.register( |
| 165 |
new ve.ui.Sequence( |
| 166 |
'autolinkMagicLinkIsbn10', 'autolinkMagicLink', /\bISBN\s+(?!97[89])([0-9][ -]?){9}[0-9Xx]$/, 0, |
| 167 |
{ |
| 168 |
setSelection: true, |
| 169 |
delayed: false, |
| 170 |
checkOnPaste: true |
| 171 |
} |
| 172 |
) |
| 173 |
); |
| 174 |
ve.ui.sequenceRegistry.register( |
| 175 |
new ve.ui.Sequence( |
| 176 |
'autolinkMagicLinkIsbn13', 'autolinkMagicLink', /\bISBN\s+(97[89])[ -]?([0-9][ -]?){9}[0-9Xx]$/, 0, |
| 177 |
{ |
| 178 |
setSelection: true, |
| 179 |
delayed: false, |
| 180 |
checkOnPaste: true |
| 181 |
} |
| 182 |
) |
| 183 |
); |
| 184 |
ve.ui.sequenceRegistry.register( |
| 185 |
new ve.ui.Sequence( |
| 186 |
'autolinkMagicLinkIsbn', 'autolinkMagicLink', /\bISBN\s+(97[89][ -]?)?([0-9][ -]?){9}[0-9Xx]$/, 0, |
| 187 |
{ |
| 188 |
setSelection: true, |
| 189 |
delayed: true, |
| 190 |
checkOnPaste: true |
| 191 |
} |
| 192 |
) |
| 193 |
); |
| 194 |
ve.ui.sequenceRegistry.register( |
| 195 |
new ve.ui.Sequence( |
| 196 |
'autolinkMagicLinkRfcPmid', 'autolinkMagicLink', /\b(RFC|PMID)\s+[0-9]+$/, 0, |
| 197 |
{ |
| 198 |
setSelection: true, |
| 199 |
delayed: true, |
| 200 |
checkOnPaste: true |
| 201 |
} |
| 202 |
) |
| 203 |
); |