Module talk:Delink: Difference between revisions

Content deleted Content added
Gnosygnu (talk | contribs)
 
(32 intermediate revisions by 18 users not shown)
Line 13:
:That's a neat trick! It's certainly better than the character-by-character concatenation mess that I created. We should be able to increase the performance further by using the Lua string library rather than the mw.ustring library where possible. Using mw.ustring has the drawback of having to cross back and forth between Lua and PHP all the time, which reduces the performance by quite a bit. Also, your version has some regressions in dealing with interwiki links, but that should be fixed easily enough. I'll have a look and see if I can improve it. Best — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 14:51, 17 April 2014 (UTC)
 
::I've notice that calling a simple function from mw.stringustring is also about 10 times slower than calling the same function from string, but I do not know what can be replace without risk, and to be able to mesure this difference I run the same function 1 million times, so I just keep mw.stringustring for know.
::I'd be glad to know the regressions. I've tried to deep the same result, except when I notice Mediawiki did not give the same result the delink function. My goal was to have the same text as seen on screen (even if there is brackets).
::[[User:Zebulon84|Zebulon84]] ([[User talk:Zebulon84|talk]]) 19:56, 17 April 2014 (UTC)
Line 28:
== delinkURL sometimes fails with "Tried to write global s_decoded" if used from a module with Module:No_globals ==
 
{{edit template-protected|answered=yes}}
 
Hi. My apologies for using the wrong "edit template-protected". I know this is a Module, and that it is unprotected, but I think it's being used on many pages and I wasn't sure if I should make the edit myself.
 
Line 52 ⟶ 51:
Let me know if you need any other info. Thanks.
[[User_talk:Gnosygnu|gnosygnu]] 23:51, 19 July 2014 (UTC)
 
