jmnote / SimpleMathJax

MediaWiki Extension SimpleMathJax
https://www.mediawiki.org/wiki/Extension:SimpleMathJax
MIT License
30 stars 23 forks source link

Fix path to ext.SimpleMathJax.js in ResourceModules (#1) #40

Closed pastakhov closed 3 months ago

pastakhov commented 1 year ago

Mediawiki tries to load extensions/SimpleMathJax/resources/resources/ext.SimpleMathJax.js file when ResourceLoader in debug mode, the patch fixes the path

TripleCamera commented 7 months ago

@jmnote Hi. Could you please review this Pull Request? This issue is occurring on a wiki I know, which upgraded to MediaWiki 1.41 a few days ago. (I have no idea why it doesn't affect other wikis.)

jmnote commented 6 months ago

Thanks for the PR. But I'm not sure if it's right to change it that way. I don't see any problems with the existing code. Would you like to check out the following examples and documentation?

    "ResourceFileModulePaths": {
        "localBasePath": "resources",
        "remoteExtPath": "FooBar/resources"
    }

https://www.mediawiki.org/wiki/Manual:Extension.json/Schema

    "ResourceFileModulePaths": {
        "localBasePath": "modules",
        "remoteExtPath": "CodeEditor/modules"
    },

https://github.com/wikimedia/mediawiki-extensions-CodeEditor/blob/wmf/1.40.0-wmf.4/extension.json#L139-L142

Is it possible that it is affected by other configs? I think you might need to check the extension.json file. Also, if the problem occurs only in version 1.41, we should check the release notes. https://mediawiki.org/wiki/Release_notes/1.41

TripleCamera commented 6 months ago

Hi. A few days ago, the webmaster told me that the issue of his wiki failing to load JS modules was caused by other extensions. Sorry that I didn't update my comment in advance.

According to @AlPha5130, for SimpleMathJax, the value of localBasePath is correct, while the value of remoteExtPath is incorrect. The former one is responsible for loading the modules when browsing the wiki, and the latter one is responsible for the URL endpoint, which is provided to anyone who may concern.

https://github.com/jmnote/SimpleMathJax/blob/7c9de84d219d15243aa153867339ac1a9c1a22e5/extension.json#L25-L34

Currently, the URL endpoint is /w/extensions/SimpleMathJax/resources/resources/ext.SimpleMathJax.js (remoteExtPath + scripts), but it is expected to be /w/extensions/SimpleMathJax/resources/ext.SimpleMathJax.js. Nobody has used this endpoint so far, and MediaWiki only tries to load this file in debug mode (append ?debug=1 to URL). So for now, this is not causing any problem, but fixing it would be better. :blush:

PS. MediaWiki extension Purge just fixed this a few days ago. You can see it here.

jmnote commented 6 months ago

This issue involves deciding whether or not to enter resources in three places as shown below.

"ResourceModules": {
  "ext.SimpleMathJax": {
    "scripts": ["(resources/???)ext.SimpleMathJax.js"],
    ...
"ResourceFileModulePaths": {
  "localBasePath": "(resources???)",
  "remoteExtPath": "SimpleMathJax(/resources???)"

A total of 8 $(=2^3)$ test cases were tested by expressing the number of all cases bitwise as follows. (My testing environment: MediaWiki 1.39)

What we see in cases 000, 001, 110, and 111 is that we must enter resources only in either scripts or localBasePath.

Also, it has been reported that case 101, the current state (main branch), has a problem. We have to choose from the remaining cases 010, 011, and 100. The current PR corresponds to case 100, but it would be better to refer to Manual or Purge and modify it as follows according to case 011. What do you think?

"ResourceModules": {
  "ext.SimpleMathJax": {
    "scripts": ["ext.SimpleMathJax.js"],
    ...
"ResourceFileModulePaths": {
  "localBasePath": "resources",
  "remoteExtPath": "SimpleMathJax/resources"
AlPha5130 commented 6 months ago

The current PR corresponds to case 100, but it would be better to refer to Manual or Purge and modify it as follows according to case 011. What do you think?

It depends on how you would organize the JS file hierarchy. In my case (Purge) I set the "root" path (i.e. localBasePath) to resources as all my JS files will be put there. If you have other JS files which do not fit in resources you can set localBasePath to "".