[Mediawiki-l] Simple Extension and $wgOut->addScript

Stephen Earl Steve.Earl at cdw.com
Tue Sep 15 13:38:19 UTC 2009


Hi,

I'm working on what I think is a relatively simple extension to insert some javascript and css links into the head element of a particular page.  I'm pretty new to MediaWiki so I'm sure that I'm just missing something here.  Anyway, in the code below, the extjsHead method is my preferred method of inserting the links within the head tags in my page.  However, nothing is ever inserted in the head tag when I use $wgOut->addScript(...).  The only way I've found to do this is to use the extjsBody method to insert the script tags within the body of my page.

Am I just missing something or is it not possible to use $wgOut->addScript in this manner?

Steve E.


<code>
<?php
                # Setup and Hooks for the ExtJS extension.

                if( !defined( 'MEDIAWIKI' ) ) {
                                echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
                                die();
                }

                ## Register extension setup hook and credits:
                $wgExtensionFunctions[]             = 'fnExtJS';

                $wgExtensionCredits['other'][] = array(
                                'name'                  => 'ExtJS (version 0.1)',
                                'author'                => 'Steve Earl',
                                'url'                         => 'http://www.cdw.com',
                                'description'       => 'Inserts ExtJS javascript library.'
                );

                function fnExtJS() {
                                global $wgParser;
                                $wgParser->setHook('extjsHead', 'fnExtJSShowHookHead');
                                $wgParser->setHook('extjsBody', 'fnExtJSShowHookBody');
                }

                function fnExtJSShowHookHead($input, $argv, &$parser) {
                                global $wgScriptPath, $wgOut;

                                $wgOut->addScript("<script type=\"text/javascript\" src=\"" . $wgScriptPath . "/extensions/ExtJS/includes/ext-all-debug.js\"></script>\n");
                                $wgOut->addScript("<script type=\"text/javascript\" src=\"" . $wgScriptPath . "/extensions/ExtJS/includes/adapter/ext/ext-base-debug.js\"></script>\n");

                                return "":
                }

                function fnExtJSShowHookBody($input, $argv, &$parser) {
                                global $wgScriptPath;

                  $html = "";

                  # ADD ExtJS JAVASCRIPT
                                $html .= "<script type=\"text/javascript\" src=\"" . $wgScriptPath . "/extensions/ExtJS/includes/ext-all-debug.js\"></script>\n";
                                $html .= "<script type=\"text/javascript\" src=\"" . $wgScriptPath . "/extensions/ExtJS/includes/adapter/ext/ext-base-debug.js\"></script>\n";

                  # ADD CSS
                                $html .= "<style type='text/css'>\n";
                                $html .= "@import '" . $wgScriptPath . "/extensions/ExtJS/includes/resources/css/ext-all.css';\n";
                                $html .= "</style>\n";

                                return $html;
                }
?>
</code>



More information about the MediaWiki-l mailing list