Talk:TemplateScript

Latest comment: 9 months ago by Ignacio Rodríguez in topic Adaptations to Vector 2022

global.js

edit
The following discussion is marked as answered (suggested change added). If you have a new comment, add it just below the box.

The line in the pages says

Copy the following code to your common.js page.

as this can also be added to global.js, is that worth mentioning there too?  — billinghurst sDrewth 04:39, 3 November 2014 (UTC)Reply

Done. Thanks for the suggestion. :) —Pathoschild 04:54, 03 November 2014 (UTC)

Question about regex session

edit

@Pathoschild: Just as bats wings are both different and similar to birds wings, our it.source (and mul.source) "memoRegex" is both similar and different to your Regex editor. I browsed a little bit the code (a very hard job for my limited skill!), and I found how/where session are stored. My question: is there a tool to save permanently regex editor session data into a page code? --Alex brollo (talk) 19:24, 16 August 2015 (UTC)Reply

Hi Alex brollo. The sessions are saved to localstorage, but soon we might add them to user preferences instead. That means they'd be saved permanently for your user account, even if you use a different browser or computer. Would that work for you? —Pathoschild 19:44, 16 August 2015 (UTC)

Using TemplateScript for a OCR checker?

edit

At English Wikisource there is a discussion about how to check for Commons OCR errors. What scope is there to have TemplateScript or a targeted variation, have a namespace ability to look for a compiled list of common OCR errors when the page is visited/previewed/saved. Thinking that in the Page: ns that it can check a common page or problematic words, one per line, and highlight text found on that page.  — billinghurst sDrewth

