Community Wishlist Survey 2022/Bots and gadgets/Add built in API to add buttons for editing gadgets

Add built in API to add buttons for editing gadgets

  • Problem: It's hard to add buttons for editing tools in a single, visible group.
  • Proposed solution: Basically want I want is a replacement for this toolbar library. It allows adding buttons but it is kind of hard to maintain especially when new editor is added/removed. Same with VE editor (code and non-code) -- don't really have a simple, unified API that would allow adding buttons to toolbars.
  • Who would benefit: Gadget creators and gadget users.
  • More comments: Also it is hard to add something else then an image. Like and image with text which would be less confusing then just an image. Or add a button with an input (the code adds the button to advanced section which kind of sucks and is said to be bad, but I see no other way).
  • Phabricator tickets:
  • Proposer: Nux (talk) 00:06, 12 January 2022 (UTC)

Discussion

  • @Nux: Could you say a bit more about the shortcomings with adding new buttons to the toolbar? The existing system for adding a button in a gadget (to the existing top-level 'insert' group) is something like this:
    		mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
    			$textarea.wikiEditor( 'addToToolbar', {
    				section: "main",
    				group: "insert",
    				tools: {
    					strikethrough: {
    						type: "button",
    						label: "Strike-through",
    						oouiIcon: "strikethrough"
    					}
    				}
    			} );
    		} );
    
    This seems reasonable, but I'm probably missing some context of your proposal.
    For the second part, would T286759 Allow arbitrary HTML for buttons solve for what you're trying to do? It certainly would be good to be able to add things other than icon-buttons (CommTech might even get to doing this quite soon as part of the Real Time Preview for Wikitext wish).
    SWilson (WMF) (talk) 06:06, 12 January 2022 (UTC)
    That is just a bad API for me, at least for gadgets:
    1. A section is not added if its is missing.
    2. A group is not added if its is missing.
    3. The image must be a square.
    4. No way to provide a text beside the image or instead of the image (or at least none that I know of).
    Nux (talk) 19:49, 14 January 2022 (UTC)
  • Gadgets and user scripts are having some codes for this, and I think we don't need to add buttons. Thingofme (talk) 11:03, 13 January 2022 (UTC)
  • "don't really have a simple, unified API that would allow adding buttons to toolbars." I'll also note that part of this is because a lot of (requested) complexity has been added over the years. VE and the old editors are very different in design and capabilities. Wrapping a 'button' to work in multiple, much more advanced editors (which I think is what you want) is just not that easy to do and doesn't actually make it much easier to work with. —TheDJ (talkcontribs) 23:07, 13 January 2022 (UTC)
    Sure, I can understand it is not easy. That's why I would prefer not to do that 😉. We (at plwiki) always figured some way to do that. But lately there is this discussion about using API rather then hacking into classes or relaying on structure. I'm all for using APIs if they are good enough. In all of the editors you basically need: an icon, maybe text, a handler and a container for all that. Most of the time that should be enough.
    Adding stuff like "action: encapsulate" might be fun for doing something for yourself, but seems to simple for a gadget. At least I don't have any gadgets like that... Well I think I added one button like that on plwiki, but not as a gadget.
    BTW. Making an easier API for manipulation text and selection in an editor would be great, but that is another problem. Nux (talk) 20:07, 14 January 2022 (UTC)

Voting