Extension talk:Arrays

Jump to navigation Jump to search

About this board

Old messages until March 2011 are archived.


184.20.10.253 (talkcontribs)

Extension:Arrays#Fatal bug


$egArraysExpansionEscapeTemplates is currently not initialized correctly, I think because of JSON code:

"config": {
		"ArraysCompatibilityMode": {
			"description": "Set to false by default since version 2.0.",
			"value": false
		},
		"ArraysExpansionEscapeTemplates": {
			"description": "Contains a key-value pair list of characters that should be replaced by a template or parser function call within array values included into an '#arrayprint'. By replacing these special characters before including the values into the string which is being expanded afterwards, array values can't distract the surrounding MW code. Otherwise the array values themselves would be parsed as well.\n\nThis has no effect in case $egArraysCompatibilityMode is set to false! If set to null, Arrays will jump to compatibility mode behavior on this, independently from $egArraysCompatibilityMode.",
			"value": [
				{
					"=": "{{=}}"
				},
				{
					"|": "{{!}}"
				},
				{
					"{{": "{{((}}"
				},
				{
					"}}": "{{))}}"
				}
			]
		}
	},

The PHP code produces an associative array that matches how escapeForExpansion uses it. escapeForExpansion produces a PHP diagnostic. Oddly though I didn't see it until I had a page name with an apostrophe in it. So it's possible escapeForExpansion isn't always utilized, without doing more analysis. Note, escapeForExpansion is the only consumer of $egArraysExpansionEscapeTemplates at least inside of ExtArrays.php.

$egArraysExpansionEscapeTemplates = [
	'='  => '{{=}}',
	'|'  => '{{!}}',
	'{{' => '{{((}}',
	'}}' => '{{))}}'
];
Dinoguy1000 (talkcontribs)
184.20.10.253 (talkcontribs)

Thank you, looking at https://phabricator.wikimedia.org/T240111 I suggest explaining the extension.json code is the likely source of the error. I think it was probably written in haste, since extension.json is a new framework. This report here in Talk is a better resource I think. I tried to make the explanation in the Article easy to understand without tearing into details, so people can figure out a way to initialize the variable manually, since that's the only way to fix it (without modifying the JSON file or converting the JSON result into the expected result, whichever is correct. I don't know enough about the JSON setup to solve the problem.)

184.20.10.253 (talkcontribs)

Here (Topic:Vcpmy66hprtm34jy) is attempt an editor made to hide the problem, they should be prepared to fix it them, or any case the problem is hidden now, so I hope someone is seeing it through. Someone should be interested in shepherding this new JSON system since someone saw fit to institute it.

Reply to "Nonworking status 1.33.1"
AdSvS (talkcontribs)

These very useful parser functions are part of Page Forms. Couldn't/Shouldn't they be part of this extension?

I think there has been some discussion elsewhere about these parser functions but I can't remember where that was.

Dinoguy1000 (talkcontribs)
Reply to "#arraymap and #arraymaptemplate"
MGChecker (talkcontribs)

Currently, the Arrays extension isn't actively maintained and poses some weird behavior, as well as questionable implementation in some cases. Considering this, we should collect all issues in one place and decide what should be done about that afterwards.

Additionally I'd like to ask: Does anyone still use this CompatibilityMode feature introduced seven years ago? There are people thinking about removing that functionality.

As I consider Flow even worse than wikitext for dicussions and really confusing as well, I would like to discuss this topic on Phabricator instead. This will tracking the issues identified there easier as well. However, if you have any trouble in setting up OAuth for Phabricator, feel free to speak ub in this thread as well.

Kghbln (talkcontribs)

Basically there has not been any development to this extension since version 2 was released. That's why we still have the CompatibilityMode among other things. I you would like to take over maintaining it I am all for it including the place there discussions etc. should take place.

Reply to "Future of the Arrays extension"

Disallowed character combinations?

3
Cavila (talkcontribs)

I think I just bumped into a weird character issue. I fed a string to an array using regex that allow for multiple delimiters (“ or ” = quotation marks). See code below. The body of the wiki page turned up blank. The problematic part of the string appeared to be the en dash – (not to be confused with - or the em dash) in combination with those delimiters. Removing it from the string solves it as does including the en dash among the delimiters.

{{#arraydefine:@somearray|Bla bla bla bla – oh well bla bla |/[“”]/}} {{#arrayprint:@somearray|;}}

Not sure if those quotation marks hold any special meaning in the syntax.

Dinoguy1000 (talkcontribs)

This sounds a lot like the issue I ran into in this topic four years ago. To be clear, are you saying that an en dash causes this, but an em dash does not?

Cavila (talkcontribs)

No, I was trying to make unambiguously clear what character was causing trouble in this specific case. I just tested the same string with the em dash and the same thing happens. It does resemble the issue you ran into but I'm vague about the details. I should test if the problem can be worked around by resorting to a piped sequence of characters or character strings.

Reply to "Disallowed character combinations?"
Yukii (talkcontribs)

can someone say if this extension works with MW1.30.x?

Dinoguy1000 (talkcontribs)

It does, yes.

CroMagnon (talkcontribs)

Unfortunately, at least version 491256a (last one from REL1_30) leads to problems with Mobile Frontend and the Minerva skin. The little arrows at the sections are not displayed, and the sections won't collapse again once they have been expanded once. I'll investigate that problem further. It's a pity that it isn't maintained, but perhaps someone has the skills to fix that bug, so if I can reproduce it I'll report it at Phabricator.

CroMagnon (talkcontribs)

It works with the "master" branch (version 2166695). And it seems to be maintained still. *phew*

ParallaxMonkey (talkcontribs)

Why would this be "abandoned"? I have found it useful for my wiki. Not sure how to do some things otherwise. Are there suitable alternates if this truly is abandoned?

Dinoguy1000 (talkcontribs)

It's not abandoned, it simply doesn't currently have a maintainer. The current version works with MediaWiki 1.30, and was released less than a year ago, though, so even without being actively maintained I expect it to continue working for a while.

Reply to "Works with MW 1.30.X ?"
Lady Aleena (talkcontribs)

I would like to make the following tiny, but I am not sure what will and will not break the functions.


 {{#arraydefine:array-list | {{{array}}}}}
 {{#ifeq: {{#arraysize:array-list}} | 1 |
   {{{array}}} [[Category:{{{array}}} category]] |
   {{#arrayprint:array-list||@@@@|<nowiki/>
   * @@@@ [[Category:@@@@ category]]}}
   }}

I am getting an array, then checking to see how many items there are. If there is one item, just print the array as a normal parameter with a category. If there are two or more, print the array as a list with each item getting its own category.

Right now it just looks bad. So, can someone please clean it up, and maybe offer better ways to write it?

Thank you in advance! Lady Aleena (talk) 06:16, 19 November 2017 (UTC)

Henryfunk (talkcontribs)

This answer perhaps goes in another direction than what you expected, but anyway: One change I would consider an improvement would be to change category names so they don't end in the string " category". It's redundant, and getting rid of it would in this case make your code 18 characters shorter :-)

Lady Aleena (talkcontribs)

The above use was as an example. I will put up the actual use if wanted. Lady Aleena (talk) 21:05, 23 November 2017 (UTC)

Henryfunk (talkcontribs)

Ah, OK. I don't think the code in your example can be tidied up much. Do post it here, if you find a better solution.

Dinoguy1000 (talkcontribs)

Do you mean to categorize the page(s) this code will be used on? If not, make sure to link the categories by adding <code>:</code> at the beginning of the link.

I think that's about how I'd do this too (except using StringFunctions, see below). Really the only option for shortening the code that I can see would be to just always output the items as list items, even when there's only one. Of course, if someone else knows a way to shorten this, I'd also be interested in seeing. =)

If StringFunctions are enabled on your wiki, I would recommend the following code instead:

{{#if: {{#pos:{{{array}}} | , }} |
{{#arraydefine:array-list | {{{array}}} }}{{#arrayprint:array-list||@@@@|<nowiki/>
* @@@@ [[Category:@@@@ category]]}} |
{{{array}}} [[Category:{{{array}}} category]]
}}

This lets you avoid touching array functions at all unless you have more than one item to display.

Lady Aleena (talkcontribs)

I was just looking for a way to "tidy" the code, make it look good. Sort of like HTML Tidy. Thank you for stopping by! Lady Aleena (talk) 20:20, 19 November 2017 (UTC)

I just realized that I might need to change the delimiter. Names can have commas in them, so I am going to try to use a semicolon. Lady Aleena (talk) 20:37, 19 November 2017 (UTC)

Reply to "Tidy array?"
Nakohdo (talkcontribs)

Hi,

I'm using a combination of #arraydefine, #arraysort and #arrayprint to print a sorted list of page titles. I had to change the delimiter for #arraydefine and #arraysort from the default comma to a semicolon because some page titles contain commas. However, now I get semicolons in the output. I suspect that #arrayprint doesn't recognize them as delimiter. Could that be the case? Or am I missing something? Any pointers welcome.

TIA

Frank

Dinoguy1000 (talkcontribs)

You also need to specify the delimiter in #arrayprint: {{ #arraydefine: @array | this; is; an; array | ; }}{{ #arrayprint: @array | ; | ... }}.

On a semirelated note, for dealing with page titles, I'd recommend using some delimiter that you know can't appear in page titles; my usual go-to is an asterisk (with some care you might be able to use non-parenthesis brackets, though I've never tried (and yes, I realize that asterisks can appear in page titles, but in practice this is so rare that, unless your wiki has some specialized scope making it likely to happen, you can generally safely ignore the possibility)).

Henryfunk (talkcontribs)

Good advice re choice of delimiter. Just to clarify: Nakohodo wanted to get rid of the semi-colons. To do so he should use {{ #arrayprint: @array || ... }}.

Nakohdo (talkcontribs)

Many thanks for your quick reply and the pointer. The culprit was actually another semicolon I had added somewhere else in the template code. Using an asterisk makes the code more readable and should indeed be safer with page titles.

Speaking of SMW code readability, I've created a syntax highlighting scheme for Notepad++ to make life easier: https://github.com/nakohdo/NPP.SemanticMediaWiki

Reply to "#arrayprint: Default delimiter?"
Lady Aleena (talkcontribs)

Is there a list of patterns? I was guessing with what I wrote in my previous question, using @@@@ as a pattern. However, I didn't see a link to a page with patterns. So, what are the patterns I can use? Lady Aleena (talk) 06:18, 19 November 2017 (UTC)

Dinoguy1000 (talkcontribs)

@@@@ is just an identifier, like "array-list", and it can be anything you want it to, as long as you're certain it won't appear in the input (since if it does, it will be replaced anywhere it appears, which is probably not what you want). Where I don't bother to name the identifier at all, I'm rather fond of using something like $x$ myself, though as far as being instantly recognizable goes, @@@@ works just as well (maybe a bit better, even). When I do name the identifier, I use $<name>, e.g. $el or $item.

Lady Aleena (talkcontribs)

That is great! I am very used to $name since I write a little bit of perl, and I am more comfortable with scalars using $ to start the name. Thank you! Lady Aleena (talk) 20:31, 19 November 2017 (UTC)

Reply to "Patterns"

Using multiple multiple-character delimiters

2
Cavila (talkcontribs)
Danwe (talkcontribs)

That's because you do not use the arraydefine regular expression syntax correctly. If you want to use a regular expression as delimiter you had to use /\s*(?:\band\b|,)\s*/

Reply to "Using multiple multiple-character delimiters"
86.141.179.229 (talkcontribs)

How do I do this?

Danwe (talkcontribs)

Should be possible with a regular expression as delimiter.

Reply to "Use a break line as a delimiter"