Extension:Javascript

From Organic Design wiki
Revision as of 11:24, 22 May 2008 by Nad (talk | contribs) ({{legacy}})
Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.

<php><?php

  1. Extension:Javascript
  2. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  3. - Author: http://www.organicdesign.co.nz/nad
  4. - Started: 2007-06-25, see article history

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

define('JAVASCRIPT_VERSION','1.0.2, 2007-06-27');

if (!isset($wgJavascriptPaths)) $wgJavascriptPaths = array(); $wgJavascriptFiles = array();

$wgExtensionFunctions[] = 'wfSetupJavascript';

  1. 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 .= "

  • [$wgServer$file ".basename($file)."]
  • \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 );

    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 js scripts
    5. defined from the LocalSettings.php global variable $wgJavascriptPaths

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

    ?> </php>