LinkTitles icon indicating copy to clipboard operation
LinkTitles copied to clipboard

Autolinking in templates doesn't work?

Open GerardNL opened this issue 3 years ago • 4 comments

There is a reasonable chance that I'm doing something wrong, but as far as I could figure out, no links were added inside a template. I've tried to narrow it down to something simple:

{{ infobox
| above       = Test Infobox
| label1      = Some label
| data1       = Some Page Title
}}

With "Some Page Title" being one of the pages in my Wiki. After saving (as a major change) or even after running the special page, "Some Page Title" doesn't become a link.

Just to be sure, I added "$wgLinkTitlesSkipTemplates = false;" to my settings. (Manually adding [[ ]] to the source makes it into a regular link that works)

Am I indeed doing something wrong or does this has something to do with how I used the template?

Thanks for your help in advance!

Gerard

GerardNL avatar May 13 '21 08:05 GerardNL

Yes, it does not work... Thanks for pointing this out. The regular expression that is supposed to split templates into chunks looks like this: '{{[^|]*?(?:(?:\[\[[^]]+]])?)[^|]*?(?:\|(?:\w+=)?|(?:}}))|\|\w+=|' -- needless to say, I'll have to be very much awake and concentrate to be able to figure this out ;-) I'm a bit short on spare time but I'll look into this.

bovender avatar May 17 '21 05:05 bovender

Yes, it does not work... Thanks for pointing this out. The regular expression that is supposed to split templates into chunks looks like this: '{{[^|]*?(?:(?:\[\[[^]]+]])?)[^|]*?(?:\|(?:\w+=)?|(?:}}))|\|\w+=|' -- needless to say, I'll have to be very much awake and concentrate to be able to figure this out ;-) I'm a bit short on spare time but I'll look into this.

That requires some strong coffee! These regular expressions are amazingly powerfull, but also amazingly complex. Looking for characters that are also regex operators is not helping either.

But maybe this helps a little bit: If I remove the spaces, it works !!

So the lines below will work with your code:

{{ infobox
|above= Test Infobox
|label1= Some label
|data1= Some Page Title
}}

So I guess the regex will need to ignore spaces in the parts it are not data. Is that slightly helpful?

There is of course no rush and I now have a work around, just trying to contribute is a small way.

Gerard

GerardNL avatar May 17 '21 09:05 GerardNL

Hm, I finally realized that the default value of $wgLinkTitlesSkipTemplates is true -- I changed that to false in my own wiki, and I have to say, it does work for me regardless of any spaces before and after the parameter name and regardless of any linebreaks in the template call.

Could it be that \w in the above regex is interpreted differently on your system than on mine? I use a Docker container based in the official Mediawiki image, and that runs on PHP 7.3.22. What's your PHP version, could that possibly make a difference?

bovender avatar May 18 '21 17:05 bovender

Interesting. I should have included these rather important details in my original entry: I'm using Mediawiki version 1.35.2 on PHP 8.0.5 (fpm-fcgi). Reading some more, it seems I took the "Use PHP 7.4.3 or later" more literal than intended.

I was using this page: https://regexr.com/ to figure out that the additional spaces seemed to be an issue. So it could be indeed related to different implementations of regex and php8 is doing \w differently than php7?

I can't figure out yet how to fix it completely, but did find a small correction:

from: ....|\|\w+=| 
to: ....|\|*\w+=|   (so an added asterisk)

This tiny change allows for spaces between the | and the parameter. This doesn't cover the spaces yet on the other side of the parameter (before the = sign), but is in the right direction? I hope that still works well on your version too.

GerardNL avatar May 19 '21 08:05 GerardNL