Extension talk:Javascript

The existing JavaScript.php gives a PHP warning on line 28 if there are no *.js files along with it and on line 39 if there are no *.css files along with it like: PHP Warning: Invalid argument supplied for foreach in /var/www/mediawiki/extensions/JavaScript/JavaScript.php on line 28, referer: http://www.....

This is because the glob PHP function cannot distinguish between no entries and an error condition when returning false.

It can be remedied with a check to eliminate the warnings by making the file as:
 * Wheres the rest of this code? A PHP alway and with a ?> . But your code don't end with it.


 * I think it will still work without the closing php tag. I have seen many PHP source code on mediawiki without the closing tag. But I always add it before copying it to my extensions directory. 60.241.61.96 13:45, 30 September 2011 (UTC)

Advantage over MediaWiki:Common.js is not clear
Could someone update the description of this extension so that its advantage over MediaWiki:Common.js is more clear? Badon 05:26, 23 November 2011 (UTC)

'Undefined variable: organicdesign' error when using this extension
I got error Undefined variable: organicdesign when using this script. Can someone please explain how to fix it?


 * simply write  somewhere before the first use of the variable   (possibly after line 23) Kappa (talk) 17:31, 4 March 2014 (UTC)

Revised version
The original version of this excellent little extension has a few issues. I have added a revised version below. In it I have removed the support for Mediawiki versions 1.7 and lower since I have no way of testing the script in an old version of Mediawiki and users should upgrade to a more recent version anyway. I have also removed the support for loading stylesheets (CSS files) as this is not what the extension is about. I have edited the meta-information displayed for this extension on Mediawiki's 'Version' page. The 'organicdesign' bug referred to elsewhere has been removed.

 "JavaScript",	'author'      => "User:Nad. Rev. Henrik Thiil Nielsen",	'description' => "Includes all *.js files found in the directory containing this extension",	'url'         => "http://www.mediawiki.org/wiki/Extension:Javascript",	'version'     => JAVASCRIPT_VERSION );

$wgJavaScriptExterenalPath = wfJavaScriptExternalPath( dirname( __FILE__ ) );

$wgResourceModules['ext.JavaScript'] = array(	'scripts' => array,	'styles' => array,	'dependencies' => array( 'jquery' ),	'localBasePath' => dirname( __FILE__ ),	'remoteExtPath' => basename( dirname( __FILE__ ) ),	'position' => 'top' );

foreach( glob( dirname( __FILE__ ). "/*.js" ) as $file ) { $wgResourceModules['ext.JavaScript']['scripts'][] = basename( $file ); }

$wgHooks['BeforePageDisplay'][] = 'wfJavaScriptAddModules'; function wfJavaScriptAddModules( &$out, $skin = false ) { $out->addModules( 'ext.JavaScript' ); return true; }

/** * Convert an internal resource path to an external one function wfJavaScriptExternalPath( $internalPath ) { global $wgScriptPath; return preg_replace( "|^.*/extensions|", "$wgScriptPath/extensions", $internalPath ); }

?>