Jump to content

Module talk:NUMBEROF

Add topic
From Meta, a Wikimedia project coordination wiki
Latest comment: 2 months ago by Johnuniq in topic New aliases

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

New aliases

[edit]

Hi @Johnuniq@GreenC Should wikifunctions = 'www.wikifunctions' be added as an alias? Thx in advance --Mohanad (talk) 17:47, 9 September 2024 (UTC)Reply

Also species = 'species.wikimedia' --Mohanad (talk) 18:37, 9 September 2024 (UTC)Reply

I don't remember much about the module but this works:
  • {{NUMBEROF|articles|www.wikifunctions}} → 12125
  • {{NUMBEROF|articles|species.wikimedia}} → 896168
Using the suggested aliases would allow cleaner wikitext. @GreenC: I guess there would be no problem with me adding these two aliases to en:Module:NUMBEROF? Can you recall how to work out whether there are other aliases that should be added at the same time? Will I copy it from enwiki to here or should you do it? Groan, I guess you would have to update the million other places the module is used. Johnuniq (talk) 03:48, 10 September 2024 (UTC)Reply
I have fallen behind keeping the other sites updated due to the extreme amount of work. It was always a courtesy thing anyway, up to each wiki. They are in the main in sync. Only alias, it can wait until there is core change to sync across all wikis.
Other possible aliases:
  • www.wikidata
  • meta.wikimedia
  • commons.wikimedia
  • incubator.wikimedia
  • foundation.wikimedia
  • wikimania.wikimedia
  • wikitech.wikimedia
  • donate.wikimedia
-- GreenC (talk) 02:43, 12 September 2024 (UTC)Reply

I have updated the module at enwiki and here. The following is a test of all aliases.

Normal

  • {{NUMBEROF|articles|commons.wikimedia}} → 107710930
  • {{NUMBEROF|articles|donate.wikimedia}} → 157
  • {{NUMBEROF|articles|foundation.wikimedia}} → 168
  • {{NUMBEROF|articles|incubator.wikimedia}} → 162880
  • {{NUMBEROF|articles|meta.wikimedia}} → 150860
  • {{NUMBEROF|articles|species.wikimedia}} → 896168
  • {{NUMBEROF|articles|www.wikidata}} → 114766168
  • {{NUMBEROF|articles|www.wikifunctions}} → 12125
  • {{NUMBEROF|articles|wikimania.wikimedia}} → 87
  • {{NUMBEROF|articles|wikitech.wikimedia}} → 2646

Using alias

  • {{NUMBEROF|articles|commons}} → 107710930
  • {{NUMBEROF|articles|donate}} → 157
  • {{NUMBEROF|articles|foundation}} → 168
  • {{NUMBEROF|articles|incubator}} → 162880
  • {{NUMBEROF|articles|meta}} → 150860
  • {{NUMBEROF|articles|species}} → 896168
  • {{NUMBEROF|articles|wikidata}} → 114766168
  • {{NUMBEROF|articles|wikifunctions}} → 12125
  • {{NUMBEROF|articles|wikimania}} → 87
  • {{NUMBEROF|articles|wikitech}} → 2646

Johnuniq (talk) 04:00, 29 September 2024 (UTC)Reply