mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 03:08:42 +00:00
Merge "Bug 37821 - Add support for oldid"
This commit is contained in:
commit
8c0249bb89
|
@ -18,13 +18,21 @@ class ApiVisualEditor extends ApiBase {
|
|||
$params = $this->extractRequestParams();
|
||||
$page = Title::newFromText( $params['page'] );
|
||||
|
||||
$parserParams = array();
|
||||
if ( is_numeric( $params['oldid'] ) ) {
|
||||
$parserParams['oldid'] = intval( $params['oldid'] );
|
||||
}
|
||||
|
||||
if ( $params['paction'] === 'parse' ) {
|
||||
if ( $page->exists() ) {
|
||||
$parsed = Http::get(
|
||||
// Insert slash since wgVisualEditorParsoidURL does not
|
||||
// end in a slash
|
||||
$parsoid . '/' . $wgVisualEditorParsoidPrefix . '/' .
|
||||
urlencode( $page->getPrefixedDBkey() )
|
||||
wfAppendQuery(
|
||||
$parsoid . '/' . $wgVisualEditorParsoidPrefix . '/' .
|
||||
urlencode( $page->getPrefixedDBkey() ),
|
||||
$parserParams
|
||||
)
|
||||
);
|
||||
|
||||
if ( $parsed ) {
|
||||
|
@ -48,7 +56,8 @@ class ApiVisualEditor extends ApiBase {
|
|||
} elseif ( $params['paction'] === 'save' /* means user is not blocked */ ) {
|
||||
// API Posts HTML to Parsoid Service, receives Wikitext,
|
||||
// API Saves Wikitext to page.
|
||||
$wikitext = Http::post( $parsoid . '/' . $page->getPrefixedDBkey(),
|
||||
$wikitext = Http::post(
|
||||
$parsoid . '/' . $page->getPrefixedDBkey(),
|
||||
array( 'postData' => array( 'content' => $params['html'] ) )
|
||||
);
|
||||
|
||||
|
@ -122,6 +131,9 @@ class ApiVisualEditor extends ApiBase {
|
|||
'paction' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
),
|
||||
'oldid' => array(
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
),
|
||||
'minor' => array(
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
),
|
||||
|
@ -147,6 +159,7 @@ class ApiVisualEditor extends ApiBase {
|
|||
return array(
|
||||
'page' => 'The page to perform actions on.',
|
||||
'paction' => 'Which action? parse or save.',
|
||||
'oldid' => 'The revision number to use.',
|
||||
'minor' => 'Flag for minor edit.',
|
||||
'html' => 'HTML to send to parsoid in exchange for wikitext'
|
||||
);
|
||||
|
|
|
@ -9,7 +9,8 @@ $messages['en'] = array(
|
|||
'visualeditor-desc' => 'Visual editor for MediaWiki',
|
||||
'visualeditor-feedback-prompt' => 'Leave feedback',
|
||||
'visualeditor-feedback-dialog-title' => 'Leave feedback about VisualEditor Sandbox',
|
||||
'visualeditor-notification-saved' => 'Your changes have been saved.',
|
||||
'visualeditor-notification-saved' => 'Your changes to $1 have been saved.',
|
||||
'visualeditor-notification-created' => '$1 has been created.',
|
||||
'visualeditor-ca-editsource' => 'Edit source',
|
||||
'visualeditor-linkinspector-title' => 'Edit link',
|
||||
'visualeditor-linkinspector-label-pagetitle' => 'Page title',
|
||||
|
|
|
@ -106,6 +106,7 @@ $wgResourceModules += array(
|
|||
'tooltip-ca-edit',
|
||||
'viewsource',
|
||||
'visualeditor-notification-saved',
|
||||
'visualeditor-notification-created',
|
||||
'visualeditor-ca-editsource',
|
||||
'visualeditor-loadwarning',
|
||||
'visualeditor-feedback-prompt',
|
||||
|
|
|
@ -16,8 +16,12 @@
|
|||
* @param {String} title Page title of target
|
||||
*/
|
||||
ve.init.mw.ViewPageTarget = function () {
|
||||
var currentUri = new mw.Uri( window.location.toString() );
|
||||
|
||||
// Inheritance
|
||||
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.$surface = $( '<div class="ve-surface"></div>' );
|
||||
|
@ -45,15 +49,15 @@ ve.init.mw.ViewPageTarget = function () {
|
|||
}
|
||||
}
|
||||
};
|
||||
this.currentUri = new mw.Uri( window.location.toString() );
|
||||
this.section = this.currentUri.query.vesection || null;
|
||||
this.currentUri = currentUri;
|
||||
this.section = currentUri.query.vesection || null;
|
||||
this.namespaceName = mw.config.get( 'wgCanonicalNamespace' );
|
||||
this.viewUri = new mw.Uri( mw.util.wikiGetlink( this.pageName ) );
|
||||
this.veEditUri = this.viewUri.clone().extend( { 'veaction': 'edit' } );
|
||||
this.isViewPage = (
|
||||
this.namespaceName === 'VisualEditor' &&
|
||||
mw.config.get( 'wgAction' ) === 'view' &&
|
||||
this.currentUri.query.diff === undefined
|
||||
currentUri.query.diff === undefined
|
||||
);
|
||||
this.canBeActivated = (
|
||||
(
|
||||
|
@ -62,7 +66,7 @@ ve.init.mw.ViewPageTarget = function () {
|
|||
) &&
|
||||
(
|
||||
$.client.test( ve.init.mw.ViewPageTarget.compatibility ) ||
|
||||
'vewhitelist' in this.currentUri.query
|
||||
'vewhitelist' in currentUri.query
|
||||
)
|
||||
);
|
||||
this.editSummaryByteLimit = 255;
|
||||
|
@ -77,13 +81,22 @@ ve.init.mw.ViewPageTarget = function () {
|
|||
|
||||
// Initialization
|
||||
if ( this.canBeActivated ) {
|
||||
if ( currentUri.query.venotify ) {
|
||||
mw.util.jsMessage(
|
||||
ve.msg( 'visualeditor-notification-' + currentUri.query.venotify, this.pageName )
|
||||
);
|
||||
if ( window.history.replaceState ) {
|
||||
delete currentUri.query.venotify;
|
||||
window.history.replaceState( null, document.title, currentUri );
|
||||
}
|
||||
}
|
||||
this.setupSkinTabs();
|
||||
this.setupSectionEditLinks();
|
||||
if ( this.isViewPage ) {
|
||||
this.setupToolbarSaveButton();
|
||||
this.setupToolbarFeedbackButton();
|
||||
this.setupSaveDialog();
|
||||
if ( this.currentUri.query.veaction === 'edit' ) {
|
||||
if ( currentUri.query.veaction === 'edit' ) {
|
||||
this.activate();
|
||||
}
|
||||
}
|
||||
|
@ -250,10 +263,12 @@ 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 ( Number( mw.config.get( 'wgArticleId', 0 ) ) === 0 ) {
|
||||
if ( Number( mw.config.get( 'wgArticleId', 0 ) ) === 0 || this.oldId ) {
|
||||
// This is a page creation, refresh the page
|
||||
this.teardownBeforeUnloadHandler();
|
||||
window.location.href = this.viewUri;
|
||||
window.location.href = this.viewUri.extend( {
|
||||
'venotify': this.oldId ? 'saved' : 'created'
|
||||
} );
|
||||
} else {
|
||||
// Update watch link to match 'watch checkbox' in save dialog.
|
||||
// User logged in if module loaded.
|
||||
|
@ -273,7 +288,7 @@ ve.init.mw.ViewPageTarget.prototype.onSave = function ( html ) {
|
|||
this.replacePageContent( html );
|
||||
this.teardownBeforeUnloadHandler();
|
||||
this.deactivate( true );
|
||||
mw.util.jsMessage( ve.msg( 'visualeditor-notification-saved' ) );
|
||||
mw.util.jsMessage( ve.msg( 'visualeditor-notification-saved', this.pageName ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -747,7 +762,7 @@ ve.init.mw.ViewPageTarget.prototype.showPageContent = function () {
|
|||
* @method
|
||||
*/
|
||||
ve.init.mw.ViewPageTarget.prototype.mutePageContent = function () {
|
||||
$( '#bodyContent > :visible:not(#siteSub)' )
|
||||
$( '#bodyContent > :visible:not(#siteSub,#contentSub)' )
|
||||
.addClass( 've-init-mw-viewPageTarget-content' )
|
||||
.fadeTo( 'fast', 0.6 );
|
||||
};
|
||||
|
@ -758,7 +773,7 @@ ve.init.mw.ViewPageTarget.prototype.mutePageContent = function () {
|
|||
* @method
|
||||
*/
|
||||
ve.init.mw.ViewPageTarget.prototype.hidePageContent = function () {
|
||||
$( '#bodyContent > :visible:not(#siteSub)' )
|
||||
$( '#bodyContent > :visible:not(#siteSub,#contentSub)' )
|
||||
.addClass( 've-init-mw-viewPageTarget-content' )
|
||||
.hide();
|
||||
};
|
||||
|
@ -906,7 +921,7 @@ ve.init.mw.ViewPageTarget.prototype.transformPageTitle = function () {
|
|||
* @method
|
||||
*/
|
||||
ve.init.mw.ViewPageTarget.prototype.mutePageTitle = function () {
|
||||
$( '#firstHeading, #siteSub:visible' ).fadeTo( 'fast', 0.6 );
|
||||
$( '#firstHeading, #siteSub:visible, #contentSub:visible' ).fadeTo( 'fast', 0.6 );
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -915,7 +930,7 @@ ve.init.mw.ViewPageTarget.prototype.mutePageTitle = function () {
|
|||
* @method
|
||||
*/
|
||||
ve.init.mw.ViewPageTarget.prototype.restorePageTitle = function () {
|
||||
$( '#firstHeading, #siteSub:visible' ).fadeTo( 'fast', 1 );
|
||||
$( '#firstHeading, #siteSub:visible, #contentSub:visible' ).fadeTo( 'fast', 1 );
|
||||
setTimeout( function () {
|
||||
$( '#firstHeading' ).removeClass( 've-init-mw-viewPageTarget-pageTitle' );
|
||||
}, 1000 );
|
||||
|
|
|
@ -14,12 +14,13 @@
|
|||
* @constructor
|
||||
* @param {String} pageName Name of target page
|
||||
*/
|
||||
ve.init.mw.Target = function ( pageName ) {
|
||||
ve.init.mw.Target = function ( pageName, oldId ) {
|
||||
// Inheritance
|
||||
ve.EventEmitter.call( this );
|
||||
|
||||
// Properties
|
||||
this.pageName = pageName;
|
||||
this.oldId = oldId;
|
||||
this.editToken = mw.user.tokens.get( 'editToken' );
|
||||
this.apiUrl = mw.util.wikiScript( 'api' );
|
||||
this.modules = ['ext.visualEditor.core', 'ext.visualEditor.specialMessages'];
|
||||
|
@ -175,6 +176,7 @@ ve.init.mw.Target.prototype.load = function () {
|
|||
'action': 've-parsoid',
|
||||
'paction': 'parse',
|
||||
'page': this.pageName,
|
||||
'oldid': this.oldId,
|
||||
'format': 'json'
|
||||
},
|
||||
'dataType': 'json',
|
||||
|
@ -225,6 +227,7 @@ ve.init.mw.Target.prototype.save = function ( dom, options ) {
|
|||
'action': 've-parsoid',
|
||||
'paction': 'save',
|
||||
'page': this.pageName,
|
||||
'oldid': this.oldId,
|
||||
'html': $( dom ).html(),
|
||||
'token': this.editToken,
|
||||
'summary': options.summary,
|
||||
|
|
Loading…
Reference in a new issue