Last modified: 2014-02-12 23:32:45 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T49480, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 47480 - Watching pages (AJAX) requires WriteAPI
Watching pages (AJAX) requires WriteAPI
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Watchlist (Other open bugs)
1.20.x
All All
: Normal major with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
: javascript
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-04-21 19:51 UTC by Patrick Westerhoff
Modified: 2014-02-12 23:32 UTC (History)
6 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Patrick Westerhoff 2013-04-21 19:51:52 UTC
The new† AJAX method of watching pages, implemented in `/resources/mediawiki.page/mediawiki.page.watch.ajax.js`, makes uses of the MW API methods for watching pages (http://www.mediawiki.org/wiki/API:Watch).

Unfortunately, this API method is part of the editing API and as such requires `$wgEnableWriteAPI` to be enabled *and* the `writeapi` right.

As `$wgEnableWriteAPI` is enabled by default since 1.14, it’s somewhat safe to assume that it is enabled. The `writeapi` right however should not be required for a basic functionality such as watching pages.

On our wiki, we have the `writeapi` enabled for autoconfirmed users and above. This is mainly to prevent vandals to create new users and then use the API to quickly vandalize the wiki (yes, that has happened before).

Now with the new AJAX functionality, this implies that only autoconfirmed users can watch pages. This is a terrible usability issue.

Watching pages, which is a very fundamental functionality for registered users, should not be restricted by either the `writeapi` right, or even the `$egEnableWriteAPI` setting. It makes perfect sense for wikis to disable the write API altogether while still expecting users to be able to watch pages.

In a first step, I would argue why watching pages via the API even requires the write API. Yes, it is a “changing” operation, but it should not be considered an operation that changes wiki *content*. And it is restricted to the current user anyway.

In a second step though, I think that such AJAX functionality should not make use of the API at all, *if* said API can be disabled. Watching pages should use a separate API which is not affected by the `$wgEnableWriteAPI` and `$wgEnableAPI` setting.


† I actually have no idea when that was added; I have been stuck on a old MW version for quite a while now.
Comment 1 Sam Reed (reedy) 2013-04-21 23:58:00 UTC
(In reply to comment #0)
> The new† AJAX method of watching pages, implemented in
> `/resources/mediawiki.page/mediawiki.page.watch.ajax.js`, makes uses of the
> MW
> API methods for watching pages (http://www.mediawiki.org/wiki/API:Watch).
> 
> Unfortunately, this API method is part of the editing API and as such
> requires
> `$wgEnableWriteAPI` to be enabled *and* the `writeapi` right.
> 
> As `$wgEnableWriteAPI` is enabled by default since 1.14, it’s somewhat safe
> to
> assume that it is enabled. The `writeapi` right however should not be
> required
> for a basic functionality such as watching pages.
> 
> On our wiki, we have the `writeapi` enabled for autoconfirmed users and
> above.
> This is mainly to prevent vandals to create new users and then use the API to
> quickly vandalize the wiki (yes, that has happened before).
> 
> Now with the new AJAX functionality, this implies that only autoconfirmed
> users
> can watch pages. This is a terrible usability issue.
> 
> Watching pages, which is a very fundamental functionality for registered
> users,
> should not be restricted by either the `writeapi` right, or even the
> `$egEnableWriteAPI` setting. It makes perfect sense for wikis to disable the
> write API altogether while still expecting users to be able to watch pages.
> 
> In a first step, I would argue why watching pages via the API even requires
> the
> write API. Yes, it is a “changing” operation, but it should not be considered
> an operation that changes wiki *content*. And it is restricted to the current
> user anyway.

Seems a bit of a daft exclusion case. Same problem occurs if the api is disabled completely. Should api watch still work? Should we really add numerous exceptions for action=watch?
Comment 2 Patrick Westerhoff 2013-04-22 07:59:18 UTC
(In reply to comment #1)
> Should api watch still work? Should we really add numerous
> exceptions for action=watch?

I think the questio is rather, if the normal API should be used for watching pages at all. After all that function is accessed from the normal wiki website served via index.php.

Before, it used a special “API” in index.php to (un)watch pages, and I think it should continue to do that, as long as the API is not a guaranteed feature (i.e. as long as you can turn it off).
Comment 3 Andre Klapper 2013-04-22 09:47:30 UTC
[Restoring reset priority]
Comment 4 Brion Vibber 2013-04-22 22:12:45 UTC
I recommend removing the old 'write-mode' switch entirely, as front-end code nowadays expects to have full read-write access via the API.
Comment 5 Robert Morley 2013-06-07 20:18:19 UTC
I bumped up the importance to High, since this essentially means you either break your Watch tab, or are forced to open up access to the write API, which can be a significant security issue.
Comment 6 Jesús Martínez Novo (Ciencia Al Poder) 2013-06-07 20:30:04 UTC
This has been reported as an error here [1] ;)

The "watch/unwatch" tab is actually a link, in the form of index.php?title=PAGENAME&action=watch&token=WATCHTOKEN.

If I open that link in a new tab, it performs the watch/unwatch action without problems.

What I suggest here is to detect if the api is disabled, or just the writeapi, and if that's true, let the browser follow the link instead of using the api. We already have wgEnableWriteAPI as a JavaScript variable [2], so mediawiki.action.watch should check it and act accordingly.

----


[1] https://www.mediawiki.org/wiki/Thread:Project:Support_desk/Error_when_trying_to_watch_pages

[2] https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#mw.config
Comment 7 Jesús Martínez Novo (Ciencia Al Poder) 2013-06-07 20:31:10 UTC
Adding +javascript keyword, as per my proposal at comment #6
Comment 8 Alex Monk 2013-06-07 20:34:13 UTC
(In reply to comment #4)
> I recommend removing the old 'write-mode' switch entirely, as front-end code
> nowadays expects to have full read-write access via the API.

I agree, this should be WONTFIX.
Comment 9 Robert Morley 2013-06-07 20:56:07 UTC
Alex: what else in the base MediaWiki software expects write access to the API?
Comment 10 Alex Monk 2013-06-07 21:17:14 UTC
The feedback module, but nothing that comes in the basic install with no extensions or custom JS etc. as far as I'm aware (I doubt any modern wikis run from the base software without any extensions or helpful JS stuff though).
Comment 11 Robert Morley 2013-06-07 21:21:22 UTC
True, but the base software should gracefully handle any reasonable rights configuration a wiki might want. A number of wikis I've seen, including our own and obviously the OP's, disable or limit access to the API to discourage unauthorized bot editing. It's not a perfect system, but it's one of a number of security measures you can take. I'm strongly opposed to the idea that the base software would force a specific security configuration on all users, or break basic functionality.
Comment 12 Chris Steipp 2013-06-07 21:52:36 UTC
I do think core should gracefully handle any legitimate configurations.

On this particular issue, I will say that at this point, I think the write api is as secure as the web interface. I know early on there were a lot of bugs, and a lot of places where access controls in the api didn't match the website. But as far as I'm aware, those have all been fixed.

It's nice that users can turn it off and remove that attack surface entirely, but I'm not sure how much that's worth against the tradeoff in development costs.
Comment 13 Patrick Westerhoff 2013-06-07 22:34:23 UTC
(In reply to comment #6)
> What I suggest here is to detect if the api is disabled, or just the
> writeapi,
> and if that's true, let the browser follow the link instead of using the api.
> We already have wgEnableWriteAPI as a JavaScript variable [2], so
> mediawiki.action.watch should check it and act accordingly.

I think that would be a very good way to solve this. I didn’t realize that the tab link is already correct. The simplest way would be to just not make this use an AJAX call when the WriteAPI is disabled. I’ll try to come up with a patch.
Comment 14 Robert Morley 2013-06-07 22:39:27 UTC
Thanks, Patrick! From what little I know of the MW code, I don't think it'll be a problem, but if it's too difficult to detect writeapi permissions for the current user (as in the scenario the OP describes) at runtime for whatever reason, even adding something like $wgWatchUseWriteApi to LocalSettings would be sufficient for most cases, I would imagine.
Comment 15 Patrick Westerhoff 2013-06-07 22:48:52 UTC
(In reply to comment #14)
> if it's too difficult to detect writeapi permissions for the
> current user (as in the scenario the OP describes) at runtime for whatever
> reason, even adding something like $wgWatchUseWriteApi to LocalSettings would
> be sufficient for most cases, I would imagine.

Well the simplest way would be to just have it on the server-side say “nope, you don’t get AJAX for this”, so it does not even need to be handled by JavaScript.

Btw. I am the OP ;)
Comment 16 Robert Morley 2013-06-07 22:50:39 UTC
> Btw. I am the OP ;)

D'oh! :)
Comment 17 Andre Klapper 2013-06-08 21:52:05 UTC
[not high priority, resetting]
Comment 18 Patrick Westerhoff 2013-06-12 11:51:54 UTC
Okay, maybe this is not as simple as I would it like to be. The AJAX'ifying happens in mediawiki.page.watch.ajax.js[1]. As we don’t want to serve different JS modules based on the user rights, we would have to add some kind of switch to the module that won’t execute the function then.

We *could* use the mediaWiki.user module[2] to get the rights of the current user, but that would involve another API call, so that’s not a good idea.

We could also either add some switch class to the body tag which the ajax module filters for, or define another config variable that indicates if the write API is available right now or not. But I’m not sure what the official stance on adding such things is for MediaWiki.

And then another option would be to add a "noapi" class to all the generated watch links which then again could be filtered for.


What do you think? What would be an acceptable solution?


[1] https://git.wikimedia.org/blob/mediawiki%2Fcore/HEAD/resources%2Fmediawiki.page%2Fmediawiki.page.watch.ajax.js#L103
[2] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules#mediaWiki.user
Comment 19 contrafibularity 2013-07-02 07:35:39 UTC
What can you do when you encounter this bug? My users and I have been wrestling with this kind of problem for four months now and I was wondering if it may be related.
Comment 20 Patrick Westerhoff 2013-07-02 11:15:14 UTC
> What can you do when you encounter this bug?

The only thing you can do to make it work is to enable Write-API [1], and give your users the necessary group rights to access it [2]. For example the following configuration disallows the write API for unregistered users but allows it for registered users, making them use the watch API:

    $wgGroupPermissions['*']['writeapi'] = false;
    $wgGroupPermissions['user']['writeapi'] = true;


[1] http://www.mediawiki.org/wiki/Manual:$wgEnableWriteAPI
[2] http://www.mediawiki.org/wiki/Manual:User_rights
Comment 21 contrafibularity 2013-07-02 19:44:30 UTC
Thanks. Unfortunately, that doesn't seem to work on my installation, MW 1.19.2. Is there perhaps any specific order in which those configuration statements should be given in localsettings.php ?

See the MW thread here:

http://www.mediawiki.org/wiki/Thread:Project:Support_desk/Watchlist_error_after_upgrade_to_1.18.1

No javascript conflict was detected other than this:

TypeError: $link.attr(...) is undefined

which refers to

accesskeyTip = $link.attr( 'title' ).match( mw.util.tooltipAccessKeyRegexp ),
Comment 22 contrafibularity 2013-07-04 06:40:02 UTC
[Edit:] It probably is the skin I'm using after all, which appears to have broken following a change in MediaWiki (whether or not it is related to the one outlined above). 

The reason that I dismissed this before is that switching to another skin, such as Vector, did not have any positive effect on the watch / unwatch action. One can only guess why, but I did notice later on, in quite another cotext, that changes relating to Ajax require some time to take effect.
Comment 23 Umherirrender 2013-07-12 18:25:26 UTC
Gerrit change #65785 adds checks for writeapi permission before loading the javascript module.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links