Fix broken contribution listings with postgres by adding a new variable
[lhc/web/wiklou.git] / includes / Skin.php
index 8816ac0..43c7695 100644 (file)
@@ -139,7 +139,7 @@ class Skin extends Linker {
 
        /** @return string path to the skin stylesheet */
        function getStylesheet() {
-               return 'common/wikistandard.css?1';
+               return 'common/wikistandard.css';
        }
 
        /** @return string skin name */
@@ -157,7 +157,7 @@ class Skin extends Linker {
        }
 
        function initPage( &$out ) {
-               global $wgFavicon, $wgScriptPath;
+               global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
 
                $fname = 'Skin::initPage';
                wfProfileIn( $fname );
@@ -170,7 +170,8 @@ class Skin extends Linker {
                $out->addLink( array( 
                        'rel' => 'search', 
                        'type' => 'application/opensearchdescription+xml',
-                       'href' => "$wgScriptPath/opensearch_desc.php"
+                       'href' => "$wgScriptPath/opensearch_desc.php",
+                       'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})",
                ));
 
                $this->addMetadataLinks($out);
@@ -295,7 +296,7 @@ class Skin extends Linker {
        }
 
        function getHeadScripts() {
-               global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
+               global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion;
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
                global $wgTitle, $wgCanonicalNamespaceNames, $wgOut;
 
@@ -322,7 +323,15 @@ class Skin extends Linker {
 
                $r = self::makeGlobalVariablesScript( $vars );
 
-               $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
+               $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";
+                       }
+               }
                if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
                        $userpage = $wgUser->getUserPage();
                        $userjs = htmlspecialchars( self::makeUrl(
@@ -359,11 +368,12 @@ class Skin extends Linker {
 
        # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
        function getUserStylesheet() {
-               global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
+               global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
                $sheet = $this->getStylesheet();
                $action = $wgRequest->getText('action');
-               $s = "@import \"$wgStylePath/$sheet\";\n";
-               if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
+               $s = "@import \"$wgStylePath/common/common.css?$wgStyleVersion\";\n";
+               $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
+               if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
 
                $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
                $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
@@ -374,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
@@ -476,7 +504,8 @@ END;
                        }
                        $a['onload'] .= 'setupRightClickEdit()';
                }
-               $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr");
+               $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
+               ' '.Sanitizer::escapeId( 'page-'.$wgTitle->getPrefixedText() );
                return $a;
        }
 
@@ -575,9 +604,8 @@ END;
                $pop = '</span>';
                $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
 
-               $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks ));
-               $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
-                       $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
+               $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
+               $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
                        . ': ' . $t;
 
                # optional 'dmoz-like' category browser. Will be shown under the list
@@ -833,7 +861,7 @@ END;
                        } else { $q = "returnto={$rt}"; }
 
                        $s .= "\n<br />" . $this->makeKnownLinkObj(
-                               Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
+                               SpecialPage::getTitleFor( 'Userlogin' ),
                                wfMsg( 'login' ), $q );
                } else {
                        $n = $wgUser->getName();
@@ -845,7 +873,7 @@ END;
 
                        $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
                          $n ) . "{$tl}<br />" .
-                         $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
+                         $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
                          "returnto={$rt}" ) . ' | ' .
                          $this->specialLink( 'preferences' );
                }
@@ -856,7 +884,7 @@ END;
        }
 
        function getSearchLink() {
-               $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
+               $searchPage =& SpecialPage::getTitleFor( 'Search' );
                return $searchPage->getLocalURL();
        }
 
@@ -891,7 +919,38 @@ END;
                }
                # Many people don't like this dropdown box
                #$s .= $sep . $this->specialPagesList();
+               
+               $s .= $this->variantLinks();
+               
+               $s .= $this->extensionTabLinks();
 
+               return $s;
+       }
+       
+       /**
+        * Compatibility for extensions adding functionality through tabs.
+        * Eventually these old skins should be replaced with SkinTemplate-based
+        * versions, sigh...
+        * @return string
+        */
+       function extensionTabLinks() {
+               $tabs = array();
+               $s = '';
+               wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
+               foreach( $tabs as $tab ) {
+                       $s .= ' | ' . Xml::element( 'a',
+                               array( 'href' => $tab['href'] ),
+                               $tab['text'] );
+               }
+               return $s;
+       }
+       
+       /**
+        * Language/charset variant links for classic-style skins
+        * @return string
+        */
+       function variantLinks() {
+               $s = '';
                /* show links to different language variants */
                global $wgDisableLangConversion, $wgContLang, $wgTitle;
                $variants = $wgContLang->getVariants();
@@ -900,10 +959,9 @@ END;
                                $varname = $wgContLang->getVariantname( $code );
                                if( $varname == 'disable' )
                                        continue;
-                               $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
+                               $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
                        }
                }
