php – Mediawiki Extension在Header中添加Javascript

前端之家收集整理的这篇文章主要介绍了php – Mediawiki Extension在Header中添加Javascript前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨我的问题是我无法加载一些 javascript文件@我的特殊页面扩展名.
我尝试使用addcript和其他一些方法,但唯一发生的事情是javascript被取消导致no-js的mediawiki软件.

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

这是一些代码(大多数特殊页面的例子).

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

<?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:
$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;

}
原文链接:https://www.f2er.com/php/139152.html

猜你在找的PHP相关文章