Hello Billinghurst. TemplateScript already lets you register a custom script (which can fetch another page's content and interact with the current page), but it's really meant to be triggered by the user. It doesn't support running scripts automatically on save, but you can intercept the form submission directly without TemplateScript. —Pathoschild 17:49, 08 January 2016 (UTC)

New code editors

edit
The following discussion is marked as answered (fixed by updating from the regex menu framework to TemplateScript). If you have a new comment, add it just below the box.

Doesn't seem to work in the RegEx part on the new code editor enabled namespaces, like templates, or content pages where Visual editor edit window gets messed up. KPu3uC B Poccuu (talk) 16:43, 8 January 2016 (UTC)Reply

Hello KPu3uC B Poccuu. VisualEditor isn't supported yet, but CodeEditor should work. Can you provide an example page with CodeEditor where it doesn't work? —Pathoschild 17:06, 08 January 2016 (UTC)
Hello. I tried it on ru:Шаблон:Param. The editor becomes a strange mess of colored blocks. KPu3uC B Poccuu (talk) 17:51, 8 January 2016 (UTC)Reply
It looks like you're not using TemplateScript; you have a custom version of the obsolete regex menu framework instead. There are also a few errors in the other scripts you're using; for example, User:KPu3uC B Poccuu/rqedit.js uses sajax_init_object (which no longer exists) and User:js/dabfixer.js calls addFuncBtn (which doesn't seem to exist). I suggest:
  1. removing any scripts you no longer use;
  2. transferring your translations from User:KPu3uC B Poccuu/RegExFramework.js to TemplateScript#Translation;
  3. replacing the regex menu framework (which is no longer supported) with TemplateScript (which has equivalent features).
Do you want me to help you do that? —Pathoschild 21:08, 08 January 2016 (UTC)
Would be really nice, the sole reason I kept both was I wasn't sure how to convert my custom replace rules to the new system. Dabfixer and rqedit aren't my scripts, the latter was simply adopted and changed a bit, BTW. KPu3uC B Poccuu (talk) 01:14, 9 January 2016 (UTC)Reply
Wait, I do use it, it's on my global.js. KPu3uC B Poccuu (talk) 01:15, 9 January 2016 (UTC)Reply
Hello? KPu3uC B Poccuu (talk) 01:16, 12 January 2016 (UTC)Reply
Don't worry, I haven't forgotten you. :) I was focused on Synchbot this weekend; I'll update your scripts this week. —Pathoschild 01:23, 12 January 2016 (UTC)
If you wanna fix colored mess with the code editor, you just need to insert the RegExp tool form before $('#wpTextbox1'). KPu3uC B Poccuu (talk) 13:41, 12 January 2016 (UTC)Reply
This was fixed by updating from the regex menu framework to TemplateScript (see discussion). —Pathoschild 21:29, 17 January 2016 (UTC)

Russian localization

edit

See User:KPu3uC B Poccuu/global.js. You may revert that after you copy it. KPu3uC B Poccuu (talk) 11:40, 17 January 2016 (UTC)Reply

Thanks! Your translations are added and deployed. :) —Pathoschild 15:49, 17 January 2016 (UTC)
There is untranslated menu item title ("Regex editor") and a wild "tutorial" (should be "справку" in the same quotes as in other places).
@KPu3uC B Poccuu: the menu item is translated, but TemplateScript is loaded before the translations in User:KPu3uC B Poccuu/global.js. Make sure that ru.js is imported first (since otherwise it's not available when TemplateScript renders the menu).
I'll correct the 'tutorial' translation. Can you translate the link title ("JavaScript regex tutorial") too? Should the link point to ru:Регулярные выражения instead? —Pathoschild 02:10, 20 January 2016 (UTC)
It may point to https://learn.javascript.ru/regular-expressions-javascript instead. I don't see such a string anywhere in the form though. KPu3uC B Poccuu (talk) 03:23, 20 January 2016 (UTC)Reply
It's in the regexeditor.instructions string. Here's the translated string so far (just missing the title= text):

Вы можете указать любое количество шаблонов для использования. Шаблон поиска может выглядеть как «{code|text=шаблон поиска}», либо как «{code|text=/шаблон/флаги}», а шаблон замены может содержать ссылки на группы вида «{code|text=$1}» (см. {helplink|text=справку|title=JavaScript regex tutorial|url=https://learn.javascript.ru/regular-expressions-javascript}).

Pathoschild 03:34, 20 January 2016 (UTC)
Alright: Справка по регулярным выражениям JavaScript. KPu3uC B Poccuu (talk) 03:49, 20 January 2016 (UTC)Reply
Done! You may need to update your browser cache to see the updated translations. —Pathoschild 04:58, 20 January 2016 (UTC)

Regex editor

edit

Hi! I just started using TemplateScript, and have been finding the regex editor really useful. However, I am a little frustrated by a few things. I wish the editor would automatically bring up a script that I have been repeatedly using, rather than requiring me to click on the save each time. And I wonder if it would be possible to allow it to overwrite previous saves of the script, so that I don't have to save the new version of the script and then delete the previous version of the script in the saved scripts menu. That would save a few clicks. Are there any options for setting the behavior of the regex editor to make it more convenient? Erutuon (talk) 10:10, 2 February 2017 (UTC)Reply

I realized I can just add a script that contains the regex I want to use; much simpler. Erutuon (talk) 20:25, 2 February 2017 (UTC)Reply

Bug in script

edit

On Wiktionary, when I use a script that adds {{subst:chars|grc|}}, it returns that template plus the character immediately before the cursor. So if I click the script when the cursor is immediately after a pipe, it returns {{subst:chars|grc|}}|. Can this be fixed? Erutuon (talk) 21:21, 2 February 2017 (UTC)Reply

Hi Erutuon. Sorry, I didn't see this message earlier. I just released a fix for that; you may need to bypass your cache to see the changes. —Pathoschild 16:10, 23 September 2017 (UTC)Reply
@Pathoschild: Thanks! The problem is fixed now. Erutuon (talk) 20:31, 26 September 2017 (UTC)Reply

updating my scripts

edit

@Pathoschild:I have been informed that my scripts, in particular EngvarB.js, is using a deprecated framework, and that I ought to migrate to this one. My problem is that I have received a lot of coding help and advice on an ongoing basis, am out of my depth in updating them. Can anyone advise me how to do this in a step by step manner? --Ohconfucius (talk) 19:17, 31 August 2017 (UTC)Reply

Hi Ohconfucius. Sure, I can update your scripts for you. Which one do you want to start with, and how do you want me to update it (e.g. should I update the test version for you to review)? Feel free to ping me when you reply, since I don't actively monitor my watchlist anymore. —Pathoschild 15:32, 23 September 2017 (UTC)Reply

Conflict with Wikitext highlighting

edit

I'm trying out the new wikitext highlighting on the English Wiktionary, but I find I can't use my TemplateScript scripts anymore. I click the buttons on the sidebar and they do nothing. My other editing scripts work fine. Not sure where the problem lies, but just letting you know. Erutuon (talk) 20:24, 26 September 2017 (UTC)Reply

The wikitext highlighting feature replaces the textbox with CodeMirror, which TemplateScript doesn't support yet. I'll look into adding CodeMirror support sometime soonish. —Pathoschild 14:29, 27 September 2017 (UTC)Reply

Script not functioning. Can we generate a local copy?

edit

@Pathoschild: Hi. I know that there was some discussion on github though I wasn't fully paying attention. Anyway, there is no functioning script being called. Do we have a ready workaround in the absence of the script? Can we pull a local copy at least as a temporary measure?  — billinghurst sDrewth 02:58, 1 October 2019 (UTC)Reply

Sorry about that! I had to revamp the Toolforge structure a bit to fix some performance issues with the web tools, which left a broken symlink in the static hosting. That's fixed now. (You might need to bypass your cache to see the fix.) —Pathoschild 03:18, 01 October 2019 (UTC)Reply

Make the regex apply to all things it matches?

edit

Hi! I just made a template with the regex editor to remove smart quotes/apostrophes. One problem is that each click only runs the patterns once — only replacing one smart quote at a time. How can I make it do this to each match at once instead? Thanks, DemonDays64 (talk) 05:12, 22 March 2020 (UTC) (please ping on reply)Reply

@DemonDays64: add a "g" switch after the closing "/" /your regex/g (g = global). Have a look at s:user:billinghurst/common.js for examples  — billinghurst sDrewth 11:33, 22 March 2020 (UTC)Reply
There is a smart quote replacement there '" fwiw  — billinghurst sDrewth 11:36, 22 March 2020 (UTC)Reply
@Billinghurst: thanks, the flag works great! Also where are the templates I save from the regex editor stored? DemonDays64 (talk) 14:06, 22 March 2020 (UTC)Reply
@DemonDays64: If you are talking about those that you save from the interface, they are stored in your local PC browser settings. Pathoschild can tell you the intricate details, that is blackmagic to me. Those that you see in my common.js appear in the sidebar of my browser, some in all editing windows, some in editing window for a namespace.  — billinghurst sDrewth 04:57, 23 March 2020 (UTC)Reply

Positive lookbehind syntax shows as erroneous

edit

When using the syntax /(?<=lookbehind)regex the (? ) components show as errors in red. The syntax works without issue, though it doesn't seem to be recognised as valid.  — billinghurst sDrewth 15:25, 1 August 2021 (UTC)Reply

@billinghurst Sorry, I missed this message. It's using the open-source regex-colorizer library for the syntax highlighting, so it'd need to be fixed in that code. The author doesn't seem to be active though, so we might need to find a different library to support those. —Pathoschild 05:09, 29 January 2023 (UTC)Reply

Regex editor in WikiEditor2010

edit

Hello, the recent changes for the new realtime previewin WikiEditor2010 seem to conflict with the Regex editor of TemplateScript. The area on bottom of the edit form is affected. The exact, but at least partly defunct appearance seems to depend on both text length and whether syntaxhighlighting (Code Mirror) is enabled. If you insist I could open an issue ticket in GitHub and add some images.

Speaking about the regex editor: Could it made as movable as the default search&replace form or even be merged with it? This should fix the above issue. On the other hand I always loved that it has been inserted above the text and so does not hide content which could happen with a movable modal window. — Speravir – 01:39, 15 January 2023 (UTC)Reply

Pathoschild, didn’t you notice my message? — Speravir – 01:59, 24 January 2023 (UTC)Reply
Hi! That should be fixed now; let me know if you have any issues after bypassing your cache. (Nope, I don't get notified for messages here unless I'm mentioned, since it's not my user talk page.) —Pathoschild 04:58, 29 January 2023 (UTC)Reply
Thank you, Pathoschild, works fine, again! — Speravir – 23:22, 29 January 2023 (UTC)Reply

Vector-2022 incompatibility

edit

Using the 2022 skin, every Category specification is rendered as "General". This can be seen even without custom scripts because it also applies to the Regex Editor. Other skins display as expected. This so obvious I'm sure it is known, but is it a TemplateScript bug or a Vector-2022 bug? DavidBrooks (talk) 04:59, 11 January 2024 (UTC) ETA: should have pinged Pathoschild. DavidBrooks (talk) 14:58, 11 January 2024 (UTC)Reply

Can't restrict to Main namespace

edit

@Pathoschild: While I am here, the forNamespaces option doesn't seem to be able to restrict to Article space. Whether I give a value of 0 or "", the link appears in every namespace. Other values work as expected. DavidBrooks (talk) 18:58, 11 January 2024 (UTC)Reply

Adaptations to Vector 2022

edit

@Pathoschild Vector2022 in every wiki means that almost no one will see the scripts we have prepared in each local wiki. We were thinking at my local project, that maybe if we could move our scripts as buttons in the "new" toolbar, that could make it easier. Is there an established way to do it? I know the "Changing how the UI is rendered" section is for exactly that, but no one in our community is versed enough in Javascript to try to understand how to do such thing. I think many communities will benefit from having an "official" Vector2022 renderer. If it's not possible, can you at least provide an example of how a "renderer" could look like? Ignacio Rodríguez (talk) 00:40, 16 March 2024 (UTC)Reply

Is there an established way to do it? mw.util.addPortlet(). Nardog (talk) 01:36, 17 March 2024 (UTC)Reply
(Please read the content page of this talk) I'm talking about the Changing how the UI is rendered section. In the example provided there,
> For example, let's say you want to add tools to the Visual Editor toolbar instead:
they don't anticipate how such a "renderer" would look like, even in pseudocode, we get "// custom rendering logic". In some communities we have relied on TemplateScript's simplicity to make editor tools that suits our needs, but we don't have any developer that can create such "renderer" in JavaScript. But with the advent of Vector2022 those tools will be hidden by default. We want to take our TemplateScript set of "buttons" and put them in the toolbar or somewhere else, visible and usable. Ignacio Rodríguez (talk) 15:15, 19 March 2024 (UTC)Reply
Return to "TemplateScript" page.