Adding various global JS variables, fixing bug 6030 completely and 6806 mostly.
authorDaniel Kinzler <daniel@users.mediawiki.org>
Fri, 28 Jul 2006 19:05:27 +0000 (19:05 +0000)
committerDaniel Kinzler <daniel@users.mediawiki.org>
Fri, 28 Jul 2006 19:05:27 +0000 (19:05 +0000)
includes/Skin.php
includes/SkinTemplate.php
includes/Xml.php
skins/MonoBook.php

index a2d38f6..d15fca1 100644 (file)
@@ -262,7 +262,33 @@ class Skin extends Linker {
 
        function getHeadScripts() {
                global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
-               $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
+               global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
+               global $wgTitle, $wgCanonicalNamespaceNames;
+
+               $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>
+               ';
+
+               $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
                if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
                        $userpage = $wgUser->getUserPage();
                        $userjs = htmlspecialchars( $this->makeUrl(
index 7263191..ddbc40b 100644 (file)
@@ -141,6 +141,7 @@ class SkinTemplate extends Skin {
                global $wgPageShowWatchingUsers;
                global $wgUseTrackbacks;
                global $wgDBname;
+               global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
 
                $fname = 'SkinTemplate::outputPage';
                wfProfileIn( $fname );
@@ -193,6 +194,14 @@ class SkinTemplate extends Skin {
                $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
                $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
 
+               $nsname = @$wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ];
+               if ( $nsname === NULL ) $nsname = $this->mTitle->getNsText();
+               
+               $tpl->set( 'nscanonical', $nsname );
+               $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
+               $tpl->set( 'titletext', $this->mTitle->getText() );
+               $tpl->set( 'articleid', $this->mTitle->getArticleId() );
+                               
                $tpl->setRef( "thispage", $this->thispage );
                $subpagestr = $this->subPageSubtitle();
                $tpl->set(
@@ -230,6 +239,7 @@ class SkinTemplate extends Skin {
                $tpl->set('headscripts', $out->getScript() );
                $tpl->setRef( 'wgScript', $wgScript );
                $tpl->setRef( 'skinname', $this->skinname );
+               $tpl->set( 'skinclass', get_class( $this ) );
                $tpl->setRef( 'stylename', $this->stylename );
                $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
                $tpl->setRef( 'loggedin', $this->loggedin );
@@ -245,15 +255,19 @@ class SkinTemplate extends Skin {
                $tpl->set( 'searchaction', $this->escapeSearchLink() );
                $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
                $tpl->setRef( 'stylepath', $wgStylePath );
+               $tpl->setRef( 'articlepath', $wgArticlePath );
+               $tpl->setRef( 'scriptpath', $wgScriptPath );
+               $tpl->setRef( 'serverurl', $wgServer );
                $tpl->setRef( 'logopath', $wgLogo );
                $tpl->setRef( "lang", $wgContLanguageCode );
                $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
                $tpl->set( 'rtl', $wgContLang->isRTL() );
                $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
                $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
-               $tpl->setRef( 'username', $this->username );
+               $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
                $tpl->setRef( 'userpage', $this->userpage);
                $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
+               $tpl->set( 'userlang', $wgLang->getCode() );
                $tpl->set( 'pagecss', $this->setupPageCss() );
                $tpl->setRef( 'usercss', $this->usercss);
                $tpl->setRef( 'userjs', $this->userjs);
@@ -1057,6 +1071,13 @@ class QuickTemplate {
                echo htmlspecialchars( $this->data[$str] );
        }
 
+       /**
+        * @private
+        */
+       function jstext( $str ) {
+               echo Xml::escapeJsString( $this->data[$str] );
+       }
+
        /**
         * @private
         */
index 8928895..3026242 100644 (file)
@@ -228,6 +228,9 @@ class Xml {
                        # To avoid closing the element or CDATA section\r
                        "<" => "\\x3c",\r
                        ">" => "\\x3e",\r
+\r
+                       # To avoid any complaints about bad entity refs                        \r
+                       "&" => "\\x26",\r
                );\r
                return strtr( $string, $pairs );\r
        }\r
index 1de2d6b..0890be9 100644 (file)
@@ -64,7 +64,31 @@ class MonoBookTemplate extends QuickTemplate {
                <!--[if IE 7]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE70Fixes.css?1";</style><![endif]-->
                <!--[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->text('skinname')?>';var stylepath = '<?php $this->text('stylepath')?>';</script>
+               
+               <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>
+                
                <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?1"><!-- wikibits js --></script>
 <?php  if($this->data['jsvarurl'  ]) { ?>
                <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('jsvarurl'  ) ?>"><!-- site js --></script>