-
                return $s;
        }
 
@@ -976,7 +1034,7 @@ END;
 
                if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
                        $dbr =& wfGetDB( DB_SLAVE );
-                       extract( $dbr->tableNames( 'watchlist' ) );
+                       $watchlist = $dbr->tableName( 'watchlist' );
                        $sql = "SELECT COUNT(*) AS n FROM $watchlist
                                WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
                                "' AND  wl_namespace=" . $wgTitle->getNamespace() ;
@@ -1087,7 +1145,6 @@ END;
         */
        function specialPagesList() {
                global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
-               require_once('SpecialPage.php');
                $a = array();
                $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
                foreach ( $pages as $name => $page ) {
@@ -1241,7 +1298,7 @@ END;
                global $wgTitle;
 
                if ( $wgTitle->userCanMove() ) {
-                       return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
+                       return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
                          wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
                } else {
                        // no message if page is protected - would be redundant
@@ -1259,15 +1316,17 @@ END;
        function whatLinksHere() {
                global $wgTitle;
 
-               return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
-                 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
+               return $this->makeKnownLinkObj( 
+                       SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ), 
+                       wfMsg( 'whatlinkshere' ) );
        }
 
        function userContribsLink() {
                global $wgTitle;
 
-               return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
-                 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
+               return $this->makeKnownLinkObj( 
+                       SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
+                       wfMsg( 'contributions' ) );
        }
 
        function showEmailUser( $id ) {
@@ -1284,8 +1343,9 @@ END;
        function emailUserLink() {
                global $wgTitle;
 
-               return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
-                 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
+               return $this->makeKnownLinkObj( 
+                       SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
+                       wfMsg( 'emailuser' ) );
        }
 
        function watchPageLinksLink() {
@@ -1294,9 +1354,9 @@ END;
                if ( ! $wgOut->isArticleRelated() ) {
                        return '(' . wfMsg( 'notanarticle' ) . ')';
                } else {
-                       return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
-                         'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
-                         'target=' . $wgTitle->getPrefixedURL() );
+                       return $this->makeKnownLinkObj( 
+                               SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ), 
+                               wfMsg( 'recentchangeslinked' ) );
                }
        }
 
@@ -1438,7 +1498,7 @@ END;
 
        /* these are used extensively in SkinTemplate, but also some other places */
        static function makeSpecialUrl( $name, $urlaction = '' ) {
-               $title = Title::makeTitle( NS_SPECIAL, $name );
+               $title = SpecialPage::getTitleFor( $name );
                return $title->getLocalURL( $urlaction );
        }
 
@@ -1510,14 +1570,14 @@ END;
         * @private
         */
        function buildSidebar() {
-               global $wgDBname, $parserMemc, $wgEnableSidebarCache;
+               global $parserMemc, $wgEnableSidebarCache;
                global $wgLang, $wgContLang;
 
                $fname = 'SkinTemplate::buildSidebar';
 
                wfProfileIn( $fname );
 
-               $key = "{$wgDBname}:sidebar";
+               $key = wfMemcKey( 'sidebar' );
                $cacheSidebar = $wgEnableSidebarCache &&
                        ($wgLang->getCode() == $wgContLang->getCode());
                
@@ -1547,7 +1607,19 @@ END;
                                                $text = $line[1];
                                        if (wfEmptyMsg($line[0], $link))
                                                $link = $line[0];
-                                       $href = self::makeInternalOrExternalUrl( $link );
+
+                                       if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
+                                               $href = $link;
+                                       } else {
+                                               $title = Title::newFromText( $link );
+                                               if ( $title ) {
+                                                       $title = $title->fixSpecialName();
+                                                       $href = $title->getLocalURL();
+                                               } else {
+                                                       $href = 'INVALID-TITLE';
+                                               }
+                                       }
+
                                        $bar[$heading][] = array(
                                                'text' => $text,
                                                'href' => $href,