From 584c456a942fc8aec1cbb5c9f84772d049fb34e1 Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Fri, 28 Jul 2006 19:05:27 +0000 Subject: [PATCH] Adding various global JS variables, fixing bug 6030 completely and 6806 mostly. --- includes/Skin.php | 28 +++++++++++++++++++++++++++- includes/SkinTemplate.php | 23 ++++++++++++++++++++++- includes/Xml.php | 3 +++ skins/MonoBook.php | 26 +++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 3 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index a2d38f6fb2..d15fca1e3b 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -262,7 +262,33 @@ class Skin extends Linker { function getHeadScripts() { global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType; - $r = "\n"; + global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang; + global $wgTitle, $wgCanonicalNamespaceNames; + + $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ]; + if ( $nsname === NULL ) $nsname = $wgTitle->getNsText(); + + $r = ' + '; + + $r .= "\n"; if( $wgAllowUserJs && $wgUser->isLoggedIn() ) { $userpage = $wgUser->getUserPage(); $userjs = htmlspecialchars( $this->makeUrl( diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 7263191898..ddbc40b3f7 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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 */ diff --git a/includes/Xml.php b/includes/Xml.php index 8928895870..3026242f7c 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -228,6 +228,9 @@ class Xml { # To avoid closing the element or CDATA section "<" => "\\x3c", ">" => "\\x3e", + + # To avoid any complaints about bad entity refs + "&" => "\\x26", ); return strtr( $string, $pairs ); } diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 1de2d6b12c..0890be9781 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -64,7 +64,31 @@ class MonoBookTemplate extends QuickTemplate { - + + + data['jsvarurl' ]) { ?> -- 2.20.1