Mediawiki extension adds javascript in title

Hi, my problem is that I cannot load some javascript file @ my special page extension. I tried this with addcript and some other methods, but the only thing that happened was that javascript was canceled, causing non-js mediawiki software.

In the folder of my extension is the new.js file, which I want to get only on my special page.

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

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, eg $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 ); } } } ?> 

I hope you help me.

+2
source share
2 answers

addScript works in version 1.16 and earlier. 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; } 
+2
source

I added it to the skin file, in the function function setupSkinUserCss $ For the street> addHeadItem ('maketree.js', "

 <script type='text/javascript' src='/js/mktree.js'></script>"); 
0
source

Source: https://habr.com/ru/post/975481/


All Articles