| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.MWExportWikitextDialog = function VeUiMwExportWikitextDialog( config ) { |
| 18 |
|
| 19 |
ve.ui.MWExportWikitextDialog.super.call( this, config ); |
| 20 |
|
| 21 |
|
| 22 |
this.$element.addClass( 've-ui-mwExportWikitextDialog' ); |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
OO.inheritClass( ve.ui.MWExportWikitextDialog, OO.ui.ProcessDialog ); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
ve.ui.MWExportWikitextDialog.static.name = 'mwExportWikitext'; |
| 32 |
|
| 33 |
ve.ui.MWExportWikitextDialog.static.title = ve.msg( 'visualeditor-rebase-client-export' ); |
| 34 |
|
| 35 |
ve.ui.MWExportWikitextDialog.static.actions = [ |
| 36 |
{ |
| 37 |
label: OO.ui.deferMsg( 'visualeditor-dialog-action-done' ), |
| 38 |
flags: [ 'safe', 'close' ] |
| 39 |
} |
| 40 |
]; |
| 41 |
|
| 42 |
ve.ui.MWExportWikitextDialog.static.size = 'larger'; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
ve.ui.MWExportWikitextDialog.prototype.initialize = function () { |
| 48 |
|
| 49 |
ve.ui.MWExportWikitextDialog.super.prototype.initialize.call( this ); |
| 50 |
|
| 51 |
this.titleInput = new mw.widgets.TitleInputWidget( { |
| 52 |
value: ve.init.target.getImportTitle() |
| 53 |
}, { api: ve.init.target.getContentApi() } ); |
| 54 |
this.titleButton = new OO.ui.ButtonWidget( { |
| 55 |
label: ve.msg( 'visualeditor-rebase-client-export-start' ), |
| 56 |
flags: [ 'primary', 'progressive' ] |
| 57 |
} ); |
| 58 |
this.titleField = new OO.ui.ActionFieldLayout( this.titleInput, this.titleButton, { |
| 59 |
align: 'top', |
| 60 |
label: ve.msg( 'visualeditor-rebase-client-import-name' ), |
| 61 |
help: ve.msg( 'visualeditor-rebase-client-title-help' ), |
| 62 |
helpInline: true |
| 63 |
} ); |
| 64 |
|
| 65 |
this.titleButton.on( 'click', this.export.bind( this ) ); |
| 66 |
|
| 67 |
this.wikitextLayout = new mw.widgets.CopyTextLayout( { |
| 68 |
align: 'top', |
| 69 |
label: ve.msg( 'visualeditor-savedialog-review-wikitext' ), |
| 70 |
multiline: true, |
| 71 |
textInput: { |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
classes: [ 'mw-editfont-' + mw.user.options.get( 'editfont' ) ], |
| 77 |
autosize: true, |
| 78 |
readOnly: true, |
| 79 |
|
| 80 |
rows: 99 |
| 81 |
} |
| 82 |
} ); |
| 83 |
|
| 84 |
|
| 85 |
this.titleField.$element.css( 'max-width', 'none' ); |
| 86 |
this.titleInput.$element.css( 'max-width', 'none' ); |
| 87 |
this.wikitextLayout.$element.css( 'max-width', 'none' ); |
| 88 |
this.wikitextLayout.$field.css( 'max-width', 'none' ); |
| 89 |
this.wikitextLayout.textInput.$element.css( 'max-width', 'none' ); |
| 90 |
|
| 91 |
const $content = $( '<div>' ); |
| 92 |
$content.append( |
| 93 |
this.titleField.$element, |
| 94 |
this.wikitextLayout.$element |
| 95 |
); |
| 96 |
|
| 97 |
const panel = new OO.ui.PanelLayout( { |
| 98 |
padded: true, |
| 99 |
expanded: false, |
| 100 |
$content: $content |
| 101 |
} ); |
| 102 |
this.$body.append( panel.$element ); |
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.ui.MWExportWikitextDialog.prototype.getSetupProcess = function ( data ) { |
| 109 |
return ve.ui.MWExportWikitextDialog.super.prototype.getSetupProcess.call( this, data ) |
| 110 |
.next( () => { |
| 111 |
const surface = ve.init.target.getSurface(), |
| 112 |
wikitextInput = this.wikitextLayout.textInput; |
| 113 |
this.titleButton.setDisabled( true ); |
| 114 |
this.wikitextLayout.textInput.pushPending(); |
| 115 |
ve.init.target.getWikitextFragment( surface.getModel().getDocument() ).then( ( wikitext ) => { |
| 116 |
wikitextInput.setValue( wikitext.trim() ); |
| 117 |
wikitextInput.$input.scrollTop( 0 ); |
| 118 |
wikitextInput.popPending(); |
| 119 |
this.titleButton.setDisabled( false ); |
| 120 |
this.updateSize(); |
| 121 |
}, () => { |
| 122 |
|
| 123 |
wikitextInput.popPending(); |
| 124 |
} ); |
| 125 |
} ); |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
ve.ui.MWExportWikitextDialog.prototype.getReadyProcess = function ( data ) { |
| 132 |
return ve.ui.MWExportWikitextDialog.super.prototype.getReadyProcess.call( this, data ) |
| 133 |
.next( () => { |
| 134 |
this.titleInput.focus(); |
| 135 |
|
| 136 |
|
| 137 |
this.wikitextLayout.textInput.$input.css( 'max-height', '' ); |
| 138 |
const overflow = this.$body[ 0 ].scrollHeight - this.$body[ 0 ].clientHeight; |
| 139 |
if ( overflow > 0 ) { |
| 140 |
|
| 141 |
this.wikitextLayout.textInput.$input.css( |
| 142 |
'max-height', |
| 143 |
Math.max( |
| 144 |
this.wikitextLayout.textInput.$input[ 0 ].clientHeight - overflow, |
| 145 |
50 |
| 146 |
) |
| 147 |
); |
| 148 |
} |
| 149 |
|
| 150 |
} ); |
| 151 |
}; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
ve.ui.MWExportWikitextDialog.prototype.getTeardownProcess = function ( data ) { |
| 157 |
return ve.ui.MWExportWikitextDialog.super.prototype.getTeardownProcess.call( this, data ) |
| 158 |
.next( () => { |
| 159 |
this.wikitextLayout.textInput.setValue( '' ); |
| 160 |
} ); |
| 161 |
}; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
ve.ui.MWExportWikitextDialog.prototype.export = function () { |
| 167 |
const wikitext = this.wikitextLayout.textInput.getValue(), |
| 168 |
title = this.titleInput.getMWTitle(), |
| 169 |
importTitle = ve.init.target.getImportTitle(); |
| 170 |
|
| 171 |
const $form = $( '<form>' ).attr( { method: 'post', enctype: 'multipart/form-data' } ).addClass( 'oo-ui-element-hidden' ); |
| 172 |
let params = { |
| 173 |
format: 'text/x-wiki', |
| 174 |
model: 'wikitext', |
| 175 |
wpTextbox1: wikitext, |
| 176 |
wpEditToken: mw.user.tokens.get( 'csrfToken' ), |
| 177 |
|
| 178 |
|
| 179 |
wpUnicodeCheck: 'β³π²β₯πππΎπΈβ΄πΉβ―', |
| 180 |
wpUltimateParam: true, |
| 181 |
wpDiff: true |
| 182 |
}; |
| 183 |
if ( |
| 184 |
importTitle && title && |
| 185 |
importTitle.toString() === title.toString() |
| 186 |
) { |
| 187 |
params = ve.extendObject( { |
| 188 |
oldid: ve.init.target.revid, |
| 189 |
basetimestamp: ve.init.target.baseTimeStamp, |
| 190 |
starttimestamp: ve.init.target.startTimeStamp |
| 191 |
}, params ); |
| 192 |
} |
| 193 |
|
| 194 |
for ( const key in params ) { |
| 195 |
$form.append( $( '<input>' ).attr( { type: 'hidden', name: key, value: params[ key ] } ) ); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
const submitUrl = title.getUrl( { |
| 200 |
action: 'submit', |
| 201 |
veswitched: '1' |
| 202 |
} ); |
| 203 |
$form.attr( 'action', submitUrl ).appendTo( 'body' ).trigger( 'submit' ); |
| 204 |
}; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
ve.ui.windowFactory.register( ve.ui.MWExportWikitextDialog ); |