mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-24 10:48:42 +00:00
Create getters for localised APIs (getContentApi/getLocalApi)
Pass through the current document when available, otherwise assume the current surface's document. Also add a getter for getPageName, so that can vary based on the target document. Bug: T193856 Change-Id: Ifdc951fdc6a43b924d102e3fcd7e59e52023757b
This commit is contained in:
parent
b54f427078
commit
478b0bcbb9
|
@ -106,7 +106,7 @@ ve.ce.MWImageNode.prototype.generateContents = function () {
|
|||
return deferred.reject().promise();
|
||||
}
|
||||
|
||||
xhr = new mw.Api().get( {
|
||||
xhr = ve.init.target.getContentApi( this.getModel().getDocument() ).get( {
|
||||
action: 'query',
|
||||
prop: 'imageinfo',
|
||||
iiprop: 'url',
|
||||
|
|
|
@ -96,7 +96,7 @@ ve.ce.MWSignatureNode.prototype.onTeardown = function () {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.ce.MWSignatureNode.prototype.generateContents = function () {
|
||||
var wikitext, signatureNode, api, deferred, xhr;
|
||||
var wikitext, signatureNode, deferred, xhr;
|
||||
// Parsoid doesn't support pre-save transforms. PHP parser doesn't support Parsoid's
|
||||
// meta attributes (that may or may not be required).
|
||||
|
||||
|
@ -107,9 +107,8 @@ ve.ce.MWSignatureNode.prototype.generateContents = function () {
|
|||
wikitext = '<span>~~~~</span>';
|
||||
signatureNode = this;
|
||||
|
||||
api = new mw.Api();
|
||||
deferred = $.Deferred();
|
||||
xhr = api.post( {
|
||||
xhr = ve.init.target.getContentApi( this.getModel().getDocument() ).post( {
|
||||
action: 'parse',
|
||||
text: wikitext,
|
||||
contentmodel: 'wikitext',
|
||||
|
|
|
@ -16,17 +16,20 @@
|
|||
* @mixins OO.EventEmitter
|
||||
*
|
||||
* @constructor
|
||||
* @param {ve.dm.Document} doc Document to use associate with API requests
|
||||
*/
|
||||
ve.dm.MWTransclusionModel = function VeDmMWTransclusionModel() {
|
||||
ve.dm.MWTransclusionModel = function VeDmMWTransclusionModel( doc ) {
|
||||
// Mixin constructors
|
||||
OO.EventEmitter.call( this );
|
||||
|
||||
// Properties
|
||||
this.doc = doc;
|
||||
this.parts = [];
|
||||
this.uid = 0;
|
||||
this.requests = [];
|
||||
this.queue = [];
|
||||
this.specCache = specCache;
|
||||
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
@ -304,7 +307,7 @@
|
|||
};
|
||||
|
||||
ve.dm.MWTransclusionModel.prototype.fetchRequest = function ( titles, specs, queue ) {
|
||||
var xhr = new mw.Api().get( {
|
||||
var xhr = ve.init.target.getContentApi( this.doc ).get( {
|
||||
action: 'templatedata',
|
||||
titles: titles,
|
||||
lang: mw.config.get( 'wgUserLanguage' ),
|
||||
|
|
|
@ -322,7 +322,7 @@
|
|||
if ( mw.user.options.get( 'visualeditor-editor' ) === editor ) {
|
||||
return $.Deferred().resolve();
|
||||
}
|
||||
return new mw.Api().saveOption( 'visualeditor-editor', editor ).then( function () {
|
||||
return ve.init.target.getLocalApi().saveOption( 'visualeditor-editor', editor ).then( function () {
|
||||
mw.user.options.set( 'visualeditor-editor', editor );
|
||||
} );
|
||||
}
|
||||
|
@ -1230,7 +1230,7 @@
|
|||
} );
|
||||
|
||||
if ( prefSaysShowWelcome ) {
|
||||
new mw.Api().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
||||
ve.init.target.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
||||
mw.user.options.set( 'visualeditor-hidebetawelcome', '1' );
|
||||
} else if ( !isLoggedIn && !urlSaysHideWelcome ) {
|
||||
if ( !mw.storage.set( 've-beta-welcome-dialog', 1 ) ) {
|
||||
|
|
|
@ -50,7 +50,7 @@ ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config
|
|||
} else {
|
||||
this.initialEditSummary = this.currentUri.query.summary;
|
||||
}
|
||||
this.viewUri = new mw.Uri( mw.util.getUrl( this.pageName ) );
|
||||
this.viewUri = new mw.Uri( mw.util.getUrl( this.getPageName() ) );
|
||||
this.isViewPage = (
|
||||
mw.config.get( 'wgAction' ) === 'view' &&
|
||||
this.currentUri.query.diff === undefined
|
||||
|
@ -360,7 +360,7 @@ ve.init.mw.DesktopArticleTarget.prototype.loadSuccess = function () {
|
|||
$.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } );
|
||||
}
|
||||
} else {
|
||||
new mw.Api().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
||||
ve.init.target.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
||||
mw.user.options.set( 'visualeditor-hidebetawelcome', '1' );
|
||||
}
|
||||
this.suppressNormalStartupDialogs = true;
|
||||
|
@ -839,7 +839,7 @@ ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () {
|
|||
* @param {ve.dm.MetaItem} metaItem Item that was inserted
|
||||
*/
|
||||
ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaItem ) {
|
||||
var metaList = this.surface.getModel().getMetaList();
|
||||
var metaList = this.getSurface().getModel().getMetaList();
|
||||
switch ( metaItem.getType() ) {
|
||||
case 'mwRedirect':
|
||||
this.setFakeRedirectInterface( metaItem.getAttribute( 'title' ) );
|
||||
|
@ -858,7 +858,7 @@ ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaIt
|
|||
* @param {number} index Index within that offset the item was at
|
||||
*/
|
||||
ve.init.mw.DesktopArticleTarget.prototype.onMetaItemRemoved = function ( metaItem ) {
|
||||
var metaList = this.surface.getModel().getMetaList();
|
||||
var metaList = this.getSurface().getModel().getMetaList();
|
||||
switch ( metaItem.getType() ) {
|
||||
case 'mwRedirect':
|
||||
this.setFakeRedirectInterface( null );
|
||||
|
@ -878,7 +878,7 @@ ve.init.mw.DesktopArticleTarget.prototype.rebuildCategories = function ( categor
|
|||
var target = this;
|
||||
// We need to fetch this from the API because the category list is skin-
|
||||
// dependent, so the HTML output could be absolutely anything.
|
||||
new mw.Api().post( {
|
||||
this.getContentApi().post( {
|
||||
formatversion: 2,
|
||||
action: 'parse',
|
||||
contentmodel: 'wikitext',
|
||||
|
@ -1192,7 +1192,7 @@ ve.init.mw.DesktopArticleTarget.prototype.teardownToolbar = function () {
|
|||
* Change the document title to state that we are now editing.
|
||||
*/
|
||||
ve.init.mw.DesktopArticleTarget.prototype.changeDocumentTitle = function () {
|
||||
var title = mw.Title.newFromText( this.pageName );
|
||||
var title = mw.Title.newFromText( this.getPageName() );
|
||||
|
||||
// Use the real title if we loaded a view page, otherwise reconstruct it
|
||||
this.originalDocumentTitle = this.isViewPage ? document.title : ve.msg( 'pagetitle', title.getPrefixedText() );
|
||||
|
|
|
@ -183,7 +183,7 @@ ve.init.mw.MobileArticleTarget.prototype.attachToolbarSaveButton = function () {
|
|||
if ( !this.$title ) {
|
||||
this.$title = $( '<div>' ).addClass( 've-init-mw-mobileArticleTarget-title-container' ).append(
|
||||
$( '<div>' ).addClass( 've-init-mw-mobileArticleTarget-title' ).text(
|
||||
new mw.Title( ve.init.target.pageName ).getMainText()
|
||||
new mw.Title( ve.init.target.getPageName() ).getMainText()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ mw.libs.ve.EditingTabDialog.static.actions = [
|
|||
mw.libs.ve.EditingTabDialog.prototype.getSetupProcess = function ( action ) {
|
||||
return mw.libs.ve.EditingTabDialog.super.prototype.getSetupProcess.call( this, action )
|
||||
.next( function () {
|
||||
new mw.Api().saveOption( 'visualeditor-hidetabdialog', 1 );
|
||||
ve.init.target.getLocalApi().saveOption( 'visualeditor-hidetabdialog', 1 );
|
||||
mw.user.options.set( 'visualeditor-hidetabdialog', 1 );
|
||||
} );
|
||||
};
|
||||
|
@ -79,7 +79,7 @@ mw.libs.ve.EditingTabDialog.prototype.getActionProcess = function ( action ) {
|
|||
action.pushPending();
|
||||
dialog.pushPending();
|
||||
|
||||
new mw.Api().saveOption( 'visualeditor-tabs', act ).done( function () {
|
||||
ve.init.target.getLocalApi().saveOption( 'visualeditor-tabs', act ).done( function () {
|
||||
action.popPending();
|
||||
mw.user.options.set( 'visualeditor-tabs', act );
|
||||
dialog.close( { action: act } );
|
||||
|
|
|
@ -41,7 +41,7 @@ mw.libs.ve.SwitchPopupWidget = function MWLibsVESwitchPopupWidget( mode, config
|
|||
showAgainCheckbox = new OO.ui.CheckboxInputWidget()
|
||||
.on( 'change', function ( value ) {
|
||||
var configValue = value ? '1' : '';
|
||||
new mw.Api().saveOption( option, configValue );
|
||||
ve.init.target.getLocalApi().saveOption( option, configValue );
|
||||
mw.user.options.set( option, configValue );
|
||||
} );
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ ve.init.mw.ArticleTarget = function VeInitMwArticleTarget( config ) {
|
|||
this.edited = false;
|
||||
this.restoring = !!this.requestedRevId && this.requestedRevId !== this.currentRevisionId;
|
||||
this.pageDeletedWarning = false;
|
||||
this.submitUrl = ( new mw.Uri( mw.util.getUrl( this.pageName ) ) )
|
||||
this.submitUrl = ( new mw.Uri( mw.util.getUrl( this.getPageName() ) ) )
|
||||
.extend( {
|
||||
action: 'submit',
|
||||
veswitched: 1
|
||||
|
@ -422,7 +422,7 @@ ve.init.mw.ArticleTarget.prototype.loadSuccess = function ( response ) {
|
|||
this.checkboxesByName = {};
|
||||
if ( [ 'edit', 'submit' ].indexOf( mw.util.getParamValue( 'action' ) ) !== -1 ) {
|
||||
$( '#firstHeading' ).text(
|
||||
mw.Title.newFromText( this.pageName ).getPrefixedText()
|
||||
mw.Title.newFromText( this.getPageName() ).getPrefixedText()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -553,7 +553,7 @@ ve.init.mw.ArticleTarget.prototype.storeDocState = function ( html ) {
|
|||
var mode = this.getSurface().getMode();
|
||||
this.getSurface().getModel().storeDocState( {
|
||||
request: {
|
||||
pageName: this.pageName,
|
||||
pageName: this.getPageName(),
|
||||
mode: mode,
|
||||
// Only source mode fetches data by section
|
||||
section: mode === 'source' ? this.section : null
|
||||
|
@ -1122,10 +1122,10 @@ ve.init.mw.ArticleTarget.prototype.onSaveDialogPreview = function () {
|
|||
wikitext = '== ' + this.sectionTitle.getValue() + ' ==\n\n' + wikitext;
|
||||
}
|
||||
|
||||
new mw.Api().post( {
|
||||
this.getContentApi().post( {
|
||||
action: 'visualeditor',
|
||||
paction: 'parsedoc',
|
||||
page: this.pageName,
|
||||
page: this.getPageName(),
|
||||
wikitext: wikitext,
|
||||
pst: true
|
||||
} ).always( function ( response, details ) {
|
||||
|
@ -1197,7 +1197,7 @@ ve.init.mw.ArticleTarget.prototype.getVisualDiffGeneratorPromise = function () {
|
|||
// re-fetch the HTML
|
||||
target.originalDmDocPromise = $.Deferred().resolve( target.constructor.static.createModelFromDom( target.doc, 'visual' ) ).promise();
|
||||
} else {
|
||||
target.originalDmDocPromise = mw.libs.ve.diffLoader.fetchRevision( target.revid, target.pageName, undefined, target.section !== null ? target.section : undefined );
|
||||
target.originalDmDocPromise = mw.libs.ve.diffLoader.fetchRevision( target.revid, target.getPageName(), undefined, target.section !== null ? target.section : undefined );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1293,7 +1293,7 @@ ve.init.mw.ArticleTarget.prototype.load = function ( dataPromise ) {
|
|||
this.events.trackActivationStart( mw.libs.ve.activationStart );
|
||||
mw.libs.ve.activationStart = null;
|
||||
|
||||
this.loading = dataPromise || mw.libs.ve.targetLoader.requestPageData( this.getDefaultMode(), this.pageName, {
|
||||
this.loading = dataPromise || mw.libs.ve.targetLoader.requestPageData( this.getDefaultMode(), this.getPageName(), {
|
||||
sessionStore: true,
|
||||
section: this.section,
|
||||
oldId: this.requestedRevId,
|
||||
|
@ -1411,12 +1411,12 @@ ve.init.mw.ArticleTarget.prototype.prepareCacheKey = function ( doc ) {
|
|||
if ( aborted ) {
|
||||
return $.Deferred().reject();
|
||||
}
|
||||
xhr = new mw.Api().postWithToken( 'csrf',
|
||||
xhr = target.getContentApi().postWithToken( 'csrf',
|
||||
{
|
||||
action: 'visualeditoredit',
|
||||
paction: 'serializeforcache',
|
||||
html: deflatedHtml,
|
||||
page: target.pageName,
|
||||
page: target.getPageName(),
|
||||
oldid: target.revid,
|
||||
etag: target.etag
|
||||
},
|
||||
|
@ -1497,7 +1497,7 @@ ve.init.mw.ArticleTarget.prototype.clearPreparedCacheKey = function () {
|
|||
* @return {jQuery.Promise}
|
||||
*/
|
||||
ve.init.mw.ArticleTarget.prototype.tryWithPreparedCacheKey = function ( doc, options, eventName ) {
|
||||
var data, postData, preparedCacheKey,
|
||||
var data, postData, preparedCacheKey, api,
|
||||
target = this;
|
||||
|
||||
if ( this.getSurface().getMode() === 'source' ) {
|
||||
|
@ -1513,10 +1513,11 @@ ve.init.mw.ArticleTarget.prototype.tryWithPreparedCacheKey = function ( doc, opt
|
|||
postData.sectiontitle = this.sectionTitle.getValue();
|
||||
postData.summary = undefined;
|
||||
}
|
||||
api = this.getContentApi();
|
||||
if ( postData.token ) {
|
||||
return new mw.Api().post( postData, { contentType: 'multipart/form-data' } );
|
||||
return api.post( postData, { contentType: 'multipart/form-data' } );
|
||||
}
|
||||
return new mw.Api().postWithToken( 'csrf', postData, { contentType: 'multipart/form-data' } );
|
||||
return api.postWithToken( 'csrf', postData, { contentType: 'multipart/form-data' } );
|
||||
}
|
||||
|
||||
preparedCacheKey = this.getPreparedCacheKey( doc );
|
||||
|
@ -1542,10 +1543,11 @@ ve.init.mw.ArticleTarget.prototype.tryWithPreparedCacheKey = function ( doc, opt
|
|||
}
|
||||
return deflatePromise
|
||||
.then( function () {
|
||||
var api = target.getContentApi();
|
||||
if ( data.token ) {
|
||||
return new mw.Api().post( data, { contentType: 'multipart/form-data' } );
|
||||
return api.post( data, { contentType: 'multipart/form-data' } );
|
||||
}
|
||||
return new mw.Api().postWithToken( 'csrf', data, { contentType: 'multipart/form-data' } );
|
||||
return api.postWithToken( 'csrf', data, { contentType: 'multipart/form-data' } );
|
||||
} )
|
||||
.then(
|
||||
function ( response, jqxhr ) {
|
||||
|
@ -1738,7 +1740,7 @@ ve.init.mw.ArticleTarget.prototype.save = function ( doc, options, isRetry ) {
|
|||
data = ve.extendObject( {}, options, {
|
||||
action: 'visualeditoredit',
|
||||
paction: 'save',
|
||||
page: this.pageName,
|
||||
page: this.getPageName(),
|
||||
oldid: this.revid,
|
||||
basetimestamp: this.baseTimeStamp,
|
||||
starttimestamp: this.startTimeStamp,
|
||||
|
@ -1797,7 +1799,7 @@ ve.init.mw.ArticleTarget.prototype.getWikitextDiffPromise = function ( doc ) {
|
|||
this.wikitextDiffPromise = this.tryWithPreparedCacheKey( doc, {
|
||||
action: 'visualeditoredit',
|
||||
paction: 'diff',
|
||||
page: this.pageName,
|
||||
page: this.getPageName(),
|
||||
oldid: this.revid,
|
||||
etag: this.etag
|
||||
}, 'diff' ).then( function ( response ) {
|
||||
|
@ -1893,7 +1895,7 @@ ve.init.mw.ArticleTarget.prototype.serialize = function ( doc, callback ) {
|
|||
this.serializing = this.tryWithPreparedCacheKey( doc, {
|
||||
action: 'visualeditoredit',
|
||||
paction: 'serialize',
|
||||
page: this.pageName,
|
||||
page: this.getPageName(),
|
||||
oldid: this.revid,
|
||||
etag: this.etag
|
||||
}, 'serialize' )
|
||||
|
@ -2369,7 +2371,7 @@ ve.init.mw.ArticleTarget.prototype.maybeShowWelcomeDialog = function () {
|
|||
}
|
||||
|
||||
if ( prefSaysShow ) {
|
||||
new mw.Api().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
||||
ve.init.target.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
||||
mw.user.options.set( 'visualeditor-hidebetawelcome', '1' );
|
||||
|
||||
// No need to set a cookie every time for logged-in users that have already
|
||||
|
@ -2401,7 +2403,7 @@ ve.init.mw.ArticleTarget.prototype.switchToWikitextEditor = function ( discardCh
|
|||
|
||||
if ( ve.init.target.isModeAvailable( 'source' ) && !leaveVE ) {
|
||||
if ( discardChanges ) {
|
||||
dataPromise = mw.libs.ve.targetLoader.requestPageData( 'source', this.pageName, {
|
||||
dataPromise = mw.libs.ve.targetLoader.requestPageData( 'source', this.getPageName(), {
|
||||
sessionStore: true,
|
||||
section: this.section,
|
||||
oldId: this.requestedRevId,
|
||||
|
@ -2477,7 +2479,7 @@ ve.init.mw.ArticleTarget.prototype.switchToVisualEditor = function () {
|
|||
windowManager.destroy();
|
||||
} );
|
||||
} else {
|
||||
dataPromise = mw.libs.ve.targetLoader.requestParsoidData( this.pageName, {
|
||||
dataPromise = mw.libs.ve.targetLoader.requestParsoidData( this.getPageName(), {
|
||||
oldId: this.revid,
|
||||
targetName: this.constructor.static.trackingName,
|
||||
modified: this.edited,
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
isVisual = mode === 'visual';
|
||||
|
||||
mw.user.options.set( 'visualeditor-diffmode-historical', mode );
|
||||
new mw.Api().saveOption( 'visualeditor-diffmode-historical', mode );
|
||||
ve.init.target.getLocalApi().saveOption( 'visualeditor-diffmode-historical', mode );
|
||||
$visualDiffContainer.toggleClass( 'oo-ui-element-hidden', !isVisual );
|
||||
$wikitextDiffBody.toggleClass( 'oo-ui-element-hidden', isVisual );
|
||||
$revSlider.toggleClass( 've-init-mw-diffPage-revSlider-visual', isVisual );
|
||||
|
|
|
@ -120,7 +120,7 @@ ve.init.mw.Platform.prototype.setUserConfig = function ( keyOrValueMap, value )
|
|||
Object.keys( keyOrValueMap ).forEach( function ( key ) {
|
||||
jsonValues[ key ] = JSON.stringify( keyOrValueMap[ key ] );
|
||||
} );
|
||||
new mw.Api().saveOptions( jsonValues );
|
||||
ve.init.target.getLocalApi().saveOptions( jsonValues );
|
||||
return mw.user.options.set( jsonValues );
|
||||
} else {
|
||||
if ( value === this.getUserConfig( keyOrValueMap ) ) {
|
||||
|
@ -128,7 +128,7 @@ ve.init.mw.Platform.prototype.setUserConfig = function ( keyOrValueMap, value )
|
|||
}
|
||||
// JSON encode the value for API storage
|
||||
jsonValue = JSON.stringify( value );
|
||||
new mw.Api().saveOption( keyOrValueMap, jsonValue );
|
||||
ve.init.target.getLocalApi().saveOption( keyOrValueMap, jsonValue );
|
||||
return mw.user.options.set( keyOrValueMap, jsonValue );
|
||||
}
|
||||
};
|
||||
|
|
|
@ -435,10 +435,11 @@ ve.init.mw.Target.prototype.setSurface = function ( surface ) {
|
|||
* token was expired / the user changed. If the user did change, this updates
|
||||
* the current user.
|
||||
*
|
||||
* @param {ve.dm.Document} [doc] Document to associate with the API request
|
||||
* @return {jQuery.Promise} Promise resolved with whether we switched users
|
||||
*/
|
||||
ve.init.mw.Target.prototype.refreshEditToken = function () {
|
||||
var api = new mw.Api(),
|
||||
ve.init.mw.Target.prototype.refreshEditToken = function ( doc ) {
|
||||
var api = this.getContentApi( doc ),
|
||||
deferred = $.Deferred(),
|
||||
target = this;
|
||||
api.get( {
|
||||
|
@ -506,7 +507,7 @@ ve.init.mw.Target.prototype.getWikitextFragment = function ( doc, useRevision, i
|
|||
token: this.editToken,
|
||||
paction: 'serialize',
|
||||
html: ve.dm.converter.getDomFromModel( doc ).body.innerHTML,
|
||||
page: this.pageName
|
||||
page: this.getPageName()
|
||||
};
|
||||
|
||||
// Optimise as a no-op
|
||||
|
@ -519,7 +520,7 @@ ve.init.mw.Target.prototype.getWikitextFragment = function ( doc, useRevision, i
|
|||
params.etag = this.etag;
|
||||
}
|
||||
|
||||
xhr = new mw.Api().post(
|
||||
xhr = this.getContentApi( doc ).post(
|
||||
params,
|
||||
{ contentType: 'multipart/form-data' }
|
||||
);
|
||||
|
@ -531,7 +532,7 @@ ve.init.mw.Target.prototype.getWikitextFragment = function ( doc, useRevision, i
|
|||
return $.Deferred().reject();
|
||||
}, function ( error ) {
|
||||
if ( error === 'badtoken' && !isRetry ) {
|
||||
return target.refreshEditToken().then( function () {
|
||||
return target.refreshEditToken( doc ).then( function () {
|
||||
return target.getWikitextFragment( doc, useRevision, true );
|
||||
} );
|
||||
}
|
||||
|
@ -549,15 +550,52 @@ ve.init.mw.Target.prototype.getWikitextFragment = function ( doc, useRevision, i
|
|||
*
|
||||
* @param {string} wikitext Wikitext
|
||||
* @param {boolean} pst Perform pre-save transform
|
||||
* @param {ve.dm.Document} [doc] Parse for a specific document
|
||||
* @param {ve.dm.Document} [doc] Parse for a specific document, defaults to current surface's
|
||||
* @return {jQuery.Promise} Abortable promise
|
||||
*/
|
||||
ve.init.mw.Target.prototype.parseWikitextFragment = function ( wikitext, pst ) {
|
||||
return new mw.Api().post( {
|
||||
ve.init.mw.Target.prototype.parseWikitextFragment = function ( wikitext, pst, doc ) {
|
||||
return this.getContentApi( doc ).post( {
|
||||
action: 'visualeditor',
|
||||
paction: 'parsefragment',
|
||||
page: this.pageName,
|
||||
page: this.getPageName( doc ),
|
||||
wikitext: wikitext,
|
||||
pst: pst
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the page name associated with a specific document
|
||||
*
|
||||
* @param {ve.dm.Document} [doc] Document, defaults to current surface's
|
||||
* @return {string} Page name
|
||||
*/
|
||||
ve.init.mw.Target.prototype.getPageName = function () {
|
||||
return this.pageName;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an API object associated with the wiki where the document
|
||||
* content is hosted.
|
||||
*
|
||||
* This would be overridden if editing content on another wiki.
|
||||
*
|
||||
* @param {ve.dm.Document} [doc] API for a specific document, should default to document of current surface.
|
||||
* @param {Object} [options] API options
|
||||
* @return {mw.Api} API object
|
||||
*/
|
||||
ve.init.mw.Target.prototype.getContentApi = function ( doc, options ) {
|
||||
return new mw.Api( options );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an API object associated with the local wiki.
|
||||
*
|
||||
* For example you would always use getLocalApi for actions
|
||||
* associated with the current user.
|
||||
*
|
||||
* @param {Object} [options] API options
|
||||
* @return {mw.Api} API object
|
||||
*/
|
||||
ve.init.mw.Target.prototype.getLocalApi = function ( options ) {
|
||||
return new mw.Api( options );
|
||||
};
|
||||
|
|
|
@ -745,7 +745,7 @@ ve.ui.MWMediaDialog.prototype.fetchThumbnail = function ( imageName, dimensions
|
|||
if ( dimensions.height ) {
|
||||
apiObj.iiurlheight = dimensions.height;
|
||||
}
|
||||
return new mw.Api().get( apiObj )
|
||||
return ve.init.target.getContentApi( this.getFragment().getDocument() ).get( apiObj )
|
||||
.then( function ( response ) {
|
||||
var thumburl = ve.getProp(
|
||||
response.query.pages[ response.query.pageids[ 0 ] ],
|
||||
|
|
|
@ -226,9 +226,9 @@ ve.ui.MWSaveDialog.prototype.showPreview = function ( docOrMsg, baseDoc ) {
|
|||
// Document title will only be set if wikitext contains {{DISPLAYTITLE}}
|
||||
if ( docOrMsg.title ) {
|
||||
// HACK: Parse title as it can contain basic wikitext (T122976)
|
||||
new mw.Api().post( {
|
||||
ve.init.target.getContentApi().post( {
|
||||
action: 'parse',
|
||||
title: ve.init.target.pageName,
|
||||
title: ve.init.target.getPageName(),
|
||||
prop: 'displaytitle',
|
||||
text: '{{DISPLAYTITLE:' + docOrMsg.title + '}}\n'
|
||||
} ).then( function ( response ) {
|
||||
|
@ -251,7 +251,7 @@ ve.ui.MWSaveDialog.prototype.showPreview = function ( docOrMsg, baseDoc ) {
|
|||
|
||||
this.$previewViewer.empty().append(
|
||||
// TODO: This won't work with formatted titles (T122976)
|
||||
$heading.text( docOrMsg.title || mw.Title.newFromText( ve.init.target.pageName ).getPrefixedText() ),
|
||||
$heading.text( docOrMsg.title || mw.Title.newFromText( ve.init.target.getPageName() ).getPrefixedText() ),
|
||||
$redirect,
|
||||
$( '<div>' ).addClass( 'mw-content-' + mw.config.get( 'wgVisualEditor' ).pageLanguageDir ).append(
|
||||
contents
|
||||
|
@ -387,7 +387,7 @@ ve.ui.MWSaveDialog.prototype.swapPanel = function ( panel, noFocus ) {
|
|||
this.$reviewEditSummary.parent()
|
||||
.removeClass( 'oo-ui-element-hidden' )
|
||||
.addClass( 'mw-ajax-loader' );
|
||||
this.editSummaryXhr = new mw.Api().post( {
|
||||
this.editSummaryXhr = ve.init.target.getContentApi().post( {
|
||||
action: 'parse',
|
||||
summary: currentEditSummaryWikitext
|
||||
} ).done( function ( result ) {
|
||||
|
|
|
@ -455,7 +455,7 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
|
|||
// Properties
|
||||
this.loaded = false;
|
||||
this.altered = false;
|
||||
this.transclusionModel = new ve.dm.MWTransclusionModel();
|
||||
this.transclusionModel = new ve.dm.MWTransclusionModel( this.getFragment().getDocument() );
|
||||
|
||||
// Events
|
||||
this.transclusionModel.connect( this, {
|
||||
|
|
|
@ -222,7 +222,7 @@ ve.ui.MWAdvancedSettingsPage.prototype.setup = function ( metaList ) {
|
|||
displayTitleItem = this.getMetaItem( 'mwDisplayTitle' );
|
||||
displayTitle = displayTitleItem && displayTitleItem.getAttribute( 'content' ) || '';
|
||||
if ( !displayTitle ) {
|
||||
displayTitle = mw.Title.newFromText( ve.init.target.pageName ).getPrefixedText();
|
||||
displayTitle = mw.Title.newFromText( ve.init.target.getPageName() ).getPrefixedText();
|
||||
}
|
||||
this.displayTitleInput.setValue( displayTitle );
|
||||
this.displayTitleTouched = false;
|
||||
|
@ -300,7 +300,7 @@ ve.ui.MWAdvancedSettingsPage.prototype.teardown = function ( data ) {
|
|||
// Display title items
|
||||
currentDisplayTitleItem = this.getMetaItem( 'mwDisplayTitle' );
|
||||
newDisplayTitle = this.displayTitleInput.getValue();
|
||||
if ( newDisplayTitle === mw.Title.newFromText( ve.init.target.pageName ).getPrefixedText() ) {
|
||||
if ( newDisplayTitle === mw.Title.newFromText( ve.init.target.getPageName() ).getPrefixedText() ) {
|
||||
newDisplayTitle = '';
|
||||
}
|
||||
newDisplayTitleItem = { type: 'mwDisplayTitle', attributes: { content: newDisplayTitle } };
|
||||
|
|
|
@ -167,10 +167,10 @@ ve.ui.MWLanguagesPage.prototype.getLocalLanguageItems = function () {
|
|||
ve.ui.MWLanguagesPage.prototype.getAllLanguageItems = function () {
|
||||
var deferred = $.Deferred();
|
||||
// TODO: Detect paging token if results exceed limit
|
||||
new mw.Api().get( {
|
||||
ve.init.target.getContentApi().get( {
|
||||
action: 'visualeditor',
|
||||
paction: 'getlanglinks',
|
||||
page: ve.init.target.pageName
|
||||
page: ve.init.target.getPageName()
|
||||
} )
|
||||
.done( this.onAllLanguageItemsSuccess.bind( this, deferred ) )
|
||||
.fail( this.onAllLanguageItemsError.bind( this, deferred ) );
|
||||
|
|
|
@ -250,7 +250,7 @@ ve.ui.MWParameterPage.prototype.createValueInput = function () {
|
|||
type === 'wiki-page-name' &&
|
||||
( value === '' || mw.Title.newFromText( value ) )
|
||||
) {
|
||||
return new mw.widgets.TitleInputWidget( valueInputConfig );
|
||||
return new mw.widgets.TitleInputWidget( valueInputConfig, { api: ve.init.target.getContentApi() } );
|
||||
} else if (
|
||||
type === 'wiki-user-name' &&
|
||||
( value === '' || mw.Title.newFromText( value ) )
|
||||
|
@ -260,13 +260,14 @@ ve.ui.MWParameterPage.prototype.createValueInput = function () {
|
|||
// TODO: Check against unicode blacklist regex from MW core's User::isValidUserName
|
||||
return !!mw.Title.newFromText( value );
|
||||
};
|
||||
return new mw.widgets.UserInputWidget( valueInputConfig );
|
||||
return new mw.widgets.UserInputWidget( valueInputConfig, { api: ve.init.target.getContentApi() } );
|
||||
} else if (
|
||||
type === 'wiki-template-name' &&
|
||||
( value === '' || mw.Title.newFromText( value ) )
|
||||
) {
|
||||
return new mw.widgets.TitleInputWidget( $.extend( {}, valueInputConfig, {
|
||||
namespace: mw.config.get( 'wgNamespaceIds' ).template
|
||||
namespace: mw.config.get( 'wgNamespaceIds' ).template,
|
||||
api: ve.init.target.getContentApi()
|
||||
} ) );
|
||||
} else if ( type === 'boolean' && ( value === '1' || value === '0' ) ) {
|
||||
return new ve.ui.MWParameterCheckboxInputWidget( valueInputConfig );
|
||||
|
|
|
@ -78,7 +78,8 @@ ve.ui.MWSettingsPage = function VeUiMWSettingsPage( name, config ) {
|
|||
);
|
||||
this.redirectTargetInput = new mw.widgets.TitleInputWidget( {
|
||||
placeholder: ve.msg( 'visualeditor-dialog-meta-settings-redirect-placeholder' ),
|
||||
$overlay: config.$overlay
|
||||
$overlay: config.$overlay,
|
||||
api: ve.init.target.getContentApi()
|
||||
} );
|
||||
this.redirectTargetField = new OO.ui.FieldLayout(
|
||||
this.redirectTargetInput,
|
||||
|
|
|
@ -32,7 +32,8 @@ ve.ui.MWTemplatePlaceholderPage = function VeUiMWTemplatePlaceholderPage( placeh
|
|||
|
||||
this.addTemplateInput = new ve.ui.MWTemplateTitleInputWidget( {
|
||||
$overlay: config.$overlay,
|
||||
showDescriptions: true
|
||||
showDescriptions: true,
|
||||
api: ve.init.target.getContentApi()
|
||||
} )
|
||||
.connect( this, {
|
||||
change: 'onTemplateInputChange',
|
||||
|
|
|
@ -105,7 +105,7 @@ ve.ui.MWEducationPopupTool.prototype.onPopupCloseButtonClick = function () {
|
|||
ve.init.target.openEducationPopupTool = undefined;
|
||||
|
||||
if ( prefSaysShow ) {
|
||||
new mw.Api().saveOption( 'visualeditor-hideusered', 1 );
|
||||
ve.init.target.getLocalApi().saveOption( 'visualeditor-hideusered', 1 );
|
||||
mw.user.options.set( 'visualeditor-hideusered', 1 );
|
||||
} else if ( !usePrefs ) {
|
||||
if ( !mw.storage.set( 've-hideusered', 1 ) ) {
|
||||
|
|
|
@ -253,7 +253,7 @@ ve.ui.MWHelpPopupTool.prototype.onSelect = function () {
|
|||
if ( !this.versionPromise && this.popup.isVisible() ) {
|
||||
$version = $( '<div>' ).addClass( 've-ui-mwHelpPopupTool-item oo-ui-pendingElement-pending' ).text( '\u00a0' );
|
||||
this.$items.append( $version );
|
||||
this.versionPromise = new mw.Api().get( {
|
||||
this.versionPromise = ve.init.target.getLocalApi( {
|
||||
action: 'query',
|
||||
meta: 'siteinfo',
|
||||
format: 'json',
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* @constructor
|
||||
* @param {ve.ui.MWCategoryWidget} categoryWidget
|
||||
* @param {Object} [config] Configuration options
|
||||
* @cfg {mw.Api} [api] API object to use, creates a default mw.Api instance if not specified
|
||||
* @cfg {mw.Api} [api] API object to use, uses Target#getContentApi if not specified
|
||||
*/
|
||||
ve.ui.MWCategoryInputWidget = function VeUiMWCategoryInputWidget( categoryWidget, config ) {
|
||||
// Config initialization
|
||||
|
@ -31,7 +31,7 @@ ve.ui.MWCategoryInputWidget = function VeUiMWCategoryInputWidget( categoryWidget
|
|||
|
||||
// Properties
|
||||
this.categoryWidget = categoryWidget;
|
||||
this.api = config.api || new mw.Api();
|
||||
this.api = config.api || ve.init.target.getContentApi();
|
||||
|
||||
// Initialization
|
||||
this.$element.addClass( 've-ui-mwCategoryInputWidget' );
|
||||
|
|
|
@ -274,7 +274,7 @@ ve.ui.MWCategoryWidget.prototype.queryCategoryStatus = function ( categoryNames
|
|||
|
||||
// Batch this up into groups of 50
|
||||
while ( index < categoryNamesToQuery.length ) {
|
||||
promises.push( new mw.Api().get( {
|
||||
promises.push( ve.init.target.getContentApi().get( {
|
||||
action: 'query',
|
||||
prop: 'pageprops',
|
||||
titles: categoryNamesToQuery.slice( index, index + batchSize ),
|
||||
|
|
|
@ -60,6 +60,7 @@ ve.ui.MWInternalLinkAnnotationWidget.prototype.createInputWidget = function ( co
|
|||
excludeCurrentPage: true,
|
||||
showImages: mw.config.get( 'wgVisualEditor' ).usePageImages,
|
||||
showDescriptions: mw.config.get( 'wgVisualEditor' ).usePageDescriptions,
|
||||
api: ve.init.target.getContentApi(),
|
||||
cache: ve.init.platform.linkCache
|
||||
}, config ) );
|
||||
|
||||
|
|
Loading…
Reference in a new issue