Jump to content

Extension talk:ReplaceSet

Add topic
From mediawiki.org
Latest comment: 5 years ago by Loizbec in topic number recognition

ReplaceSet and Defaultsort

[edit]

At first, this extension seemed to me an ideal solution for automating "defaultsorting", correcting or adapting the default key by which MW sorts pages in categories. So I added the following syntax to a template:

{{#if:{{{Defaultsort|}}}
|{{DEFAULTSORT:{{{Defaultsort|}}}}}
|{{DEFAULTSORT:{{#replaceset:{{PAGENAME}}|ĂĄ=a|Ă©=e|Ă­=i|Ăł=o|Ăș=u|Ăœ=y}}}}
}}

In other words, if the value for the magic word "Defaultsort" isn't manually defined, then the default sortkey is determined using ReplaceSet to substitute characters with diacritics for characters without diacritics.

However, this is not what happened. All pages are instead sorted under the symbol "<", which obviously, isn't very helpful. Is this due to a bug, a syntax error or something else entirely? Cavila MW 1.17, MySQL 5.5.16, Php 5.3.8 10:53, 21 May 2012 (UTC)Reply

Aha! I did a few tweaks and found out that leaving a bit of space between some of the squirly bracket solved it - an undifferentiated sequence of them is not understood, apparently. Maybe it's a bug or a limitation to using parser functions, but nothing specifically to do with ReplaceSet, I suppose. Cavila MW 1.17, MySQL 5.5.16, Php 5.3.8 11:36, 21 May 2012 (UTC)Reply

Upper limit of number of arguments?

[edit]

I get an error saying something like ”the limit in number of calls to the function ReplaceSet is reached”. Would be nice if the limits where documented here! rotsee (talk) 13:02, 3 November 2012 (UTC)Reply

Replacing Equals Sign

[edit]

In the documentation, it says I should be able to replace an equals sign using the following code. However, when I tried it, the string is unchanged. Other substitutions are working as they should. Am I missing something obvious? (MW 1.19.2, PHP 5.3.16, MySQL 5.5.21) -- Mw.clearish (talk) 09:41, 10 January 2013 (UTC)Reply

 {{#replaceset:A=B|<nowiki>=</nowiki>=&}}
You update to the latest version? = support is part of the most recent version. Daniel Friesen (Dantman) (talk) 09:57, 10 January 2013 (UTC)Reply
Thanks, that was the problem! I'd originally followed the link to Special:ExtensionDistributor/ReplaceSet and selected 1.19.x. Now I've got the Git master instead. -- Mw.clearish (talk) 10:55, 10 January 2013 (UTC)Reply

Replacing round bracket

[edit]

There is any way to use round bracket '(' as replacing text? If I try to do that, following error is output: The regex pattern "(" is missing the ending delimiter ')'. --Arex rus (talk) 04:49, 18 May 2013 (UTC)Reply

I devised. I used a regex pattern. For example:
{{#replaceset:Any ( text|/\(/i=-}}
would produce Any - text. --Arex rus (talk) 05:21, 18 May 2013 (UTC)Reply

how do i

[edit]

I have the following field in a template where users usually paste e-mails:


! Problem Details
|  [[Problem Details::{{{Problem Details|}}}]]
|-


the problem is, when e-mails contain characters [, ] and | the form goes crazy. I tried using Replaceset to change these characters into something else (doesn't really matter, can be changed to "-" for example but it did not work.

Any ideas how to do this?

185.31.48.30 12:59, 22 April 2014 (UTC)Reply

This doesn't really look like a ReplaceSet issue. For starters try using the #set function instead. Daniel Friesen (Dantman) (talk) 19:32, 22 April 2014 (UTC)Reply
Hello, it actually is and I managed to replace everything but pipe characters:

I now have this and it replaces ] and [ with - but this does not work with |. How can I escape that?

 |  [[Problem Details::{{#replaceset:{{{Problem Details|}}}|/\[/i=-|/\]/i=-}}]]

185.31.48.30 07:03, 23 April 2014 (UTC)Reply

The traditional trick is to create a Template:! with just the contents | and then use {{!}} where you need a |. Daniel Friesen (Dantman) (talk) 07:16, 23 April 2014 (UTC)Reply
The problem is, the data is entered into a form by users and they would have to replace every pipe with the template caller. I know that and I am looking for a way that does this automatically. 185.31.48.30 08:35, 23 April 2014 (UTC)Reply
If there are pipes in the template invocation then anything after them won't even exist as part of the Problem Details variable. There's simply no way around that.
Also I seriously recommend you switch to using #set instead of SMW's link style location. That notation is not intended for use in templates and the escaping you're doing would become pointless since as a parser function #set doesn't suffer any of the deficiencies that the link syntax has. Daniel Friesen (Dantman) (talk) 09:07, 23 April 2014 (UTC)Reply
Thank you. How can I use #set in a form? Normally I would have this syntax with #replaceset: | [[Problem Details::{{#replaceset:{{{Problem Details|}}}|text to replace=text after replace}}]]
I know with set I cannot use this sytax and I also have to use #show to display the data. So I came up with this:

| {{#set:Problem Details}}{{#show:{{PAGENAME}}|?Problem Details}} but it does not work. How do I pass the text from the input form into the #set function? 185.31.48.30 10:41, 23 April 2014 (UTC)Reply

| {{#set:Problem Details={{{Problem Details|}}}}}{{{Problem Details|}}} Daniel Friesen (Dantman) (talk) 10:53, 23 April 2014 (UTC)Reply
Thank you very much but it seems to do the very same thing as [[Problem Details::{{{Problem Details|}}}]] :( 185.31.48.30 12:14, 23 April 2014 (UTC)Reply

number recognition

[edit]

Hi, I want to find a number with replaceSet and then modify it, but there seems to be some character encoding[1] or other datatype issue:

{{#replaceset:{{{parameter}}}|/(\d+)/='''#debug:\1/{{formatnum:{{#expr:\1}}}}!!!'''}}

↓↓↓returns ↓↓↓

Which means it recognizes the pattern is able to retrieve it, but I can't treat it as a number (I tried to formatnum it without the #expr, it does not work either).

Any Idea what I could do ?

Thanks in advance

--Loizbec (talk) 17:15, 9 September 2019 (UTC)Reply

Solved with regex fun e option --Loizbec (talk) 08:06, 10 September 2019 (UTC)Reply
  1. ↑ /u (PCRE_UTF8) PCRE modifier is not recognized can't know if it's that I have non ASCII characters in my page