mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-23 22:13:34 +00:00
Store importTitle in document, and display in sub heading
Change-Id: I431b721d8af3180b78a565e322a45745d06f67a1
This commit is contained in:
parent
68f83cab37
commit
5be3be4ba4
|
@ -520,7 +520,8 @@
|
|||
],
|
||||
"messages" : [
|
||||
"collabpad",
|
||||
"collabpad-doctitle"
|
||||
"collabpad-doctitle",
|
||||
"collabpad-import-subtitle"
|
||||
],
|
||||
"targets": [
|
||||
"desktop",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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',
|
||||
$( '<a>' ).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 );
|
||||
|
|
Loading…
Reference in a new issue