WordPress / browsehappy

101 stars 36 forks source link

Firefox version missing – use Wikidata? #37

Closed Krinkle closed 7 years ago

Krinkle commented 7 years ago

See also https://github.com/WordPress/browsehappy/issues/7 - Chrome version missing.

See also https://github.com/WordPress/browsehappy/issues/11 – Firefox version formatting issue.


A few months ago this Wikipedia template edit in May 2016 changed the internal template to display "stable" and "preview" versions separately.

At the time, it did so by wrapping the "LSR" template (with takes the latest_release_version parameter, which BrowseHappy looks for in functions.php#L119). Later, another edit two weeks ago changed it to use the {{Multiple releases}} template instead of calling {{LSR}} twice. This one takes the stable version as parameter version1.

Wikipedia template markup is not an API. Aside from templates and internal syntax frequently changing and being fragile to parse externally, a lot of data is also moving away from infoboxes on Wikipedia entirely, in favour of dynamic querying of the Wikidata API.

It seems the Firefox article on the English Wikipedia does not yet use Wikidata as its data source, but nonetheless the data is concurrently being maintained and updated by Wikimedia contributors on Wikidata as well.

Here's how you'd query it from Wikidata (it uses Sparql, more about that in the Wikidata query manual):

SELECT ?version WHERE {
  wd:Q698 p:P348 [
    ps:P348 ?version;
    pq:P548 wd:Q12355314;
    wikibase:rank wikibase:PreferredRank
  ].
}

Explained:

Query Viewer: https://query.wikidata.org/#SELECT%20%3Fversion%20WHERE%20%7B%0A%20%20wd%3AQ698%20p%3AP348%20%5B%0A%20%20%20%20ps%3AP348%20%3Fversion%3B%0A%20%20%20%20pq%3AP548%20wd%3AQ12355314%3B%0A%20%20%20%20wikibase%3Arank%20wikibase%3APreferredRank%0A%20%20%5D.%0A%7D

JSON API: https://query.wikidata.org/sparql?format=json&query=SELECT%20%3Fversion%20WHERE%20%7B%0A%20%20wd%3AQ698%20p%3AP348%20%5B%0A%20%20%20%20ps%3AP348%20%3Fversion%3B%0A%20%20%20%20pq%3AP548%20wd%3AQ12355314%3B%0A%20%20%20%20wikibase%3Arank%20wikibase%3APreferredRank%0A%20%20%5D.%0A%7D

This could be fetched by BrowserHappy in PHP by using wp_remote_get and json_decode.