| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
ve.ui.MWSaveDialog = function VeUiMwSaveDialog( config ) { |
| 21 |
|
| 22 |
ve.ui.MWSaveDialog.super.call( this, config ); |
| 23 |
|
| 24 |
|
| 25 |
this.editSummaryCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' ); |
| 26 |
this.restoring = false; |
| 27 |
this.messages = {}; |
| 28 |
this.setupDeferred = ve.createDeferred(); |
| 29 |
this.checkboxesByName = null; |
| 30 |
this.changedEditSummary = false; |
| 31 |
this.canReview = false; |
| 32 |
this.canPreview = false; |
| 33 |
this.hasDiff = false; |
| 34 |
this.diffElement = null; |
| 35 |
this.diffElementPromise = null; |
| 36 |
this.getDiffElementPromise = null; |
| 37 |
|
| 38 |
|
| 39 |
this.$element.addClass( 've-ui-mwSaveDialog' ); |
| 40 |
}; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
OO.inheritClass( ve.ui.MWSaveDialog, OO.ui.ProcessDialog ); |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
ve.ui.MWSaveDialog.static.name = 'mwSave'; |
| 49 |
|
| 50 |
ve.ui.MWSaveDialog.static.title = |
| 51 |
OO.ui.deferMsg( 'visualeditor-savedialog-title-save' ); |
| 52 |
|
| 53 |
ve.ui.MWSaveDialog.static.actions = [ |
| 54 |
{ |
| 55 |
action: 'save', |
| 56 |
|
| 57 |
flags: [ 'primary', 'progressive' ], |
| 58 |
modes: [ 'save', 'review', 'preview' ] |
| 59 |
}, |
| 60 |
{ |
| 61 |
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-resume-editing' ), |
| 62 |
flags: [ 'safe', OO.ui.isMobile() ? 'back' : 'close' ], |
| 63 |
modes: [ 'save', 'conflict' ] |
| 64 |
}, |
| 65 |
{ |
| 66 |
action: 'review', |
| 67 |
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review' ), |
| 68 |
modes: [ 'save', 'preview' ] |
| 69 |
}, |
| 70 |
{ |
| 71 |
action: 'preview', |
| 72 |
label: OO.ui.deferMsg( 'showpreview' ), |
| 73 |
modes: [ 'save', 'review' ] |
| 74 |
}, |
| 75 |
{ |
| 76 |
action: 'approve', |
| 77 |
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review-good' ), |
| 78 |
flags: [ 'safe', 'back' ], |
| 79 |
modes: [ 'review', 'preview' ] |
| 80 |
}, |
| 81 |
{ |
| 82 |
action: 'resolve', |
| 83 |
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-resolve-conflict' ), |
| 84 |
flags: [ 'primary', 'progressive' ], |
| 85 |
modes: 'conflict' |
| 86 |
} |
| 87 |
]; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ve.ui.MWSaveDialog.prototype.setDiffAndReview = function ( wikitextDiffPromise, visualDiffGeneratorPromise, baseDoc ) { |
| 133 |
this.clearDiff(); |
| 134 |
|
| 135 |
function createDiffElement( visualDiff ) { |
| 136 |
const diffElement = new ve.ui.DiffElement( visualDiff ); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
diffElement.$document.addClass( [ |
| 141 |
'mw-body-content', |
| 142 |
'mw-parser-output', |
| 143 |
'mw-content-' + visualDiff.newDoc.getDir() |
| 144 |
] ); |
| 145 |
ve.targetLinksToNewWindow( diffElement.$document[ 0 ] ); |
| 146 |
|
| 147 |
ve.init.platform.linkCache.styleParsoidElements( diffElement.$document, baseDoc ); |
| 148 |
mw.libs.ve.fixFragmentLinks( diffElement.$document[ 0 ], mw.Title.newFromText( ve.init.target.getPageName() ), 'mw-save-visualdiff-' ); |
| 149 |
return diffElement; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
this.$reviewVisualDiff.append( new OO.ui.ProgressBarWidget().$element ); |
| 154 |
|
| 155 |
this.getDiffElementPromise = function () { |
| 156 |
return visualDiffGeneratorPromise.then( ( visualDiffGenerator ) => createDiffElement( visualDiffGenerator() ) ); |
| 157 |
}; |
| 158 |
|
| 159 |
this.baseDoc = baseDoc; |
| 160 |
|
| 161 |
|
| 162 |
this.$reviewWikitextDiff.append( new OO.ui.ProgressBarWidget().$element ); |
| 163 |
wikitextDiffPromise.then( ( wikitextDiff ) => { |
| 164 |
if ( wikitextDiff ) { |
| 165 |
|
| 166 |
|
| 167 |
this.$reviewWikitextDiff.empty().append( wikitextDiff ); |
| 168 |
|
| 169 |
|
| 170 |
this.$reviewWikitextDiff.find( '.ve-init-mw-diffPage-diffMode' ).empty(); |
| 171 |
} else { |
| 172 |
this.$reviewWikitextDiff.empty().append( |
| 173 |
$( '<div>' ).addClass( 've-ui-mwSaveDialog-no-changes' ).text( ve.msg( 'visualeditor-diff-no-changes' ) ) |
| 174 |
); |
| 175 |
} |
| 176 |
}, ( code, errorObject ) => { |
| 177 |
const $errorMessage = ve.init.target.extractErrorMessages( errorObject ); |
| 178 |
|
| 179 |
this.$reviewWikitextDiff.empty().append( |
| 180 |
new OO.ui.MessageWidget( { |
| 181 |
type: 'error', |
| 182 |
label: $errorMessage |
| 183 |
} ).$element |
| 184 |
); |
| 185 |
} ).always( () => { |
| 186 |
this.updateSize(); |
| 187 |
} ); |
| 188 |
|
| 189 |
this.hasDiff = true; |
| 190 |
this.popPending(); |
| 191 |
this.swapPanel( 'review' ); |
| 192 |
}; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
ve.ui.MWSaveDialog.prototype.showPreview = function ( response ) { |
| 200 |
if ( response instanceof $ ) { |
| 201 |
this.$previewViewer.empty().append( |
| 202 |
|
| 203 |
$( '<em>' ).append( response ) |
| 204 |
); |
| 205 |
} else { |
| 206 |
const data = response.parse, |
| 207 |
config = mw.config.get( 'wgVisualEditor' ); |
| 208 |
|
| 209 |
mw.config.set( data.jsconfigvars ); |
| 210 |
mw.loader.using( ( data.modules || [] ).concat( data.modulestyles || [] ) ); |
| 211 |
|
| 212 |
|
| 213 |
this.$previewHeading.html( data.displaytitle ); |
| 214 |
|
| 215 |
this.$previewViewer.empty().append( |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
$( '<div>' ) |
| 221 |
.addClass( 'mw-content-' + config.pageLanguageDir ) |
| 222 |
.attr( { |
| 223 |
lang: config.pageLanguageCode, |
| 224 |
dir: config.pageLanguageDir |
| 225 |
} ) |
| 226 |
.html( data.text ), |
| 227 |
data.categorieshtml |
| 228 |
); |
| 229 |
|
| 230 |
ve.targetLinksToNewWindow( this.$previewViewer[ 0 ] ); |
| 231 |
mw.libs.ve.fixFragmentLinks( this.$previewViewer[ 0 ], mw.Title.newFromText( ve.init.target.getPageName() ), 'mw-save-preview-' ); |
| 232 |
|
| 233 |
|
| 234 |
mw.hook( 'wikipage.content' ).fire( this.$previewViewer ); |
| 235 |
} |
| 236 |
|
| 237 |
this.popPending(); |
| 238 |
this.swapPanel( 'preview' ); |
| 239 |
}; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
ve.ui.MWSaveDialog.prototype.pushPending = function () { |
| 245 |
this.getActions().setAbilities( { review: false, preview: false } ); |
| 246 |
return ve.ui.MWSaveDialog.super.prototype.pushPending.call( this ); |
| 247 |
}; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
ve.ui.MWSaveDialog.prototype.popPending = function () { |
| 253 |
const ret = ve.ui.MWSaveDialog.super.prototype.popPending.call( this ); |
| 254 |
if ( !this.isPending() ) { |
| 255 |
this.getActions().setAbilities( { review: true, preview: true } ); |
| 256 |
} |
| 257 |
return ret; |
| 258 |
}; |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
ve.ui.MWSaveDialog.prototype.clearDiff = function () { |
| 264 |
this.$reviewWikitextDiff.empty(); |
| 265 |
this.$reviewVisualDiff.empty(); |
| 266 |
this.$previewViewer.empty(); |
| 267 |
this.hasDiff = false; |
| 268 |
this.diffElement = null; |
| 269 |
this.diffElementPromise = null; |
| 270 |
this.getDiffElementPromise = null; |
| 271 |
}; |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
ve.ui.MWSaveDialog.prototype.swapPanel = function ( panel, noFocus ) { |
| 281 |
if ( ( [ 'save', 'review', 'preview', 'conflict' ].indexOf( panel ) ) === -1 ) { |
| 282 |
throw new Error( 'Unknown saveDialog panel: ' + panel ); |
| 283 |
} |
| 284 |
|
| 285 |
const mode = panel, |
| 286 |
panelObj = this[ panel + 'Panel' ]; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
this.title.setLabel( ve.msg( 'visualeditor-savedialog-title-' + panel ) ); |
| 295 |
|
| 296 |
|
| 297 |
this.actions.setAbilities( { save: true } ); |
| 298 |
|
| 299 |
if ( !noFocus ) { |
| 300 |
|
| 301 |
|
| 302 |
this.$content[ 0 ].focus(); |
| 303 |
} |
| 304 |
|
| 305 |
let size = 'medium'; |
| 306 |
switch ( panel ) { |
| 307 |
case 'save': |
| 308 |
if ( !noFocus && this.panels.getCurrentItem() !== this.savePanel ) { |
| 309 |
|
| 310 |
setTimeout( () => { |
| 311 |
this.editSummaryInput.moveCursorToEnd(); |
| 312 |
} ); |
| 313 |
} |
| 314 |
break; |
| 315 |
case 'conflict': |
| 316 |
this.actions.setAbilities( { save: false } ); |
| 317 |
break; |
| 318 |
case 'preview': |
| 319 |
size = 'full'; |
| 320 |
this.previewPanel.$element[ 0 ].focus(); |
| 321 |
this.previewPanel.$element.prepend( this.$previewEditSummaryContainer ); |
| 322 |
break; |
| 323 |
case 'review': |
| 324 |
size = 'larger'; |
| 325 |
this.reviewModeButtonSelect.$element.after( this.$previewEditSummaryContainer ); |
| 326 |
setTimeout( () => { |
| 327 |
this.updateReviewMode(); |
| 328 |
|
| 329 |
ve.track( |
| 330 |
'activity.' + this.constructor.static.name, |
| 331 |
{ action: 'review-initial-' + this.reviewModeButtonSelect.findSelectedItem().getData() } |
| 332 |
); |
| 333 |
} ); |
| 334 |
break; |
| 335 |
} |
| 336 |
if ( panel === 'preview' || panel === 'review' ) { |
| 337 |
const currentEditSummaryWikitext = this.editSummaryInput.getValue(); |
| 338 |
if ( this.lastEditSummaryWikitext === undefined || this.lastEditSummaryWikitext !== currentEditSummaryWikitext ) { |
| 339 |
if ( this.editSummaryXhr ) { |
| 340 |
this.editSummaryXhr.abort(); |
| 341 |
} |
| 342 |
this.lastEditSummaryWikitext = currentEditSummaryWikitext; |
| 343 |
this.$previewEditSummary.empty(); |
| 344 |
|
| 345 |
if ( !currentEditSummaryWikitext || currentEditSummaryWikitext.trim() === '' ) { |
| 346 |
|
| 347 |
this.$previewEditSummary.text( ve.msg( 'visualeditor-savedialog-review-nosummary' ) ); |
| 348 |
} else { |
| 349 |
this.$previewEditSummary.parent().removeClass( 'oo-ui-element-hidden' ); |
| 350 |
const $spinner = $.createSpinner(); |
| 351 |
this.$previewEditSummary.append( $spinner ); |
| 352 |
this.editSummaryXhr = ve.init.target.getContentApi().post( { |
| 353 |
action: 'parse', |
| 354 |
title: ve.init.target.getPageName(), |
| 355 |
prop: '', |
| 356 |
summary: currentEditSummaryWikitext |
| 357 |
} ).done( ( result ) => { |
| 358 |
if ( result.parse.parsedsummary === '' ) { |
| 359 |
this.$previewEditSummary.parent().addClass( 'oo-ui-element-hidden' ); |
| 360 |
this.$previewEditSummary.empty(); |
| 361 |
} else { |
| 362 |
|
| 363 |
const wrappedSummary = ve.escapeHtml( ve.msg( 'parentheses' ) ) |
| 364 |
.replace( '$1', () => result.parse.parsedsummary ); |
| 365 |
|
| 366 |
|
| 367 |
this.$previewEditSummary.html( wrappedSummary ); |
| 368 |
ve.targetLinksToNewWindow( this.$previewEditSummary[ 0 ] ); |
| 369 |
} |
| 370 |
} ).fail( () => { |
| 371 |
this.$previewEditSummary.parent().addClass( 'oo-ui-element-hidden' ); |
| 372 |
this.$previewEditSummary.empty(); |
| 373 |
} ).always( () => { |
| 374 |
this.updateSize(); |
| 375 |
} ); |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
this.panels.setItem( panelObj ); |
| 382 |
this.setSize( size ); |
| 383 |
|
| 384 |
|
| 385 |
this.actions.setMode( mode ); |
| 386 |
|
| 387 |
|
| 388 |
this.actions.forEach( { actions: 'preview' }, ( action ) => { |
| 389 |
action.toggle( this.canPreview && panel !== 'preview' ); |
| 390 |
} ); |
| 391 |
|
| 392 |
|
| 393 |
this.actions.forEach( { actions: 'review' }, ( action ) => { |
| 394 |
action.toggle( this.canReview && panel !== 'review' ); |
| 395 |
} ); |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
OO.ui.Element.static.reconsiderScrollbars( panelObj.$element[ 0 ] ); |
| 401 |
|
| 402 |
mw.hook( 've.saveDialog.stateChanged' ).fire(); |
| 403 |
}; |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
ve.ui.MWSaveDialog.prototype.showMessage = function ( name, label, config ) { |
| 414 |
if ( !this.messages[ name ] ) { |
| 415 |
const messageWidget = new OO.ui.MessageWidget( ve.extendObject( { |
| 416 |
classes: [ 've-ui-mwSaveDialog-message' ], |
| 417 |
label: label, |
| 418 |
inline: true, |
| 419 |
type: 'warning' |
| 420 |
}, config ) ); |
| 421 |
this.$saveMessages.append( messageWidget.$element.css( 'display', 'none' ) ); |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
const promise = messageWidget.$element.slideDown( { |
| 426 |
duration: 250, |
| 427 |
progress: this.updateSize.bind( this ) |
| 428 |
} ).promise(); |
| 429 |
|
| 430 |
this.swapPanel( 'save' ); |
| 431 |
|
| 432 |
|
| 433 |
this.messages[ name ] = messageWidget.$element; |
| 434 |
|
| 435 |
return promise; |
| 436 |
} |
| 437 |
return ve.createDeferred().reject().promise(); |
| 438 |
}; |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
ve.ui.MWSaveDialog.prototype.clearMessage = function ( name ) { |
| 446 |
const $message = this.messages[ name ]; |
| 447 |
if ( $message ) { |
| 448 |
|
| 449 |
|
| 450 |
$message.slideUp( { |
| 451 |
duration: 250, |
| 452 |
progress: this.updateSize.bind( this ) |
| 453 |
} ).promise().then( () => { |
| 454 |
$message.remove(); |
| 455 |
this.updateSize(); |
| 456 |
} ); |
| 457 |
delete this.messages[ name ]; |
| 458 |
} |
| 459 |
}; |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
ve.ui.MWSaveDialog.prototype.clearAllMessages = function () { |
| 465 |
this.$saveMessages.empty(); |
| 466 |
this.messages = {}; |
| 467 |
}; |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
ve.ui.MWSaveDialog.prototype.reset = function () { |
| 473 |
|
| 474 |
this.editSummaryInput.setValue( '' ); |
| 475 |
|
| 476 |
if ( this.checkboxesByName.wpMinoredit ) { |
| 477 |
this.checkboxesByName.wpMinoredit.setSelected( false ); |
| 478 |
} |
| 479 |
this.clearDiff(); |
| 480 |
}; |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
ve.ui.MWSaveDialog.prototype.setupCheckboxes = function ( checkboxFields ) { |
| 490 |
this.setupDeferred.done( () => { |
| 491 |
checkboxFields.forEach( ( field ) => { |
| 492 |
this.$saveCheckboxes.append( field.$element ); |
| 493 |
} ); |
| 494 |
this.updateOptionsBar(); |
| 495 |
} ); |
| 496 |
}; |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
ve.ui.MWSaveDialog.prototype.setEditSummary = function ( summary ) { |
| 506 |
this.setupDeferred.done( () => { |
| 507 |
this.editSummaryInput.setValue( summary ); |
| 508 |
} ); |
| 509 |
}; |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
ve.ui.MWSaveDialog.prototype.initialize = function () { |
| 515 |
const mwString = require( 'mediawiki.String' ); |
| 516 |
|
| 517 |
|
| 518 |
ve.ui.MWSaveDialog.super.prototype.initialize.call( this ); |
| 519 |
|
| 520 |
|
| 521 |
this.panels = new OO.ui.StackLayout( { scrollable: false } ); |
| 522 |
this.savePanel = new OO.ui.PanelLayout( { |
| 523 |
expanded: false, |
| 524 |
padded: true, |
| 525 |
classes: [ 've-ui-mwSaveDialog-savePanel' ] |
| 526 |
} ); |
| 527 |
|
| 528 |
|
| 529 |
this.editSummaryCountLabel = new OO.ui.LabelWidget( { |
| 530 |
classes: [ 've-ui-mwSaveDialog-editSummary-count' ], |
| 531 |
label: '', |
| 532 |
title: ve.msg( 'visualeditor-editsummary-characters-remaining' ) |
| 533 |
} ); |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
this.$editSummaryLabel = $( '<div>' ).addClass( 've-ui-mwSaveDialog-summaryLabel' ) |
| 538 |
.html( ve.init.platform.getParsedMessage( 'summary' ) ); |
| 539 |
ve.targetLinksToNewWindow( this.$editSummaryLabel[ 0 ] ); |
| 540 |
this.editSummaryInput = new ve.ui.MWEditSummaryWidget( { |
| 541 |
$overlay: this.$overlay, |
| 542 |
placeholder: ve.msg( 'visualeditor-editsummary' ), |
| 543 |
classes: [ 've-ui-mwSaveDialog-summary' ] |
| 544 |
} ); |
| 545 |
|
| 546 |
this.editSummaryInput.on( 'enter', () => { |
| 547 |
this.showMessage( |
| 548 |
'keyboard-shortcut-submit', |
| 549 |
ve.msg( |
| 550 |
'visualeditor-savedialog-keyboard-shortcut-submit', |
| 551 |
new ve.ui.Trigger( ve.ui.commandHelpRegistry.lookup( 'dialogConfirm' ).shortcuts[ 0 ] ).getMessage() |
| 552 |
) |
| 553 |
).then( () => { |
| 554 |
|
| 555 |
this.editSummaryInput.focus(); |
| 556 |
} ); |
| 557 |
} ); |
| 558 |
|
| 559 |
this.editSummaryInput.$input.codePointLimit( this.editSummaryCodePointLimit ); |
| 560 |
this.editSummaryInput.on( 'change', () => { |
| 561 |
const remaining = this.editSummaryCodePointLimit - mwString.codePointLength( this.editSummaryInput.getValue() ); |
| 562 |
|
| 563 |
this.changedEditSummary = true; |
| 564 |
if ( remaining > 99 ) { |
| 565 |
this.editSummaryCountLabel.setLabel( '' ); |
| 566 |
} else { |
| 567 |
this.editSummaryCountLabel.setLabel( mw.language.convertNumber( remaining ) ); |
| 568 |
} |
| 569 |
|
| 570 |
this.updateOptionsBar(); |
| 571 |
} ); |
| 572 |
this.editSummaryInput.on( 'resize', () => { |
| 573 |
if ( this.overflowTimeout !== undefined ) { |
| 574 |
clearTimeout( this.overflowTimeout ); |
| 575 |
} |
| 576 |
this.panels.$element.css( 'overflow', 'hidden' ); |
| 577 |
this.updateSize(); |
| 578 |
this.overflowTimeout = setTimeout( () => { |
| 579 |
this.panels.$element.css( 'overflow', '' ); |
| 580 |
}, 250 ); |
| 581 |
} ); |
| 582 |
|
| 583 |
this.$saveCheckboxes = $( '<div>' ).addClass( 've-ui-mwSaveDialog-checkboxes' ); |
| 584 |
this.$saveOptions = $( '<div>' ).addClass( 've-ui-mwSaveDialog-options' ).append( |
| 585 |
this.$saveCheckboxes, |
| 586 |
this.editSummaryCountLabel.$element |
| 587 |
); |
| 588 |
this.$license = $( '<p>' ).addClass( 've-ui-mwSaveDialog-license' ); |
| 589 |
this.$saveMessages = $( '<div>' ).addClass( 've-ui-mwSaveDialog-messages' ); |
| 590 |
this.$saveFoot = $( '<div>' ).addClass( 've-ui-mwSaveDialog-foot' ).append( this.$license ); |
| 591 |
ve.targetLinksToNewWindow( this.$saveFoot[ 0 ] ); |
| 592 |
this.savePanel.$element.append( |
| 593 |
this.$editSummaryLabel, |
| 594 |
this.editSummaryInput.$element, |
| 595 |
this.$saveOptions, |
| 596 |
this.$saveMessages, |
| 597 |
this.$saveFoot |
| 598 |
); |
| 599 |
|
| 600 |
this.updateOptionsBar(); |
| 601 |
|
| 602 |
|
| 603 |
this.reviewPanel = new OO.ui.PanelLayout( { |
| 604 |
expanded: false, |
| 605 |
padded: true |
| 606 |
} ); |
| 607 |
|
| 608 |
this.$reviewVisualDiff = $( '<div>' ).addClass( 've-ui-mwSaveDialog-viewer' ); |
| 609 |
this.$reviewWikitextDiff = $( '<div>' ).addClass( 've-ui-mwSaveDialog-viewer' ); |
| 610 |
|
| 611 |
this.reviewModeButtonSelect = new OO.ui.ButtonSelectWidget( { |
| 612 |
items: [ |
| 613 |
new OO.ui.ButtonOptionWidget( { data: 'visual', icon: 'eye', label: ve.msg( 'visualeditor-savedialog-review-visual' ) } ), |
| 614 |
new OO.ui.ButtonOptionWidget( { data: 'source', icon: 'wikiText', label: ve.msg( 'visualeditor-savedialog-review-wikitext' ) } ) |
| 615 |
], |
| 616 |
classes: [ 've-ui-mwSaveDialog-reviewMode' ] |
| 617 |
} ); |
| 618 |
this.reviewModeButtonSelect.connect( this, { |
| 619 |
choose: 'onReviewChoose', |
| 620 |
select: 'updateReviewMode' |
| 621 |
} ); |
| 622 |
|
| 623 |
this.$previewEditSummary = $( '<span>' ).addClass( 've-ui-mwSaveDialog-summaryPreview' ).addClass( 'comment' ); |
| 624 |
this.$previewEditSummaryContainer = $( '<div>' ) |
| 625 |
.addClass( 'mw-summary-preview' ) |
| 626 |
.text( ve.msg( 'summary-preview' ) ) |
| 627 |
.append( $( '<br>' ), this.$previewEditSummary ); |
| 628 |
this.$reviewActions = $( '<div>' ).addClass( 've-ui-mwSaveDialog-actions' ); |
| 629 |
this.reviewPanel.$element.append( |
| 630 |
this.reviewModeButtonSelect.$element, |
| 631 |
this.$reviewVisualDiff, |
| 632 |
this.$reviewWikitextDiff, |
| 633 |
this.$reviewActions |
| 634 |
); |
| 635 |
|
| 636 |
|
| 637 |
this.previewPanel = new OO.ui.PanelLayout( { |
| 638 |
classes: [ 've-ui-mwSaveDialog-preview' ], |
| 639 |
expanded: false, |
| 640 |
padded: true |
| 641 |
} ); |
| 642 |
this.$previewHeading = $( '<h1>' ).addClass( 'firstHeading' ); |
| 643 |
this.$previewViewer = $( '<div>' ).addClass( [ |
| 644 |
'mw-body-content', |
| 645 |
'mw-parser-output' |
| 646 |
] ); |
| 647 |
this.previewPanel.$element |
| 648 |
|
| 649 |
.prop( 'tabIndex', 0 ) |
| 650 |
.append( |
| 651 |
$( '<div>' ).addClass( 'mw-content-container' ).append( |
| 652 |
$( '<div>' ).addClass( 'mw-body' ).append( |
| 653 |
this.$previewHeading, |
| 654 |
this.$previewViewer |
| 655 |
) |
| 656 |
) |
| 657 |
); |
| 658 |
|
| 659 |
|
| 660 |
this.conflictPanel = new OO.ui.PanelLayout( { |
| 661 |
expanded: false, |
| 662 |
padded: true |
| 663 |
} ); |
| 664 |
|
| 665 |
this.$conflict = $( '<div>' ).addClass( 've-ui-mwSaveDialog-conflict' ) |
| 666 |
.html( ve.init.platform.getParsedMessage( 'visualeditor-editconflict' ) ); |
| 667 |
ve.targetLinksToNewWindow( this.$conflict[ 0 ] ); |
| 668 |
this.conflictPanel.$element.append( this.$conflict ); |
| 669 |
|
| 670 |
|
| 671 |
this.panels.addItems( [ |
| 672 |
this.savePanel, |
| 673 |
this.reviewPanel, |
| 674 |
this.previewPanel, |
| 675 |
this.conflictPanel |
| 676 |
] ); |
| 677 |
|
| 678 |
|
| 679 |
this.$body.append( this.panels.$element ); |
| 680 |
|
| 681 |
this.setupDeferred.resolve(); |
| 682 |
}; |
| 683 |
|
| 684 |
ve.ui.MWSaveDialog.prototype.updateOptionsBar = function () { |
| 685 |
const showOptions = !!this.editSummaryCountLabel.getLabel() || !this.$saveCheckboxes.is( ':empty' ); |
| 686 |
if ( showOptions !== this.showOptions ) { |
| 687 |
this.savePanel.$element.toggleClass( 've-ui-mwSaveDialog-withOptions', showOptions ); |
| 688 |
this.showOptions = showOptions; |
| 689 |
this.updateSize(); |
| 690 |
} |
| 691 |
}; |
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
ve.ui.MWSaveDialog.prototype.updateReviewMode = function () { |
| 699 |
if ( !this.hasDiff ) { |
| 700 |
return; |
| 701 |
} |
| 702 |
|
| 703 |
const diffMode = this.reviewModeButtonSelect.findSelectedItem().getData(), |
| 704 |
surfaceMode = ve.init.target.getSurface().getMode(), |
| 705 |
isVisual = diffMode === 'visual'; |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
ve.userConfig( 'visualeditor-diffmode-' + surfaceMode, diffMode ); |
| 711 |
|
| 712 |
this.$reviewVisualDiff.toggleClass( 'oo-ui-element-hidden', !isVisual ); |
| 713 |
this.$reviewWikitextDiff.toggleClass( 'oo-ui-element-hidden', isVisual ); |
| 714 |
if ( isVisual ) { |
| 715 |
if ( !this.diffElement ) { |
| 716 |
if ( !this.diffElementPromise ) { |
| 717 |
this.diffElementPromise = this.getDiffElementPromise().then( ( diffElement ) => { |
| 718 |
this.diffElement = diffElement; |
| 719 |
this.$reviewVisualDiff.empty().append( diffElement.$element ); |
| 720 |
this.positionDiffElement(); |
| 721 |
} ); |
| 722 |
} |
| 723 |
return; |
| 724 |
} |
| 725 |
this.positionDiffElement(); |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
OO.ui.Element.static.reconsiderScrollbars( this.reviewPanel.$element[ 0 ] ); |
| 732 |
|
| 733 |
this.updateSize(); |
| 734 |
}; |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
ve.ui.MWSaveDialog.prototype.onReviewChoose = function ( item ) { |
| 742 |
ve.track( 'activity.' + this.constructor.static.name, { action: 'review-switch-' + item.getData() } ); |
| 743 |
}; |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
ve.ui.MWSaveDialog.prototype.setDimensions = function () { |
| 749 |
|
| 750 |
ve.ui.MWSaveDialog.super.prototype.setDimensions.apply( this, arguments ); |
| 751 |
|
| 752 |
if ( !this.positioning ) { |
| 753 |
this.positionDiffElement(); |
| 754 |
} |
| 755 |
}; |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
ve.ui.MWSaveDialog.prototype.positionDiffElement = function () { |
| 763 |
if ( this.panels.getCurrentItem() === this.reviewPanel ) { |
| 764 |
setTimeout( () => { |
| 765 |
this.withoutSizeTransitions( () => { |
| 766 |
|
| 767 |
if ( this.diffElement && this.isVisible() && this.reviewModeButtonSelect.findSelectedItem().getData() === 'visual' ) { |
| 768 |
this.diffElement.positionDescriptions(); |
| 769 |
this.positioning = true; |
| 770 |
this.updateSize(); |
| 771 |
this.positioning = false; |
| 772 |
} |
| 773 |
} ); |
| 774 |
}, OO.ui.theme.getDialogTransitionDuration() ); |
| 775 |
} |
| 776 |
}; |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) { |
| 792 |
return ve.ui.MWSaveDialog.super.prototype.getSetupProcess.call( this, data ) |
| 793 |
.next( () => { |
| 794 |
const surfaceMode = ve.init.target.getSurface().getMode(); |
| 795 |
|
| 796 |
this.canReview = !!data.canReview; |
| 797 |
this.canPreview = !!data.canPreview; |
| 798 |
|
| 799 |
this.$license.html( data.copyrightWarning ); |
| 800 |
this.setupCheckboxes( data.checkboxFields || [] ); |
| 801 |
this.checkboxesByName = data.checkboxesByName || {}; |
| 802 |
|
| 803 |
|
| 804 |
this.$saveCheckboxes.toggleClass( 've-ui-mwSaveDialog-checkboxes-withExpiry', !!this.checkboxesByName.wpWatchlistExpiry ); |
| 805 |
|
| 806 |
|
| 807 |
if ( this.checkboxesByName.wpWatchthis && this.checkboxesByName.wpWatchlistExpiry ) { |
| 808 |
|
| 809 |
this.checkboxesByName.wpWatchlistExpiry.setDisabled( !this.checkboxesByName.wpWatchthis.isSelected() ); |
| 810 |
|
| 811 |
this.checkboxesByName.wpWatchthis.on( 'change', ( enabled ) => { |
| 812 |
this.checkboxesByName.wpWatchlistExpiry.setDisabled( !enabled ); |
| 813 |
} ); |
| 814 |
} |
| 815 |
|
| 816 |
function trackCheckbox( n ) { |
| 817 |
ve.track( 'activity.mwSave', { action: 'checkbox-' + n } ); |
| 818 |
} |
| 819 |
for ( const name in this.checkboxesByName ) { |
| 820 |
this.checkboxesByName[ name ].$element.off( '.mwSave' ).on( 'click.mwSave', trackCheckbox.bind( this, name ) ); |
| 821 |
} |
| 822 |
|
| 823 |
if ( data.sectionTitle ) { |
| 824 |
this.setEditSummary( ve.msg( 'newsectionsummary', data.sectionTitle ) ); |
| 825 |
this.editSummaryInput.setDisabled( true ); |
| 826 |
} else { |
| 827 |
this.editSummaryInput.setDisabled( false ); |
| 828 |
if ( !this.changedEditSummary ) { |
| 829 |
this.setEditSummary( data.editSummary ); |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
this.reviewModeButtonSelect.selectItemByData( |
| 837 |
ve.userConfig( 'visualeditor-diffmode-' + surfaceMode ) || surfaceMode |
| 838 |
); |
| 839 |
|
| 840 |
|
| 841 |
this.clearAllMessages(); |
| 842 |
|
| 843 |
this.swapPanel( data.initialPanel || 'save', true ); |
| 844 |
|
| 845 |
this.actions.forEach( { actions: 'save' }, ( action ) => { |
| 846 |
action.setLabel( data.saveButtonLabel ); |
| 847 |
} ); |
| 848 |
} ); |
| 849 |
}; |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
ve.ui.MWSaveDialog.prototype.getReadyProcess = function ( data ) { |
| 855 |
return ve.ui.MWSaveDialog.super.prototype.getReadyProcess.call( this, data ) |
| 856 |
.next( () => { |
| 857 |
|
| 858 |
|
| 859 |
OO.ui.Element.static.reconsiderScrollbars( this.panels.getCurrentItem().$element[ 0 ] ); |
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
if ( this.panels.getCurrentItem() === this.savePanel ) { |
| 866 |
|
| 867 |
this.editSummaryInput.moveCursorToEnd(); |
| 868 |
} |
| 869 |
} ); |
| 870 |
}; |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
ve.ui.MWSaveDialog.prototype.getTeardownProcess = function ( data ) { |
| 876 |
return ve.ui.MWSaveDialog.super.prototype.getTeardownProcess.call( this, data ) |
| 877 |
.next( () => { |
| 878 |
this.emit( 'close' ); |
| 879 |
} ); |
| 880 |
}; |
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
ve.ui.MWSaveDialog.prototype.getActionProcess = function ( action ) { |
| 886 |
ve.track( 'activity.' + this.constructor.static.name, { action: 'dialog-' + ( action || 'abort' ) } ); |
| 887 |
|
| 888 |
if ( action === 'save' ) { |
| 889 |
return new OO.ui.Process( () => { |
| 890 |
const saveDeferred = ve.createDeferred(); |
| 891 |
this.clearMessage( 'keyboard-shortcut-submit' ); |
| 892 |
this.emit( 'save', saveDeferred ); |
| 893 |
return saveDeferred.promise(); |
| 894 |
} ); |
| 895 |
} |
| 896 |
if ( action === 'review' || action === 'preview' || action === 'resolve' ) { |
| 897 |
return new OO.ui.Process( () => { |
| 898 |
this.emit( action ); |
| 899 |
} ); |
| 900 |
} |
| 901 |
if ( action === 'approve' ) { |
| 902 |
return new OO.ui.Process( () => { |
| 903 |
this.swapPanel( 'save' ); |
| 904 |
} ); |
| 905 |
} |
| 906 |
|
| 907 |
return ve.ui.MWSaveDialog.super.prototype.getActionProcess.call( this, action ); |
| 908 |
}; |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
ve.ui.MWSaveDialog.prototype.getBodyHeight = function () { |
| 914 |
|
| 915 |
return this.panels.getCurrentItem().$element.outerHeight( true ); |
| 916 |
}; |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
ve.ui.MWSaveDialog.prototype.onRetryButtonClick = function () { |
| 924 |
this.emit( 'retry' ); |
| 925 |
ve.ui.MWSaveDialog.super.prototype.onRetryButtonClick.apply( this, arguments ); |
| 926 |
}; |
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
ve.ui.windowFactory.register( ve.ui.MWSaveDialog ); |