Pass the user as an argument to 'isValidPassword' hook callbacks; see docs/hooks...
[lhc/web/wiklou.git] / includes / Skin.php
index a23e7c9..21b60ec 100644 (file)
@@ -297,6 +297,7 @@ class Skin extends Linker {
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
                global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
                global $wgBreakFrames, $wgRequest;
+               global $wgUseAjax, $wgAjaxWatch;
 
                $ns = $wgTitle->getNamespace();
                $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
@@ -334,6 +335,14 @@ class Skin extends Linker {
                        $vars['wgLivepreviewMessageError']   = wfMsg( 'livepreview-error' );
                }
 
+               if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
+                       $msgs = (object)array();
+                       foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
+                               $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
+                       }
+                       $vars['wgAjaxWatch'] = $msgs;
+               }
+
                return self::makeVariablesScript( $vars );
        }
 
@@ -345,11 +354,12 @@ class Skin extends Linker {
                $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
                global $wgUseSiteJs;
                if ($wgUseSiteJs) {
-                       if ($wgUser->isLoggedIn()) {
-                               $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&smaxage=0&gen=js'))."\"><!-- site js --></script>\n";
-                       } else {
-                               $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&gen=js'))."\"><!-- site js --></script>\n";
-                       }
+                       $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
+                       $r .= "<script type=\"$wgJsMimeType\" src=\"".
+                               htmlspecialchars(self::makeUrl('-',
+                                       "action=raw$jsCache&gen=js&useskin=" .
+                                       urlencode( $this->getSkinName() ) ) ) .
+                               "\"><!-- site js --></script>\n";
                }
                if( $allowUserJs && $wgUser->isLoggedIn() ) {
                        $userpage = $wgUser->getUserPage();
@@ -403,36 +413,28 @@ class Skin extends Linker {
        }
 
        /**
-        * This returns MediaWiki:Common.js.  For some bizarre reason, it does
-        * *not* return any custom user JS from user subpages.  Huh?
+        * This returns MediaWiki:Common.js, and derived classes may add other JS.
+        * Despite its name, it does *not* return any custom user JS from user
+        * subpages.  The returned script is sitewide and publicly cacheable and
+        * therefore must not include anything that varies according to user,
+        * interface language, etc. (although it may vary by skin).  See
+        * makeGlobalVariablesScript for things that can vary per page view and are
+        * not cacheable.
         *
-        * @return string
+        * @return string Raw JavaScript to be returned
         */
-       function getUserJs() {
+       public function getUserJs() {
                wfProfileIn( __METHOD__ );
 
                global $wgStylePath;
                $s = "/* generated javascript */\n";
-               $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
+               $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n";
+               $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
                $s .= "\n\n/* MediaWiki:Common.js */\n";
                $commonJs = wfMsgForContent('common.js');
                if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
                        $s .= $commonJs;
                }
-
-               global $wgUseAjax, $wgAjaxWatch;
-               if($wgUseAjax && $wgAjaxWatch) {
-                       $s .= "
-
-/* AJAX (un)watch (see /skins/common/ajaxwatch.js) */
-var wgAjaxWatch = {
-       watchMsg: '".       str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watch', array() ) )."',
-       unwatchMsg: '".     str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatch', array() ) )."',
-       watchingMsg: '".    str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watching', array() ) )."',
-       unwatchingMsg: '".  str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatching', array() ) )."'
-};";
-               }
-
                wfProfileOut( __METHOD__ );
                return $s;
        }
@@ -1650,5 +1652,5 @@ END;
                wfProfileOut( $fname );
                return $bar;
        }
-}
-
+       
+}
\ No newline at end of file