r92944 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92943‎ | r92944 | r92945 >
Date:12:45, 23 July 2011
Author:ankitgarg833
Status:deferred
Tags:
Comment:
added func. to loadJavascriptAndCSS . copied from SF code.
Modified paths:
  • /trunk/extensions/PageSchemas/PageSchemas.classes.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/PageSchemas.classes.php
@@ -10,6 +10,142 @@
1111
1212 /* Functions */
1313 //Copied from SFUtils
 14+ public static function loadJavascriptAndCSS( $parser = null ) {
 15+ // Handling depends on whether or not this form is embedded
 16+ // in another page.
 17+ if ( !is_null( $parser ) ) {
 18+ $output = $parser->getOutput();
 19+ } else {
 20+ global $wgOut;
 21+ $output = $wgOut;
 22+ }
 23+ $output->addModules( 'ext.semanticforms.main' );
 24+ $output->addModules( 'ext.semanticforms.fancybox' );
 25+ $output->addModules( 'ext.semanticforms.autogrow' );
 26+ $output->addModules( 'ext.semanticforms.submit' );
 27+ $output->addModules( 'ext.smw.tooltips' );
 28+ $output->addModules( 'ext.smw.sorttable' );
 29+ }
 30+ /**
 31+ * Javascript files to be added regardless of the MediaWiki version
 32+ * (i.e., even if the ResourceLoader exists).
 33+ */
 34+ public static function addJavascriptFiles( $parser ) {
 35+ global $wgOut, $wgFCKEditorDir, $wgScriptPath, $wgJsMimeType;
 36+
 37+ $scripts = array();
 38+
 39+ wfRunHooks( 'sfAddJavascriptFiles', array( &$scripts ) );
 40+
 41+ // The FCKeditor extension has no defined ResourceLoader
 42+ // modules yet, so we have to call the scripts directly.
 43+ // @TODO Move this code into the FCKeditor extension.
 44+ if ( $wgFCKEditorDir && class_exists( 'FCKEditor' ) ) {
 45+ $scripts[] = "$wgScriptPath/$wgFCKEditorDir/fckeditor.js";
 46+ }
 47+
 48+ foreach ( $scripts as $js ) {
 49+ if ( $parser ) {
 50+ $script = "<script type=\"$wgJsMimeType\" src=\"$js\"></script>\n";
 51+ $parser->getOutput()->addHeadItem( $script );
 52+ } else {
 53+ $wgOut->addScriptFile( $js );
 54+ }
 55+ }
 56+ }
 57+
 58+ /**
 59+ * Includes the necessary Javascript and CSS files for the form
 60+ * to display and work correctly.
 61+ *
 62+ * Accepts an optional Parser instance, or uses $wgOut if omitted.
 63+ */
 64+ public static function addJavascriptAndCSS( $parser = null ) {
 65+ global $wgOut;
 66+
 67+ if ( !$parser ) {
 68+ $wgOut->addMeta( 'robots', 'noindex,nofollow' );
 69+ }
 70+
 71+ self::addJavascriptFiles( $parser );
 72+
 73+ // MW 1.17 +
 74+ if ( class_exists( 'ResourceLoader' ) ) {
 75+ self::loadJavascriptAndCSS( $parser );
 76+ return;
 77+ }
 78+ global $sfgScriptPath, $smwgScriptPath, $wgScriptPath, $wgJsMimeType, $sfgUseFormEditPage;
 79+ global $smwgJQueryIncluded, $smwgJQUIAutoIncluded;
 80+ // jQuery and jQuery UI are used so often in forms, we might as
 81+ // well assume they'll always be used, and include them in
 82+ // every form
 83+ $smwgJQueryIncluded = true;
 84+ $smwgJQUIAutoIncluded = true;
 85+
 86+ $css_files = array(
 87+ "$smwgScriptPath/skins/SMW_custom.css",
 88+ "$sfgScriptPath/skins/jquery-ui/base/jquery.ui.all.css",
 89+ "$sfgScriptPath/skins/SemanticForms.css",
 90+ "$sfgScriptPath/skins/SF_submit.css",
 91+ "$sfgScriptPath/skins/jquery.fancybox.css"
 92+ );
 93+ foreach ( $css_files as $css_file ) {
 94+ $link = array(
 95+ 'rel' => 'stylesheet',
 96+ 'type' => 'text/css',
 97+ 'media' => "screen",
 98+ 'href' => $css_file
 99+ );
 100+ if ( !is_null( $parser ) ) {
 101+ $parser->getOutput()->addHeadItem( Xml::element( 'link', $link ) );
 102+ } else {
 103+ $wgOut->addLink( $link );
 104+ }
 105+ }
 106+
 107+ $scripts = array();
 108+ if ( !$sfgUseFormEditPage )
 109+ $scripts[] = "$sfgScriptPath/libs/SF_ajax_form_preview.js";
 110+ $realFunction = array( 'SMWOutputs', 'requireHeadItem' );
 111+ if ( is_callable( $realFunction ) ) {
 112+ SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP );
 113+ SMWOutputs::requireHeadItem( SMW_HEADER_SORTTABLE );
 114+ // TODO - should this be called directly here, or is
 115+ // there a "smarter" (in some way) place to put it?
 116+ SMWOutputs::commitToOutputPage( $wgOut );
 117+ } else {
 118+ $scripts[] = "$smwgScriptPath/skins/SMW_tooltip.js";
 119+ $scripts[] = "$smwgScriptPath/skins/SMW_sorttable.js";
 120+ }
 121+ $realFunction = array( 'OutputPage', 'includeJQuery' );
 122+ if ( is_callable( $realFunction ) ) {
 123+ $wgOut->includeJQuery();
 124+ } else {
 125+ $scripts[] = "$sfgScriptPath/libs/jquery-1.4.2.min.js";
 126+ }
 127+ $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.core.min.js";
 128+ $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.widget.min.js";
 129+ $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.button.min.js";
 130+ $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.position.min.js";
 131+ $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.autocomplete.min.js";
 132+ $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.mouse.min.js";
 133+ $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.sortable.min.js";
 134+ $scripts[] = "$sfgScriptPath/libs/jquery.fancybox.js";
 135+ $scripts[] = "$sfgScriptPath/libs/SF_autogrow.js";
 136+ $scripts[] = "$sfgScriptPath/libs/SF_submit.js";
 137+ $scripts[] = "$sfgScriptPath/libs/SemanticForms.js";
 138+
 139+ global $wgOut;
 140+ foreach ( $scripts as $js ) {
 141+ if ( $parser ) {
 142+ $script = "<script type=\"$wgJsMimeType\" src=\"$js\"></script>\n";
 143+ $parser->getOutput()->addHeadItem( $script );
 144+ } else {
 145+ $wgOut->addScriptFile( $js );
 146+ }
 147+ }
 148+ }
 149+
14150 public static function titleString( $title ) {
15151 $namespace = $title->getNsText();
16152 if ( $namespace != '' ) {

Status & tagging log