Mediawiki Extension在Header中添加Javascript [英] Mediawiki Extension add Javascript in Header

查看:92
本文介绍了Mediawiki Extension在Header中添加Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我的问题是我无法加载一些javascript文件@我的特殊页面扩展名。
我尝试使用addcript和其他一些方法,但唯一发生的事情是javascript被取消导致no-js的mediawiki软件。

Hi my problem is that i cant load some javascript file @ my special page extension. I tried it with addscript and some other methods but the only thing what happened was that the javascript was canceled cause no-js of the mediawiki software.

In我的扩展名的文件夹是一个new.js文件,我只想在我的特殊页面上访问它。

In the folder of my extension is a new.js file which i want to have access only on my special page.

这是一些代码(大多数代码都是特殊页面。)

Here is some code (most of it of the example of the special pages).

MyExentions.php

MyExentions.php

<?php
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' => '-',
    'author' => 'Thomas Döring',
    'descriptionmsg' => '-',
    'version' => '0.0.1',
);

$dir = dirname(__FILE__) . '/';
$wgAutoloadClasses['SpecialMyExtension'] = $dir . 'SpecialMyExtension.php'; 
$wgExtensionMessagesFiles['MyExtension'] = $dir . 'MyExtension.i18n.php';
$wgExtensionMessagesFiles['MyExtensionAlias'] = $dir . 'MyExtension.alias.php'; 
$wgSpecialPages['MyExtension'] = 'SpecialMyExtension'; 

SpecialMyExtension.php

SpecialMyExtension.php

 <?php
 class SpecialMyExtension extends SpecialPage {
    function __construct() {
            parent::__construct( 'MyExtension' );
    }

    function execute( $par ) {
            $request = $this->getRequest();
            $output = $this->getOutput();
            $this->setHeaders();

            # Get request data from, e.g.
            $param = $request->getText('param');

            # Do stuff
            # ...

            if(file_exists("extensions/TimeLine/TimeLine/data.xml"))
            {
                    $data = simplexml_load_file("extensions/TimeLine/TimeLine/data.xml");

                    foreach($data->event as $event)
                    {
                        $html.="<tr><td>".$event['title']."</td><td>".$event['start']."</td></tr>";
                    }
                    $html.="</table>";

                    $html.="<a href=\"javascript:hello()\">klick</a>";

                    $output->addHTML($html);

                 }
                 else
                 {
                    $wikitext = 'Datei nicht gefunden!';
                    $output->addWikiText( $wikitext );
                 }

    }


 }
 ?>

我希望你能帮助我。

推荐答案

addScript适用于1.16及更早版本。在1.17及更高版本中你应该使用addHeadItem:

addScript works in version 1.16 and before. In 1.17 and later you should use addHeadItem:

$wgHooks['ParserBeforeTidy'][] = 'wgAddJquery';

function wgAddJquery(&$parser, &$text) {

  global $addJqueryScripts;
  if ($addJqueryScripts === true) return true;

  $parser->mOutput->addHeadItem(
    '<script language="JavaScript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>'
  );

  $addJqueryScripts = true;

  return true;

}

这篇关于Mediawiki Extension在Header中添加Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