How can I make the Topbar extension work with the newest MediaWiki?

爱⌒轻易说出口 提交于 2019-12-13 01:27:49

问题


I run a MediaWiki site which uses the Topbar extension. I recently upgraded the installation to the bleeding edge version from MediaWiki's master branch: version 1.28.0-alpha (91e56cc).

Afterwards, the Topbar extension no longer works:

  • Usually, the topbar div is not inserted at all.
  • Occasionally, the topbar div appears but the links are nonfunctional.

The latter issue may be a problem with my CSS (I do not know), but the intermittent behavior concerns me. So the first order of business is to make sure the topbar div at least appears every time.

This extension is just a small javascript that is supposed to run when the page loads, to add a chunk of HTML near the top (<div id="mw-writh-topbar" ...>). It does so using a jQuery function.

Unfortunately, I am not really a web developer, so even this simple routine is a bit over my head.

Here's what I do know:

  • There are no 500 server errors, no overt problem with the PHP.
  • At some point early in my investigation, the developer console sometimes complained about Uncaught ReferenceError: jQuery is not defined, but I cannot reproduce it anymore now. Research vaguely suggested it could be because the extension does not use the new ResourceLoader mechanism, so I tried to migrate Topbar to use the ResourceLoader mechanism (via maintenance/convertExtensionToRegistration.php, and then wfLoadExtension('Topbar') in LocalSettings.php) but it did not seem to make any difference.
  • The Topbar hooks seem to be called, because css/Topbar.css gets added to the page. But I have no clue whether js/Topbar.js ever runs, and if so, what happens.

So: how can I debug this?


回答1:


You need to convert the code to use ResourceLoader - currently the extension adds the code using OutputPage's addScriptFile(), and just assumes jQuery will be available by the time it runs. Starting with MediaWiki 1.26, everything loads asynchronously, so this doesn't work, and thus the need to convert it to the new system.

Instructions for doing so are here:

  • https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_for_extension_developers
  • https://www.mediawiki.org/wiki/ResourceLoader/Developing_with_ResourceLoader#Registering

Two notes:

  1. Since MediaWiki 1.25, extensions are supposed to use the so-called "extension registration" instead of following the above manuals, but this might require more work and expertise.
  2. Ugly hack warning: you can ignore all of this, and simply wrap the code in the JS file using RLQ.push( function(){ /* All of the code here */ } );. This shoves it all into the ResourceLoader's queue, so it will load after jQuery is available. I do not recommend this, but show it here for completeness' sake.


来源:https://stackoverflow.com/questions/37423269/how-can-i-make-the-topbar-extension-work-with-the-newest-mediawiki

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!