Mediawiki 1.27.4未加载jquery

Mediawiki 1.27.4未加载jquery,jquery,mediawiki,Jquery,Mediawiki,我不熟悉Mediawiki和Resourceloader之类的东西。我最近下载了MediaWiki 1.27.4 LTS版本,安装后,我发现即使他们说默认情况下加载了jquery,也找不到它(我正在查看chrome开发者工具中的sources选项卡)。 在我的一个使用BeforePageDisplay钩子的扩展中,我想使用jquery.cookie,所以我声明了以下resourceloader $wgResourceModules['ext.myFirstExtension'] = array(

我不熟悉Mediawiki和Resourceloader之类的东西。我最近下载了MediaWiki 1.27.4 LTS版本,安装后,我发现即使他们说默认情况下加载了jquery,也找不到它(我正在查看chrome开发者工具中的sources选项卡)。 在我的一个使用BeforePageDisplay钩子的扩展中,我想使用jquery.cookie,所以我声明了以下resourceloader

$wgResourceModules['ext.myFirstExtension'] = array(           
        'dependencies' => array( 'jquery.cookie'),            
        'localBasePath' => dirname( __FILE__ ),            
        'remoteExtPath' => 'myFirstExtension',
        'position' => 'top'
);
在我的扩展文件中,我正在自动加载一个类,并在其中执行 在脚本中,我只是执行下面的代码,它会抛出$undefined的典型错误,因为jquery没有加载

$(document).ready(function(){
alert("here");
});
是的,我使用的是矢量皮肤,没有任何修改。此外,除了VisualEdit,我没有使用任何其他扩展,它工作得非常好

我还尝试了我的中的mw.loader.load('jquery'),它还抱怨mw没有被识别

我还添加了$wgrourceloaderdebug=true;在我的本地设置中,这样资源加载器就不会捆绑我的脚本和css

我怀疑没有jquery,Mediawiki在内部无法运行。。但是现在我如何才能让jquery正确加载到扩展中,以便使用jquery.cookie


谢谢

问题可能是模块注册的
'position'=>'top'
选项,这可能导致模块在jQuery之前加载


通常没有理由使用
'position'=>'top'
,除非资源是仅CSS的模块。

只有在Common.js或用户的自定义vector.js页面中有任何JQuery代码要执行时,才会加载JQuery

在导入任何外部库之前,必须确保JQuery正常工作,请执行以下步骤:

  • 将以下内容添加到LocalSettings.php文件中
  • $wgAllowUserJs=true

  • 转到您的帐户custom vector.js页面(即user:/vector.js)并键入任何JQuery代码,如
  • $(文档).ready(函数(){
    警报(“此处”);
    });
    
    保存页面后,必须使用“here”字样提醒浏览器


    如果没有,则应检查浏览器中是否启用了Javascript,如果通过URL导入JQuery cookies,则应检查URL是否通过https协议运行,因为MediaWiki将不接受任何不应用https协议的外部源。

    在努力使JQuery在扩展类中工作之后,我决定创建一个审判延期,以证明我认为可能是这样的理论:

    这是我的扩展文件:

    <?php
    # Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
    if (!defined('MEDIAWIKI')) {
        echo <<<EOT
    To install my extension, put the following line in LocalSettings.php:
    require_once( "$IP/extensions/MyExtension/MyExtension.php" );
    EOT;
        exit( 1 );
    }
    
    $wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'TryExtension',
        'author' => 'Andy',
        'url' => 'https://home.com',
        'descriptionmsg' => 'Trial Extension',
        'version' => '1.0.0',
    );
    
    $dir = dirname(__FILE__) . '/';
    
    $wgAutoloadClasses['TryExtension'] = $dir . 'tryExtension.class.php'; # Location of the SpecialMyExtension class (Tell MediaWiki to load this file)
    
    $wgHooks['BeforePageDisplay'][] = 'TryExtension::execute';
    
    $wgResourceModules['ext.TryExtension'] = array(    
        'scripts' => array('scripts/tryjQuery.js'),    
        'dependencies' => array( 'jquery.cookie'),    
        'localBasePath' => dirname( __FILE__ ),    
        'remoteExtPath' => 'TryExtension',
        'position' => 'top'
    );
    
    下面是扩展类:

    <?php
    class TryExtension extends SpecialPage
    {
     public function execute(){
         global $wgOut;
         $wgOut->addModules( 'ext.TryExtension' );
        ?>
         <script>
            $(document).ready(function () {
            alert("from class - here");
        }); 
        </script>
         <?php
     }
    }
    
    
    $(文档).ready(函数(){
    警报(“来自课堂-此处”);
    }); 
    
    另外,我查看了vector.js,它的第一行本身以jquery匿名函数jquery(function($){…})开始,因此jquery看起来是默认加载的。当我放置$(document).ready(function(){…})时,它执行得很好。但我的扩展中的同一段代码不起作用。可能是我在扩展的“执行”方法中使用内联javascript??有什么建议吗?西恩西亚,我试过你的建议,但没有用。还有其他建议吗?
    <?php
    class TryExtension extends SpecialPage
    {
     public function execute(){
         global $wgOut;
         $wgOut->addModules( 'ext.TryExtension' );
        ?>
         <script>
            $(document).ready(function () {
            alert("from class - here");
        }); 
        </script>
         <?php
     }
    }