Difference between revisions of "Extension:Javascript"
m |
(ready for debgging) |
||
Line 8: | Line 8: | ||
define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25'); | define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25'); | ||
+ | |||
+ | $JavascriptFiles = array(); | ||
+ | $JavascriptScripts = array(); | ||
$wgExtensionFunctions[] = 'wfSetupJavascript'; | $wgExtensionFunctions[] = 'wfSetupJavascript'; | ||
+ | |||
+ | # Build list of files from list, no duplicate names | ||
+ | foreach ($JavascriptFiles as $path) { | ||
+ | if (is_file($path)) $JavascriptFiles[$path] = true; | ||
+ | elseif (is_dir($path)) { | ||
+ | if ($dir = opendir($path)) { | ||
+ | while (false !== ($file = readdir($dir))) $JavascriptFiles[$file] = true; | ||
+ | closedir($dir); | ||
+ | } | ||
+ | } | ||
+ | } | ||
$wgExtensionCredits['other'][] = array( | $wgExtensionCredits['other'][] = array( | ||
'name' => 'Javascript', | 'name' => 'Javascript', | ||
'author' => '[http://www.organicdesign.co.nz/nad User:Nad]', | 'author' => '[http://www.organicdesign.co.nz/nad User:Nad]', | ||
− | 'description' => 'Handles the loading of Javascript files', | + | 'description' => 'Handles the loading of Javascript files. Scripts loaded: '.join(', ',$JavascriptFiles), |
'url' => 'http://www.mediawiki.org/wiki/Extension:Javascript', | 'url' => 'http://www.mediawiki.org/wiki/Extension:Javascript', | ||
'version' => JAVASCRIPT_VERSION | 'version' => JAVASCRIPT_VERSION | ||
Line 20: | Line 34: | ||
# Notes: | # Notes: | ||
− | # Load all files in $ | + | # Load all dirs/files in $JavascriptPaths into $JavascriptScripts using filename as key |
# Other extensions can add to the list if they need to | # Other extensions can add to the list if they need to | ||
# After all extenions are loaded and $wgOut is established, add all the script | # After all extenions are loaded and $wgOut is established, add all the script | ||
function wfSetupJavascript() { | function wfSetupJavascript() { | ||
− | global $wgOut,$ | + | global $wgOut,$JavascriptFiles; |
+ | foreach (array_keys($JavascriptFiles) as $src) | ||
+ | $wgOut->addScript("<script type=\"text/javascript\" src=\"$src\"></script>\n"); | ||
} | } | ||
?> | ?> |
Revision as of 01:11, 25 June 2007
<?php
- Extension:JavascriptTemplate:Php
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
- - Started: 2007-06-25, see article history
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25');
$JavascriptFiles = array(); $JavascriptScripts = array();
$wgExtensionFunctions[] = 'wfSetupJavascript';
- Build list of files from list, no duplicate names
foreach ($JavascriptFiles as $path) { if (is_file($path)) $JavascriptFiles[$path] = true; elseif (is_dir($path)) { if ($dir = opendir($path)) { while (false !== ($file = readdir($dir))) $JavascriptFiles[$file] = true; closedir($dir); } } }
$wgExtensionCredits['other'][] = array( 'name' => 'Javascript', 'author' => 'User:Nad', 'description' => 'Handles the loading of Javascript files. Scripts loaded: '.join(', ',$JavascriptFiles), 'url' => 'http://www.mediawiki.org/wiki/Extension:Javascript', 'version' => JAVASCRIPT_VERSION );
- Notes:
- Load all dirs/files in $JavascriptPaths into $JavascriptScripts using filename as key
- Other extensions can add to the list if they need to
- After all extenions are loaded and $wgOut is established, add all the script
function wfSetupJavascript() { global $wgOut,$JavascriptFiles; foreach (array_keys($JavascriptFiles) as $src) $wgOut->addScript("<script type=\"text/javascript\" src=\"$src\"></script>\n"); }
?>