r15871 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15870‎ | r15871 | r15872 >
Date:19:05, 28 July 2006
Author:daniel
Status:old
Tags:
Comment:
Adding various global JS variables, fixing bug 6030 completely and 6806 mostly.
Modified paths:
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/MonoBook.php
@@ -64,7 +64,31 @@
6565 <!--[if IE 7]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE70Fixes.css?1";</style><![endif]-->
6666 <!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js"></script>
6767 <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
68 - <script type="<?php $this->text('jsmimetype') ?>">var skin = '<?php $this->text('skinname')?>';var stylepath = '<?php $this->text('stylepath')?>';</script>
 68+
 69+ <script type="<?php $this->text('jsmimetype') ?>">
 70+ var skin = "<?php $this->jstext('skinname')?>";
 71+ var stylepath = "<?php $this->jstext('stylepath')?>";
 72+
 73+ var wgArticlePath = "<?php $this->jstext( 'articlepath' ); ?>";
 74+ var wgScriptPath = "<?php $this->jstext( 'scriptpath' ); ?>";
 75+ var wgServer = "<?php $this->jstext( 'serverurl' ); ?>";
 76+
 77+ var wgCanonicalNamespace = "<?php $this->jstext( 'nscanonical' ); ?>";
 78+ var wgPageName = "<?php $this->jstext( 'titleprefixeddbkey' ); ?>";
 79+ var wgTitle = "<?php $this->jstext( 'titletext' ); ?>";
 80+ var wgArticleId = <?php (int) $this->jstext( 'articleid' ); ?>;
 81+
 82+<?php if($this->data['username']) { ?>
 83+ var wgUserName = "<?php $this->jstext( 'username' ); ?>";
 84+ var wgUserLanguage = "<?php $this->jstext( 'userlang' ); ?>";
 85+<?php } else { ?>
 86+ var wgUserName = null;
 87+ var wgUserLanguage = "<?php $this->jstext( 'userlang' ); ?>";
 88+<?php } ?>
 89+ var wgContentLanguage = "<?php $this->jstext( 'lang' ); ?>";
 90+ var wgSkinClass = "<?php $this->jstext( 'skinclass' ); ?>";
 91+ </script>
 92+
6993 <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?1"><!-- wikibits js --></script>
7094 <?php if($this->data['jsvarurl' ]) { ?>
7195 <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('jsvarurl' ) ?>"><!-- site js --></script>
Index: trunk/phase3/includes/Skin.php
@@ -262,7 +262,33 @@
263263
264264 function getHeadScripts() {
265265 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
266 - $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
 266+ global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
 267+ global $wgTitle, $wgCanonicalNamespaceNames;
 268+
 269+ $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
 270+ if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
 271+
 272+ $r = '<script type= "'.$wgJsMimeType.'">
 273+ var skin = "' . Xml::escapeJsString( $this->getSkinName() ) . '";
 274+ var stylepath = "' . Xml::escapeJsString( $wgStylePath ) . '";
 275+
 276+ var wgArticlePath = "' . Xml::escapeJsString( $wgArticlePath ) . '";
 277+ var wgScriptPath = "' . Xml::escapeJsString( $wgScriptPath ) . '";
 278+ var wgServer = "' . Xml::escapeJsString( $wgServer ) . '";
 279+
 280+ var wgCanonicalNamespace = "' . Xml::escapeJsString( $nsname ) . '";
 281+ var wgPageName = "' . Xml::escapeJsString( $wgTitle->getPrefixedDBKey() ) . '";
 282+ var wgTitle = "' . Xml::escapeJsString( $wgTitle->getText() ) . '";
 283+ var wgArticleId = ' . (int)$wgTitle->getArticleId() . ';
 284+
 285+ var wgUserName = ' . ( $wgUser->isAnon() ? 'null' : ( '"' . Xml::escapeJsString( $wgUser->getName() ) . '"' ) ) . ';
 286+ var wgUserLanguage = "' . Xml::escapeJsString( $wgLang->getCode() ) . '";
 287+ var wgContentLanguage = "' . Xml::escapeJsString( $wgContLang->getCode() ) . '";
 288+ var wgSkinClass = "' . Xml::escapeJsString( get_class( $this ) ) . '";
 289+ </script>
 290+ ';
 291+
 292+ $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
267293 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
268294 $userpage = $wgUser->getUserPage();
269295 $userjs = htmlspecialchars( $this->makeUrl(
Index: trunk/phase3/includes/Xml.php
@@ -228,6 +228,9 @@
229229 # To avoid closing the element or CDATA section
230230 "<" => "\\x3c",
231231 ">" => "\\x3e",
 232+
 233+ # To avoid any complaints about bad entity refs
 234+ "&" => "\\x26",
232235 );
233236 return strtr( $string, $pairs );
234237 }
Index: trunk/phase3/includes/SkinTemplate.php
@@ -141,6 +141,7 @@
142142 global $wgPageShowWatchingUsers;
143143 global $wgUseTrackbacks;
144144 global $wgDBname;
 145+ global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
145146
146147 $fname = 'SkinTemplate::outputPage';
147148 wfProfileIn( $fname );
@@ -193,6 +194,14 @@
194195 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
195196 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
196197
 198+ $nsname = @$wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ];
 199+ if ( $nsname === NULL ) $nsname = $this->mTitle->getNsText();
 200+
 201+ $tpl->set( 'nscanonical', $nsname );
 202+ $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
 203+ $tpl->set( 'titletext', $this->mTitle->getText() );
 204+ $tpl->set( 'articleid', $this->mTitle->getArticleId() );
 205+
197206 $tpl->setRef( "thispage", $this->thispage );
198207 $subpagestr = $this->subPageSubtitle();
199208 $tpl->set(
@@ -230,6 +239,7 @@
231240 $tpl->set('headscripts', $out->getScript() );
232241 $tpl->setRef( 'wgScript', $wgScript );
233242 $tpl->setRef( 'skinname', $this->skinname );
 243+ $tpl->set( 'skinclass', get_class( $this ) );
234244 $tpl->setRef( 'stylename', $this->stylename );
235245 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
236246 $tpl->setRef( 'loggedin', $this->loggedin );
@@ -245,15 +255,19 @@
246256 $tpl->set( 'searchaction', $this->escapeSearchLink() );
247257 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
248258 $tpl->setRef( 'stylepath', $wgStylePath );
 259+ $tpl->setRef( 'articlepath', $wgArticlePath );
 260+ $tpl->setRef( 'scriptpath', $wgScriptPath );
 261+ $tpl->setRef( 'serverurl', $wgServer );
249262 $tpl->setRef( 'logopath', $wgLogo );
250263 $tpl->setRef( "lang", $wgContLanguageCode );
251264 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
252265 $tpl->set( 'rtl', $wgContLang->isRTL() );
253266 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
254267 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
255 - $tpl->setRef( 'username', $this->username );
 268+ $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
256269 $tpl->setRef( 'userpage', $this->userpage);
257270 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
 271+ $tpl->set( 'userlang', $wgLang->getCode() );
258272 $tpl->set( 'pagecss', $this->setupPageCss() );
259273 $tpl->setRef( 'usercss', $this->usercss);
260274 $tpl->setRef( 'userjs', $this->userjs);
@@ -1060,6 +1074,13 @@
10611075 /**
10621076 * @private
10631077 */
 1078+ function jstext( $str ) {
 1079+ echo Xml::escapeJsString( $this->data[$str] );
 1080+ }
 1081+
 1082+ /**
 1083+ * @private
 1084+ */
10641085 function html( $str ) {
10651086 echo $this->data[$str];
10661087 }