Wikipedia talk:Lua
| WP:Lua Project |
WT:Lua Project talk |
Help |
To do |
Requests |
Resources en: m: mw: external |
| Wikipedia:Lua/To do was nominated for deletion on 21 May 2015. The result of the discussion was keep. |
| To help centralise discussions and keep related topics together, all Wikipedia:Lua subpages' talk pages and Help talk:Lua redirect here. For discussions about Wikipedia:Lua/Requests from February to March 2013, see Wikipedia talk:Lua/Requests/Archive 1. For discussions about Wikipedia:Lua/To do from December 2013 to February 2014, see Wikipedia talk:Lua/To do/Archive 1. |
Archives (Index) |
|
|
Contents
- 1 Template:Country data Ahuachapán Department
- 2 Infobox
- 3 Proposal to restrict page moves in the "Module:" namespace to administrators
- 4 Lua code editor
- 5 Beginner question on string concatenation
- 6 Metamodule for wikitable
- 7 Help someone fix a small bug in a template or gadget: It's Google Code-In time!
- 8 Detecting ref tag
- 9 Module:Random
Template:Country data Ahuachapán Department[edit]
Transclusions of Template:Country data Ahuachapán Department are being generated by Module:Flagg for some reason. It seems odd since the place where mw.title.new is being called is nested inside a branch of an elseif which is not being accessed, as far as I can tell (i.e, mi=="i" and mn=="b" in this example). Any ideas on how to fix this? @SiBr4:. 98.230.192.179 (talk) 02:38, 30 August 2015 (UTC)
- I found this while cleaning up Wikipedia:Database reports/Transclusions of deleted templates/1. 98.230.192.179 (talk) 02:39, 30 August 2015 (UTC)
- The "mw.title.new" part is only used to determine whether or not a template is a redirect in the d (data template) format. The transclusions are coming from the internally used Module:CountryData, which uses transclusion and string comparison to non-expensively determine whether or not a data template exists. I didn't think of it being counted as a broken transclusion in database reports for non-existing ones. I don't know if a similarly non-expensive alternative method exists, or if expensive functions must be resorted to (Flags of country subdivisions would most certainly hit the limit of 500 if so). SiBr4 (talk) 09:15, 30 August 2015 (UTC)
- User:SiBr4, is the 'data' loaded from that module used when invoked with 'isb'? If not, perhaps you could wrap the loading of the data inside an if statement so it doesn't try to load it when it doesn't need it. this would seem to be even less expensive, and fix the issue? Frietjes (talk) 16:03, 30 August 2015 (UTC)
- for example, if me is not equal to 'e' and the image parameter has been set, then it seems as though the data is not used (unless it is used by clink?). also, there appears to be a logic error where the internal variable clink is used before it is defined? Frietjes (talk) 16:08, 30 August 2015 (UTC)
- The country data is used for the image name (and its size and border), the display name for e, and the country link ("clink"), each of which can be overridden. Only in the very rare case that
"image" set and (name set or "e" not used) and ("clink" set or "link" set)(pseudocode) is it useful to add an internal switch to not load the data at all if it isn't used. I could add a format letter or parameter to not load a data template if it is certain to not exist, or to switch between direct transclusion and expensive existence functions. - I have fixed the "clink" issue, which prevented the altlink to be changed using the
|clink=parameter. SiBr4 (talk) 18:04, 30 August 2015 (UTC)- User:SiBr4, I like the idea of having a letter which turns off the loading of the country data template as you suggested. although, I am having a hard time imaging a case where you would use
|image=when the country data template exists. if you don't want the default image, you use the 'variant' parameter? it would seem odd that you would want to show a variant that isn't in the country data template, rather than just adding an additional variant. Frietjes (talk) 14:43, 1 September 2015 (UTC)- At Flags of country subdivisions I used
{{flagg|isb|Akrotiri and Dhekelia|image=}}to replace the Union Jack with a blank flag.{{flagg|xsb|Akrotiri and Dhekelia}}would do the same thing, but would create an inconsistency between the format codes. I can think of hypothetical reasons to replace a flag image with one that should not be added as a variant, for example wanting to represent a subdivision or city with the respective national flag, like is common in lists of sister cities (e.g. "
Albuquerque, United States"). One may also set |image=to not have to navigate to the data template to check if it exists, or to use a variant flag with known filename without having to find out the variant label. - My idea was to add a parameter that can go all three ways: trying to load the data template like now (which in case of non-existing templates works but causes appearance in maintenance reports), conditionally loading it by checking its existence (which is expensive), or not loading it. I'm doubting as for which of the first two should be the default. Not loading if
|image=is specified and loading otherwise could work too. - Since a transclusion of a non-existing data template can indicate it is wanted, and doesn't actually break the flag template or display a redlink in case of
{{flagg}}, I'm wondering if there is a way to simply exclude entries resulting from it from the database report. SiBr4 (talk) 21:46, 1 September 2015 (UTC)- the database report isn't for transclusions of non-existing templates, but transclusions of deleted templates. a template is deleted for a reason, although not always for a good reason. Frietjes (talk) 23:37, 1 September 2015 (UTC)
- It seemed to include more than just deleted templates, because I didn't think so many of the nonexisting data templates "transcluded" on the subnational flags article did in fact exist years ago. Additionally, Template:Country data Ahuachapán Department has never been deleted, though I now see it isn't included in the database report at all (the OP's post is therefore kind of confusing). In that case, a parameter/format letter to either avoid loading or check existence (which would be better?) for just those entities whose templates have been deleted before would work. After your creation of these capital city and Indonesian province templates that's only the Taiwanese counties.
- As a separate idea, usages of the
|image=parameter where a data template exists could be collected in a tracking category (since in some cases that does indicate the custom image is already in, or should be added to, the template) instead of not loading the data template if|image=is set. SiBr4 (talk) 13:04, 2 September 2015 (UTC)
- the database report isn't for transclusions of non-existing templates, but transclusions of deleted templates. a template is deleted for a reason, although not always for a good reason. Frietjes (talk) 23:37, 1 September 2015 (UTC)
- At Flags of country subdivisions I used
- User:SiBr4, I like the idea of having a letter which turns off the loading of the country data template as you suggested. although, I am having a hard time imaging a case where you would use
- The country data is used for the image name (and its size and border), the display name for e, and the country link ("clink"), each of which can be overridden. Only in the very rare case that
Infobox[edit]
At Latvian Wikipedia, I would like to track down those articles, which use |caption=, but don't have |image= (of course, also caption2, caption3 etc.). I added just a random category, but it isn't working as expected. When there is both image and caption (first example), the category shows up, but when there is caption without image (second example), category doesn't show up (second example). And yes, it is important - want to put images directly from Wikidata, when there is such, but it can't be done without such check. --Edgars2007 (talk/contribs) 20:39, 4 September 2015 (UTC)
- The
imagevariable you use in your check is never defined, so it always evaluates to false. Does the category check work after this change? SiBr4 (talk) 20:51, 4 September 2015 (UTC)- No. --Edgars2007 (talk/contribs) 20:56, 4 September 2015 (UTC)
- A blank
|image=is discarded earlier on, so it never loops through the image parameters. Furthermore,|caption=depends on|image=and is discarded if|image=is not set (line 373). Alakzi (talk) 21:04, 4 September 2015 (UTC)- Yes, I know, that caption is discarded. But if you get Wikidata image directly and there was some caption left in article (as it was here), then there will be incorrect caption, what I want to avoid. Just don't want to do such tracking job one infobox by one - want to centralise things. --Edgars2007 (talk/contribs) 21:22, 4 September 2015 (UTC)
- Perhaps we need an image-caption property for Wikidata, to be used as a qualifier, and as monlingual text. Maybe "alt", too.Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 22:07, 4 September 2015 (UTC)
- Yes, I know, that caption is discarded. But if you get Wikidata image directly and there was some caption left in article (as it was here), then there will be incorrect caption, what I want to avoid. Just don't want to do such tracking job one infobox by one - want to centralise things. --Edgars2007 (talk/contribs) 21:22, 4 September 2015 (UTC)
- A blank
- No. --Edgars2007 (talk/contribs) 20:56, 4 September 2015 (UTC)
Proposal to restrict page moves in the "Module:" namespace to administrators[edit]
Simply put, I propose that page moves of pages in the "Module:" namespace be restricted to administrators. In other words, I think that the entire namespace should be move-protected. There is one major reason why I think this is necessary, should have been done long ago, and why I don't believe that even template editors should be allowed to move the pages in that namespace. The reason is: when a page gets moved from a title in the "Module:" namespace, it never leaves a redirect. This situation is problematic since, for one, it is the equivalent of having access to the "delete" function while not being an administrator and, for two, if there are any pages that run the module by its previous name (such as pages in the "Template:" namespace), they all break after the move (and since there are no redirects in the "Module:" namespace, there is no way to avoid the pages that run the modules from temporarily going down after the page move.) Steel1943 (talk) 02:39, 18 September 2015 (UTC)
- This sounds like a deeper problem. Why do Module: namespace pages not leave redirects when moved? That is what seems to be the issue. Dustin (talk) 02:47, 18 September 2015 (UTC)
- A move can be done without breaking uses of the old module with a copy-and-paste to the new module name (which of course requires attribution back to the original module), and then modifying the old module to simply invoke the new one. isaacl (talk) 02:49, 18 September 2015 (UTC)
- This solution is problematic since it breaks edit history attribution and in a case where the module may be renamed twice, then there will be a module invoking a module that is invoking a module, and that could blog up the site. Also, if this is the only resolution, it enforces the need to move-protect the namespace. Steel1943 (talk) 02:55, 18 September 2015 (UTC)
- Yes, I noted the issue with edit history attribution. If a module is renamed again, all of the old module names can be modified to invoke the latest module name directly. I'm not suggesting this is the ideal way, but simply that it is not impossible with the current setup to rename a module without breaking uses of the old module name. isaacl (talk) 03:08, 18 September 2015 (UTC)
- Right. I'm not doubting what you are saying as a resolution though; from what I see, it's the only resolution. And if this is the only solution, there should be almost no reason why a page move should occur since they will always break something if another page is set up to invoke the module. If anything, maybe a new speedy deletion criterion could be set up if there is proof that a "Module:" has been copied to a new title, and there is proof that there is no longer any pages set up to invoke the module at the old name. Steel1943 (talk) 03:36, 18 September 2015 (UTC)
- Yes, I noted the issue with edit history attribution. If a module is renamed again, all of the old module names can be modified to invoke the latest module name directly. I'm not suggesting this is the ideal way, but simply that it is not impossible with the current setup to rename a module without breaking uses of the old module name. isaacl (talk) 03:08, 18 September 2015 (UTC)
- This solution is problematic since it breaks edit history attribution and in a case where the module may be renamed twice, then there will be a module invoking a module that is invoking a module, and that could blog up the site. Also, if this is the only resolution, it enforces the need to move-protect the namespace. Steel1943 (talk) 02:55, 18 September 2015 (UTC)
- I'm willing to believe you have identified a real problem, but I am not convinced this is the correct solution. The reason is that admins are not by any means experts on the module namespace. I've been an admin for six years and I don't even know what it is, or desire to find out. So, this will inevitably lead to persons who do know what this is and how it works asking for adminship so that there is somebody who is both able to deal with these moves and knows what they are doing, and they will be shot down as single-purpose candidates always are these days. And so these pages will be stuck where they are, or admins will make bad moves of them when someone asks, and the problem will persist, just in a different form. I would suggest that despite your misgivings this should be given to the technically-minded folks in the template editor group, who are more likely to understand the issues involved and respond appropriately than admins at large. Last time I checked, modules, whatever they are, have absolutely nothing to do with site administration. Beeblebrox (talk) 04:27, 18 September 2015 (UTC)
-
- @Beeblebrox: That hits a point I meant to bring up in addition to my proposal; possibly an edit notice explaining to administrators performing these moves requirements that have to be met prior to a moving a page in the "Module:" namespace (an explanation that could be understood by any administrator, regardless their technical knowledge; the simplest start to the edit notice would ask the administrator to ensure that no transclusions of the old name exist.) In such a case, if an administrator doesn't feel comfortable that the requirements as outlined in the edit notice are met, then they should not be fulfilling the move request. In fact, on that point, it may just be best to never allow pages in that namespace to be moved, but I know that is kind of crazy and will never happen, so I'm trying to find an acceptable alternative. Steel1943 (talk) 04:44, 18 September 2015 (UTC)
- Have there been any actual problems with moves by non-admins breaking modules? My first instinct is that this proposal isn't necessary, and that normal page protection will be enough to protect the modules most at risk. However, I could be persuaded otherwise if we are consistently having problems with this. — Mr. Stradivarius ♪ talk ♪ 04:32, 18 September 2015 (UTC)
-
- @Mr. Stradivarius: Well, I can tell you that I messed up once, but then had enough common sense to revert myself after realizing that a redirect wasn't created. However, there's no way to guarantee that other editors may realize this if they make a similar mistake. If there is no way to technically move a module without causing problems without the "copy-paste" resolution above, then why should that option even be available? Steel1943 (talk) 04:38, 18 September 2015 (UTC)
-
- Also, I can see the move request currently occurring at Module talk:Citation/CS1#Requested move 9 September 2015 turning out disastrous if it is fulfilled by an administrator who is not sure how the "Module:" namespace works. Steel1943 (talk) 05:00, 18 September 2015 (UTC)
- I agree with Mr. Stradivarius, and was already thinking so much before I read his comment. I don‘t see any problem that needs addressing by this, such as lots of damaging moves. High usage modules are already protected which prevents them being moved, so the scope for damage is therefore minimal even in theory. And there may be good reason for a non-admin/non-TE to move a module. Perhaps they are working on it and need to move it from a temporary name to a permanent one, or for consistency with other modules. It is easy to move most modules without causing problems: just update the template or templates invoking them (which should have the same level of protection). I can't think of any that are invoked directly that this won’t work on. So I don’t see any problem that isn’t already dealt with our current protection policy.--JohnBlackburnewordsdeeds 04:56, 18 September 2015 (UTC)
- @JohnBlackburne: Actually, there is no way to move a module without causing downtime for any templates that call them. As I stated above, since redirects in the module namespace do not exist, nor do they work since redirects cannot run the code, the only way to prevent any downtime is by the method that Isaacl suggested above (which is essentially a cut-and-paste move which causes WP:CWW issues. That, and I cannot see a valid reason for a module to be moved to another title is it is a module that is transcluded anywhere given these issues. Maybe we need a separate edit notice when a page is created in the "Module:" namespace to ask the editor "Are you sure this is the title you want this page? Afterwards, it cannot be moved." Steel1943 (talk) 05:11, 18 September 2015 (UTC)
-
- You can move almost any module without causing problems: simply move the module and update the template at the same time. 'the template' as it is almost always just one. If there are more update them too. As for why one might be moved I gave you some reasons immediately above. Another might be a typo when creating the page. That is probably as likely as any other page but we don’t have special warnings, even though it is more problematic to tidy up after misspelling an article as the redirects need to be deleted. Another reason not to do this: modules are simply not targets of test or bad edits, that I’ve seen. Templates sometimes are, articles often are, but not modules. The module protection policy is based on number of transculsions, not which have been vandalism/disruption targets as none have.--JohnBlackburnewordsdeeds 05:45, 18 September 2015 (UTC)
- Looking back at the previous discussion you initiated on this topic, it seems there has been progress in implementing a redirect feature, where the Lua code to effectively accomplish a redirect would be treated by the MediaWiki software as a directive to perform a redirect. Whether or not it gets implemented, though, perhaps the move capability can be modified to leave behind the appropriate Lua redirection code in the old module. isaacl (talk) 16:19, 18 September 2015 (UTC)
- @Isaacl: Good find. Since it seems that there is currently "behind-the-scenes" work happening to get this concern resolved, I'm going to move this discussion away from Wikipedia:Village pump (proposals) to Wikipedia talk:Lua here in a moment. Steel1943 (talk) 16:44, 18 September 2015 (UTC)
-
- @Isaacl: By the way, I think that idea is genius. Jackmcbarn, is that the direction the above gerrit request is taking, or was another path discovered, or will this require a new request? (I'm really not familiar with how the gerrit boards work, though I have seen some if the requests fulfilled in action.) Steel1943 (talk) 17:26, 18 September 2015 (UTC)
- I'll see if I can get that here soon-ish. I'd much rather do that than lock down the Module namespace like this. Jackmcbarn (talk) 17:58, 18 September 2015 (UTC)
- @Isaacl: By the way, I think that idea is genius. Jackmcbarn, is that the direction the above gerrit request is taking, or was another path discovered, or will this require a new request? (I'm really not familiar with how the gerrit boards work, though I have seen some if the requests fulfilled in action.) Steel1943 (talk) 17:26, 18 September 2015 (UTC)
The same used to have happened with css and js pages, but now redirects are supported for those pages. A non-admin can only move css and js pages in his or her own userspace. 107.142.8.44 (talk) 00:17, 19 September 2015 (UTC)
- css and js files are parts of the Mediawiki software, and can be used on all pages, so any edit or move would have massive impact. Apart from that they do not exist anywhere apart from in userspace, where they could be as disruptive an individual editor’s experience so can only normally be edited by that editor. I.e. they are nothing like modules.--JohnBlackburnewordsdeeds 00:23, 19 September 2015 (UTC)
Lua code editor[edit]
I've been away too long. Can someone tell me what is the/a code editor for Lua? I'd like to have syntax highlighting in wiki. -DePiep (talk) 21:49, 20 October 2015 (UTC)
- @DePiep: The default code editor is mw:Extension:CodeEditor, which is enabled on all WMF wikis. You can toggle it on and off by clicking the "<>" symbol at the top-left of the edit window when you edit Lua modules, JavaScript pages or CSS pages. It requires JavaScript, and it also requires the "Enable enhanced editing toolbar" option in your preferences. — Mr. Stradivarius ♪ talk ♪ 23:24, 20 October 2015 (UTC)
- Sorry, couldn't get this working. Ido not have the "<>" symbol (somewhere top-left) you mention. I think I checked the other settings well. -DePiep (talk) 11:55, 29 October 2015 (UTC)
(strange: now that I edit this section, I see its text marking by bg-colors, but these are shifted some 5 lines up i.e. starts above the editbox). -DePiep (talk)12:00, 29 October 2015 (UTC)- That's by Syntax highlighter I just enabled. Different topic, so I struck. -DePiep (talk) 12:05, 29 October 2015 (UTC)
- Do you get any errors in the JavaScript console when you edit module pages? There might be something in your settings which is causing JavaScript to fail. — Mr. Stradivarius ♪ talk ♪ 13:50, 29 October 2015 (UTC)
- That's by Syntax highlighter I just enabled. Different topic, so I struck. -DePiep (talk) 12:05, 29 October 2015 (UTC)
Beginner question on string concatenation[edit]
I've been playing with Lua for the very first time (under my other account) and I got pretty close to replacing the broken Bugzilla links by Phabricator links on mw:Developers/Maintainers in https://www.mediawiki.org/w/index.php?title=Module:Bugzilla&oldid=1922142 but I could not solve one issue: If the "component" is e.g. the string "JobQueue", the component string has incorrect surrounding dashes so the incorrectly constructed URL is "https://phabricator.wikimedia.org/tag/mediawiki--jobqueue-". How do I avoid these dashes around the component name (it should be "-jobqueue" and not "--jobqueue-")? Thanks in advance for any pointers! --Malyacko (talk) 21:52, 24 October 2015 (UTC)
- you might want to
mw.text.trim()component before you replace spaces with dashes. If component has leading and/or trailing white space, they will be replaces with dashes and then when you concatenate with another dash ... - —Trappist the monk (talk) 22:14, 24 October 2015 (UTC)
Metamodule for wikitable[edit]
Is there a metamodule to build a wikitext WP:wikitable? Or would that be inefficient/inelegant coding? -DePiep (talk) 12:09, 29 October 2015 (UTC)
- There isn't one as far as I know. It wouldn't be inefficient or inelegant to use one, in my opinion, but most people just use
mw.htmlwith<table>tags, as in most cases that does all that you need. Also, if you just need a simple wikitable you might get away with something like themakeWikitablefunction that I wrote in Module:Find sources/autodoc. — Mr. Stradivarius ♪ talk ♪ 13:46, 29 October 2015 (UTC)
Help someone fix a small bug in a template or gadget: It's Google Code-In time![edit]
- Are you a developer and have small, self-contained, "easy" bugs in your Wikimedia code that you would love to get fixed?
- Would you enjoy helping someone port your template to Lua?
- Does your gadget use some deprecated API calls?
- Does the documentation of your code need some improvements?
- Do you enjoy mentoring to a new contributor fixing small tasks?
Google Code-In (GCI) will take place again in December and January: a contest for 13-17 year old students to provide small contributions to free software projects. Wikimedia will apply again to take part and would like to offer a wide range of tasks. Just one example: Multimedia saw some impressive achievements in last year's contest!
Tasks should take an experienced contributed about two-three hours ("beginner tasks" also welcome which are smaller) and can be of the categories Code, Documentation/Training, Outreach/Research, Quality Assurance, and User Interface/Design. For more information, check the wiki page and if something is unclear, please ask on the talk page!
Thank you, --AKlapper (WMF) (talk) 00:01, 2 November 2015 (UTC)
Detecting ref tag[edit]
I want to detect if the input has an initial <ref> tag. Long time ago I learned that in input strings this shows up as strip marker like ?UNIQ...QINU?, and that it is a risky to use that knowledge (mw code may change). However, it seems to be the only way to detect the tag in Lua.
My question is: is there a (more or less) stable way to detect a ref in the input string? Planned usage is: in a comment (suffix) parameter, check whether it starts with a reference tag. In that case, do not add the space:
|distance=100 km|comment=<ref>example.com</ref> as the cow flies- to show:
100 km[1] as the cow flies - otherwise, show:
100 km_as the cow flies(_=space added)
I see module:Convert has something like (search QINU):
... match('^(\127UNIQ[^\127]*%-ref%-%x+%-QINU\127)')
Any wisdom? -DePiep (talk) 09:58, 8 November 2015 (UTC)
- First, I see no added space, so I must be missing something. Second, tags are always stripped by the preprocessor before being send of to the LUA interpreter, so what you want as such is not possible. That code from the Convert module is already a hack...
-- [[User:Edokter]] {{talk}}10:16, 8 November 2015 (UTC)- Yes, the convert code is a gross hack, but I had to do it because people add references to numbers in infoboxes, and those numbers (with the ref or refs) are then passed to convert. The hack has already broken once due to a MediaWiki change because convert originally carefully checked for the exact format used at the time on the principle that I didn't want any false hits. In the example above, the comment parameter would strip any leading/trailing spaces from the text, so I guess DePiep needs to add the space to save the user the hassle of entering
at the start, or some other workaround. @DePiep: Why can't the user just add the ref after the distance? Johnuniq (talk) 10:44, 8 November 2015 (UTC) - (edit conflict) @Edokter: I imagine that the module code is something like
, which withargs.distance .. args.comment|distance=100km|comment=<ref>example.com</ref> as the cow flieswill render as100 km[1] as the cow flies. With|distance=100km|comment=as the cow flies, though, it would render as100 kmas the cow flies, hence the need for an extra space in the Lua module. (I like the cow flying image, by the way.) @DePiep: It's just as Edokter says - you can't get the raw ref tags from Lua, you have to rely on searching for the strip markers, which is a hack, and may change with future versions of MediaWiki. I don't think strip markers are very likely to change in the near future, though. I would do it by splitting the strip-marker-matching code out into a separate function, so that if the MediaWiki code changes, all you have to do is update that code. In fact, it might be worth making a stand-alone module for this so that any modules that work with strip markers can be updated straight away if the MediaWiki code changes. Come to think of it, Scribunto has mw.text.killMarkers, which will remove all strip markers from a string, so you can check whether a string s has strip markers or not with the code. I don't think there's a 100% certain way to check whether the strip marker is a reference or if it is at the start of the string without making your own Lua pattern, though. — Mr. Stradivarius ♪ talk ♪ 10:57, 8 November 2015 (UTC)s ~= mw.text.killMarkers(s)- Yes, using killMarkers like that is a good idea. It doesn't matter whether it is some other kind of marker like <math>, the template can insert a space if killMarkers did not find any kind of marker. That would be perfect for the usage needed, although it would not be right for cases like the ref being at the end of comment rather than at the beginning. Johnuniq (talk) 22:35, 8 November 2015 (UTC)
- Marked the added space (diff: starts with ref=no space, starts with regular text=add space). The value ('100 km') is best to be by separate parameter in my case. -DePiep (talk) 22:40, 8 November 2015 (UTC)
- @Johnuniq: "Why can't the user just add the ref after the distance?" - I need the value in a distinct parameter to format the value.
- If I can not detect the opening ref (in the suffix parameter input), I and the editor needs two params:
|suffix_ref=and|suffix_anytext=to omit/add the space. This is what currently happens in {{Chembox}}: every value actually has two such suffix params. -DePiep (talk) 22:47, 8 November 2015 (UTC)- Re general: as Stradivarius describes. Using killMarkers instead if hardcoding into a small module is safer, esp in case of mw changes. All other tags firing just as well is a rare and minor nuisance (to be documented in the template /doc). (And 'the cow flies' :-) originally was a typo I saw & kept). -DePiep (talk) 23:00, 8 November 2015 (UTC)
- Yes, using killMarkers like that is a good idea. It doesn't matter whether it is some other kind of marker like <math>, the template can insert a space if killMarkers did not find any kind of marker. That would be perfect for the usage needed, although it would not be right for cases like the ref being at the end of comment rather than at the beginning. Johnuniq (talk) 22:35, 8 November 2015 (UTC)
- Yes, the convert code is a gross hack, but I had to do it because people add references to numbers in infoboxes, and those numbers (with the ref or refs) are then passed to convert. The hack has already broken once due to a MediaWiki change because convert originally carefully checked for the exact format used at the time on the principle that I didn't want any false hits. In the example above, the comment parameter would strip any leading/trailing spaces from the text, so I guess DePiep needs to add the space to save the user the hassle of entering
The following is probably sufficient. If comment does not start with a marker, a space is inserted before comment.
comment = 'as the cow flies' -- this comes from the template parameter
if comment:sub(1, 1) ~= '\127' then comment = ' ' .. comment end
The above relies on the fact that every marker starts with a delete character, and that is enough for this application. Using killMarkers would fail for:
|distance=100 km |comment=as the cow flies<ref>example.com</ref>
Johnuniq (talk) 00:24, 9 November 2015 (UTC)
Module:Random[edit]
Hello,
Can somebody add an option (like others options of this module module : same, limit...) in order to have an intern link (ex : Bogota and not Bogota) without having to write for example {{#invoke:random|item|[[Bogota]]|[[Paris]]|[[Berlin]]}} but simply {{#invoke:random|item|Bogota|Paris|Berlin}}.
PS: on the spanish version of the module:list , there is a fonction enlazar whitch seems to do what I need but I don't know how to integrate it on module:random.
Thanks. Lepsyleon (talk) 11:13, 9 November 2015 (UTC)
- @Lepsyleon: That's an easy one: just use
[[{{#invoke:random|item|Bogota|Paris|Berlin}}]]. Best — Mr. Stradivarius ♪ talk ♪ 11:15, 9 November 2015 (UTC)- @Mr. Stradivarius:, sorry but it doesn't work if you use some options of this modul like limit. For example, with
{{#invoke:random|text_list|Bogota|Paris|Berlin|Londres|Madrid|limit=3}}, it makes ONE red lind with THREE terms. That's why I ask if it's possible to add a new option like enlazar (link). Best. Lepsyleon (talk) 11:39, 9 November 2015 (UTC)- @Lepsyleon: Hmm, ok. I'm reluctant to add just a "link" option, because other people might want their results formatted in different ways, for example made into an external link or put into a template invocation. How about an option that specifies a pattern to format the result with? Perhaps something like
{{#invoke:random|text_list|Bogota|Paris|Berlin|Londres|Madrid|limit=3|format=[[$1]]}}, which would return, e.g.[[Berlin]], [[Bogota]] and [[Paris]]. For things like template invocations this would need to be done with nowiki tags, like{{#invoke:random|text_list|Bogota|Paris|Berlin|Londres|Madrid|limit=3|format=<nowiki>{{my template|$1}}</nowiki>}}. But then, for most uses{{#invoke:random|text_list|[[Bogota]]|[[Paris]]|[[Berlin]]|[[Londres]]|[[Madrid]]|limit=3}}isn't really that complicated. Did you have any more complicated uses in mind? — Mr. Stradivarius ♪ talk ♪ 13:59, 9 November 2015 (UTC)- @Mr. Stradivarius: OK for
{{#invoke:random|text_list|Bogota|Paris|Berlin|Londres|Madrid|limit=3|format=[[$1]]}}but when I try it,there is no internal links. - The matter with
{{#invoke:random|text_list|[[Bogota]]|[[Paris]]|[[Berlin]]|[[Londres]]|[[Madrid]]|limit=3}}is the weight of the pages generated with this model when there is a lot of items. - Lepsyleon (talk) 14:41, 9 November 2015 (UTC)
- Someone can help me, please ? Best. Lepsyleon (talk) 21:24, 11 November 2015 (UTC)
- @Lepsyleon: What do you mean by weight of the pages? Jackmcbarn (talk) 02:48, 12 November 2015 (UTC)
- @Jackmcbarn: : weight = bytes for a page. For example, I use the module:random with a javascript code for the french version of [1]. With it, I can make a list of all the articles linked to this portal. But when there is too much articles linked to a portal, the javascript code is bugging, because the weight of the page is big. And if I use [[ ]] for each item like with
{{#invoke:random|text_list|[[Bogota]]|[[Paris]]|[[Berlin]]|[[Londres]]|[[Madrid]]|limit=3}}, the weight of the page generated is bigger. Lepsyleon (talk) 08:24, 12 November 2015 (UTC)- The page's output is exactly the same size no matter what the module does to generate it. I'm not sure what you're referring to that's changing sizes. Jackmcbarn (talk) 16:50, 12 November 2015 (UTC)
- Lepsyleon is talking about the size of the source wikitext. This is edited by fr:MediaWiki:Gadget-PageAuHasard.js (see e.g. this page history). The gadget is apparently having problems on pages with a large source size. — Mr. Stradivarius ♪ talk ♪ 02:13, 13 November 2015 (UTC)
- The page's output is exactly the same size no matter what the module does to generate it. I'm not sure what you're referring to that's changing sizes. Jackmcbarn (talk) 16:50, 12 November 2015 (UTC)
- @Jackmcbarn: : weight = bytes for a page. For example, I use the module:random with a javascript code for the french version of [1]. With it, I can make a list of all the articles linked to this portal. But when there is too much articles linked to a portal, the javascript code is bugging, because the weight of the page is big. And if I use [[ ]] for each item like with
- @Lepsyleon: What do you mean by weight of the pages? Jackmcbarn (talk) 02:48, 12 November 2015 (UTC)
- Someone can help me, please ? Best. Lepsyleon (talk) 21:24, 11 November 2015 (UTC)
- @Mr. Stradivarius: OK for
- @Lepsyleon: Hmm, ok. I'm reluctant to add just a "link" option, because other people might want their results formatted in different ways, for example made into an external link or put into a template invocation. How about an option that specifies a pattern to format the result with? Perhaps something like
- @Mr. Stradivarius:, sorry but it doesn't work if you use some options of this modul like limit. For example, with

