MediaWiki fails executing JavaScript which gets executed fine in browser console

纵然是瞬间 提交于 2019-12-11 17:59:20

问题


The following global JavaScript code is the only JavaScript code I use in my entire all-core, Hebrew, MediaWiki 1.33.0 website:

/* כל הסקריפטים הנכתבים כאן ייטענו עבור כל המשתמשים בכל טעינת עמוד. */

const list = document.querySelector("#footnotes_list");
document.querySelectorAll(".footnote>sup").forEach((footnote, i) => {
    const li = document.createElement("li");
    li.append(...footnote.childNodes); // move content
    list.appendChild(li);
    footnote.textContent = i+1;
});

Related templates

The above JavaScript code is related to the following two templates.
The following Hebrew template names mean "footnote" and "footnotes" respectively:

תבנית:הערה

<p><span class="footnote"><sup>{{{1}}}</sup></span></p><noinclude>
[[קטגוריה:תבניות עריכה]]
</noinclude>

תבנית:הערות שוליים

<ol id="footnotes_list"></ol><noinclude>
[[קטגוריה:תבניות עריכה]]
</noinclude>

Purpose

This HTML-WIKI-JavaScript combo serves as potential substitute to common references extensions as it allows each footnote to appear sorted in a footnotes section.
I think it should be useful for people desiring to avoid installing any extensions or skins from various reasons such as the desire to reduce PHP complexity, minimalism philosophy, personal comfortability and possibly more.

My problem

If I try to execute the JavaScript code from browser console it works fine --- Every footnote inserted to article body appears sorted (respective) under the "footnotes" ol chapter.

Yet, if I try to execute that JavaScript code from https://example.com//index.php?title=מדיה_ויקי:Common.js, it doesn't work; clearing Chrome cache with CTRL+F5 didn't help.

My question

What causes MediaWiki to fail running the JavaScript code and how could that be fixed?


Side note: credit goes to user:trincot for developing the utilized JavaScript.


回答1:


It seems to me that MediaWiki's latest release for now (1.33.0) allegedly can only execute ES3.

This session - question and accepted answer details more and include a solution.



来源:https://stackoverflow.com/questions/57638079/mediawiki-fails-executing-javascript-which-gets-executed-fine-in-browser-console

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