1

One can download MediaWiki via a web browser GUI here:

https://www.mediawiki.org/wiki/Download

The download link there isn't version agnostic (it changes any time a new version comes out), that makes it impossible to download by the same link because the link always changes.

How could I still download the latest MediaWiki in a version agnostic way? How to "target" the dynamic download link from command line? Possibly some regex is needed but possibly not.

1 Answers1

2

If you have an XML parser such as xmlstarlet that understands HTML you can use something like this:

curl --silent https://www.mediawiki.org/wiki/Download |
    xmlstarlet format -H 2>/dev/null |
    xmlstarlet sel -T -t -m '//a[@class="external text" and contains(., "Download MediaWiki")]' -v '@href' -n

The first xmlstarlet line formats HTML into strict XML. I've discarded stderr because otherwise we would see a warning message that's of no relevance here. The second one parses the result to select the href attribute value from every <a class="external text"/> element that contains Download MediaWiki in its value.

Output

https://releases.wikimedia.org/mediawiki/1.38/mediawiki-1.38.4.zip

References

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • Thank you a lot. Sadly this code is hard for me to understand, I am not a sys admin, rather a curious amateur, is there perhaps something simpler for laymen such as myself? – automation Oct 07 '22 at 20:36
  • @automation this is a reliable solution - much more so than trying to pick out a string using a regular expression. Since you're curious (a good thing), truncate the line at the first pipe symbol and review the output in whatever way suits you. For example pipe through a pager such as less. Then repeat but add in the second command. The xmlstarlet command can be used to format and slice'n'dice XML documents. There are quite a number of questions referencing it. – Chris Davies Oct 07 '22 at 21:31
  • Well I try to take it step by step, why is the redirection to dev/null ("output suppression") is needed? won't we want to pipe the HTML output as-is to the second xmlstarlet? – automation Oct 08 '22 at 02:11
  • I guess that understanding sel -T -t -m would help, sel is "select" right? Can we write select instead? What are the options? – automation Oct 08 '22 at 12:08