use newer spec for html5 metadata
[lhc/web/wiklou.git] / includes / Skin.php
index 4b5cdc0..17da161 100644 (file)
@@ -355,17 +355,18 @@ class Skin extends Linker {
                        # Weird back-compat stuff.
                        $skinName = $skinName['skinname'];
                }
-               global $wgScript, $wgTitle, $wgStylePath, $wgUser;
+               global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
-               global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
+               global $wgOut, $wgArticle;
                global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
                global $wgUseAjax, $wgAjaxWatch;
                global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
                global $wgRestrictionTypes, $wgLivePreview;
                global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
+               global $wgSitename, $wgEnableIframeApiProxy, $wgEnableJS2system;
 
                $ns = $wgTitle->getNamespace();
-               $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
+               $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
                $separatorTransTable = $wgContLang->separatorTransformTable();
                $separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
                $compactSeparatorTransTable = array(
@@ -383,14 +384,17 @@ class Skin extends Linker {
                $vars = array(
                        'skin' => $skinName,
                        'stylepath' => $wgStylePath,
+                       'urlprotocols' => wfUrlProtocols(),
                        'wgArticlePath' => $wgArticlePath,
                        'wgScriptPath' => $wgScriptPath,
+                       'wgScriptExtension' => $wgScriptExtension,
                        'wgScript' => $wgScript,
                        'wgVariantArticlePath' => $wgVariantArticlePath,
                        'wgActionPaths' => (object)$wgActionPaths,
                        'wgServer' => $wgServer,
                        'wgCanonicalNamespace' => $nsname,
-                       'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ),
+                       'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
+                               SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
                        'wgNamespaceNumber' => $wgTitle->getNamespace(),
                        'wgPageName' => $wgTitle->getPrefixedDBKey(),
                        'wgTitle' => $wgTitle->getText(),
@@ -411,15 +415,16 @@ class Skin extends Linker {
                        'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null,
                        'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
                        'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
+                       'wgSiteName' => $wgSitename,
                );
                if ( $wgContLang->hasVariants() ) {
                        $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
                }
 
                //if on upload page output the extension list & js_upload
-               if( SpecialPage::resolveAlias( $wgTitle->getDBkey() ) ==  "Upload" ){
+               if( SpecialPage::resolveAlias( $wgTitle->getDBkey() ) ==  "Upload" ) {
                        global $wgFileExtensions, $wgAjaxUploadInterface;
-                       $vars['wgFileExtensions']        = $wgFileExtensions;
+                       $vars['wgFileExtensions'] = $wgFileExtensions;
                        $vars['wgAjaxUploadInterface'] = $wgAjaxUploadInterface;
                }
 
@@ -440,6 +445,17 @@ class Skin extends Linker {
                        $vars['wgLivepreviewMessageError']   = wfMsg( 'livepreview-error' );
                }
 
+               //add api proxy var and script link if on the special proxy page:
+               if( $wgEnableJS2system &&
+                       $wgTitle->getNamespace() == NS_MEDIAWIKI &&
+                       $wgTitle->getDBKey() == 'ApiProxy' )
+               {
+                       $vars['wgEnableIframeApiProxy'] = $wgEnableIframeApiProxy;                      
+                       //also add the apiProxy Page script if we are on that page
+                       if( $wgEnableIframeApiProxy )
+                               $wgOut->addScriptClass( 'apiProxyPage' );
+               }
+
                if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
                        $msgs = (object)array();
                        foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
@@ -453,42 +469,6 @@ class Skin extends Linker {
 
                return self::makeVariablesScript( $vars );
        }
-       /**
-        * Return a random selection of the scripts we want in the header, 
-        * according to no particular rhyme or reason.  Various other scripts are 
-        * returned from a haphazard assortment of other functions scattered over 
-        * various files.  This entire hackish system needs to be burned to the 
-        * ground and rebuilt.
-        *
-        * @param $out OutputPage object, should be $wgOut
-        *
-        * @return string Raw HTML to output to <head>
-        */
-       function getHeadScripts( OutputPage $out ) {
-               global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion, $wgOut;
-               global $wgUseSiteJs;
-
-               $vars = self::makeGlobalVariablesScript( $this->getSkinName() );
-
-               //moved wikibits to be called earlier on
-               //$out->addScriptFile( "{$wgStylePath}/common/wikibits.js" );
-               if( $wgUseSiteJs ) {
-                       $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
-                       $wgOut->addScriptFile(  self::makeUrl( '-',
-                                       "action=raw$jsCache&gen=js&useskin=" .
-                                       urlencode( $this->getSkinName() )
-                                       )
-                               );
-               }
-               if( $out->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
-                       $userpage = $wgUser->getUserPage();
-                       $userjs =  self::makeUrl(
-                               $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
-                               'action=raw&ctype='.$wgJsMimeType );
-                       $wgOut->addScriptFile( $userjs );
-               }
-               return $vars . "\n" . $out->mScripts;
-       }
 
        /**
         * To make it harder for someone to slip a user a fake
@@ -499,9 +479,8 @@ class Skin extends Linker {
         *
         * @param string $action
         * @return bool
-        * @private
         */
-       function userCanPreview( $action ) {
+       public function userCanPreview( $action ) {
                global $wgRequest, $wgUser;
 
                if( $action != 'submit' )
@@ -527,15 +506,15 @@ class Skin extends Linker {
         * top.  For now Monobook.js will be maintained, but it should be consi-
         * dered deprecated.
         *
-        * @param force_skin  lets you override the skin name
+        * @param $force_skin string If set, overrides the skin name
         *
         * @return string
         */
-       public function generateUserJs( $skinName = null) {
+       public function generateUserJs( $skinName = null ) {
                global $wgStylePath;
 
                wfProfileIn( __METHOD__ );
-               if(!$skinName){
+               if( !$skinName ) {
                        $skinName =     $this->getSkinName();
                }
 
@@ -551,7 +530,7 @@ class Skin extends Linker {
                $s .= "\n\n/* MediaWiki:".ucfirst( $skinName ).".js */\n";
                // avoid inclusion of non defined user JavaScript (with custom skins only)
                // by checking for default message content
-               $msgKey = ucfirst( $skinName ).'.js';
+               $msgKey = ucfirst( $skinName ) . '.js';
                $userJS = wfMsgForContent( $msgKey );
                if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
                        $s .= $userJS;
@@ -673,9 +652,8 @@ END;
                        $action = $wgRequest->getVal( 'action' );
                        # If we're previewing the CSS page, use it
                        if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
-                               $previewCss = $wgRequest->getText( 'wpTextbox1' );
                                // @FIXME: properly escape the cdata!
-                               $this->usercss = "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
+                               $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
                        } else {
                                $out->addStyle( self::makeUrl( $this->userpage . '/' . $this->getSkinName() .'.css',
                                        'action=raw&ctype=text/css' ) );
@@ -897,11 +875,17 @@ END;
        }
 
        function getCategories() {
-               $catlinks=$this->getCategoryLinks();
+               $catlinks = $this->getCategoryLinks();
 
                $classes = 'catlinks';
 
-               if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false ) {
+               // Check what we're showing
+               global $wgOut, $wgUser;
+               $allCats = $wgOut->getCategoryLinks();
+               $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
+                                               $this->mTitle->getNamespace() == NS_CATEGORY;
+
+               if( empty($allCats['normal']) && !( !empty($allCats['hidden']) && $showHidden ) ) {
                        $classes .= ' catlinks-allhidden';
                }
 
@@ -955,13 +939,48 @@ END;
        protected function generateDebugHTML() {
                global $wgShowDebug, $wgOut;
                if ( $wgShowDebug ) {
-                       $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext ) );
-                       return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
-                               $listInternals . "</li></ul>\n";
+                       $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
+                       return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
+                               $listInternals . "</ul>\n";
                }
                return '';
        }
 
+       private function formatDebugHTML( $debugText ) {
+               $lines = explode( "\n", $debugText );
+               $curIdent = 0;
+               $ret = '<li>';
+               foreach( $lines as $line ) {
+                       $m = array();
+                       $display = ltrim( $line );
+                       $ident = strlen( $line ) - strlen( $display );
+                       $diff = $ident - $curIdent;
+
+                       if ( $display == '' )
+                               $display = "\xc2\xa0";
+
+                       if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
+                               $ident = $curIdent;
+                               $diff = 0;
+                               $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
+                       } else {
+                               $display = htmlspecialchars( $display );
+                       }
+
+                       if ( $diff < 0 )
+                               $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
+                       elseif ( $diff == 0 )
+                               $ret .= "</li><li>\n";
+                       else
+                               $ret .= str_repeat( "<ul><li>\n", $diff );
+                       $ret .= $display . "\n";
+
+                       $curIdent = $ident;
+               }
+               $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
+               return $ret;
+       }
+
        /**
         * This gets called shortly before the </body> tag.
         * @return String HTML to be put before </body>