Page MenuHomePhabricator

Create mediawiki.api.edit module to abstract API action=edit
Closed, ResolvedPublic

Description

From Krinkle's comment on T36733:

It [the function "postWithEditToken"] doesn't edit a page by default, it's used as a pre-processor basically to either continue or get an edit token first. You still need to set action=edit in the params (or something else). Looks like an mw.Api.prototype.edit function should be created separate from this that'll call it with action=edit. Not related to this bug [bug 34733] though, create a new enhancement bug for it and a patch if you like :)


Version: 1.19
Severity: enhancement

Details

Reference
bz34744

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 22 2014, 12:17 AM
bzimport set Reference to bz34744.
bzimport added a subscriber: Unknown Object (MLST).
He7d3r created this task.Feb 26 2012, 7:45 PM

Yes, though it doens't make sense to create a separate resourceloader module for every possible value of the "action" parameter.

Certain actions have dedicated modules to abstract certain logic. It isn't just for the purpose of specifying the action.

mw.Api#post is not an internal method in anyway, so there's nothing wrong with:

mw.Api#post({
action: foo,
param: example
});

Creating a module for it only changes it to:

mw.Api#foo({
param: example
});

At the cost of having to specify a dependency on mediawiki.api.foo and the extra code being downloaded, executed and increasing the function call stack (user > foo > post > ajax > jquery.ajax > ...).

Unless this proposed module would do something useful beyond just passing through the parameters and tacking .action = foo on it, recommending closing as WONTFIX.

Was added with r105646

(In reply to comment #2)

Was added with r105646

Not really. The module "mediawiki.api.edit" introduced on r105646 is the one I was talking about on bug 34733 comment 3:

do the function name "postWithEditToken" need to contain the word "Token"?
Wouldn't be more intuitive if the user didn't have to write that when using
the API to edit a page? E.g. api.edit( params, ok, err )?
One more question: is this module new in MW 1.19? If so, and in the case the
function name will change, could this change be backported to MW 1.19?

I'm not sure what the request is here.

There is both a way to use action=edit (mediawiki.api.edit), which already existed since 1.18.1.

And an abstract interface to post with tokens exists as well (and edit token is even available already through mw.user.tokens now).

This bug seems obsolete.

He7d3r added a comment.Feb 5 2014, 9:17 AM

That is missing here is the part about having a simple name such as "edit" instead of the obscure "postWithEditToken":

api.edit( params ).done( fn ).fail( err )

Compare with the simplicity of "watch" and "unwatch".

matmarex updated the task description. (Show Details)Dec 21 2014, 6:45 PM
matmarex edited projects, added MediaWiki-General; removed MediaWiki-JavaScript.
matmarex set Security to None.
matmarex removed a subscriber: Unknown Object (MLST).
matmarex added a subscriber: matmarex.

A mediawiki.api.edit module exists now, but doesn't do anything useful.

Krinkle added a comment.EditedJan 8 2015, 9:51 PM

A mediawiki.api.edit module exists now, but doesn't do anything useful.

It existed since MediaWiki 1.18.1 as mentioned in T36744#399004. But doesn't implement an #edit method, only utilities such method would use.

However it's trivial to do really.

/**
 * @param {string} options.title
 * @param {string} options.text
 * @param {string} [options.summary]
 * @return {jQuery.Promise}
 */
edit = function ( options ) {
    return this.postWithEditToken( $.extend( {
        action: 'edit'
    }, options ) );
};

Which would expose it as:

api.edit( { title: 'Sandbox', appendtext: '\nHello.' } );

Instead of:

api.postWithEditToken( { action: 'edit', title: 'Sandbox', appendtext: '\nHello.' } );

I'm happy to add that.

A mw.Api#newSection method exists already.

I say let's do that. We should also add a convenient way to get the current wikitext of any page, but I guess this bug doesn't cover it. :)

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 13 2016, 10:14 AM

Unless this proposed module would do something useful beyond just passing through the parameters and tacking .action = foo on it, recommending closing as WONTFIX.

👍

matmarex closed this task as Resolved.Nov 14 2018, 2:27 PM
matmarex assigned this task to Krinkle.

'edit' and 'create' methods have been implemented in rMWaf9981495e66: mediawiki.api.edit: Add edit() and create() methods.