Difference between revisions of "Extension:Javascript"

From Organic Design wiki
(ready for debgging)
m
Line 9: Line 9:
 
define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25');
 
define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25');
  
$JavascriptFiles   = array();
+
$wgJavascriptFiles   = array();
$JavascriptScripts = array();
+
$wgJavascriptScripts = array();
  
 
$wgExtensionFunctions[] = 'wfSetupJavascript';
 
$wgExtensionFunctions[] = 'wfSetupJavascript';
  
 
# Build list of files from list, no duplicate names
 
# Build list of files from list, no duplicate names
foreach ($JavascriptFiles as $path) {
+
foreach ($wgJavascriptFiles as $path) {
if (is_file($path)) $JavascriptFiles[$path] = true;
+
if (is_file($path)) $wgJavascriptFiles[$path] = true;
 
elseif (is_dir($path)) {
 
elseif (is_dir($path)) {
 
if ($dir = opendir($path)) {
 
if ($dir = opendir($path)) {
while (false !== ($file = readdir($dir))) $JavascriptFiles[$file] = true;
+
while (false !== ($file = readdir($dir))) $wgJavascriptFiles[$file] = true;
 
closedir($dir);
 
closedir($dir);
 
}
 
}
Line 28: Line 28:
 
'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. Scripts loaded: '.join(', ',$JavascriptFiles),
+
'description' => 'Handles the loading of Javascript files. Scripts loaded: '.join(', ',$wgJavascriptFiles),
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:Javascript',
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:Javascript',
 
'version'    => JAVASCRIPT_VERSION
 
'version'    => JAVASCRIPT_VERSION
Line 34: Line 34:
  
 
# Notes:
 
# Notes:
# Load all dirs/files in $JavascriptPaths into $JavascriptScripts using filename as key
+
# Load all dirs/files in $wgJavascriptPaths into $wgJavascriptScripts 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,$JavascriptFiles;
+
global $wgOut,$wgJavascriptFiles;
foreach (array_keys($JavascriptFiles) as $src)
+
foreach (array_keys($wgJavascriptFiles) as $src)
 
$wgOut->addScript("<script type=\"text/javascript\" src=\"$src\"></script>\n");
 
$wgOut->addScript("<script type=\"text/javascript\" src=\"$src\"></script>\n");
 
}
 
}
  
 
?>
 
?>

Revision as of 01:13, 25 June 2007

<?php

  1. Extension:JavascriptTemplate:Php
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.
  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: http://www.organicdesign.co.nz/nad
  3. - Started: 2007-06-25, see article history

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25');

$wgJavascriptFiles = array(); $wgJavascriptScripts = array();

$wgExtensionFunctions[] = 'wfSetupJavascript';

  1. Build list of files from list, no duplicate names

foreach ($wgJavascriptFiles as $path) { if (is_file($path)) $wgJavascriptFiles[$path] = true; elseif (is_dir($path)) { if ($dir = opendir($path)) { while (false !== ($file = readdir($dir))) $wgJavascriptFiles[$file] = true; closedir($dir); } } }

$wgExtensionCredits['other'][] = array( 'name' => 'Javascript', 'author' => 'User:Nad', 'description' => 'Handles the loading of Javascript files. Scripts loaded: '.join(', ',$wgJavascriptFiles), 'url' => 'http://www.mediawiki.org/wiki/Extension:Javascript', 'version' => JAVASCRIPT_VERSION );

  1. Notes:
  2. Load all dirs/files in $wgJavascriptPaths into $wgJavascriptScripts using filename as key
  3. Other extensions can add to the list if they need to
  4. After all extenions are loaded and $wgOut is established, add all the script

function wfSetupJavascript() { global $wgOut,$wgJavascriptFiles; foreach (array_keys($wgJavascriptFiles) as $src) $wgOut->addScript("<script type=\"text/javascript\" src=\"$src\"></script>\n"); }

?>