Factored code for global JS variables into a function
authorDaniel Kinzler <daniel@users.mediawiki.org>
Fri, 28 Jul 2006 22:52:46 +0000 (22:52 +0000)
committerDaniel Kinzler <daniel@users.mediawiki.org>
Fri, 28 Jul 2006 22:52:46 +0000 (22:52 +0000)
includes/Skin.php
skins/MonoBook.php

index d15fca1..d8dbc16 100644 (file)
@@ -260,6 +260,29 @@ class Skin extends Linker {
                $out->out( "\n</body></html>" );
        }
 
+       /*static*/ function makeGlobalVariablesScript( $data ) {
+               $r = '<script type= "' . $data['jsmimetype'] . '">
+                       var skin = "' . Xml::escapeJsString( $data['skinname'] ) . '";
+                       var stylepath = "' . Xml::escapeJsString( $data['stylepath'] ) . '";
+
+                       var wgArticlePath = "' . Xml::escapeJsString( $data['articlepath'] ) . '";
+                       var wgScriptPath = "' . Xml::escapeJsString( $data['scriptpath'] ) . '";
+                       var wgServer = "' . Xml::escapeJsString( $data['serverurl'] ) . '";
+                        
+                       var wgCanonicalNamespace = "' . Xml::escapeJsString( $data['nscanonical'] ) . '";
+                       var wgPageName = "' . Xml::escapeJsString( $data['titleprefixeddbkey'] ) . '";
+                       var wgTitle = "' . Xml::escapeJsString( $data['titletext'] ) . '";
+                       var wgArticleId = ' . (int)$data['articleid'] . ';
+                        
+                       var wgUserName = ' . ( $data['username'] == NULL ? 'null' : ( '"' . Xml::escapeJsString( $data['username'] ) . '"' ) ) . ';
+                       var wgUserLanguage = "' . Xml::escapeJsString( $data['userlang'] ) . '";
+                       var wgContentLanguage = "' . Xml::escapeJsString( $data['lang'] ) . '";
+               </script>
+               ';
+               
+               return $r;
+       }
+
        function getHeadScripts() {
                global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
@@ -268,26 +291,24 @@ class Skin extends Linker {
                $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
                if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
 
-               $r = '<script type= "'.$wgJsMimeType.'">
-                       var skin = "' . Xml::escapeJsString( $this->getSkinName() ) . '";
-                       var stylepath = "' . Xml::escapeJsString( $wgStylePath ) . '";
-
-                       var wgArticlePath = "' . Xml::escapeJsString( $wgArticlePath ) . '";
-                       var wgScriptPath = "' . Xml::escapeJsString( $wgScriptPath ) . '";
-                       var wgServer = "' . Xml::escapeJsString( $wgServer ) . '";
-                        
-                       var wgCanonicalNamespace = "' . Xml::escapeJsString( $nsname ) . '";
-                       var wgPageName = "' . Xml::escapeJsString( $wgTitle->getPrefixedDBKey() ) . '";
-                       var wgTitle = "' . Xml::escapeJsString( $wgTitle->getText() ) . '";
-                       var wgArticleId = ' . (int)$wgTitle->getArticleId() . ';
-                        
-                       var wgUserName = ' . ( $wgUser->isAnon() ? 'null' : ( '"' . Xml::escapeJsString( $wgUser->getName() ) . '"' ) ) . ';
-                       var wgUserLanguage = "' . Xml::escapeJsString( $wgLang->getCode() ) . '";
-                       var wgContentLanguage = "' . Xml::escapeJsString( $wgContLang->getCode() ) . '";
-                       var wgSkinClass = "' . Xml::escapeJsString( get_class( $this ) ) . '";
-               </script>
-               ';
+               $vars = array( 
+                       'jsmimetype' => $wgJsMimeType,
+                       'skinname' => $this->getSkinName(),
+                       'stylepath' => $wgStylePath,
+                       'articlepath' => $wgArticlePath,
+                       'scriptpath' => $wgScriptPath,
+                       'serverurl' => $wgServer,
+                       'nscanonical' => $nsname,
+                       'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
+                       'titletext' => $wgTitle->getText(),
+                       'articleid' => $wgTitle->getArticleId(),
+                       'username' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
+                       'userlang' => $wgLang->getCode(),
+                       'lang' => $wgContLang->getCode(),
+               );
 
+               $r = Skin::makeGlobalVariablesScript( $vars );
+                
                $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
                if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
                        $userpage = $wgUser->getUserPage();
index 0890be9..9532eab 100644 (file)
@@ -65,29 +65,7 @@ class MonoBookTemplate extends QuickTemplate {
                <!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js"></script>
                <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
                
-               <script type="<?php $this->text('jsmimetype') ?>">
-                       var skin = "<?php $this->jstext('skinname')?>";
-                       var stylepath = "<?php $this->jstext('stylepath')?>";
-
-                       var wgArticlePath = "<?php $this->jstext( 'articlepath' ); ?>";
-                       var wgScriptPath = "<?php $this->jstext( 'scriptpath' ); ?>";
-                       var wgServer = "<?php $this->jstext( 'serverurl' ); ?>";
-                        
-                       var wgCanonicalNamespace = "<?php $this->jstext( 'nscanonical' ); ?>";
-                       var wgPageName = "<?php $this->jstext( 'titleprefixeddbkey' ); ?>";
-                       var wgTitle = "<?php $this->jstext( 'titletext' ); ?>";
-                       var wgArticleId = <?php (int) $this->jstext( 'articleid' ); ?>;
-                        
-<?php  if($this->data['username']) { ?>
-                       var wgUserName = "<?php $this->jstext( 'username' ); ?>";
-                       var wgUserLanguage = "<?php $this->jstext( 'userlang' ); ?>";
-<?php  } else { ?>
-                       var wgUserName = null;
-                       var wgUserLanguage = "<?php $this->jstext( 'userlang' ); ?>";
-<?php  } ?>
-                       var wgContentLanguage = "<?php $this->jstext( 'lang' ); ?>";
-                       var wgSkinClass = "<?php $this->jstext( 'skinclass' ); ?>";
-               </script>
+               <?php print Skin::makeGlobalVariablesScript( $this->data ); ?>
                 
                <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?1"><!-- wikibits js --></script>
 <?php  if($this->data['jsvarurl'  ]) { ?>