Extension:Javascript

From Organic Design wiki
Revision as of 04:36, 25 June 2007 by Nad (talk | contribs) (special:version shows details)

<?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','1.0.0, 2007-06-25');

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); } } }

  1. Show a list of the files successfully imported in the Special:Version page

$list = ; foreach (array_keys($wgJavascriptFiles) as $file)

$list .= "

  • [$wgServer$wgScriptPath/$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. Add the script-import to the output page

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

    ?>