Talk:VisualEditor/Gadgets/Add a tool

Jump to navigation Jump to search

About this board

How to wrap selection in a simple template?

2
Varlin (talkcontribs)

Hi, following the examples given, I have been able to insert an all-defined template at cursor position, but unable to do something as simple as to wrap selection in a (mono-argument) template. I.e :

  1. I select "some text"
  2. I trigger the template
  3. I get "{{MyTemplate|some text}}"

I guess it is really simple but I spend hours trying to figure out how to do that... Any help would be highly appreciated !

EDIT : I precise I know how to do it using getText(), but it returns the plain text selection and so it removes the links and wikitext formatting.

Whatamidoing (WMF) (talkcontribs)

I don't know how to solve your problem, sorry.

Is it always the same template? I think this can be done with quotation marks, in the VisualEditor/Special characters tool, and (if your wiki only needs one template to work like this), I wonder if it might be faster and easier to pretend that {{MyTemplate| and }} were just strange quotation marks.

Reply to "How to wrap selection in a simple template?"

How can I enclose a selected text with a specific tag?

3
احمد نورالله (talkcontribs)

Hi, I have been trying to create a gadget that enclose the currently selected text with a "math" tag. Can anyone guide me to a tutorial (or doc) explains that?

احمد نورالله (talkcontribs)

I figured out how. That what I was looking for: ve.init.target.surface.getModel().getFragment().insertHtml() (if you are interested in).

Whatamidoing (WMF) (talkcontribs)
Reply to "How can I enclose a selected text with a specific tag?"

Can you include instruction for the layperson, please?

3
69.203.102.97 (talkcontribs)

"execute it in your browser's console before VE is loaded"

You lost me right there. How do I do that?

One reason I've chosen MediaWiki is that it can be installed and maintain by a non-programmer. I can follow a PHP code cookbook and copy routines and tweak their parameters to do new things, but there are many gaps in my knowledge. They might appear elementary to you, but they're chasms for me.

69.203.102.97 (talkcontribs)

Also, examples of the results might be helpful.

I'm not even sure this page is what I'm looking for. I just want to add a tool to the visual editor toolbar, so the users can insert text at the cursor point. (In this case, it will be a relatively long string of code to create expandable text). My understanding that the function would be another "tool," but is that the same thing as a "gadget"?

Whatamidoing (WMF) (talkcontribs)

Hmm. Well, speaking as one strictly-non-programmer to another, here are the things that I know, and perhaps that will answer some questions:

  • Nobody is entirely satisfied with this guide. We're not sure how to fix it yet, but it's not as good as we'd like.
  • Generally, in MediaWiki-land, a "gadget" is a user script that has been added to MediaWiki:Gadgets-definition (so that normal users can turn it on or off in Special:Preferences). https://en.wikipedia.org/wiki/User:PleaseStand/userinfo.js is an example of one of my favorite user scripts; if you install this in your account (or as a gadget, and turn it on), then when you visit someone's userpage, it adds a note near the title that says how old the account is and whether the person is a sysop.
  • I wonder whether your goal is a template, rather than a tool. Can you tell me more about what you want to achieve? Have you seen anything similar at another wiki?
Reply to "Can you include instruction for the layperson, please?"
There are no older topics