diff --git a/extension.json b/extension.json index ec4080998f..10b4b94e55 100644 --- a/extension.json +++ b/extension.json @@ -520,7 +520,8 @@ ], "messages" : [ "collabpad", - "collabpad-doctitle" + "collabpad-doctitle", + "collabpad-import-subtitle" ], "targets": [ "desktop", diff --git a/i18n/ve-mw/en.json b/i18n/ve-mw/en.json index 1f095c9958..5e9ec857f7 100644 --- a/i18n/ve-mw/en.json +++ b/i18n/ve-mw/en.json @@ -63,6 +63,7 @@ "apihelp-visualeditoredit-param-wikitext": "The wikitext to act with.", "apihelp-visualeditoredit-summary": "Save an HTML5 page to MediaWiki (converted to wikitext via the Parsoid service).", "collabpad-doctitle": "CollabPad: $1", + "collabpad-import-subtitle": "Imported from $1", "collabpad": "CollabPad", "tooltip-ca-createsource": "Create the source code of this page", "tooltip-ca-edit": "Edit this page using wikitext", diff --git a/i18n/ve-mw/qqq.json b/i18n/ve-mw/qqq.json index 57f7ad2054..9c2c4972e4 100644 --- a/i18n/ve-mw/qqq.json +++ b/i18n/ve-mw/qqq.json @@ -77,6 +77,7 @@ "apihelp-visualeditoredit-param-wikitext": "{{doc-apihelp-param|visualeditoredit|wikitext}}", "apihelp-visualeditoredit-summary": "{{doc-apihelp-summary|visualeditoredit}}", "collabpad-doctitle": "Name of CollabPad special page with a document subtitle", + "collabpad-import-subtitle": "Subtitle of CollabPad page, linking to the page the content was imported from", "collabpad": "Name of CollabPad special page", "tooltip-ca-createsource": "Tooltip of the {{msg-mw|Visualeditor-ca-createsource}} tab, used if the page does not exist.\n\nSee also:\n* {{msg-mw|Tooltip-ca-editsource}} - tooltip of the {{msg-mw|Visualeditor-ca-editsource}} tab, used if the page already exists", "tooltip-ca-edit": "Over-ridden tooltip of the wikitext \"Edit source\" tab.", diff --git a/modules/ve-mw-collab/ve.init.mw.CollabTarget.js b/modules/ve-mw-collab/ve.init.mw.CollabTarget.js index dec299c4c9..5aa9c68ca4 100644 --- a/modules/ve-mw-collab/ve.init.mw.CollabTarget.js +++ b/modules/ve-mw-collab/ve.init.mw.CollabTarget.js @@ -27,7 +27,7 @@ ve.init.mw.CollabTarget = function VeInitMwCollabTarget( title, rebaserUrl, conf this.title = title; this.rebaserUrl = rebaserUrl; - this.importTitle = config.importTitle; + this.importTitle = config.importTitle || null; // Parent constructor ve.init.mw.CollabTarget.super.call( this, config ); @@ -101,6 +101,7 @@ ve.init.mw.CollabTarget.prototype.transformPage = function () { */ ve.init.mw.CollabTarget.prototype.restorePage = function () { this.$element.parent().append( this.$originalContent.children() ); + $( '#contentSub' ).empty(); }; /** @@ -175,17 +176,25 @@ ve.init.mw.CollabTarget.prototype.setSurface = function ( surface ) { ); synchronizer.once( 'initDoc', function () { - var initPromise; + var initPromise, title; if ( target.importTitle && !surface.getModel().getDocument().getCompleteHistoryLength() ) { initPromise = mw.libs.ve.targetLoader.requestParsoidData( target.importTitle.toString(), { targetName: 'collabpad' } ).then( function ( response ) { - var doc, dmDoc, + var doc, dmDoc, fragment, content = ve.getProp( response, 'visualeditor', 'content' ); if ( content ) { doc = target.constructor.static.parseDocument( content ); dmDoc = target.constructor.static.createModelFromDom( doc ); - surface.getModel().getLinearFragment( new ve.Range( 0, 2 ) ).insertDocument( dmDoc ); + fragment = surface.getModel().getLinearFragment( new ve.Range( 0, 2 ) ); + fragment.insertDocument( dmDoc ); + // Store the importTitle as a hidden meta item + if ( target.importTitle ) { + fragment.collapseToEnd().insertContent( [ + { type: 'alienMeta', attributes: { importTitle: target.importTitle.toString() } }, + { type: '/alienMeta' } + ] ); + } surface.getModel().selectFirstContentOffset(); } else { // Import failed @@ -205,6 +214,17 @@ ve.init.mw.CollabTarget.prototype.setSurface = function ( surface ) { surface.getModel().selectFirstContentOffset(); // Resolve progress bar importDeferred.resolve(); + if ( ( title = target.getImportTitle() ) ) { + $( '#contentSub' ).html( + ve.htmlMsg( + 'collabpad-import-subtitle', + $( '' ).attr( 'href', title.getUrl() ).text( title.getMainText() ) + ) + ); + ve.targetLinksToNewWindow( $( '#contentSub' )[ 0 ] ); + } else { + $( '#contentSub' ).empty(); + } } ); } ); @@ -215,6 +235,28 @@ ve.init.mw.CollabTarget.prototype.setSurface = function ( surface ) { ve.init.mw.CollabTarget.super.prototype.setSurface.apply( this, arguments ); }; +/** + * Get the title of the imported document, if there was one + * + * @return {mw.Title|null} Title of imported document + */ +ve.init.mw.CollabTarget.prototype.getImportTitle = function () { + var surfaceModel, + target = this; + + if ( !this.importTitle ) { + surfaceModel = this.getSurface().getModel(); + surfaceModel.getMetaList().getItemsInGroup( 'misc' ).some( function ( item ) { + var importTitle = item.getAttribute( 'importTitle' ); + if ( importTitle ) { + target.importTitle = mw.Title.newFromText( importTitle ); + return true; + } + } ); + } + return this.importTitle; +}; + /* Registration */ ve.init.mw.targetFactory.register( ve.init.mw.CollabTarget );