| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
ve.init.mw.ArticleTarget = function VeInitMwArticleTarget( config ) { |
| 22 |
config = config || {}; |
| 23 |
config.toolbarConfig = ve.extendObject( { |
| 24 |
shadow: true, |
| 25 |
actions: true, |
| 26 |
floatable: true |
| 27 |
}, config.toolbarConfig ); |
| 28 |
|
| 29 |
|
| 30 |
ve.init.mw.ArticleTarget.super.call( this, config ); |
| 31 |
|
| 32 |
|
| 33 |
if ( config.register !== false ) { |
| 34 |
|
| 35 |
|
| 36 |
ve.init.articleTarget = this; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
this.saveDialog = null; |
| 41 |
this.saveDeferred = null; |
| 42 |
this.saveFields = {}; |
| 43 |
this.docToSave = null; |
| 44 |
this.originalDmDocPromise = null; |
| 45 |
this.originalHtml = null; |
| 46 |
this.toolbarSaveButton = null; |
| 47 |
this.pageExists = mw.config.get( 'wgRelevantArticleId', 0 ) !== 0; |
| 48 |
const enableVisualSectionEditing = mw.config.get( 'wgVisualEditorConfig' ).enableVisualSectionEditing; |
| 49 |
this.enableVisualSectionEditing = enableVisualSectionEditing === true || enableVisualSectionEditing === this.constructor.static.trackingName; |
| 50 |
this.toolbarScrollOffset = mw.config.get( 'wgVisualEditorToolbarScrollOffset', 0 ); |
| 51 |
this.currentUrl = new URL( location.href ); |
| 52 |
this.section = null; |
| 53 |
this.visibleSection = null; |
| 54 |
this.visibleSectionOffset = null; |
| 55 |
this.sectionTitle = null; |
| 56 |
this.editSummaryValue = null; |
| 57 |
this.initialEditSummary = null; |
| 58 |
this.initialCheckboxes = {}; |
| 59 |
|
| 60 |
this.viewUrl = new URL( mw.util.getUrl( this.getPageName() ), location.href ); |
| 61 |
this.isViewPage = ( |
| 62 |
mw.config.get( 'wgAction' ) === 'view' && |
| 63 |
!this.currentUrl.searchParams.has( 'diff' ) |
| 64 |
); |
| 65 |
|
| 66 |
this.copyrightWarning = null; |
| 67 |
this.checkboxFields = null; |
| 68 |
this.checkboxesByName = null; |
| 69 |
this.$saveAccessKeyElements = null; |
| 70 |
|
| 71 |
this.$editableContent = this.getEditableContent(); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
this.requestedRevId = mw.config.get( 'wgEditLatestRevision' ) ? mw.config.get( 'wgCurRevisionId' ) : mw.config.get( 'wgRevisionId' ) || undefined; |
| 77 |
this.currentRevisionId = mw.config.get( 'wgCurRevisionId' ) || undefined; |
| 78 |
this.revid = this.requestedRevId || this.currentRevisionId; |
| 79 |
|
| 80 |
this.edited = false; |
| 81 |
this.restoring = !!this.requestedRevId && this.requestedRevId !== this.currentRevisionId; |
| 82 |
this.pageDeletedWarning = false; |
| 83 |
this.events = { |
| 84 |
track: () => {}, |
| 85 |
trackActivationStart: () => {}, |
| 86 |
trackActivationComplete: () => {} |
| 87 |
}; |
| 88 |
|
| 89 |
this.preparedCacheKeyPromise = null; |
| 90 |
this.clearState(); |
| 91 |
|
| 92 |
|
| 93 |
this.$element.addClass( 've-init-mw-articleTarget' ); |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
OO.inheritClass( ve.init.mw.ArticleTarget, ve.init.mw.Target ); |
| 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 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
ve.init.mw.ArticleTarget.static.name = 'article'; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
ve.init.mw.ArticleTarget.static.trackingName = 'mwTarget'; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
ve.init.mw.ArticleTarget.static.integrationType = 'page'; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
ve.init.mw.ArticleTarget.static.platformType = 'other'; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
ve.init.mw.ArticleTarget.static.documentCommands = [ |
| 185 |
...ve.init.mw.ArticleTarget.super.static.documentCommands, |
| 186 |
|
| 187 |
'commandHelp', |
| 188 |
|
| 189 |
'showSave', |
| 190 |
'showChanges', |
| 191 |
'showPreview', |
| 192 |
'showMinoredit', |
| 193 |
'showWatchthis' |
| 194 |
]; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
ve.init.mw.ArticleTarget.static.parseDocument = function ( documentString, mode, section, onlySection ) { |
| 202 |
|
| 203 |
|
| 204 |
if ( mode === 'source' && documentString ) { |
| 205 |
documentString += '\n'; |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
return ve.init.mw.ArticleTarget.super.static.parseDocument.call( this, documentString, mode, section, onlySection ); |
| 210 |
}; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
ve.init.mw.ArticleTarget.prototype.getEditableContent = function () { |
| 218 |
return $( '#mw-content-text' ); |
| 219 |
}; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
ve.init.mw.ArticleTarget.static.buildRedirectSub = function () { |
| 227 |
const $subMsg = mw.message( 'redirectpagesub' ).parseDom(); |
| 228 |
|
| 229 |
|
| 230 |
return $( '<span>' ) |
| 231 |
.attr( 'id', 'redirectsub' ) |
| 232 |
.append( $subMsg ); |
| 233 |
}; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
ve.init.mw.ArticleTarget.static.buildRedirectMsg = function ( title ) { |
| 242 |
const $link = $( '<a>' ) |
| 243 |
.attr( { |
| 244 |
href: mw.Title.newFromText( title ).getUrl(), |
| 245 |
title: mw.msg( 'visualeditor-redirect-description', title ) |
| 246 |
} ) |
| 247 |
.text( title ); |
| 248 |
ve.init.platform.linkCache.styleElement( title, $link ); |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
return $( '<div>' ) |
| 253 |
.addClass( 'redirectMsg' ) |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
.addClass( 'mw-content-' + mw.config.get( 'wgVisualEditor' ).pageLanguageDir ) |
| 259 |
.append( |
| 260 |
$( '<p>' ).text( mw.msg( 'redirectto' ) ), |
| 261 |
$( '<ul>' ) |
| 262 |
.addClass( 'redirectText' ) |
| 263 |
.append( $( '<li>' ).append( $link ) ) |
| 264 |
); |
| 265 |
}; |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
ve.init.mw.ArticleTarget.prototype.setDefaultMode = function () { |
| 273 |
const oldDefaultMode = this.defaultMode; |
| 274 |
|
| 275 |
ve.init.mw.ArticleTarget.super.prototype.setDefaultMode.apply( this, arguments ); |
| 276 |
|
| 277 |
if ( this.defaultMode !== oldDefaultMode ) { |
| 278 |
this.updateTabs(); |
| 279 |
if ( mw.libs.ve.setEditorPreference ) { |
| 280 |
|
| 281 |
mw.libs.ve.setEditorPreference( this.defaultMode === 'visual' ? 'visualeditor' : 'wikitext' ); |
| 282 |
} |
| 283 |
} |
| 284 |
}; |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
ve.init.mw.ArticleTarget.prototype.updateTabs = function () {}; |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
ve.init.mw.ArticleTarget.prototype.loadSuccess = function ( response ) { |
| 301 |
const data = response ? ( response.visualeditor || response.visualeditoredit ) : null; |
| 302 |
|
| 303 |
if ( !data || typeof data.content !== 'string' ) { |
| 304 |
this.loadFail( 've-api', { errors: [ { |
| 305 |
code: 've-api', |
| 306 |
html: mw.message( 'api-clientside-error-invalidresponse' ).parse() |
| 307 |
} ] } ); |
| 308 |
} else if ( response.veMode && response.veMode !== this.getDefaultMode() ) { |
| 309 |
this.loadFail( 've-mode', { errors: [ { |
| 310 |
code: 've-mode', |
| 311 |
html: mw.message( 'visualeditor-loaderror-wrongmode', |
| 312 |
response.veMode, this.getDefaultMode() ).parse() |
| 313 |
} ] } ); |
| 314 |
} else { |
| 315 |
this.track( 'trace.parseResponse.enter' ); |
| 316 |
this.originalHtml = data.content; |
| 317 |
this.etag = data.etag; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
this.fromEditedState = !!data.fromEditedState || !!data.preloaded; |
| 322 |
this.switched = data.switched; |
| 323 |
const mode = this.getDefaultMode(); |
| 324 |
const section = ( mode === 'source' || this.enableVisualSectionEditing ) ? this.section : null; |
| 325 |
this.doc = this.constructor.static.parseDocument( this.originalHtml, mode, section ); |
| 326 |
this.originalDmDocPromise = null; |
| 327 |
|
| 328 |
|
| 329 |
this.initialSourceRange = data.initialSourceRange; |
| 330 |
this.recovered = data.recovered; |
| 331 |
this.isRedirect = false; |
| 332 |
|
| 333 |
|
| 334 |
if ( !this.parseMetadata( response ) ) { |
| 335 |
|
| 336 |
return; |
| 337 |
} |
| 338 |
|
| 339 |
this.track( 'trace.parseResponse.exit' ); |
| 340 |
|
| 341 |
|
| 342 |
this.documentReady( this.doc ); |
| 343 |
} |
| 344 |
|
| 345 |
if ( !this.isViewPage ) { |
| 346 |
$( '#firstHeading' ).text( |
| 347 |
mw.Title.newFromText( this.getPageName() ).getPrefixedText() |
| 348 |
); |
| 349 |
} |
| 350 |
}; |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
ve.init.mw.ArticleTarget.prototype.parseMetadata = function ( response ) { |
| 360 |
const data = response ? ( response.visualeditor || response.visualeditoredit ) : null; |
| 361 |
|
| 362 |
if ( !data ) { |
| 363 |
this.loadFail( 've-api', { errors: [ { |
| 364 |
code: 've-api', |
| 365 |
html: mw.message( 'api-clientside-error-invalidresponse' ).parse() |
| 366 |
} ] } ); |
| 367 |
return false; |
| 368 |
} |
| 369 |
|
| 370 |
this.remoteNotices = ve.getObjectValues( data.notices ); |
| 371 |
this.protectedClasses = data.protectedClasses; |
| 372 |
|
| 373 |
this.baseTimeStamp = data.basetimestamp; |
| 374 |
this.startTimeStamp = data.starttimestamp; |
| 375 |
this.revid = data.oldid || undefined; |
| 376 |
this.preloaded = !!data.preloaded; |
| 377 |
|
| 378 |
this.copyrightWarning = data.copyrightWarning; |
| 379 |
|
| 380 |
this.checkboxesDef = data.checkboxesDef; |
| 381 |
this.checkboxesMessages = data.checkboxesMessages; |
| 382 |
mw.messages.set( data.checkboxesMessages ); |
| 383 |
|
| 384 |
this.canEdit = data.canEdit; |
| 385 |
this.wouldautocreate = data.wouldautocreate; |
| 386 |
|
| 387 |
|
| 388 |
let docRevId; |
| 389 |
const aboutDoc = this.doc.documentElement && this.doc.documentElement.getAttribute( 'about' ); |
| 390 |
if ( aboutDoc ) { |
| 391 |
const docRevIdMatches = aboutDoc.match( /revision\/([0-9]*)$/ ); |
| 392 |
if ( docRevIdMatches.length >= 2 ) { |
| 393 |
docRevId = parseInt( docRevIdMatches[ 1 ] ); |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
if ( this.getDefaultMode() === 'visual' && !( this.switched && this.fromEditedState ) && docRevId !== this.revid ) { |
| 399 |
if ( this.retriedRevIdConflict ) { |
| 400 |
|
| 401 |
this.loadFail( 've-api', { errors: [ { |
| 402 |
code: 've-api', |
| 403 |
html: mw.message( 'visualeditor-loaderror-revidconflict', |
| 404 |
String( docRevId ), String( this.revid ) ).parse() |
| 405 |
} ] } ); |
| 406 |
} else { |
| 407 |
this.retriedRevIdConflict = true; |
| 408 |
|
| 409 |
|
| 410 |
this.loading = null; |
| 411 |
|
| 412 |
this.requestedRevId = Math.max( docRevId || 0, this.revid ); |
| 413 |
this.load(); |
| 414 |
} |
| 415 |
return false; |
| 416 |
} else { |
| 417 |
|
| 418 |
|
| 419 |
this.retriedRevIdConflict = false; |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
this.$saveDialogOverlay = $( '<div>' ).addClass( 'oo-ui-window-overlay' ); |
| 425 |
const checkboxes = mw.libs.ve.targetLoader.createCheckboxFields( this.checkboxesDef, { $overlay: this.$saveDialogOverlay } ); |
| 426 |
this.checkboxFields = checkboxes.checkboxFields; |
| 427 |
this.checkboxesByName = checkboxes.checkboxesByName; |
| 428 |
|
| 429 |
this.checkboxFields.forEach( ( field ) => { |
| 430 |
|
| 431 |
|
| 432 |
ve.targetLinksToNewWindow( field.$label[ 0 ] ); |
| 433 |
} ); |
| 434 |
|
| 435 |
return true; |
| 436 |
}; |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
ve.init.mw.ArticleTarget.prototype.documentReady = function () { |
| 442 |
|
| 443 |
this.editNotices = this.remoteNotices.concat( |
| 444 |
this.localNoticeMessages.map( ( msgKey ) => '<p>' + ve.init.platform.getParsedMessage( msgKey ) + '</p>' ) |
| 445 |
); |
| 446 |
|
| 447 |
this.loading = null; |
| 448 |
this.edited = this.fromEditedState; |
| 449 |
|
| 450 |
|
| 451 |
ve.init.mw.ArticleTarget.super.prototype.documentReady.apply( this, arguments ); |
| 452 |
}; |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
ve.init.mw.ArticleTarget.prototype.surfaceReady = function () { |
| 458 |
const accessKeyPrefix = $.fn.updateTooltipAccessKeys.getAccessKeyPrefix().replace( /-/g, '+' ), |
| 459 |
accessKeyModifiers = new ve.ui.Trigger( accessKeyPrefix + '-' ).modifiers, |
| 460 |
surfaceModel = this.getSurface().getModel(); |
| 461 |
|
| 462 |
|
| 463 |
ve.init.platform.linkCache.setAssumeExistence( false ); |
| 464 |
surfaceModel.connect( this, { |
| 465 |
history: 'updateToolbarSaveButtonState' |
| 466 |
} ); |
| 467 |
|
| 468 |
|
| 469 |
this.getSurface().connect( this, { |
| 470 |
cancel: 'onSurfaceCancel' |
| 471 |
} ); |
| 472 |
|
| 473 |
|
| 474 |
for ( const name in ve.ui.triggerRegistry.registry ) { |
| 475 |
const triggers = ve.ui.triggerRegistry.registry[ name ]; |
| 476 |
for ( let i = 0; i < triggers.length; i++ ) { |
| 477 |
if ( ve.compare( triggers[ i ].modifiers, accessKeyModifiers ) ) { |
| 478 |
this.disableAccessKey( triggers[ i ].primary ); |
| 479 |
} |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
if ( !mw.config.get( 'wgVisualEditorConfig' ).enableHelpCompletion ) { |
| 484 |
this.getSurface().commandRegistry.unregister( 'openHelpCompletions' ); |
| 485 |
this.getSurface().commandRegistry.unregister( 'openHelpCompletionsTrigger' ); |
| 486 |
} |
| 487 |
|
| 488 |
if ( !this.canEdit ) { |
| 489 |
this.getSurface().setReadOnly( true ); |
| 490 |
} else { |
| 491 |
|
| 492 |
if ( !this.currentUrl.searchParams.has( 'collabSession' ) ) { |
| 493 |
|
| 494 |
this.initAutosave(); |
| 495 |
} |
| 496 |
|
| 497 |
setTimeout( () => { |
| 498 |
mw.libs.ve.targetSaver.preloadDeflate(); |
| 499 |
}, 500 ); |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
ve.init.mw.ArticleTarget.super.prototype.surfaceReady.apply( this, arguments ); |
| 504 |
|
| 505 |
mw.hook( 've.activationComplete' ).fire(); |
| 506 |
}; |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
ve.init.mw.ArticleTarget.prototype.onSurfaceCancel = function () { |
| 512 |
this.tryTeardown( false, 'navigate-read' ); |
| 513 |
}; |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
ve.init.mw.ArticleTarget.prototype.afterSurfaceReady = function () { |
| 521 |
this.restoreEditSection(); |
| 522 |
}; |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
ve.init.mw.ArticleTarget.prototype.storeDocState = function ( html ) { |
| 528 |
const mode = this.getSurface().getMode(); |
| 529 |
this.getSurface().getModel().storeDocState( { |
| 530 |
request: { |
| 531 |
pageName: this.getPageName(), |
| 532 |
mode: mode, |
| 533 |
|
| 534 |
section: ( mode === 'source' || this.enableVisualSectionEditing ) ? this.section : null |
| 535 |
}, |
| 536 |
response: { |
| 537 |
etag: this.etag, |
| 538 |
fromEditedState: this.fromEditedState, |
| 539 |
switched: this.switched, |
| 540 |
preloaded: this.preloaded, |
| 541 |
notices: this.remoteNotices, |
| 542 |
protectedClasses: this.protectedClasses, |
| 543 |
basetimestamp: this.baseTimeStamp, |
| 544 |
starttimestamp: this.startTimeStamp, |
| 545 |
oldid: this.revid, |
| 546 |
canEdit: this.canEdit, |
| 547 |
wouldautocreate: this.wouldautocreate, |
| 548 |
copyrightWarning: this.copyrightWarning, |
| 549 |
checkboxesDef: this.checkboxesDef, |
| 550 |
checkboxesMessages: this.checkboxesMessages |
| 551 |
} |
| 552 |
}, html ); |
| 553 |
}; |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
ve.init.mw.ArticleTarget.prototype.disableAccessKey = function ( key ) { |
| 561 |
$( '[accesskey=' + key + ']' ).each( ( i, el ) => { |
| 562 |
const $el = $( el ); |
| 563 |
|
| 564 |
$el |
| 565 |
.attr( 'data-old-accesskey', $el.attr( 'accesskey' ) ) |
| 566 |
.removeAttr( 'accesskey' ); |
| 567 |
} ); |
| 568 |
}; |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
ve.init.mw.ArticleTarget.prototype.restoreAccessKeys = function () { |
| 574 |
$( '[data-old-accesskey]' ).each( ( i, el ) => { |
| 575 |
const $el = $( el ); |
| 576 |
|
| 577 |
$el |
| 578 |
.attr( 'accesskey', $el.attr( 'data-old-accesskey' ) ) |
| 579 |
.removeAttr( 'data-old-accesskey' ); |
| 580 |
} ); |
| 581 |
}; |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
ve.init.mw.ArticleTarget.prototype.loadFail = function () { |
| 593 |
this.loading = null; |
| 594 |
this.emit( 'loadError' ); |
| 595 |
}; |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
ve.init.mw.ArticleTarget.prototype.replacePageContent = function ( |
| 610 |
html, categoriesHtml, displayTitle, lastModified, contentSub, sections |
| 611 |
) { |
| 612 |
|
| 613 |
this.$editableContent.find( '.mw-parser-output' ).first().replaceWith( html ); |
| 614 |
mw.hook( 'wikipage.content' ).fire( this.$editableContent ); |
| 615 |
|
| 616 |
if ( displayTitle ) { |
| 617 |
|
| 618 |
$( '#firstHeading' ).html( displayTitle ); |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
if ( $( '#catlinks' ).length ) { |
| 623 |
const $categories = $( $.parseHTML( categoriesHtml ) ); |
| 624 |
mw.hook( 'wikipage.categories' ).fire( $categories ); |
| 625 |
$( '#catlinks' ).replaceWith( $categories ); |
| 626 |
} |
| 627 |
|
| 628 |
mw.util.clearSubtitle(); |
| 629 |
mw.util.addSubtitle( contentSub ); |
| 630 |
|
| 631 |
this.setRealRedirectInterface(); |
| 632 |
|
| 633 |
mw.hook( 'wikipage.tableOfContents' ).fire( sections ); |
| 634 |
}; |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
ve.init.mw.ArticleTarget.prototype.saveComplete = function ( data ) { |
| 657 |
this.editSummaryValue = null; |
| 658 |
this.initialEditSummary = null; |
| 659 |
|
| 660 |
this.saveDeferred.resolve(); |
| 661 |
this.emit( 'save', data ); |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
if ( data.nocontent || data.tempusercreated ) { |
| 666 |
|
| 667 |
this.teardown().then( () => { |
| 668 |
if ( data.newrevid !== undefined ) { |
| 669 |
let action; |
| 670 |
if ( this.restoring ) { |
| 671 |
action = 'restored'; |
| 672 |
} else if ( !this.pageExists ) { |
| 673 |
action = 'created'; |
| 674 |
} else { |
| 675 |
action = 'saved'; |
| 676 |
} |
| 677 |
require( 'mediawiki.action.view.postEdit' ).fireHookOnPageReload( action, data.tempusercreated ); |
| 678 |
} |
| 679 |
|
| 680 |
if ( data.tempusercreatedredirect ) { |
| 681 |
location.href = data.tempusercreatedredirect; |
| 682 |
} else { |
| 683 |
const newUrl = new URL( this.viewUrl ); |
| 684 |
if ( data.newrevid !== undefined ) { |
| 685 |
|
| 686 |
newUrl.searchParams.set( 'venotify', 'saved' ); |
| 687 |
} |
| 688 |
if ( data.isRedirect ) { |
| 689 |
newUrl.searchParams.set( 'redirect', 'no' ); |
| 690 |
} |
| 691 |
location.href = newUrl; |
| 692 |
} |
| 693 |
} ); |
| 694 |
} else { |
| 695 |
|
| 696 |
|
| 697 |
if ( mw.loader.getState( 'mediawiki.page.watch.ajax' ) === 'ready' ) { |
| 698 |
const watch = require( 'mediawiki.page.watch.ajax' ); |
| 699 |
|
| 700 |
watch.updatePageWatchStatus( |
| 701 |
data.watched, |
| 702 |
data.watchlistexpiry |
| 703 |
); |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
this.restoring = false; |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
this.requestedRevId = undefined; |
| 715 |
|
| 716 |
if ( data.newrevid !== undefined ) { |
| 717 |
mw.config.set( { |
| 718 |
wgCurRevisionId: data.newrevid, |
| 719 |
wgRevisionId: data.newrevid |
| 720 |
} ); |
| 721 |
this.revid = data.newrevid; |
| 722 |
this.currentRevisionId = data.newrevid; |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
mw.config.set( data.jsconfigvars ); |
| 728 |
mw.loader.load( data.modules ); |
| 729 |
|
| 730 |
mw.config.set( { |
| 731 |
wgIsRedirect: !!data.isRedirect |
| 732 |
} ); |
| 733 |
|
| 734 |
if ( this.saveDialog ) { |
| 735 |
this.saveDialog.reset(); |
| 736 |
} |
| 737 |
|
| 738 |
this.replacePageContent( |
| 739 |
data.content, |
| 740 |
data.categorieshtml, |
| 741 |
data.displayTitleHtml, |
| 742 |
data.lastModified, |
| 743 |
data.contentSub, |
| 744 |
data.sections |
| 745 |
); |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
this.tryTeardown( true ); |
| 750 |
} |
| 751 |
}; |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
ve.init.mw.ArticleTarget.prototype.saveFail = function ( doc, saveData, code, data ) { |
| 763 |
this.pageDeletedWarning = false; |
| 764 |
|
| 765 |
let handled = false; |
| 766 |
|
| 767 |
if ( !data ) { |
| 768 |
this.saveErrorEmpty(); |
| 769 |
handled = true; |
| 770 |
} |
| 771 |
|
| 772 |
if ( !handled && data.errors ) { |
| 773 |
for ( let i = 0; i < data.errors.length; i++ ) { |
| 774 |
const error = data.errors[ i ]; |
| 775 |
|
| 776 |
if ( error.code === 'assertanonfailed' || error.code === 'assertuserfailed' || error.code === 'assertnameduserfailed' ) { |
| 777 |
this.refreshUser().then( ( username ) => { |
| 778 |
|
| 779 |
|
| 780 |
if ( error.code === 'assertanonfailed' && mw.util.isTemporaryUser( username ) ) { |
| 781 |
this.startSave( this.getSaveOptions() ); |
| 782 |
} else { |
| 783 |
this.saveErrorNewUser( username ); |
| 784 |
} |
| 785 |
}, () => { |
| 786 |
this.saveErrorUnknown( data ); |
| 787 |
} ); |
| 788 |
handled = true; |
| 789 |
} else if ( error.code === 'editconflict' ) { |
| 790 |
this.editConflict(); |
| 791 |
handled = true; |
| 792 |
} else if ( error.code === 'pagedeleted' ) { |
| 793 |
this.saveErrorPageDeleted(); |
| 794 |
handled = true; |
| 795 |
} else if ( error.code === 'hookaborted' ) { |
| 796 |
this.saveErrorHookAborted( data ); |
| 797 |
handled = true; |
| 798 |
} else if ( error.code === 'readonly' ) { |
| 799 |
this.saveErrorReadOnly( data ); |
| 800 |
handled = true; |
| 801 |
} |
| 802 |
} |
| 803 |
} |
| 804 |
|
| 805 |
if ( !handled ) { |
| 806 |
const saveErrorHandlerFactory = ve.init.mw.saveErrorHandlerFactory; |
| 807 |
for ( const name in saveErrorHandlerFactory.registry ) { |
| 808 |
const handler = saveErrorHandlerFactory.lookup( name ); |
| 809 |
if ( handler.static.matchFunction( data ) ) { |
| 810 |
handler.static.process( data, this ); |
| 811 |
handled = true; |
| 812 |
} |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
if ( !handled ) { |
| 818 |
this.saveErrorUnknown( data ); |
| 819 |
handled = true; |
| 820 |
} |
| 821 |
|
| 822 |
let errorCodes; |
| 823 |
if ( data.errors ) { |
| 824 |
errorCodes = OO.unique( data.errors.map( ( err ) => err.code ) ).join( ',' ); |
| 825 |
} else if ( ve.getProp( data, 'visualeditoredit', 'edit', 'captcha' ) ) { |
| 826 |
|
| 827 |
errorCodes = 'captcha'; |
| 828 |
} else { |
| 829 |
errorCodes = 'http-' + ( ( data.xhr && data.xhr.status ) || 0 ); |
| 830 |
} |
| 831 |
this.emit( 'saveError', errorCodes ); |
| 832 |
}; |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
ve.init.mw.ArticleTarget.prototype.showSaveError = function ( msg, warning ) { |
| 842 |
this.saveDeferred.reject( [ new OO.ui.Error( msg, { warning: warning } ) ] ); |
| 843 |
}; |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
ve.init.mw.ArticleTarget.prototype.extractErrorMessages = function ( data ) { |
| 852 |
const $errorMsgs = ( new mw.Api() ).getErrorMessage( data ); |
| 853 |
|
| 854 |
$errorMsgs.toArray().forEach( ve.targetLinksToNewWindow ); |
| 855 |
return $errorMsgs; |
| 856 |
}; |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
ve.init.mw.ArticleTarget.prototype.saveErrorEmpty = function () { |
| 862 |
this.showSaveError( this.extractErrorMessages( null ) ); |
| 863 |
}; |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
ve.init.mw.ArticleTarget.prototype.saveErrorHookAborted = function ( data ) { |
| 871 |
this.showSaveError( this.extractErrorMessages( data ) ); |
| 872 |
}; |
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
ve.init.mw.ArticleTarget.prototype.saveErrorNewUser = function ( username ) { |
| 881 |
const $msg = mw.message( |
| 882 |
username === null ? |
| 883 |
'visualeditor-savedialog-identify-anon' : |
| 884 |
mw.util.isTemporaryUser( username ) ? |
| 885 |
'visualeditor-savedialog-identify-temp' : |
| 886 |
'visualeditor-savedialog-identify-user', |
| 887 |
username |
| 888 |
).parseDom(); |
| 889 |
|
| 890 |
this.showSaveError( $msg, true ); |
| 891 |
}; |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
ve.init.mw.ArticleTarget.prototype.saveErrorUnknown = function ( data ) { |
| 899 |
this.showSaveError( this.extractErrorMessages( data ) ); |
| 900 |
}; |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
ve.init.mw.ArticleTarget.prototype.saveErrorPageDeleted = function () { |
| 906 |
this.pageDeletedWarning = true; |
| 907 |
|
| 908 |
this.showSaveError( mw.msg( 'visualeditor-recreate', mw.msg( 'ooui-dialog-process-continue' ) ), true ); |
| 909 |
}; |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
ve.init.mw.ArticleTarget.prototype.saveErrorReadOnly = function ( data ) { |
| 917 |
this.showSaveError( this.extractErrorMessages( data ), true ); |
| 918 |
}; |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
ve.init.mw.ArticleTarget.prototype.editConflict = function () { |
| 924 |
this.saveDialog.popPending(); |
| 925 |
this.saveDialog.swapPanel( 'conflict' ); |
| 926 |
}; |
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
ve.init.mw.ArticleTarget.prototype.onSaveDialogReview = function () { |
| 934 |
if ( !this.saveDialog.hasDiff ) { |
| 935 |
this.emit( 'saveReview' ); |
| 936 |
this.saveDialog.pushPending(); |
| 937 |
|
| 938 |
|
| 939 |
mw.user.acquireTempUserName().then( () => { |
| 940 |
if ( this.pageExists ) { |
| 941 |
|
| 942 |
this.showChanges( this.getDocToSave() ); |
| 943 |
} else { |
| 944 |
this.serialize( this.getDocToSave() ).then( ( data ) => { |
| 945 |
this.onSaveDialogReviewComplete( data.content ); |
| 946 |
} ); |
| 947 |
} |
| 948 |
} ); |
| 949 |
} else { |
| 950 |
this.saveDialog.swapPanel( 'review' ); |
| 951 |
} |
| 952 |
}; |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
ve.init.mw.ArticleTarget.prototype.onSaveDialogPreview = function () { |
| 960 |
const api = this.getContentApi(); |
| 961 |
|
| 962 |
if ( !this.saveDialog.$previewViewer.children().length ) { |
| 963 |
this.emit( 'savePreview' ); |
| 964 |
this.saveDialog.pushPending(); |
| 965 |
|
| 966 |
const params = {}; |
| 967 |
|
| 968 |
const sectionTitle = this.sectionTitle && this.sectionTitle.getValue(); |
| 969 |
if ( sectionTitle ) { |
| 970 |
params.section = 'new'; |
| 971 |
params.sectiontitle = sectionTitle; |
| 972 |
} |
| 973 |
if ( mw.config.get( 'wgUserVariant' ) ) { |
| 974 |
params.variant = mw.config.get( 'wgUserVariant' ); |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
mw.user.acquireTempUserName().then( () => api.post( ve.extendObject( params, { |
| 980 |
action: 'parse', |
| 981 |
title: this.getPageName(), |
| 982 |
text: this.getDocToSave(), |
| 983 |
pst: true, |
| 984 |
preview: true, |
| 985 |
sectionpreview: this.section !== null, |
| 986 |
disableeditsection: true, |
| 987 |
uselang: mw.config.get( 'wgUserLanguage' ), |
| 988 |
useskin: mw.config.get( 'skin' ), |
| 989 |
mobileformat: OO.ui.isMobile(), |
| 990 |
prop: [ 'text', 'categorieshtml', 'displaytitle', 'subtitle', 'modules', 'jsconfigvars' ] |
| 991 |
} ) ) ).then( ( response ) => { |
| 992 |
this.saveDialog.showPreview( response ); |
| 993 |
}, ( errorCode, details ) => { |
| 994 |
this.saveDialog.showPreview( this.extractErrorMessages( details ) ); |
| 995 |
} ).always( () => { |
| 996 |
this.bindSaveDialogClearDiff(); |
| 997 |
} ); |
| 998 |
} else { |
| 999 |
this.saveDialog.swapPanel( 'preview' ); |
| 1000 |
} |
| 1001 |
}; |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
ve.init.mw.ArticleTarget.prototype.bindSaveDialogClearDiff = function () { |
| 1007 |
|
| 1008 |
this.getSurface().getModel().getDocument().once( 'transact', |
| 1009 |
this.saveDialog.clearDiff.bind( this.saveDialog ) |
| 1010 |
); |
| 1011 |
if ( this.sectionTitle ) { |
| 1012 |
this.sectionTitle.once( 'change', this.saveDialog.clearDiff.bind( this.saveDialog ) ); |
| 1013 |
} |
| 1014 |
}; |
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
ve.init.mw.ArticleTarget.prototype.onSaveDialogReviewComplete = function ( wikitext ) { |
| 1022 |
this.bindSaveDialogClearDiff(); |
| 1023 |
this.saveDialog.setDiffAndReview( |
| 1024 |
ve.createDeferred().resolve( $( '<pre>' ).text( wikitext ) ).promise(), |
| 1025 |
this.getVisualDiffGeneratorPromise(), |
| 1026 |
this.getSurface().getModel().getDocument().getHtmlDocument() |
| 1027 |
); |
| 1028 |
}; |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
ve.init.mw.ArticleTarget.prototype.getVisualDiffGeneratorPromise = function () { |
| 1036 |
return mw.loader.using( 'ext.visualEditor.diffLoader' ).then( () => { |
| 1037 |
const mode = this.getSurface().getMode(); |
| 1038 |
|
| 1039 |
if ( !this.originalDmDocPromise ) { |
| 1040 |
if ( mode === 'source' ) { |
| 1041 |
|
| 1042 |
this.originalDmDocPromise = mw.libs.ve.diffLoader.fetchRevision( this.revid, this.getPageName() ); |
| 1043 |
} else { |
| 1044 |
if ( !this.fromEditedState ) { |
| 1045 |
const dmDoc = this.constructor.static.createModelFromDom( this.doc, 'visual' ); |
| 1046 |
let dmDocOrNode; |
| 1047 |
if ( this.section !== null && this.enableVisualSectionEditing ) { |
| 1048 |
dmDocOrNode = dmDoc.getNodesByType( 'section' )[ 0 ]; |
| 1049 |
} else { |
| 1050 |
dmDocOrNode = dmDoc; |
| 1051 |
} |
| 1052 |
this.originalDmDocPromise = ve.createDeferred().resolve( dmDocOrNode ).promise(); |
| 1053 |
} else { |
| 1054 |
this.originalDmDocPromise = mw.libs.ve.diffLoader.fetchRevision( this.revid, this.getPageName(), this.section ); |
| 1055 |
} |
| 1056 |
} |
| 1057 |
} |
| 1058 |
|
| 1059 |
if ( mode === 'source' ) { |
| 1060 |
|
| 1061 |
|
| 1062 |
const newRevPromise = mw.user.acquireTempUserName().then( () => this.getContentApi().post( { |
| 1063 |
action: 'visualeditor', |
| 1064 |
paction: 'parse', |
| 1065 |
page: this.getPageName(), |
| 1066 |
wikitext: this.getSurface().getDom(), |
| 1067 |
section: this.section, |
| 1068 |
stash: 0, |
| 1069 |
pst: true |
| 1070 |
} ) ).then( |
| 1071 |
|
| 1072 |
( response ) => mw.libs.ve.diffLoader.getModelFromResponse( response, null ) |
| 1073 |
); |
| 1074 |
|
| 1075 |
return mw.libs.ve.diffLoader.getVisualDiffGeneratorPromise( this.originalDmDocPromise, newRevPromise ); |
| 1076 |
} else { |
| 1077 |
return this.originalDmDocPromise.then( |
| 1078 |
( originalDmDoc ) => () => new ve.dm.VisualDiff( originalDmDoc, this.getSurface().getModel().getDocument().getAttachedRoot() ) |
| 1079 |
); |
| 1080 |
} |
| 1081 |
} ); |
| 1082 |
}; |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
ve.init.mw.ArticleTarget.prototype.onSaveDialogResolveConflict = function () { |
| 1088 |
const fields = { wpSave: 1 }; |
| 1089 |
|
| 1090 |
if ( this.getSurface().getMode() === 'source' && this.section !== null ) { |
| 1091 |
|
| 1092 |
fields.section = this.section; |
| 1093 |
} |
| 1094 |
|
| 1095 |
this.serialize( this.getDocToSave() ).then( ( data ) => { |
| 1096 |
this.submitWithSaveFields( fields, data.content ); |
| 1097 |
} ); |
| 1098 |
}; |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
ve.init.mw.ArticleTarget.prototype.onSaveDialogRetry = function () { |
| 1105 |
if ( this.pageDeletedWarning ) { |
| 1106 |
this.recreating = true; |
| 1107 |
this.pageExists = false; |
| 1108 |
} |
| 1109 |
}; |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
ve.init.mw.ArticleTarget.prototype.load = function ( dataPromise ) { |
| 1121 |
|
| 1122 |
if ( this.loading ) { |
| 1123 |
return this.loading; |
| 1124 |
} |
| 1125 |
this.events.trackActivationStart( mw.libs.ve.activationStart ); |
| 1126 |
mw.libs.ve.activationStart = null; |
| 1127 |
|
| 1128 |
const url = new URL( location.href ); |
| 1129 |
dataPromise = dataPromise || mw.libs.ve.targetLoader.requestPageData( this.getDefaultMode(), this.getPageName(), { |
| 1130 |
sessionStore: true, |
| 1131 |
section: this.section, |
| 1132 |
oldId: this.requestedRevId, |
| 1133 |
targetName: this.constructor.static.trackingName, |
| 1134 |
editintro: url.searchParams.get( 'editintro' ), |
| 1135 |
preload: url.searchParams.get( 'preload' ), |
| 1136 |
preloadparams: mw.util.getArrayParam( 'preloadparams', url.searchParams ) |
| 1137 |
} ); |
| 1138 |
|
| 1139 |
this.loading = dataPromise; |
| 1140 |
dataPromise |
| 1141 |
.done( this.loadSuccess.bind( this ) ) |
| 1142 |
.fail( this.loadFail.bind( this ) ); |
| 1143 |
|
| 1144 |
return dataPromise; |
| 1145 |
}; |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
ve.init.mw.ArticleTarget.prototype.clearState = function () { |
| 1151 |
this.restoreAccessKeys(); |
| 1152 |
this.clearPreparedCacheKey(); |
| 1153 |
this.loading = null; |
| 1154 |
this.saving = null; |
| 1155 |
this.clearDiff(); |
| 1156 |
this.serializing = false; |
| 1157 |
this.submitting = false; |
| 1158 |
this.baseTimeStamp = null; |
| 1159 |
this.startTimeStamp = null; |
| 1160 |
this.checkboxes = null; |
| 1161 |
this.initialSourceRange = null; |
| 1162 |
this.doc = null; |
| 1163 |
this.originalDmDocPromise = null; |
| 1164 |
this.originalHtml = null; |
| 1165 |
this.toolbarSaveButton = null; |
| 1166 |
this.section = null; |
| 1167 |
this.visibleSection = null; |
| 1168 |
this.visibleSectionOffset = null; |
| 1169 |
this.editNotices = []; |
| 1170 |
this.remoteNotices = []; |
| 1171 |
this.localNoticeMessages = []; |
| 1172 |
this.recovered = false; |
| 1173 |
this.teardownPromise = null; |
| 1174 |
}; |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
ve.init.mw.ArticleTarget.prototype.editSource = function () { |
| 1183 |
const modified = this.fromEditedState || this.getSurface().getModel().hasBeenModified(); |
| 1184 |
|
| 1185 |
this.switchToWikitextEditor( modified ); |
| 1186 |
}; |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
ve.init.mw.ArticleTarget.prototype.getDocToSave = function () { |
| 1197 |
if ( !this.docToSave ) { |
| 1198 |
this.docToSave = this.createDocToSave(); |
| 1199 |
|
| 1200 |
const surface = this.getSurface(); |
| 1201 |
surface.getModel().getDocument().once( 'transact', this.clearDocToSave.bind( this ) ); |
| 1202 |
surface.once( 'destroy', this.clearDocToSave.bind( this ) ); |
| 1203 |
} |
| 1204 |
return this.docToSave; |
| 1205 |
}; |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
ve.init.mw.ArticleTarget.prototype.createDocToSave = function () { |
| 1213 |
return this.getSurface().getDom(); |
| 1214 |
}; |
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
ve.init.mw.ArticleTarget.prototype.clearDocToSave = function () { |
| 1220 |
this.docToSave = null; |
| 1221 |
this.clearPreparedCacheKey(); |
| 1222 |
}; |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
ve.init.mw.ArticleTarget.prototype.prepareCacheKey = function ( doc ) { |
| 1238 |
const start = ve.now(); |
| 1239 |
|
| 1240 |
if ( this.getSurface().getMode() === 'source' ) { |
| 1241 |
return; |
| 1242 |
} |
| 1243 |
|
| 1244 |
if ( this.preparedCacheKeyPromise && this.preparedCacheKeyPromise.doc === doc ) { |
| 1245 |
return; |
| 1246 |
} |
| 1247 |
this.clearPreparedCacheKey(); |
| 1248 |
|
| 1249 |
let xhr; |
| 1250 |
let aborted = false; |
| 1251 |
this.preparedCacheKeyPromise = mw.libs.ve.targetSaver.deflateDoc( doc, this.doc ) |
| 1252 |
.then( ( deflatedHtml ) => { |
| 1253 |
if ( aborted ) { |
| 1254 |
return ve.createDeferred().reject(); |
| 1255 |
} |
| 1256 |
xhr = this.getContentApi().postWithToken( 'csrf', |
| 1257 |
{ |
| 1258 |
action: 'visualeditoredit', |
| 1259 |
paction: 'serializeforcache', |
| 1260 |
html: deflatedHtml, |
| 1261 |
page: this.getPageName(), |
| 1262 |
oldid: this.revid, |
| 1263 |
etag: this.etag |
| 1264 |
}, |
| 1265 |
{ contentType: 'multipart/form-data' } |
| 1266 |
); |
| 1267 |
return xhr.then( |
| 1268 |
( response ) => { |
| 1269 |
const trackData = { duration: ve.now() - start }; |
| 1270 |
if ( response.visualeditoredit && typeof response.visualeditoredit.cachekey === 'string' ) { |
| 1271 |
this.events.track( 'performance.system.serializeforcache', trackData ); |
| 1272 |
return { |
| 1273 |
cacheKey: response.visualeditoredit.cachekey, |
| 1274 |
|
| 1275 |
html: deflatedHtml |
| 1276 |
}; |
| 1277 |
} else { |
| 1278 |
this.events.track( 'performance.system.serializeforcache.nocachekey', trackData ); |
| 1279 |
return ve.createDeferred().reject(); |
| 1280 |
} |
| 1281 |
}, |
| 1282 |
() => { |
| 1283 |
this.events.track( 'performance.system.serializeforcache.fail', { duration: ve.now() - start } ); |
| 1284 |
return ve.createDeferred().reject(); |
| 1285 |
} |
| 1286 |
); |
| 1287 |
} ) |
| 1288 |
.promise( { |
| 1289 |
abort: () => { |
| 1290 |
if ( xhr ) { |
| 1291 |
xhr.abort(); |
| 1292 |
} |
| 1293 |
aborted = true; |
| 1294 |
}, |
| 1295 |
doc: doc |
| 1296 |
} ); |
| 1297 |
}; |
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
ve.init.mw.ArticleTarget.prototype.getPreparedCacheKey = function ( doc ) { |
| 1308 |
if ( this.preparedCacheKeyPromise && this.preparedCacheKeyPromise.doc === doc ) { |
| 1309 |
return this.preparedCacheKeyPromise; |
| 1310 |
} |
| 1311 |
return ve.createDeferred().reject().promise(); |
| 1312 |
}; |
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
ve.init.mw.ArticleTarget.prototype.clearPreparedCacheKey = function () { |
| 1318 |
if ( this.preparedCacheKeyPromise ) { |
| 1319 |
this.preparedCacheKeyPromise.abort(); |
| 1320 |
this.preparedCacheKeyPromise = null; |
| 1321 |
} |
| 1322 |
}; |
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
ve.init.mw.ArticleTarget.prototype.tryWithPreparedCacheKey = function ( doc, extraData, eventName ) { |
| 1340 |
if ( this.getSurface().getMode() === 'source' ) { |
| 1341 |
const data = ve.copy( extraData ); |
| 1342 |
|
| 1343 |
|
| 1344 |
if ( this.section !== null ) { |
| 1345 |
data.section = this.section; |
| 1346 |
} |
| 1347 |
if ( this.sectionTitle ) { |
| 1348 |
data.sectiontitle = this.sectionTitle.getValue(); |
| 1349 |
data.summary = undefined; |
| 1350 |
} |
| 1351 |
|
| 1352 |
return mw.libs.ve.targetSaver.postWikitext( |
| 1353 |
doc, |
| 1354 |
data, |
| 1355 |
{ api: this.getContentApi() } |
| 1356 |
); |
| 1357 |
} |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
const htmlOrCacheKeyPromise = this.getPreparedCacheKey( doc ).then( |
| 1362 |
|
| 1363 |
null, |
| 1364 |
|
| 1365 |
() => mw.libs.ve.targetSaver.deflateDoc( doc, this.doc ).then( ( html ) => ( { html: html } ) ) ); |
| 1366 |
|
| 1367 |
return htmlOrCacheKeyPromise.then( ( htmlOrCacheKey ) => mw.libs.ve.targetSaver.postHtml( |
| 1368 |
htmlOrCacheKey.html, |
| 1369 |
htmlOrCacheKey.cacheKey, |
| 1370 |
extraData, |
| 1371 |
{ |
| 1372 |
onCacheKeyFail: this.clearPreparedCacheKey.bind( this ), |
| 1373 |
api: this.getContentApi(), |
| 1374 |
track: this.events.track.bind( this.events ), |
| 1375 |
eventName: eventName, |
| 1376 |
now: ve.now |
| 1377 |
} |
| 1378 |
) ); |
| 1379 |
}; |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
ve.init.mw.ArticleTarget.prototype.onSaveDialogSave = function ( saveDeferred ) { |
| 1391 |
if ( this.deactivating ) { |
| 1392 |
return; |
| 1393 |
} |
| 1394 |
|
| 1395 |
const saveOptions = this.getSaveOptions(); |
| 1396 |
|
| 1397 |
if ( |
| 1398 |
+mw.user.options.get( 'forceeditsummary' ) && |
| 1399 |
( saveOptions.summary === '' || saveOptions.summary === this.initialEditSummary ) && |
| 1400 |
!this.saveDialog.messages.missingsummary |
| 1401 |
) { |
| 1402 |
this.saveDialog.showMessage( |
| 1403 |
'missingsummary', |
| 1404 |
new OO.ui.HtmlSnippet( ve.init.platform.getParsedMessage( 'missingsummary' ) ) |
| 1405 |
); |
| 1406 |
this.saveDialog.popPending(); |
| 1407 |
} else { |
| 1408 |
this.emit( 'saveInitiated' ); |
| 1409 |
this.startSave( saveOptions ); |
| 1410 |
this.saveDeferred = saveDeferred; |
| 1411 |
} |
| 1412 |
}; |
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
ve.init.mw.ArticleTarget.prototype.startSave = function ( saveOptions ) { |
| 1420 |
this.save( this.getDocToSave(), saveOptions ); |
| 1421 |
}; |
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
ve.init.mw.ArticleTarget.prototype.getSaveFields = function () { |
| 1429 |
const fields = {}; |
| 1430 |
|
| 1431 |
if ( this.section === 'new' ) { |
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
fields.wpSummary = this.sectionTitle ? this.sectionTitle.getValue() : ''; |
| 1436 |
} else { |
| 1437 |
fields.wpSummary = this.saveDialog ? |
| 1438 |
this.saveDialog.editSummaryInput.getValue() : |
| 1439 |
( this.editSummaryValue || this.initialEditSummary ); |
| 1440 |
} |
| 1441 |
|
| 1442 |
let name; |
| 1443 |
|
| 1444 |
for ( name in this.saveFields ) { |
| 1445 |
fields[ name ] = this.saveFields[ name ](); |
| 1446 |
} |
| 1447 |
|
| 1448 |
if ( this.recreating ) { |
| 1449 |
fields.wpRecreate = true; |
| 1450 |
} |
| 1451 |
|
| 1452 |
for ( name in this.checkboxesByName ) { |
| 1453 |
|
| 1454 |
if ( !this.checkboxesByName[ name ].isSelected || this.checkboxesByName[ name ].isSelected() ) { |
| 1455 |
fields[ name ] = this.checkboxesByName[ name ].getValue(); |
| 1456 |
} |
| 1457 |
} |
| 1458 |
|
| 1459 |
return fields; |
| 1460 |
}; |
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
ve.init.mw.ArticleTarget.prototype.submitWithSaveFields = function ( fields, wikitext ) { |
| 1470 |
return this.submit( wikitext, ve.extendObject( this.getSaveFields(), fields ) ); |
| 1471 |
}; |
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
ve.init.mw.ArticleTarget.prototype.getSaveOptions = function () { |
| 1479 |
const options = this.getSaveFields(), |
| 1480 |
fieldMap = { |
| 1481 |
wpSummary: 'summary', |
| 1482 |
wpMinoredit: 'minor', |
| 1483 |
wpWatchthis: 'watchlist', |
| 1484 |
wpCaptchaId: 'captchaid', |
| 1485 |
wpCaptchaWord: 'captchaword' |
| 1486 |
}; |
| 1487 |
|
| 1488 |
for ( const key in fieldMap ) { |
| 1489 |
if ( options[ key ] !== undefined ) { |
| 1490 |
options[ fieldMap[ key ] ] = options[ key ]; |
| 1491 |
delete options[ key ]; |
| 1492 |
} |
| 1493 |
} |
| 1494 |
|
| 1495 |
options.watchlist = 'watchlist' in options ? 'watch' : 'unwatch'; |
| 1496 |
|
| 1497 |
return options; |
| 1498 |
}; |
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
ve.init.mw.ArticleTarget.prototype.save = function ( doc, options ) { |
| 1515 |
|
| 1516 |
if ( this.saving ) { |
| 1517 |
return this.saving; |
| 1518 |
} |
| 1519 |
|
| 1520 |
const data = ve.extendObject( {}, options, { |
| 1521 |
page: this.getPageName(), |
| 1522 |
oldid: this.revid, |
| 1523 |
basetimestamp: this.baseTimeStamp, |
| 1524 |
starttimestamp: this.startTimeStamp, |
| 1525 |
etag: this.etag, |
| 1526 |
assert: mw.user.isAnon() ? 'anon' : 'user', |
| 1527 |
assertuser: mw.user.getName() || undefined |
| 1528 |
} ); |
| 1529 |
|
| 1530 |
if ( !this.pageExists || this.restoring || !this.isViewPage ) { |
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
data.nocontent = true; |
| 1535 |
} |
| 1536 |
|
| 1537 |
if ( this.wouldautocreate ) { |
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
data.returntoquery = this.isRedirect ? 'redirect=no' : ''; |
| 1542 |
data.returntoanchor = this.getSectionHashFromPage(); |
| 1543 |
} |
| 1544 |
|
| 1545 |
const config = mw.config.get( 'wgVisualEditorConfig' ); |
| 1546 |
|
| 1547 |
const taglist = data.vetags ? data.vetags.split( ',' ) : []; |
| 1548 |
|
| 1549 |
if ( config.useChangeTagging ) { |
| 1550 |
taglist.push( |
| 1551 |
this.getSurface().getMode() === 'source' ? 'visualeditor-wikitext' : 'visualeditor' |
| 1552 |
); |
| 1553 |
} |
| 1554 |
|
| 1555 |
if ( |
| 1556 |
this.getSurface().getMode() === 'visual' && |
| 1557 |
mw.config.get( 'wgVisualEditorConfig' ).editCheckTagging |
| 1558 |
) { |
| 1559 |
const documentModel = this.getSurface().getModel().getDocument(); |
| 1560 |
|
| 1561 |
if ( mw.editcheck.hasAddedContentNeedingReference( documentModel ) ) { |
| 1562 |
taglist.push( 'editcheck-references' ); |
| 1563 |
} |
| 1564 |
|
| 1565 |
if ( mw.editcheck.hasAddedContentNeedingReference( documentModel, true ) ) { |
| 1566 |
taglist.push( 'editcheck-newcontent' ); |
| 1567 |
} |
| 1568 |
|
| 1569 |
const rejections = mw.editcheck.getRejectionReasons(); |
| 1570 |
if ( rejections.length > 0 ) { |
| 1571 |
rejections.forEach( ( reason ) => { |
| 1572 |
taglist.push( 'editcheck-reference-decline-' + reason ); |
| 1573 |
} ); |
| 1574 |
} |
| 1575 |
} |
| 1576 |
|
| 1577 |
data.vetags = taglist.join( ',' ); |
| 1578 |
|
| 1579 |
const promise = this.saving = this.tryWithPreparedCacheKey( doc, data, 'save' ) |
| 1580 |
.done( this.saveComplete.bind( this ) ) |
| 1581 |
.fail( this.saveFail.bind( this, doc, data ) ) |
| 1582 |
.always( () => { |
| 1583 |
this.saving = null; |
| 1584 |
} ); |
| 1585 |
|
| 1586 |
return promise; |
| 1587 |
}; |
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
ve.init.mw.ArticleTarget.prototype.showChanges = function ( doc ) { |
| 1595 |
|
| 1596 |
this.getSurface().getModel().getDocument().once( 'transact', () => { |
| 1597 |
this.clearDiff(); |
| 1598 |
} ); |
| 1599 |
this.saveDialog.setDiffAndReview( |
| 1600 |
this.getWikitextDiffPromise( doc ), |
| 1601 |
this.getVisualDiffGeneratorPromise(), |
| 1602 |
this.getSurface().getModel().getDocument().getHtmlDocument() |
| 1603 |
); |
| 1604 |
}; |
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
ve.init.mw.ArticleTarget.prototype.clearDiff = function () { |
| 1610 |
if ( this.saveDialog ) { |
| 1611 |
this.saveDialog.clearDiff(); |
| 1612 |
} |
| 1613 |
this.wikitextDiffPromise = null; |
| 1614 |
}; |
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
ve.init.mw.ArticleTarget.prototype.getWikitextDiffPromise = function ( doc ) { |
| 1625 |
if ( !this.wikitextDiffPromise ) { |
| 1626 |
this.wikitextDiffPromise = this.tryWithPreparedCacheKey( doc, { |
| 1627 |
paction: 'diff', |
| 1628 |
page: this.getPageName(), |
| 1629 |
oldid: this.revid, |
| 1630 |
etag: this.etag |
| 1631 |
}, 'diff' ).then( ( data ) => { |
| 1632 |
if ( !data.diff ) { |
| 1633 |
this.emit( 'noChanges' ); |
| 1634 |
} |
| 1635 |
return data.diff; |
| 1636 |
} ); |
| 1637 |
this.wikitextDiffPromise |
| 1638 |
.done( this.emit.bind( this, 'showChanges' ) ) |
| 1639 |
.fail( this.emit.bind( this, 'showChangesError' ) ); |
| 1640 |
} |
| 1641 |
return this.wikitextDiffPromise; |
| 1642 |
}; |
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
ve.init.mw.ArticleTarget.prototype.submit = function ( wikitext, fields ) { |
| 1657 |
|
| 1658 |
if ( this.submitting ) { |
| 1659 |
return false; |
| 1660 |
} |
| 1661 |
|
| 1662 |
|
| 1663 |
this.clearDocState(); |
| 1664 |
|
| 1665 |
this.submitting = true; |
| 1666 |
const $form = $( '<form>' ).attr( { method: 'post', enctype: 'multipart/form-data' } ).addClass( 'oo-ui-element-hidden' ); |
| 1667 |
const params = ve.extendObject( { |
| 1668 |
format: 'text/x-wiki', |
| 1669 |
model: 'wikitext', |
| 1670 |
oldid: this.requestedRevId, |
| 1671 |
wpStarttime: this.startTimeStamp, |
| 1672 |
wpEdittime: this.baseTimeStamp, |
| 1673 |
wpTextbox1: wikitext, |
| 1674 |
wpEditToken: mw.user.tokens.get( 'csrfToken' ), |
| 1675 |
|
| 1676 |
|
| 1677 |
wpUnicodeCheck: 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ', |
| 1678 |
wpUltimateParam: true |
| 1679 |
}, fields ); |
| 1680 |
|
| 1681 |
for ( const key in params ) { |
| 1682 |
$form.append( $( '<input>' ).attr( { type: 'hidden', name: key, value: params[ key ] } ) ); |
| 1683 |
} |
| 1684 |
|
| 1685 |
|
| 1686 |
const submitUrl = mw.util.getUrl( this.getPageName(), { |
| 1687 |
action: 'submit', |
| 1688 |
veswitched: '1' |
| 1689 |
} ); |
| 1690 |
$form.attr( 'action', submitUrl ).appendTo( 'body' ).trigger( 'submit' ); |
| 1691 |
return true; |
| 1692 |
}; |
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
ve.init.mw.ArticleTarget.prototype.serialize = function ( doc, callback ) { |
| 1709 |
|
| 1710 |
if ( this.serializing ) { |
| 1711 |
return this.serializing; |
| 1712 |
} |
| 1713 |
const promise = this.serializing = this.tryWithPreparedCacheKey( doc, { |
| 1714 |
paction: 'serialize', |
| 1715 |
page: this.getPageName(), |
| 1716 |
oldid: this.revid, |
| 1717 |
etag: this.etag |
| 1718 |
}, 'serialize' ) |
| 1719 |
.done( this.emit.bind( this, 'serializeComplete' ) ) |
| 1720 |
.fail( this.emit.bind( this, 'serializeError' ) ) |
| 1721 |
.always( () => { |
| 1722 |
this.serializing = null; |
| 1723 |
} ); |
| 1724 |
|
| 1725 |
if ( callback ) { |
| 1726 |
OO.ui.warnDeprecation( 'Passing a callback to ve.init.mw.ArticleTarget#serialize is deprecated. Use the returned promise instead.' ); |
| 1727 |
promise.then( ( data ) => { |
| 1728 |
callback.call( this, data.content ); |
| 1729 |
} ); |
| 1730 |
} |
| 1731 |
|
| 1732 |
return promise; |
| 1733 |
}; |
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
ve.init.mw.ArticleTarget.prototype.getEditNotices = function () { |
| 1741 |
return this.editNotices; |
| 1742 |
}; |
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
ve.init.mw.ArticleTarget.prototype.track = function ( name ) { |
| 1750 |
const mode = this.surface ? this.surface.getMode() : this.getDefaultMode(); |
| 1751 |
ve.track( name, { mode: mode } ); |
| 1752 |
}; |
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
ve.init.mw.ArticleTarget.prototype.createSurface = function ( dmDoc, config ) { |
| 1758 |
const sections = dmDoc.getNodesByType( 'section' ); |
| 1759 |
let attachedRoot; |
| 1760 |
if ( sections.length && sections.length === 1 ) { |
| 1761 |
attachedRoot = sections[ 0 ]; |
| 1762 |
if ( !attachedRoot.isSurfaceable() ) { |
| 1763 |
throw new Error( 'Not a surfaceable node' ); |
| 1764 |
} |
| 1765 |
} |
| 1766 |
|
| 1767 |
|
| 1768 |
const surface = ve.init.mw.ArticleTarget.super.prototype.createSurface.call( |
| 1769 |
this, |
| 1770 |
dmDoc, |
| 1771 |
ve.extendObject( { attachedRoot: attachedRoot }, config ) |
| 1772 |
); |
| 1773 |
|
| 1774 |
return surface; |
| 1775 |
}; |
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
ve.init.mw.ArticleTarget.prototype.getSurfaceClasses = function () { |
| 1781 |
const classes = ve.init.mw.ArticleTarget.super.prototype.getSurfaceClasses.call( this ); |
| 1782 |
return [ ...classes, 'mw-body-content' ]; |
| 1783 |
}; |
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
ve.init.mw.ArticleTarget.prototype.getSurfaceConfig = function ( config ) { |
| 1789 |
return ve.init.mw.ArticleTarget.super.prototype.getSurfaceConfig.call( this, ve.extendObject( { |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
nullSelectionOnBlur: this.section === 'new', |
| 1794 |
classes: this.getSurfaceClasses() |
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
.concat( this.protectedClasses ) |
| 1800 |
|
| 1801 |
.filter( ( c ) => c ) |
| 1802 |
}, config ) ); |
| 1803 |
}; |
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
ve.init.mw.ArticleTarget.prototype.teardown = function () { |
| 1809 |
if ( !this.teardownPromise ) { |
| 1810 |
const surface = this.getSurface(); |
| 1811 |
|
| 1812 |
|
| 1813 |
if ( this.$saveAccessKeyElements ) { |
| 1814 |
this.$saveAccessKeyElements.attr( 'accesskey', ve.msg( 'accesskey-save' ) ); |
| 1815 |
this.$saveAccessKeyElements = null; |
| 1816 |
} |
| 1817 |
if ( surface ) { |
| 1818 |
|
| 1819 |
surface.getModel().disconnect( this ); |
| 1820 |
} |
| 1821 |
|
| 1822 |
let saveDialogPromise = ve.createDeferred().resolve().promise(); |
| 1823 |
if ( this.saveDialog ) { |
| 1824 |
if ( this.saveDialog.isOpened() ) { |
| 1825 |
|
| 1826 |
saveDialogPromise = this.saveDialog.close().closed; |
| 1827 |
} |
| 1828 |
|
| 1829 |
this.saveDialog = null; |
| 1830 |
} |
| 1831 |
|
| 1832 |
|
| 1833 |
this.teardownPromise = ve.init.mw.ArticleTarget.super.prototype.teardown.call( this ).then( () => saveDialogPromise.then( () => { |
| 1834 |
mw.hook( 've.deactivationComplete' ).fire( this.edited ); |
| 1835 |
} ) ); |
| 1836 |
} |
| 1837 |
return this.teardownPromise; |
| 1838 |
}; |
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
ve.init.mw.ArticleTarget.prototype.tryTeardown = function ( noPrompt, trackMechanism ) { |
| 1850 |
if ( !noPrompt && this.edited && mw.user.options.get( 'useeditwarning' ) ) { |
| 1851 |
return this.getSurface().dialogs.openWindow( 'abandonedit' ) |
| 1852 |
.closed.then( ( data ) => { |
| 1853 |
if ( data && data.action === 'discard' ) { |
| 1854 |
return this.teardown( trackMechanism ); |
| 1855 |
} |
| 1856 |
return ve.createDeferred().reject().promise(); |
| 1857 |
} ); |
| 1858 |
} else { |
| 1859 |
return this.teardown( trackMechanism ); |
| 1860 |
} |
| 1861 |
}; |
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
ve.init.mw.ArticleTarget.prototype.setupToolbar = function () { |
| 1867 |
|
| 1868 |
ve.init.mw.ArticleTarget.super.prototype.setupToolbar.apply( this, arguments ); |
| 1869 |
|
| 1870 |
this.setupToolbarSaveButton(); |
| 1871 |
this.updateToolbarSaveButtonState(); |
| 1872 |
|
| 1873 |
if ( this.saveDialog ) { |
| 1874 |
this.editSummaryValue = this.saveDialog.editSummaryInput.getValue(); |
| 1875 |
this.saveDialog.disconnect( this ); |
| 1876 |
this.saveDialog = null; |
| 1877 |
} |
| 1878 |
}; |
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
ve.init.mw.ArticleTarget.prototype.getSaveButtonLabel = function ( startProcess, forceShort ) { |
| 1888 |
const suffix = startProcess ? '-start' : ''; |
| 1889 |
|
| 1890 |
if ( forceShort || OO.ui.isMobile() ) { |
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
if ( mw.config.get( 'wgEditSubmitButtonLabelPublish' ) ) { |
| 1897 |
return OO.ui.deferMsg( 'visualeditor-savedialog-label-publish-short' + suffix ); |
| 1898 |
} |
| 1899 |
|
| 1900 |
return OO.ui.deferMsg( 'visualeditor-savedialog-label-save-short' + suffix ); |
| 1901 |
} |
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
if ( mw.config.get( 'wgEditSubmitButtonLabelPublish' ) ) { |
| 1913 |
return OO.ui.deferMsg( ( !this.pageExists ? 'publishpage' : 'publishchanges' ) + suffix ); |
| 1914 |
} |
| 1915 |
|
| 1916 |
return OO.ui.deferMsg( ( !this.pageExists ? 'savearticle' : 'savechanges' ) + suffix ); |
| 1917 |
}; |
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
ve.init.mw.ArticleTarget.prototype.setupToolbarSaveButton = null; |
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
ve.init.mw.ArticleTarget.prototype.isSaveable = function () { |
| 1933 |
const surface = this.getSurface(); |
| 1934 |
if ( !surface ) { |
| 1935 |
|
| 1936 |
return false; |
| 1937 |
} |
| 1938 |
|
| 1939 |
this.edited = |
| 1940 |
|
| 1941 |
this.fromEditedState || |
| 1942 |
|
| 1943 |
surface.getModel().hasBeenModified() || |
| 1944 |
|
| 1945 |
( !!this.sectionTitle && this.sectionTitle.getValue() !== '' ); |
| 1946 |
|
| 1947 |
return this.edited || this.restoring; |
| 1948 |
}; |
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
ve.init.mw.ArticleTarget.prototype.updateToolbarSaveButtonState = function () { |
| 1954 |
|
| 1955 |
|
| 1956 |
this.toolbarSaveButton.onUpdateState(); |
| 1957 |
}; |
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
ve.init.mw.ArticleTarget.prototype.showSaveDialog = function ( action, checkboxName ) { |
| 1968 |
let firstLoad = false; |
| 1969 |
|
| 1970 |
if ( !this.isSaveable() || this.saveDialogIsOpening ) { |
| 1971 |
return; |
| 1972 |
} |
| 1973 |
|
| 1974 |
const currentWindow = this.getSurface().getDialogs().getCurrentWindow(); |
| 1975 |
if ( currentWindow && currentWindow.constructor.static.name === 'mwSave' && ( action === 'save' || action === null ) ) { |
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
currentWindow.executeAction( 'save' ); |
| 1981 |
return; |
| 1982 |
} |
| 1983 |
|
| 1984 |
this.saveDialogIsOpening = true; |
| 1985 |
|
| 1986 |
const saveProcess = new OO.ui.Process(); |
| 1987 |
mw.hook( 've.preSaveProcess' ).fire( saveProcess, this ); |
| 1988 |
|
| 1989 |
this.emit( 'saveWorkflowBegin' ); |
| 1990 |
|
| 1991 |
saveProcess.execute().done( () => { |
| 1992 |
|
| 1993 |
this.prepareCacheKey( this.getDocToSave() ); |
| 1994 |
|
| 1995 |
|
| 1996 |
this.getSurface().getDialogs().getWindow( 'mwSave' ).done( ( win ) => { |
| 1997 |
const windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() ); |
| 1998 |
|
| 1999 |
if ( !this.saveDialog ) { |
| 2000 |
this.saveDialog = win; |
| 2001 |
firstLoad = true; |
| 2002 |
|
| 2003 |
|
| 2004 |
this.saveDialog.connect( this, { |
| 2005 |
save: 'onSaveDialogSave', |
| 2006 |
review: 'onSaveDialogReview', |
| 2007 |
preview: 'onSaveDialogPreview', |
| 2008 |
resolve: 'onSaveDialogResolveConflict', |
| 2009 |
retry: 'onSaveDialogRetry', |
| 2010 |
|
| 2011 |
close: [ 'emit', 'saveWorkflowEnd' ] |
| 2012 |
} ); |
| 2013 |
|
| 2014 |
|
| 2015 |
this.saveDialog.$element.append( this.$saveDialogOverlay ); |
| 2016 |
} |
| 2017 |
|
| 2018 |
const data = this.getSaveDialogOpeningData(); |
| 2019 |
|
| 2020 |
if ( |
| 2021 |
( action === 'review' && !data.canReview ) || |
| 2022 |
( action === 'preview' && !data.canPreview ) |
| 2023 |
) { |
| 2024 |
this.saveDialogIsOpening = false; |
| 2025 |
return; |
| 2026 |
} |
| 2027 |
|
| 2028 |
if ( firstLoad ) { |
| 2029 |
for ( const name in this.checkboxesByName ) { |
| 2030 |
if ( this.initialCheckboxes[ name ] !== undefined ) { |
| 2031 |
this.checkboxesByName[ name ].setSelected( this.initialCheckboxes[ name ] ); |
| 2032 |
} |
| 2033 |
} |
| 2034 |
} |
| 2035 |
|
| 2036 |
let checkbox; |
| 2037 |
if ( checkboxName && ( checkbox = this.checkboxesByName[ checkboxName ] ) ) { |
| 2038 |
const isSelected = !checkbox.isSelected(); |
| 2039 |
|
| 2040 |
setTimeout( () => { |
| 2041 |
checkbox.setSelected( isSelected ); |
| 2042 |
} ); |
| 2043 |
} |
| 2044 |
|
| 2045 |
|
| 2046 |
if ( action === 'review' || action === 'preview' ) { |
| 2047 |
data.initialPanel = action; |
| 2048 |
} |
| 2049 |
|
| 2050 |
|
| 2051 |
const openPromise = windowAction.open( 'mwSave', data, action ); |
| 2052 |
if ( openPromise ) { |
| 2053 |
openPromise.always( () => { |
| 2054 |
this.saveDialogIsOpening = false; |
| 2055 |
} ); |
| 2056 |
} |
| 2057 |
} ); |
| 2058 |
} ).fail( () => { |
| 2059 |
this.saveDialogIsOpening = false; |
| 2060 |
} ); |
| 2061 |
}; |
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
ve.init.mw.ArticleTarget.prototype.getSaveDialogOpeningData = function () { |
| 2069 |
const mode = this.getSurface().getMode(); |
| 2070 |
return { |
| 2071 |
canPreview: mode === 'source', |
| 2072 |
canReview: !( mode === 'source' && this.section === 'new' ), |
| 2073 |
sectionTitle: this.sectionTitle && this.sectionTitle.getValue(), |
| 2074 |
saveButtonLabel: this.getSaveButtonLabel(), |
| 2075 |
copyrightWarning: this.copyrightWarning, |
| 2076 |
checkboxFields: this.checkboxFields, |
| 2077 |
checkboxesByName: this.checkboxesByName |
| 2078 |
}; |
| 2079 |
}; |
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
ve.init.mw.ArticleTarget.prototype.restoreEditSection = function () { |
| 2086 |
const section = this.section !== null ? this.section : this.visibleSection; |
| 2087 |
const surface = this.getSurface(); |
| 2088 |
const mode = surface.getMode(); |
| 2089 |
|
| 2090 |
if ( |
| 2091 |
mode === 'source' || |
| 2092 |
( this.enableVisualSectionEditing && this.section !== null ) |
| 2093 |
) { |
| 2094 |
this.$scrollContainer.scrollTop( 0 ); |
| 2095 |
} |
| 2096 |
|
| 2097 |
if ( section === null || section === 'new' || section === '0' || section === 'T-0' ) { |
| 2098 |
return; |
| 2099 |
} |
| 2100 |
|
| 2101 |
const setExactScrollOffset = this.section === null && this.visibleSection !== null && this.visibleSectionOffset !== null, |
| 2102 |
|
| 2103 |
|
| 2104 |
goToStartOfHeading = this.section !== null && !this.enableVisualSectionEditing, |
| 2105 |
setEditSummary = this.section !== null; |
| 2106 |
|
| 2107 |
let headingText; |
| 2108 |
if ( mode === 'visual' ) { |
| 2109 |
const dmDoc = surface.getModel().getDocument(); |
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
let headingModel; |
| 2114 |
dmDoc.getNodesByType( 'mwHeading' ).some( ( heading ) => { |
| 2115 |
const domElements = heading.getOriginalDomElements( dmDoc.getStore() ); |
| 2116 |
if ( |
| 2117 |
domElements && domElements[ 0 ].nodeType === Node.ELEMENT_NODE && |
| 2118 |
domElements[ 0 ].getAttribute( 'data-mw-section-id' ) === section |
| 2119 |
) { |
| 2120 |
headingModel = heading; |
| 2121 |
return true; |
| 2122 |
} |
| 2123 |
return false; |
| 2124 |
} ); |
| 2125 |
if ( headingModel ) { |
| 2126 |
const headingView = surface.getView().getDocument().getDocumentNode().getNodeFromOffset( headingModel.getRange().start ); |
| 2127 |
if ( setEditSummary && !new URL( location.href ).searchParams.has( 'summary' ) ) { |
| 2128 |
headingText = headingView.$element.text(); |
| 2129 |
} |
| 2130 |
if ( setExactScrollOffset ) { |
| 2131 |
this.scrollToHeading( headingView, this.visibleSectionOffset ); |
| 2132 |
} else if ( goToStartOfHeading ) { |
| 2133 |
this.goToHeading( headingView ); |
| 2134 |
} |
| 2135 |
} |
| 2136 |
} else if ( mode === 'source' && setEditSummary ) { |
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
headingText = surface.getModel().getDocument().data.getText( |
| 2142 |
false, |
| 2143 |
surface.getModel().getDocument().getDocumentNode().children[ 0 ].getRange() |
| 2144 |
) |
| 2145 |
|
| 2146 |
.replace( /^\s*=+\s*(.*?)\s*=+\s*$/, '$1' ) |
| 2147 |
|
| 2148 |
.replace( /\[\[:?([^[|]+)\|([^[]+)\]\]/g, '$2' ) |
| 2149 |
.replace( /\[\[:?([^[]+)\|?\]\]/g, '$1' ) |
| 2150 |
.replace( new RegExp( '\\[(?:' + ve.init.platform.getUnanchoredExternalLinkUrlProtocolsRegExp().source + ')([^ ]+?) ([^\\[]+)\\]', 'ig' ), '$3' ) |
| 2151 |
|
| 2152 |
.replace( /<[^>]+?>/g, '' ); |
| 2153 |
} |
| 2154 |
if ( headingText ) { |
| 2155 |
this.initialEditSummary = |
| 2156 |
'/* ' + |
| 2157 |
ve.graphemeSafeSubstring( headingText, 0, 244 ) + |
| 2158 |
' */ '; |
| 2159 |
} |
| 2160 |
}; |
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
ve.init.mw.ArticleTarget.prototype.goToHeading = function ( headingNode ) { |
| 2168 |
const surface = this.getSurface(), |
| 2169 |
surfaceView = surface.getView(); |
| 2170 |
|
| 2171 |
let offsetNode = headingNode, |
| 2172 |
lastHeadingLevel = -1; |
| 2173 |
let nextNode; |
| 2174 |
|
| 2175 |
while ( offsetNode instanceof ve.ce.HeadingNode && offsetNode.getModel().getAttribute( 'level' ) > lastHeadingLevel ) { |
| 2176 |
lastHeadingLevel = offsetNode.getModel().getAttribute( 'level' ); |
| 2177 |
|
| 2178 |
nextNode = offsetNode.parent.children[ offsetNode.parent.children.indexOf( offsetNode ) + 1 ]; |
| 2179 |
if ( !nextNode ) { |
| 2180 |
break; |
| 2181 |
} |
| 2182 |
offsetNode = nextNode; |
| 2183 |
} |
| 2184 |
const startOffset = offsetNode.getModel().getOffset(); |
| 2185 |
|
| 2186 |
function setSelection() { |
| 2187 |
surfaceView.selectRelativeSelectableContentOffset( startOffset, 1 ); |
| 2188 |
} |
| 2189 |
|
| 2190 |
if ( surfaceView.isFocused() ) { |
| 2191 |
setSelection(); |
| 2192 |
|
| 2193 |
|
| 2194 |
$( OO.ui.Element.static.getClosestScrollableContainer( surfaceView.$element[ 0 ] ) ).stop( true ); |
| 2195 |
} else { |
| 2196 |
|
| 2197 |
|
| 2198 |
surfaceView.once( 'focus', setSelection ); |
| 2199 |
} |
| 2200 |
this.scrollToHeading( headingNode ); |
| 2201 |
}; |
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
ve.init.mw.ArticleTarget.prototype.scrollToHeading = function ( headingNode, headingOffset ) { |
| 2211 |
this.$scrollContainer.scrollTop( |
| 2212 |
headingNode.$element.offset().top - parseInt( headingNode.$element.css( 'margin-top' ) ) - |
| 2213 |
( this.getSurface().padding.top + ( headingOffset || 0 ) ) ); |
| 2214 |
}; |
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
ve.init.mw.ArticleTarget.prototype.getSectionHashFromPage = function () { |
| 2224 |
|
| 2225 |
|
| 2226 |
const $sections = this.$editableContent.find( '.mw-editsection' ); |
| 2227 |
|
| 2228 |
let section; |
| 2229 |
if ( this.section === 'new' ) { |
| 2230 |
|
| 2231 |
section = $sections.length; |
| 2232 |
} else { |
| 2233 |
section = this.section; |
| 2234 |
} |
| 2235 |
if ( section > 0 ) { |
| 2236 |
|
| 2237 |
const $section = $sections.eq( section - 1 ) |
| 2238 |
.closest( '.mw-heading, h1, h2, h3, h4, h5, h6' ) |
| 2239 |
.find( 'h1, h2, h3, h4, h5, h6, .mw-headline' ); |
| 2240 |
|
| 2241 |
if ( $section.length && $section.attr( 'id' ) ) { |
| 2242 |
return '#' + $section.attr( 'id' ); |
| 2243 |
} |
| 2244 |
} |
| 2245 |
return ''; |
| 2246 |
}; |
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
ve.init.mw.ArticleTarget.prototype.switchToWikitextEditor = function ( modified ) { |
| 2254 |
|
| 2255 |
|
| 2256 |
if ( modified ) { |
| 2257 |
this.section = null; |
| 2258 |
} |
| 2259 |
|
| 2260 |
if ( this.isModeAvailable( 'source' ) ) { |
| 2261 |
if ( !modified ) { |
| 2262 |
this.reloadSurface( 'source' ); |
| 2263 |
} else { |
| 2264 |
const dataPromise = this.getWikitextDataPromiseForDoc( modified ); |
| 2265 |
this.reloadSurface( 'source', dataPromise ); |
| 2266 |
} |
| 2267 |
} else { |
| 2268 |
this.switchToFallbackWikitextEditor( modified ); |
| 2269 |
} |
| 2270 |
}; |
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
ve.init.mw.ArticleTarget.prototype.getWikitextDataPromiseForDoc = function ( modified ) { |
| 2279 |
return this.serialize( this.getDocToSave() ).then( ( data ) => { |
| 2280 |
|
| 2281 |
data.etag = this.etag; |
| 2282 |
data.fromEditedState = modified; |
| 2283 |
data.notices = this.remoteNotices; |
| 2284 |
data.protectedClasses = this.protectedClasses; |
| 2285 |
data.basetimestamp = this.baseTimeStamp; |
| 2286 |
data.starttimestamp = this.startTimeStamp; |
| 2287 |
data.oldid = this.revid; |
| 2288 |
data.canEdit = this.canEdit; |
| 2289 |
data.wouldautocreate = this.wouldautocreate; |
| 2290 |
data.checkboxesDef = this.checkboxesDef; |
| 2291 |
|
| 2292 |
return { visualeditoredit: data }; |
| 2293 |
} ); |
| 2294 |
}; |
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
ve.init.mw.ArticleTarget.prototype.switchToFallbackWikitextEditor = function () { |
| 2303 |
return ve.createDeferred().resolve().promise(); |
| 2304 |
}; |
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
ve.init.mw.ArticleTarget.prototype.switchToVisualEditor = function () { |
| 2310 |
if ( !this.edited ) { |
| 2311 |
this.reloadSurface( 'visual' ); |
| 2312 |
return; |
| 2313 |
} |
| 2314 |
|
| 2315 |
const url = new URL( location.href ); |
| 2316 |
const dataPromise = mw.libs.ve.targetLoader.requestParsoidData( this.getPageName(), { |
| 2317 |
oldId: this.revid, |
| 2318 |
targetName: this.constructor.static.trackingName, |
| 2319 |
modified: this.edited, |
| 2320 |
wikitext: this.getDocToSave(), |
| 2321 |
section: this.section, |
| 2322 |
editintro: url.searchParams.get( 'editintro' ), |
| 2323 |
preload: url.searchParams.get( 'preload' ), |
| 2324 |
preloadparams: mw.util.getArrayParam( 'preloadparams', url.searchParams ) |
| 2325 |
} ); |
| 2326 |
|
| 2327 |
this.reloadSurface( 'visual', dataPromise ); |
| 2328 |
}; |
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
ve.init.mw.ArticleTarget.prototype.switchToWikitextSection = function ( section, noPrompt ) { |
| 2338 |
if ( section === this.section ) { |
| 2339 |
return; |
| 2340 |
} |
| 2341 |
let promise; |
| 2342 |
if ( !noPrompt && this.edited && mw.user.options.get( 'useeditwarning' ) ) { |
| 2343 |
promise = this.getSurface().dialogs.openWindow( 'abandonedit' ) |
| 2344 |
.closed.then( ( data ) => data && data.action === 'discard' ); |
| 2345 |
} else { |
| 2346 |
promise = ve.createDeferred().resolve( true ).promise(); |
| 2347 |
} |
| 2348 |
promise.then( ( confirmed ) => { |
| 2349 |
if ( confirmed ) { |
| 2350 |
|
| 2351 |
|
| 2352 |
if ( this.saveDialog ) { |
| 2353 |
this.saveDialog.reset(); |
| 2354 |
} |
| 2355 |
|
| 2356 |
this.initialEditSummary = null; |
| 2357 |
this.section = section; |
| 2358 |
this.reloadSurface( 'source' ); |
| 2359 |
this.updateTabs(); |
| 2360 |
} |
| 2361 |
} ); |
| 2362 |
}; |
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
ve.init.mw.ArticleTarget.prototype.reloadSurface = function ( newMode, dataPromise ) { |
| 2371 |
this.setDefaultMode( newMode ); |
| 2372 |
this.clearDiff(); |
| 2373 |
const promise = this.load( dataPromise ); |
| 2374 |
this.getSurface().createProgress( |
| 2375 |
promise, |
| 2376 |
ve.msg( newMode === 'source' ? 'visualeditor-mweditmodesource-progress' : 'visualeditor-mweditmodeve-progress' ), |
| 2377 |
true |
| 2378 |
); |
| 2379 |
}; |
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
ve.init.mw.ArticleTarget.prototype.updateRedirectInterface = function ( $sub, $msg ) { |
| 2388 |
|
| 2389 |
|
| 2390 |
const $currentSub = $( '#redirectsub' ); |
| 2391 |
if ( $currentSub.length ) { |
| 2392 |
if ( $sub.length ) { |
| 2393 |
$currentSub.replaceWith( $sub ); |
| 2394 |
} else { |
| 2395 |
$currentSub.prev().filter( 'br' ).remove(); |
| 2396 |
$currentSub.remove(); |
| 2397 |
} |
| 2398 |
} else { |
| 2399 |
const $subtitle = $( '#contentSub' ); |
| 2400 |
if ( $sub.length ) { |
| 2401 |
if ( $subtitle.children().length ) { |
| 2402 |
$subtitle.append( $( '<br>' ) ); |
| 2403 |
} |
| 2404 |
$subtitle.append( $sub ); |
| 2405 |
} |
| 2406 |
} |
| 2407 |
|
| 2408 |
if ( $msg.length ) { |
| 2409 |
$msg |
| 2410 |
|
| 2411 |
.addClass( 've-redirect-header' ) |
| 2412 |
.on( 'click', ( e ) => { |
| 2413 |
const windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() ); |
| 2414 |
windowAction.open( 'meta', { page: 'settings' } ); |
| 2415 |
e.preventDefault(); |
| 2416 |
} ); |
| 2417 |
} |
| 2418 |
|
| 2419 |
const $currentMsg = $( '.ve-redirect-header' ); |
| 2420 |
if ( $currentMsg.length ) { |
| 2421 |
$currentMsg.replaceWith( $msg ); |
| 2422 |
} else { |
| 2423 |
|
| 2424 |
$( '#mw-content-text' ).before( $msg ); |
| 2425 |
} |
| 2426 |
}; |
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
ve.init.mw.ArticleTarget.prototype.setFakeRedirectInterface = function ( title ) { |
| 2434 |
this.isRedirect = !!title; |
| 2435 |
this.updateRedirectInterface( |
| 2436 |
title ? this.constructor.static.buildRedirectSub() : $(), |
| 2437 |
title ? this.constructor.static.buildRedirectMsg( title ) : $() |
| 2438 |
); |
| 2439 |
}; |
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
ve.init.mw.ArticleTarget.prototype.setRealRedirectInterface = function () { |
| 2445 |
this.updateRedirectInterface( |
| 2446 |
mw.config.get( 'wgIsRedirect' ) ? this.constructor.static.buildRedirectSub() : $(), |
| 2447 |
|
| 2448 |
$() |
| 2449 |
); |
| 2450 |
}; |
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
ve.init.mw.ArticleTarget.prototype.renderCategories = function ( categoryItems ) { |
| 2461 |
const promises = [], |
| 2462 |
categories = { hidden: {}, normal: {} }; |
| 2463 |
categoryItems.forEach( ( categoryItem, index ) => { |
| 2464 |
const attributes = ve.copy( ve.getProp( categoryItem, 'element', 'attributes' ) ); |
| 2465 |
attributes.index = index; |
| 2466 |
promises.push( ve.init.platform.linkCache.get( attributes.category ).done( ( result ) => { |
| 2467 |
const group = result.hidden ? categories.hidden : categories.normal; |
| 2468 |
|
| 2469 |
if ( !group[ attributes.category ] || group[ attributes.category ].index > attributes.index ) { |
| 2470 |
group[ attributes.category ] = attributes; |
| 2471 |
} |
| 2472 |
} ) ); |
| 2473 |
} ); |
| 2474 |
return ve.promiseAll( promises ).then( () => { |
| 2475 |
const $output = $( '<div>' ).addClass( 'catlinks' ); |
| 2476 |
function renderPageLink( page ) { |
| 2477 |
const title = mw.Title.newFromText( page ), |
| 2478 |
$link = $( '<a>' ).attr( 'rel', 'mw:WikiLink' ).attr( 'href', title.getUrl() ).text( title.getMainText() ); |
| 2479 |
|
| 2480 |
|
| 2481 |
ve.init.platform.linkCache.styleElement( title.getPrefixedText(), $link, false ); |
| 2482 |
return $link; |
| 2483 |
} |
| 2484 |
function renderPageLinks( pages ) { |
| 2485 |
const $list = $( '<ul>' ); |
| 2486 |
for ( let i = 0; i < pages.length; i++ ) { |
| 2487 |
const $link = renderPageLink( pages[ i ] ); |
| 2488 |
$list.append( $( '<li>' ).append( $link ) ); |
| 2489 |
} |
| 2490 |
return $list; |
| 2491 |
} |
| 2492 |
function categorySort( group, a, b ) { |
| 2493 |
return group[ a ].index - group[ b ].index; |
| 2494 |
} |
| 2495 |
const categoriesNormal = Object.keys( categories.normal ); |
| 2496 |
if ( categoriesNormal.length ) { |
| 2497 |
categoriesNormal.sort( categorySort.bind( null, categories.normal ) ); |
| 2498 |
const $normal = $( '<div>' ).addClass( 'mw-normal-catlinks' ); |
| 2499 |
const $pageLink = renderPageLink( ve.msg( 'pagecategorieslink' ) ).text( ve.msg( 'pagecategories', categoriesNormal.length ) ); |
| 2500 |
const $pageLinks = renderPageLinks( categoriesNormal ); |
| 2501 |
$normal.append( |
| 2502 |
$pageLink, |
| 2503 |
$( document.createTextNode( ve.msg( 'colon-separator' ) ) ), |
| 2504 |
$pageLinks |
| 2505 |
); |
| 2506 |
$output.append( $normal ); |
| 2507 |
} |
| 2508 |
const categoriesHidden = Object.keys( categories.hidden ); |
| 2509 |
if ( categoriesHidden.length ) { |
| 2510 |
categoriesHidden.sort( categorySort.bind( null, categories.hidden ) ); |
| 2511 |
const $hidden = $( '<div>' ).addClass( 'mw-hidden-catlinks' ); |
| 2512 |
if ( mw.user.options.get( 'showhiddencats' ) ) { |
| 2513 |
$hidden.addClass( 'mw-hidden-cats-user-shown' ); |
| 2514 |
} else if ( mw.config.get( 'wgNamespaceIds' ).category === mw.config.get( 'wgNamespaceNumber' ) ) { |
| 2515 |
$hidden.addClass( 'mw-hidden-cats-ns-shown' ); |
| 2516 |
} else { |
| 2517 |
$hidden.addClass( 'mw-hidden-cats-hidden' ); |
| 2518 |
} |
| 2519 |
const $hiddenPageLinks = renderPageLinks( categoriesHidden ); |
| 2520 |
$hidden.append( |
| 2521 |
$( document.createTextNode( ve.msg( 'hidden-categories', categoriesHidden.length ) ) ), |
| 2522 |
$( document.createTextNode( ve.msg( 'colon-separator' ) ) ), |
| 2523 |
$hiddenPageLinks |
| 2524 |
); |
| 2525 |
$output.append( $hidden ); |
| 2526 |
} |
| 2527 |
return $output; |
| 2528 |
} ); |
| 2529 |
}; |
| 2530 |
|
| 2531 |
|
| 2532 |
ve.ui.windowFactory.register( mw.widgets.AbandonEditDialog ); |