From ecd0b827a55d2f8a61eb68e5341f44773cadf130 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 17 Nov 2006 02:05:34 +0000 Subject: [PATCH] (bug 4178) MediaWiki:Common.js will now be included for all users if $wgUseSiteJs is enabled, in addition to (if applicable) MediaWiki:Monobook.js and user JS subpages. No extra page loads, brion! --- RELEASE-NOTES | 3 +++ includes/Skin.php | 30 ++++++++++++++++++++++++++++-- includes/SkinTemplate.php | 19 +++++++++++++------ languages/messages/MessagesEn.php | 3 +++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f7bc31e237..e841e8fd14 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -192,6 +192,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN right on Apache too! * Replace 'old-revision-navigation' message with 'revision-info' and 'revision-nav' messages, wrapped in divs with appropriate id's. +* (bug 4178) MediaWiki:Common.js will now be included for all users if + $wgUseSiteJs is enabled, in addition to (if applicable) MediaWiki:Monobook.js + and user JS subpages. == Languages updated == diff --git a/includes/Skin.php b/includes/Skin.php index 0f9ca2ca67..8d528678ac 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -324,6 +324,14 @@ class Skin extends Linker { $r = self::makeGlobalVariablesScript( $vars ); $r .= "\n"; + global $wgUseSiteJs; + if ($wgUseSiteJs) { + if ($wgUser->isLoggedIn()) { + $r .= "\n"; + } else { + $r .= "\n"; + } + } if( $wgAllowUserJs && $wgUser->isLoggedIn() ) { $userpage = $wgUser->getUserPage(); $userjs = htmlspecialchars( self::makeUrl( @@ -376,9 +384,27 @@ class Skin extends Linker { } /** - * placeholder, returns generated js in monobook + * This returns MediaWiki:Common.js. For some bizarre reason, it does + * *not* return any custom user JS from user subpages. Huh? + * + * @return string */ - function getUserJs() { return; } + function getUserJs() { + $fname = 'Skin::getUserJs'; + wfProfileIn( $fname ); + + global $wgStylePath; + $s = "/* generated javascript */\n"; + $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';"; + $s .= "\n\n/* MediaWiki:Common.js */\n"; + $commonJs = wfMsgForContent('Common.js'); + if ( !wfEmptyMsg ( 'Common.js', $commonJs ) ) { + $s .= $commonJs; + } + + wfProfileOut( $fname ); + return $s; + } /** * Return html code that include User stylesheets diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index a4238cce74..95bd8763c4 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1013,16 +1013,23 @@ class SkinTemplate extends Skin { } /** - * @public + * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate- + * nated together. For some bizarre reason, it does *not* return any + * custom user JS from subpages. Huh? + * + * There's absolutely no reason to have separate Monobook/Common JSes. + * Any JS that cares can just check the skin variable generated at the + * top. For now Monobook.js will be maintained, but it should be consi- + * dered deprecated. + * + * @return string */ - function getUserJs() { + public function getUserJs() { $fname = 'SkinTemplate::getUserJs'; wfProfileIn( $fname ); - global $wgStylePath; - $s = '/* generated javascript */'; - $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';"; - $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n"; + $s = parent::getUserJs(); + $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js (deprecated; migrate to Common.js!) */\n"; // avoid inclusion of non defined user JavaScript (with custom skins only) // by checking for default message content diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index c16609c3ff..5814df15f5 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2127,6 +2127,9 @@ ta[\'ca-nstab-template\'] = new Array(\'c\',\'View the template\'); ta[\'ca-nstab-help\'] = new Array(\'c\',\'View the help page\'); ta[\'ca-nstab-category\'] = new Array(\'c\',\'View the category page\');', +# Common.js: contains nothing but a placeholder comment +'Common.js' => '/* Any JavaScript here will be loaded for all users on every page load. */', + # image deletion 'deletedrevision' => 'Deleted old revision $1.', -- 2.20.1