I updated [[Module:Delink/sandbox]] with the latest code and added "local" there. You can use the following to test the new result:
<nowiki>{{#invoke:Gnosygnu|delink_sandbox|[http://a.org b]}}</nowiki>
 
Note that it returns "b" now, instead of "Script error"
[[User_talk:Gnosygnu|gnosygnu]] 23:58, 19 July 2014 (UTC)
:[[File:Yes check.svg|20px|link=]] '''Done'''<!-- Template:ETp --> [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 02:21, 20 July 2014 (UTC)
 
== Help for writing code ==
{{Tmbox
| type = style
| image = [[File:Help-browser.svg|60px]]
| text = You used the {{Tlx|Help me}} template, but you wanted an answer from a specific editor. If you still need help, please add your question to that editor's talk page instead. Alternatively, you can ask your question at the [[WP:THQ|Teahouse]], the [[WP:HD|help desk]], or join [[Wikipedia:IRC help disclaimer|Wikipedia's Live Help]] [[Wikipedia:IRC channels|IRC channel]] to get real-time assistance. Click [[Wikipedia:IRC help disclaimer|'''here''']] for instant access.<!-- Template:helpme-ns -->}}
Hello everyone, I need help on delinking wikilinks. The current template {{tl|delink}} works like this:
*<code><nowiki>{{delink|[[article]]}}</nowiki></code> returns <code>article</code>
*<code><nowiki>{{delink|[[article|display name]]}}</nowiki></code> returns <code>display name</code>
 
Can someone with experience provide the code to make a template, let's call it X, so that
*<code><nowiki>{{X|[[article]]}}</nowiki></code> returns <code>article</code>
*<code><nowiki>{{X|[[article|display name]]</nowiki></code> returns <code>article</code>
That is, how can I get the target of the wikilink instead of the label? I guess we can use [[Module:String]], 'cause I see many string-manipulating templates are based on it but I have no knowledge about Lua, so... Thank you in advance. [[User:Tran Xuan Hoa|Tran Xuan Hoa]] ([[User talk:Tran Xuan Hoa|talk]]) 23:24, 10 September 2016 (UTC)
:I checked around on IRC to see if I could find someone who might be able to help you and it was suggested that I direct you to {{u|Mr. Stradivarius}}. I'm going to mark this as needing a specific user to answer. Cheers! --[[User:Cameron11598|Cameron<sub><small>11598</small></sub>]] <sup>[[User Talk:Cameron11598|(Talk)]] </sup> 05:26, 11 September 2016 (UTC)
:: {{ping|Tran Xuan Hoa}} You can use :
::* wikicode : <code><nowiki>{{#invoke:String|replace|{{{1|}}}|%[%[ *([^%[%]{{!}}]+)[^%[%]]*%]%]|%1|plain=false}}</nowiki></code>
::* lua : {{code|<nowiki>article = article:gsub( '%[%[ *([^%[%]|]+)[^%[%]]*%]%]', '%1' )</nowiki>|lua}}
:: --[[User:Zebulon84|Zebulon84]] ([[User talk:Zebulon84|talk]]) 11:46, 24 September 2016 (UTC)
<span class="template-ping">@[[:User:Zebulon84|Zebulon84]]:</span> It worked. Actually I'm writing a template on my wiki. I myself was able to make up the code to achieve the same result but yours is more efficient. I will apply yours now. Thank you so much! [[User:Tran Xuan Hoa|Tran Xuan Hoa]] ([[User talk:Tran Xuan Hoa|talk]]) 13:39, 24 September 2016 (UTC)
 
== Where is this line break coming from? ==
 
I am trying to delink text that starts with a pound sign (#), and I am getting unexpected results.
 
<pre>
Foo bar {{delink|#SomethingNew}}
 
Biz Baz {{delink|Foo bar #SomethingNew}}
</pre>
 
I am expecting:
<blockquote>
Foo bar #SomethingNew
 
Biz Baz Foo bar #SomethingNew
</blockquote>
 
Actual results:
<blockquote>
Foo bar {{delink|#SomethingNew}}
 
Biz Baz {{delink|Foo bar #SomethingNew}}
</blockquote>
 
In the first example, there is a line break before the pound sign. Where is the extra line break coming from in the first example?
 
And yes, I know that the text contains no wikilinks; I am trying to strip wikilinks from all text in a template parameter (see {{tl|YouTube/sandbox}} and [[:Template:YouTube/testcases#Playlist]]) and need to ensure that delinking does not affect unlinked text that was working fine before my changes.– [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 06:39, 5 January 2020 (UTC)
:The module returns the correct text ''without'' a newline. However, something outside our control inserts a newline when a module returns text begining with certain characters, and one of the characters is <code>#</code>. See [[Template talk:Weather box#Spacing]]. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 09:05, 5 January 2020 (UTC)
:: Additional unexpected lines are often related to parser bug {{phab|T18700}}. A <code><nowiki><nowiki/></nowiki></code> before a template call can help for templates returning an HTML table. <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;">&nbsp;&nbsp;[[User:Jts1882|Jts1882]]&nbsp;&#124;[[User talk:Jts1882|&nbsp;talk]]&nbsp;</span> 09:28, 5 January 2020 (UTC)
:::This is expected behaviour and is nothing to do with tables. If the first non-whitespace character of a parameter is one of those used to generate list markup (<code>: ; * #</code>), then a list will be started. See [[H:T#Problems and workarounds]]. --[[User:Redrose64|<span style="color:#a80000; background:#ffeeee; text-decoration:inherit">Red</span>rose64]] &#x1f339; ([[User talk:Redrose64|talk]]) 10:02, 5 January 2020 (UTC)
: {{phab|T14974}} is the bug here. [[User:Anomie|Anomie]][[User talk:Anomie|⚔]] 14:31, 5 January 2020 (UTC)
::Thanks, all. That's a strange one. I have added <code><nowiki><nowiki/></nowiki></code>, which seems to have done the trick. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 15:43, 5 January 2020 (UTC)
 
== Handling HTML line breaks ==
 
{{edit template-protected|answered=yes}}
Hello!
 
On the sandbox I've made a small change which means that HTML line breaks (<nowiki><br>, <br/>, <br /></nowiki>, etc.) are replaced by newline characters and thus treated in the same way as normal newlines.
 
I've added new test cases, and it doesn't seem to have broken any existing tests.
 
Thanks - [[User:OliverGalvin|odg]] ([[User talk:OliverGalvin|talk]]) 00:25, 18 August 2020 (UTC)
:[[File:Red information icon with gradient background.svg|20px|link=|alt=]] '''Not done for now:'''<!-- Template:ETp --> It seems to remove newlines completely:
:<code><nowiki>{{delink/sandbox|[http://www.example.com HTML line breaks] between<br>two [http://www.example.com links]}}</nowiki></code> &rarr;
:{{delink/sandbox|[http://www.example.com HTML line breaks] between<br>two [http://www.example.com links]}}
:<code><nowiki>{{delink|[http://www.example.com HTML line breaks] between<br>two [http://www.example.com links]}}</nowiki></code> &rarr;
:{{delink|[http://www.example.com HTML line breaks] between<br>two [http://www.example.com links]}}
:Please try again. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 02:52, 18 August 2020 (UTC)
 
== A link with a question mark does not get delinked ==
 
A link with a question mark does not get delinked.
* See simple example: {{tlx|Delink|<nowiki>[[Name?]]</nowiki>}} -> {{Delink|[[Name?]]}}
* Real use case: {{tlx|Delink|<nowiki>[[What If...? (TV series)|What If...?]]</nowiki>}} -> {{Delink|[[What If...? (TV series)|What If...?]]}} [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 10:10, 29 September 2021 (UTC)
 
:@[[User:Gonnym|Gonnym]] I see that the issue was solved by adding a second condition [[Special:Permalink/1208348327#L-84|at line 84]]. However question marks are getting matched at that line only because the pattern includes an invisible control character (U+007F). I assume it was added by mistake and it can be removed along with the second condition [[User:Sakretsu|Sakretsu]] ([[User talk:Sakretsu|talk]]) 14:56, 31 March 2024 (UTC)
 
== Performance enhancement? ==
 
I have made a few changes to the /sandbox version
# delinkLinkClass now searches forward for the next '[' rather than one char at a time
# a check in _delink is made for the existence of '[' as Module:Delink is called often without any links to delink (eg 2018–19_UEFA_Europa_League_qualifying_phase_and_play-off_round_(Main_Path))
# in function getDelinkedLabel a check is made for the 'colon trick' - it will be the third byte or not at all
I believe this to be a helpful improvement
[[User:Desb42|Desb42]] ([[User talk:Desb42|talk]]) 07:01, 30 April 2022 (UTC)