Difference between revisions of "Extension:Javascript"
m |
(1.0.0 In use on OD) |
||
Line 1: | Line 1: | ||
<?php | <?php | ||
− | # Extension:Javascript{{php}}{{Category:Extensions| | + | # Extension:Javascript{{php}}{{Category:Extensions|Wikia}} |
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) | # - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) | ||
# - Author: http://www.organicdesign.co.nz/nad | # - Author: http://www.organicdesign.co.nz/nad | ||
Line 7: | Line 7: | ||
if (!defined('MEDIAWIKI')) die('Not an entry point.'); | if (!defined('MEDIAWIKI')) die('Not an entry point.'); | ||
− | define('JAVASCRIPT_VERSION',' | + | define('JAVASCRIPT_VERSION','1.0.0, 2007-06-25'); |
− | $wgJavascriptPaths | + | if (!isset($wgJavascriptPaths)) $wgJavascriptPaths = array(); |
$wgJavascriptFiles = array(); | $wgJavascriptFiles = array(); | ||
Line 16: | Line 16: | ||
# Build list of files from list, no duplicate names | # Build list of files from list, no duplicate names | ||
foreach ($wgJavascriptPaths as $path) { | foreach ($wgJavascriptPaths as $path) { | ||
− | if (is_file($ | + | $ipath = $_SERVER['DOCUMENT_ROOT']."/$path"; |
− | elseif (is_dir($ | + | if (is_file("$ipath")) $wgJavascriptFiles[$path] = true; |
− | if ($dir = opendir($ | + | elseif (is_dir($ipath)) { |
− | while (false !== ($file = readdir($dir))) $wgJavascriptFiles[$file] = true; | + | if ($dir = opendir($ipath)) { |
+ | while (false !== ($file = readdir($dir))) $wgJavascriptFiles["$path/$file"] = true; | ||
closedir($dir); | closedir($dir); | ||
} | } | ||
} | } | ||
} | } | ||
+ | $list = ''; | ||
+ | foreach (array_keys($wgJavascriptFiles) as $file) | ||
+ | $list .= "<li>[$wgServer$wgScriptPath/$file ".basename($file)."]</li>\n"; | ||
$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' => | + | 'description' => "Loaded Javascript files:<ul>$list</ul>", |
'url' => 'http://www.mediawiki.org/wiki/Extension:Javascript', | 'url' => 'http://www.mediawiki.org/wiki/Extension:Javascript', | ||
'version' => JAVASCRIPT_VERSION | 'version' => JAVASCRIPT_VERSION |
Revision as of 02:20, 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','1.0.0, 2007-06-25');
if (!isset($wgJavascriptPaths)) $wgJavascriptPaths = array(); $wgJavascriptFiles = array();
$wgExtensionFunctions[] = 'wfSetupJavascript';
- Build list of files from list, no duplicate names
foreach ($wgJavascriptPaths as $path) { $ipath = $_SERVER['DOCUMENT_ROOT']."/$path"; if (is_file("$ipath")) $wgJavascriptFiles[$path] = true; elseif (is_dir($ipath)) { if ($dir = opendir($ipath)) { while (false !== ($file = readdir($dir))) $wgJavascriptFiles["$path/$file"] = true; closedir($dir); } } } $list = ; foreach (array_keys($wgJavascriptFiles) as $file)
$list .= "
\n";
$wgExtensionCredits['other'][] = array( 'name' => 'Javascript', 'author' => 'User:Nad',
'description' => "Loaded Javascript files:
- $list
",
'url' => 'http://www.mediawiki.org/wiki/Extension:Javascript', 'version' => JAVASCRIPT_VERSION );
- Notes:
- Load all dirs/files in $wgJavascriptPaths into $wgJavascriptScripts 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,$wgJavascriptFiles; foreach (array_keys($wgJavascriptFiles) as $file) $wgOut->addScript("<script type=\"text/javascript\" src=\"$file\"></script>\n"); }
?>