Page MenuHomePhabricator

Show some gadgets only for admins
Closed, ResolvedPublic

Description

Author: le.korrigan

Description:
In the Gadgets extension, it would be useful to keep some gadgets for admins only. I mean that a dedicated section could show up only for admins and not for regular users, as it may contain gadgets useless for normal users or potentially harmful if used by them. Thanks.


Version: unspecified
Severity: enhancement

Details

Reference
bz12211

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:55 PM
bzimport set Reference to bz12211.
bzimport added a subscriber: Unknown Object (MLST).

That seems kind of creepy... SECRET GADGETS OMFG :)

le.korrigan wrote:

Well, just like some special pages show up only for the caba(ahem) admins...

I have been thinking about that before, but i'm not quite sure how to do it.
First question: should sections be hidden/shown based on groups, or based on permissions? Seconds question: what would be a good syntax to specify the required group/permission on the MediaWiki:Gadgets-definition page? Using some magic syntax there sucks as it is... but until now, it's pretty close to normal wikitext. No sure how to integrate this. Any suggestions?

Anyway, I don't have much time for this stuff right now - nudge me in a couple of months, or find someone else to do it :)

You should use permission keys, not groups directly, for this sort of thing. I'd also recommend indicating in the list which ones are restricted, as is doen on Special:Specialpages.

Created attachment 5049
Proposed patch, also implements bug 13742

Attached:

Reverted by Brion in r32278.

By brion in r37278:

Revert r37263 for now:

  • (bug 12211) Show some gadgets only for admins
  • (bug 13742) Allow for gadgets to be turned on by default

I'm a bit leery of the 'on by default' entirely at the moment. :)

A few comments:

  • The readme examples don't seem to clearly show the option format
  • Why are numeric constants being used as indexes to the option array? Strings are easier to work with and debug.
  • There's a lot of stuff like this which feels very ugly:

if( isset( $gadget->options[Gadget::RIGHTS] ) && !empty( $gadget->options[Gadget::RIGHTS] ) ) {

Since it's all hard-coded anyway, why not just do something nice and clear like this?

if( !empty( $gadget->rights ) ) {

  • And this: if( wfGadgetAllowed( $gadget->options ) ) { to: if( $gadget->isAllowed() ) {

Please provide a patch that addresses the above concerns.

mike.lifeguard+bugs wrote:

(In reply to comment #9)

By brion in r37278:
I'm a bit leery of the 'on by default' entirely at the moment. :)

You can do things like

var gadget_removeimagetools = 1;

in a gadget. And then check

if(typeof gadget_removeimagetools == 'undefined') gadget_removeimagetools = 0;
if(gadget_removeimagetools != 1) addOnloadHook(add_all_user_tools);

in Common.js or whatever. This lets you disable parts of the common site js.

That can be used as a workaround if that sort of thing can't be done in the php nicely. Though, I doubt Brion would be any less "leery" of this technique.

So if this is fixed now, what is the mechanism for designating a gadget so that it is only shown to admins?

Not admins, it can require any user right.
Example: * GadgetName [rights=block] | ....
I've expanded the docs at http://www.mediawiki.org/wiki/Extension:Gadgets#Options now.