Topic on Talk:ResourceLoader/Core modules

Access the API.edit.create function in MediaWiki 1.31.1

4
Summary by Jdforrester (WMF)

mediawiki.api.edit before 1.32.0

FlyDangerousO7 (talkcontribs)

I'm using the following mw.API call:

new mw.Api().create( 'Sandbox', { summary: 'Load sand particles.' }, 'Sand.');


I'm receiving an error: Uncaught TypeError: Cannot read property 'create' of undefined.

I believe that the edit module was a separate module pre-MediaWiki 1.32. I've been searching how to load the 'edit' module and access the create page function, but can't seem to find an example. I also tried to search for a git repository to backtrack the changes, but couldn't find a repository. The following documentation doesn't seem to support any other version of the API except for the newest MediaWiki version: https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Api.plugin.edit


Does someone know how to use the create page function on MediaWiki 1.31.1?


Thank you,

-Don

Od1n (talkcontribs)

Try the following:

if ( mw.loader.getState( 'mediawiki.api.edit' ) !== null ) {
    mw.loader.load( 'mediawiki.api.edit' );
}

The test is to avoid triggering an error on MediaWiki 1.32 and following.

Od1n (talkcontribs)

A more complete snippet:

var moduleApiEdit = ( mw.loader.getState( 'mediawiki.api.edit' ) !== null )
    ? 'mediawiki.api.edit' // MediaWiki before 1.32
    : 'mediawiki.api';     // MediaWiki 1.32+

mw.loader.using( moduleApiEdit, function () {
    // your code
} );
139.169.212.144 (talkcontribs)

That worked exactly as excepted! Thank you for the help. :)