matomo-mediawiki-extension
matomo-mediawiki-extension copied to clipboard
Prevent doubled output if hook is called repeatedly
MediaWiki, at least since version 1.39, calls the SkinAfterBottomScripts
hook twice. This patch prevents the output from being doubled.
Your patch probably works in your case, but I’m a bit embarassed because it’s a bit hacky and I don’t (always) observe the issue:
- on https://wiki-valley.com/wiki/Creation_de_wikis_prives_en_ligne (currently 1.39.5 with Matomo 3e9bd0c) there is only one occurence of the Matomo JS code
- on a test wiki in 1.40.1 with Matomo c75666d there is only one occurence of the Matomo JS code
- on https://fr.vikidia.org/wiki/Vikidia:Accueil (currently 1.39.4 with Matomo (probably) 3e9bd0c) there are two occurences of the Matomo JS code I would prefer to fix the root cause instead of the hiding the consequence.
Searching a bit more, indeed there might be two executions of the hook SkinAfterBottomScripts between 1.37 included and 1.39 included, but there is only one execution in 1.40 and 1.41.
Between 1.37 and 1.38, there are calls of the hook both in includes/skins/Skin.php
and includes/OutputPage.php
, and in 1.39 two calls in includes/OutputPage.php
.
I thought it was a bad interaction with some other extension, but it seems MediaWiki itself is the cause.
Contrary to my previous comment, there is no issue in 1.37 and 1.38. The issue appears with 1.39.0 (this commit) and is present in 1.40.0.
It was fixed in 1.39.5 and 1.40.1, see this Phabricator task for MediaWiki.
So I propose to users experiencing this issue to update the MediaWiki core to fix the problem.