mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Merge "(bug 41865) Save page behavior for oldid"
This commit is contained in:
commit
acc3ae5d8c
|
@ -13,8 +13,13 @@ class ApiVisualEditor extends ApiBase {
|
|||
global $wgVisualEditorParsoidURL, $wgVisualEditorParsoidPrefix,
|
||||
$wgVisualEditorParsoidTimeout;
|
||||
if ( $title->exists() ) {
|
||||
if ( !isset( $parserParams['oldid'] ) ) {
|
||||
// Don't allow race condition where the latest revision ID changes while we are waiting
|
||||
// for a response from Parsoid
|
||||
$parserParams['oldid'] = $title->getLatestRevId();
|
||||
}
|
||||
$revision = Revision::newFromId( $parserParams['oldid'] );
|
||||
if ( $content === false || $revision === null ) {
|
||||
if ( $revision === null ) {
|
||||
return false;
|
||||
}
|
||||
$content = Http::get(
|
||||
|
@ -27,6 +32,9 @@ class ApiVisualEditor extends ApiBase {
|
|||
),
|
||||
$wgVisualEditorParsoidTimeout
|
||||
);
|
||||
if ( $content === false ) {
|
||||
return false;
|
||||
}
|
||||
$timestamp = $revision->getTimestamp();
|
||||
} else {
|
||||
$content = '';
|
||||
|
@ -148,10 +156,6 @@ class ApiVisualEditor extends ApiBase {
|
|||
$parserParams = array();
|
||||
if ( is_numeric( $params['oldid'] ) ) {
|
||||
$parserParams['oldid'] = intval( $params['oldid'] );
|
||||
} else {
|
||||
// Don't allow race condition where the latest revision ID changes while we are waiting
|
||||
// for a response from Parsoid
|
||||
$parserParams['oldid'] = $page->getLatestRevId();
|
||||
}
|
||||
|
||||
if ( $params['paction'] === 'parse' ) {
|
||||
|
|
|
@ -10,9 +10,11 @@ $messages['en'] = array(
|
|||
'visualeditor-preference-enable' => 'Enable VisualEditor (main namespace only)',
|
||||
'visualeditor-notification-saved' => 'Your changes to $1 have been saved.',
|
||||
'visualeditor-notification-created' => '$1 has been created.',
|
||||
'visualeditor-notification-restored' => '$1 has been restored.',
|
||||
'visualeditor-ca-editsource' => 'Edit source',
|
||||
'visualeditor-ca-ve-edit' => 'VisualEditor',
|
||||
'visualeditor-ca-ve-create' => 'VisualEditor',
|
||||
'visualeditor-restore-page' => 'Restore page',
|
||||
'visualeditor-editnotices-button' => '$1 {{PLURAL:$1|notice|notices}}',
|
||||
'tooltip-ca-ve-edit' => 'Edit this page with VisualEditor',
|
||||
'accesskey-ca-ve-edit' => '',
|
||||
|
@ -63,8 +65,9 @@ $messages['en'] = array(
|
|||
$messages['qqq'] = array(
|
||||
'visualeditor' => 'The name of the VisualEditor extension',
|
||||
'visualeditor-desc' => '{{desc}}',
|
||||
'visualeditor-notification-saved' => '$1 is a page name.',
|
||||
'visualeditor-notification-created' => '$1 is a page name.',
|
||||
'visualeditor-notification-saved' => 'Shown after a user saves a page, $1 is a page name.',
|
||||
'visualeditor-notification-created' => 'Shown after a user creates a page, $1 is a page name.',
|
||||
'visualeditor-notification-restored' => 'Shown after a user restores a page to a previous revision, $1 is a page name.',
|
||||
'visualeditor-ca-editsource' => '{{Optional}}
|
||||
Text for the edit source link in the tab dropdown
|
||||
{{Identical|visualeditor}}',
|
||||
|
@ -72,6 +75,7 @@ Text for the edit source link in the tab dropdown
|
|||
Link text of the dedicated VisualEditor Edit tab.
|
||||
{{Identical|visualeditor}}',
|
||||
'visualeditor-ca-ve-create' => 'Link text of the dedicated VisualEditor Create tab.',
|
||||
'visualeditor-restore-page' => 'Label text for save button when the user is editing a previous revision',
|
||||
'visualeditor-editnotices-button' => 'Text of button in the toolbar that shows edit notices (such as MediaWiki:editnotice-0 and [[MediaWiki:editnotice-8/en]]) as a pop-up',
|
||||
'tooltip-ca-ve-edit' => 'Tooltip of the dedicated VisualEditor Edit tab.',
|
||||
'accesskey-ca-ve-edit' => '{{Ignore}}',
|
||||
|
|
|
@ -121,6 +121,7 @@ $wgResourceModules += array(
|
|||
'messages' => array(
|
||||
'minoredit',
|
||||
'savearticle',
|
||||
'visualeditor-restore-page',
|
||||
'watchthis',
|
||||
'tooltip-save',
|
||||
'copyrightwarning',
|
||||
|
@ -136,6 +137,7 @@ $wgResourceModules += array(
|
|||
'visualeditor-ca-ve-create',
|
||||
'visualeditor-notification-saved',
|
||||
'visualeditor-notification-created',
|
||||
'visualeditor-notification-restored',
|
||||
'visualeditor-ca-editsource',
|
||||
'visualeditor-loadwarning',
|
||||
'visualeditor-editsummary',
|
||||
|
|
|
@ -18,7 +18,7 @@ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() {
|
|||
var currentUri = new mw.Uri( window.location.toString() );
|
||||
|
||||
// Parent constructor
|
||||
ve.init.mw.Target.call( this, mw.config.get( 'wgRelevantPageName' ) );
|
||||
ve.init.mw.Target.call( this, mw.config.get( 'wgRelevantPageName' ), currentUri.query.oldid );
|
||||
|
||||
// Properties
|
||||
this.$document = null;
|
||||
|
@ -49,6 +49,7 @@ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() {
|
|||
}
|
||||
};
|
||||
this.currentUri = currentUri;
|
||||
this.restoring = !!this.oldid;
|
||||
this.section = currentUri.query.vesection || null;
|
||||
this.namespaceName = mw.config.get( 'wgCanonicalNamespace' );
|
||||
this.viewUri = new mw.Uri( mw.util.wikiGetlink( this.pageName ) );
|
||||
|
@ -82,6 +83,7 @@ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() {
|
|||
// The following messages can be used here:
|
||||
// visualeditor-notification-saved
|
||||
// visualeditor-notification-created
|
||||
// visualeditor-notification-restored
|
||||
mw.util.jsMessage(
|
||||
ve.msg( 'visualeditor-notification-' + currentUri.query.venotify, this.pageName )
|
||||
);
|
||||
|
@ -267,11 +269,11 @@ ve.init.mw.ViewPageTarget.prototype.onLoadError = function ( response, status )
|
|||
* @param {HTMLElement} html Rendered HTML from server
|
||||
*/
|
||||
ve.init.mw.ViewPageTarget.prototype.onSave = function ( html ) {
|
||||
if ( !this.pageExists || this.pageRevId ) {
|
||||
// This is a page creation, refresh the page
|
||||
if ( !this.pageExists || this.restoring ) {
|
||||
// This is a page creation or restoration, refresh the page
|
||||
this.tearDownBeforeUnloadHandler();
|
||||
window.location.href = this.viewUri.extend( {
|
||||
'venotify': this.pageExists ? 'saved' : 'created'
|
||||
'venotify': this.restoring ? 'restored' : 'created'
|
||||
} );
|
||||
} else {
|
||||
// Update watch link to match 'watch checkbox' in save dialog.
|
||||
|
@ -380,7 +382,7 @@ ve.init.mw.ViewPageTarget.prototype.onViewTabClick = function ( e ) {
|
|||
* @param {jQuery.Event} e
|
||||
*/
|
||||
ve.init.mw.ViewPageTarget.prototype.onToolbarSaveButtonClick = function () {
|
||||
if ( this.edited ) {
|
||||
if ( this.edited || this.restoring ) {
|
||||
this.showSaveDialog();
|
||||
}
|
||||
};
|
||||
|
@ -487,7 +489,7 @@ ve.init.mw.ViewPageTarget.prototype.setUpSurface = function ( dom ) {
|
|||
// Update UI
|
||||
this.hidePageContent();
|
||||
this.hideSpinner();
|
||||
if ( !this.currentUri.query.oldid ) {
|
||||
if ( !this.restoring ) {
|
||||
this.disableToolbarSaveButton();
|
||||
}
|
||||
this.active = true;
|
||||
|
@ -644,7 +646,7 @@ ve.init.mw.ViewPageTarget.prototype.setupToolbarButtons = function () {
|
|||
this.$toolbarSaveButton
|
||||
.append(
|
||||
$( '<span class="ve-init-mw-viewPageTarget-toolbar-saveButton-label"></span>' )
|
||||
.text( ve.msg( 'savearticle' ) )
|
||||
.text( ve.msg( this.restoring ? 'visualeditor-restore-page': 'savearticle' ) )
|
||||
)
|
||||
.on( {
|
||||
'mousedown': function ( e ) {
|
||||
|
@ -788,7 +790,7 @@ ve.init.mw.ViewPageTarget.prototype.setupSaveDialog = function () {
|
|||
} )
|
||||
.end()
|
||||
.find( '.ve-init-mw-viewPageTarget-saveDialog-saveButton-label' )
|
||||
.text( ve.msg( 'savearticle' ) )
|
||||
.text( ve.msg( viewPage.restoring ? 'visualeditor-restore-page' : 'savearticle' ) )
|
||||
.end()
|
||||
.find( '.ve-init-mw-viewPageTarget-saveDialog-license' )
|
||||
// FIXME license text is hardcoded English
|
||||
|
|
|
@ -14,15 +14,16 @@
|
|||
* @constructor
|
||||
* @extends {ve.EventEmitter}
|
||||
* @param {String} pageName Name of target page
|
||||
* @param {Number} [revision] Revision ID
|
||||
*/
|
||||
ve.init.mw.Target = function VeInitMwTarget( pageName ) {
|
||||
ve.init.mw.Target = function VeInitMwTarget( pageName, revision ) {
|
||||
// Parent constructor
|
||||
ve.EventEmitter.call( this );
|
||||
|
||||
// Properties
|
||||
this.pageName = pageName;
|
||||
this.pageExists = mw.config.get( 'wgArticleId', 0 ) !== 0;
|
||||
this.pageRevId = mw.config.get( 'wgCurRevisionId' );
|
||||
this.oldid = revision || '';
|
||||
this.editToken = mw.user.tokens.get( 'editToken' );
|
||||
this.apiUrl = mw.util.wikiScript( 'api' );
|
||||
this.submitUrl = ( new mw.Uri( mw.util.wikiGetlink( this.pageName ) ) )
|
||||
|
@ -250,7 +251,7 @@ ve.init.mw.Target.prototype.load = function () {
|
|||
'action': 'visualeditor',
|
||||
'paction': 'parse',
|
||||
'page': this.pageName,
|
||||
'oldid': this.pageRevId,
|
||||
'oldid': this.oldid,
|
||||
'token': this.editToken,
|
||||
'format': 'json'
|
||||
},
|
||||
|
@ -295,7 +296,7 @@ ve.init.mw.Target.prototype.save = function ( dom, options ) {
|
|||
'action': 'visualeditor',
|
||||
'paction': 'save',
|
||||
'page': this.pageName,
|
||||
'oldid': this.pageRevId,
|
||||
'oldid': this.oldid,
|
||||
'basetimestamp': this.baseTimeStamp,
|
||||
'starttimestamp': this.startTimeStamp,
|
||||
'html': $( dom ).html(),
|
||||
|
@ -341,7 +342,7 @@ ve.init.mw.Target.prototype.submit = function ( wikitext, options ) {
|
|||
$form = $( '<form method="post" enctype="multipart/form-data"></form>' ),
|
||||
params = {
|
||||
'format': 'text/x-wiki',
|
||||
'oldid': this.pageRevId || 0,
|
||||
'oldid': this.oldid,
|
||||
'wpStarttime': this.baseTimeStamp,
|
||||
'wpEdittime': this.startTimeStamp,
|
||||
'wpTextbox1': wikitext,
|
||||
|
|
Loading…
Reference in a new issue