mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-27 15:50:29 +00:00
Export to page using action=submit
Change-Id: I0d719905203d24a545d9b7dcea5bb9d032f10a76
This commit is contained in:
parent
85b33a9c5f
commit
cb10316a7b
|
@ -455,6 +455,10 @@
|
|||
"oojs-ui.styles.icons-interactions",
|
||||
"oojs-ui.styles.icons-layout"
|
||||
],
|
||||
"messages": [
|
||||
"visualeditor-rebase-client-export",
|
||||
"visualeditor-rebase-client-import-name"
|
||||
],
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
|
|
|
@ -407,6 +407,7 @@
|
|||
"visualeditor-preference-visualdiffpage-info-link": "\/\/www.mediawiki.org\/wiki\/VisualEditor\/Diffs",
|
||||
"visualeditor-preference-visualdiffpage-label": "Visual differences",
|
||||
"visualeditor-quick-access-characters.json": "null",
|
||||
"visualeditor-rebase-client-export": "Export",
|
||||
"visualeditor-rebase-client-import": "Import",
|
||||
"visualeditor-rebase-client-import-name": "Page title",
|
||||
"visualeditor-recreate": "The page has been deleted since you started editing. Press \"$1\" to recreate it.",
|
||||
|
|
|
@ -421,6 +421,7 @@
|
|||
"visualeditor-preference-visualdiffpage-info-link": "{{optional|Used on [[Special:Preferences]] as a link to a page where users can learn about this Beta Feature. Defaults to a page on MediaWiki.org.}}",
|
||||
"visualeditor-preference-visualdiffpage-label": "Used in [[Special:Preferences]].\n\nUsed as label for checkbox to enable the new visual difference mode.\n\nThe description for this checkbox is {{msg-mw|Visualeditor-preference-visualdiffpage-description}}",
|
||||
"visualeditor-quick-access-characters.json": "JSON object mapping character labels to actual characters that can be inserted using the special character inserter.\n{{Identical|Null}}",
|
||||
"visualeditor-rebase-client-export": "Label for button to export a document",
|
||||
"visualeditor-rebase-client-import": "Label for button to import a document from the wiki",
|
||||
"visualeditor-rebase-client-import-name": "Label import document input",
|
||||
"visualeditor-recreate": "Text shown when the editor fails to save the page due to it having been deleted since they opened VE. $1 is the message {{msg-mw|ooui-dialog-process-continue}}.",
|
||||
|
|
|
@ -118,8 +118,7 @@ ve.init.mw.CollabTarget.prototype.surfaceReady = function () {
|
|||
this.getSurface().getView().focus();
|
||||
|
||||
exportButton = new OO.ui.ButtonWidget( {
|
||||
icon: 'wikiText',
|
||||
label: ve.msg( 'visualeditor-savedialog-review-wikitext' ),
|
||||
label: ve.msg( 'visualeditor-rebase-client-export' ),
|
||||
flags: [ 'progressive', 'primary' ]
|
||||
} );
|
||||
exportButton.connect( this, { click: 'onExportButtonClick' } );
|
||||
|
|
|
@ -45,21 +45,51 @@ ve.ui.MWExportWikitextDialog.static.size = 'larger';
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWExportWikitextDialog.prototype.initialize = function () {
|
||||
var panel;
|
||||
var panel,
|
||||
$content = $( '<div>' );
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWExportWikitextDialog.super.prototype.initialize.call( this );
|
||||
|
||||
this.titleInput = new mw.widgets.TitleInputWidget( {
|
||||
value: ve.init.target.getImportTitle()
|
||||
}, { api: ve.init.target.getContentApi() } );
|
||||
this.titleButton = new OO.ui.ButtonWidget( {
|
||||
label: ve.msg( 'visualeditor-rebase-client-export' ),
|
||||
flags: [ 'primary', 'progressive' ]
|
||||
} );
|
||||
this.titleField = new OO.ui.ActionFieldLayout( this.titleInput, this.titleButton, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'visualeditor-rebase-client-import-name' )
|
||||
} );
|
||||
|
||||
this.titleButton.on( 'click', this.export.bind( this ) );
|
||||
|
||||
this.wikitext = new OO.ui.MultilineTextInputWidget( {
|
||||
classes: [ 'mw-editfont-' + mw.user.options.get( 'editfont' ) ],
|
||||
autosize: true,
|
||||
readOnly: true,
|
||||
rows: 20
|
||||
} );
|
||||
this.wikitext.$element.css( 'max-width', 'none' ); // Move to CSS
|
||||
this.wikitextField = new OO.ui.FieldLayout( this.wikitext, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'visualeditor-savedialog-review-wikitext' )
|
||||
} );
|
||||
|
||||
// Move to CSS
|
||||
this.titleField.$element.css( 'max-width', 'none' );
|
||||
this.titleInput.$element.css( 'max-width', 'none' );
|
||||
this.wikitext.$element.css( 'max-width', 'none' );
|
||||
|
||||
$content.append(
|
||||
this.titleField.$element,
|
||||
this.wikitextField.$element
|
||||
);
|
||||
|
||||
panel = new OO.ui.PanelLayout( {
|
||||
padded: true,
|
||||
expanded: false,
|
||||
$content: this.wikitext.$element
|
||||
$content: $content
|
||||
} );
|
||||
this.$body.append( panel.$element );
|
||||
};
|
||||
|
@ -71,11 +101,13 @@ ve.ui.MWExportWikitextDialog.prototype.getSetupProcess = function ( data ) {
|
|||
return ve.ui.MWExportWikitextDialog.super.prototype.getSetupProcess.call( this, data )
|
||||
.next( function () {
|
||||
var dialog = this;
|
||||
this.titleButton.setDisabled( true );
|
||||
this.wikitext.pushPending();
|
||||
ve.init.target.getWikitextFragment( data.surface.getModel().getDocument() ).then( function ( wikitext ) {
|
||||
dialog.wikitext.setValue( wikitext.trim() ).select();
|
||||
dialog.wikitext.setValue( wikitext.trim() );
|
||||
dialog.wikitext.$input.scrollTop( 0 );
|
||||
dialog.wikitext.popPending();
|
||||
dialog.titleButton.setDisabled( false );
|
||||
dialog.updateSize();
|
||||
}, function () {
|
||||
// TODO: Display API errors
|
||||
|
@ -84,6 +116,16 @@ ve.ui.MWExportWikitextDialog.prototype.getSetupProcess = function ( data ) {
|
|||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWExportWikitextDialog.prototype.getReadyProcess = function ( data ) {
|
||||
return ve.ui.MWExportWikitextDialog.super.prototype.getReadyProcess.call( this, data )
|
||||
.next( function () {
|
||||
this.titleInput.focus();
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
@ -94,6 +136,47 @@ ve.ui.MWExportWikitextDialog.prototype.getTeardownProcess = function ( data ) {
|
|||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* Export the document to a specific title
|
||||
*/
|
||||
ve.ui.MWExportWikitextDialog.prototype.export = function () {
|
||||
var key, $form, params,
|
||||
wikitext = this.wikitext.getValue(),
|
||||
title = this.titleInput.getMWTitle(),
|
||||
submitUrl = ( new mw.Uri( title.getUrl() ) )
|
||||
.extend( {
|
||||
action: 'submit',
|
||||
veswitched: 1
|
||||
} );
|
||||
|
||||
$form = $( '<form>' ).attr( { method: 'post', enctype: 'multipart/form-data' } ).addClass( 'oo-ui-element-hidden' );
|
||||
params = {
|
||||
format: 'text/x-wiki',
|
||||
model: 'wikitext',
|
||||
wpTextbox1: wikitext,
|
||||
wpEditToken: ve.init.target.editToken,
|
||||
// MediaWiki function-verification parameters, mostly relevant to the
|
||||
// classic editpage, but still required here:
|
||||
wpUnicodeCheck: 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ',
|
||||
wpUltimateParam: true,
|
||||
wpDiff: true
|
||||
};
|
||||
if ( ve.init.target.getImportTitle().toString() === title.toString() ) {
|
||||
params = ve.extendObject( {
|
||||
oldid: ve.init.target.revid,
|
||||
basetimestamp: ve.init.target.baseTimeStamp,
|
||||
starttimestamp: ve.init.target.startTimeStamp
|
||||
}, params );
|
||||
}
|
||||
// Add params as hidden fields
|
||||
for ( key in params ) {
|
||||
$form.append( $( '<input>' ).attr( { type: 'hidden', name: key, value: params[ key ] } ) );
|
||||
}
|
||||
// Submit the form, mimicking a traditional edit
|
||||
// Firefox requires the form to be attached
|
||||
$form.attr( 'action', submitUrl ).appendTo( 'body' ).submit();
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.windowFactory.register( ve.ui.MWExportWikitextDialog );
|
||||
|
|
|
@ -1614,7 +1614,7 @@ ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = funct
|
|||
this.getDocToSave(),
|
||||
function ( wikitext ) {
|
||||
ve.track( 'mwedit.abort', { type: 'switchwith', mechanism: 'navigate', mode: 'visual' } );
|
||||
target.submitWithSaveFields( { wpDiff: 1, wpAutoSummary: '' }, wikitext );
|
||||
target.submitWithSaveFields( { wpDiff: true, wpAutoSummary: '' }, wikitext );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue