Module talk:NUMBEROF

From Meta, a Wikimedia project coordination wiki

Module update[edit]

A new feature to allow aliases has been introduced at en:Module:NUMBEROF, see en:Template talk:NUMBEROF#Wikidata and the diff that updated the documentation.

I have copied the enwiki module to here for consistency as the enwiki module has previously been copied to many other projects. Some changes to the module had been made here but they were not necessary. There is no performance benefit from caching a result when that result is used once only. Writing mw.text.trim rather than trim (where trim is defined elsewhere) is one of the perennial programming arguments. Those favoring clarity and robustness like mw.text.trim, whereas those seeking to gain microsecond speed improvements use trim. In this module, trim is only used three times and the performance benefit is not worth the increase in code complexity.

The changes at meta included using

mw.language.new(mw.getCurrentFrame():preprocess('{{PAGELANGUAGE}}'))

rather than the Scribunto function used at enwiki

mw.language.getContentLanguage()

What benefit comes from using the former?

One style difference is that the enwiki code follows the principle of obtaining a result, then extracting everything needed from that result, then using the extracted data. That simplifies the code for readers by (slightly) reducing the number of references to a result obtained a few lines back.

A final difference is that the enwiki code returns -1 when given an unknown parameter. Whether that is a good choice could be debated but it has an advantage over returning 0, namely that zero is a valid result whereas a negative number clearly shows something is wrong. Johnuniq (talk) 03:29, 27 February 2022 (UTC)[reply]

Please ping, I don't normally login/watch meta, ping will show up on cross wiki alerts. - GreenC (talk) 05:46, 27 February 2022 (UTC)[reply]

@Johnuniq:

mw.language.getContentLanguage()

would correspond to

mw.language.new(mw.getCurrentFrame():preprocess('{{CONTENTLANGUAGE}}'))

i.e. the CONTENTLANGUAGE magic word, not PAGELANGUAGE. As you can see on the mediawiki.org page, if both the wiki and the page is in English (multilingual wikis’ content language is English on Wikimedia), there’s no difference, but if you switch to a translation (e.g. German), the page language changes, while the content language doesn’t. When the module is used on a German-language page, it should state that English Wikipedia has 6.460.517 articles, not 6,460,517, so multilingual wikis should not use the content language, only the page language. (On the other hand, this requires parsing wikitext until phab:T161976 is fixed, which is expensive, so it makes sense to use the content language on monolingual wikis, where languages other than the content language aren’t expected anyway.) I’ve reverted that part of your edit. —Tacsipacsi (talk) 22:15, 1 March 2022 (UTC)[reply]

OK, thanks. Your comments remind me of some things I learned (and forgot) at Commons a couple of years ago. Johnuniq (talk) 23:26, 1 March 2022 (UTC)[reply]

September 2023[edit]

Module:NUMBEROF is used in many different projects and it should not be adjusted without reason. The module has been restored to match the main development module at en:Module:NUMBEROF, except for the PAGELANGUAGE item discussed above. Adjustments such as rearranging expressions and attempting micro-optimizations introduce confusion with no benefit. I explained some points above and won't take more time on that unless someone wants to suggest why the module should be changed. Johnuniq (talk) 08:01, 6 September 2023 (UTC)[reply]

Thank you. Right now this module is on 82 wikis, plus meta and wikidata. All of the modules are the same, the last I checked. There might be some later revisions locally but most largely the same. Meta is not just another wiki, it's where many users download the source to install it on their local wiki. Thus it and enwiki are really important to keep in sync. If changes are important enough, let's discuss. It's an effort to keep this module in sync so we can continue to add new features and keep it updated cross wiki without creating forks. Cooperation appreciated. -- GreenC (talk) 03:13, 11 September 2023 (UTC)[reply]