Self revert, this isn't really implemented right.
[lhc/web/wiklou.git] / includes / Skin.php
index a5b7fb9..3f8c6b9 100644 (file)
@@ -1,30 +1,29 @@
 <?php
-if ( ! defined( 'MEDIAWIKI' ) )
-       die( 1 );
-
 /**
- *
- * @package MediaWiki
- * @subpackage Skins
+ * @defgroup Skins Skins
  */
 
-# See skin.txt
+if ( ! defined( 'MEDIAWIKI' ) )
+       die( 1 );
 
 /**
  * The main skin class that provide methods and properties for all other skins.
  * This base class is also the "Standard" skin.
- * @package MediaWiki
+ *
+ * See docs/skin.txt for more information.
+ *
+ * @ingroup Skins
  */
 class Skin extends Linker {
        /**#@+
         * @private
         */
-       var $lastdate, $lastline;
-       var $rc_cache ; # Cache for Enhanced Recent Changes
-       var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
-       var $rcMoveIndex;
        var $mWatchLinkNum = 0; // Appended to end of watch link id's
+       // How many search boxes have we made?  Avoid duplicate id's.
+       protected $searchboxes = '';
        /**#@-*/
+       protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
+       protected $skinname = 'standard' ;
 
        /** Constructor, call parent constructor */
        function Skin() { parent::__construct(); }
@@ -34,7 +33,7 @@ class Skin extends Linker {
         * @return array of strings
         * @static
         */
-       static function &getSkinNames() {
+       static function getSkinNames() {
                global $wgValidSkinNames;
                static $skinsInitialised = false;
                if ( !$skinsInitialised ) {
@@ -98,8 +97,7 @@ class Skin extends Linker {
                if( isset( $skinNames[$key] ) ) {
                        return $key;
                } else {
-                       // The old built-in skin
-                       return 'standard';
+                       return 'monobook';
                }
        }
 
@@ -111,28 +109,30 @@ class Skin extends Linker {
         */
        static function &newFromKey( $key ) {
                global $wgStyleDirectory;
-               
+
                $key = Skin::normalizeKey( $key );
 
                $skinNames = Skin::getSkinNames();
                $skinName = $skinNames[$key];
+               $className = 'Skin'.ucfirst($key);
 
                # Grab the skin class and initialise it.
-               // Preload base classes to work around APC/PHP5 bug
-               $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
-               if( file_exists( $deps ) ) include_once( $deps );
-               require_once( "{$wgStyleDirectory}/{$skinName}.php" );
-
-               # Check if we got if not failback to default skin
-               $className = 'Skin'.$skinName;
-               if( !class_exists( $className ) ) {
-                       # DO NOT die if the class isn't found. This breaks maintenance
-                       # scripts and can cause a user account to be unrecoverable
-                       # except by SQL manipulation if a previously valid skin name
-                       # is no longer valid.
-                       wfDebug( "Skin class does not exist: $className\n" );
-                       $className = 'SkinStandard';
-                       require_once( "{$wgStyleDirectory}/Standard.php" );
+               if ( !class_exists( $className ) ) {
+                       // Preload base classes to work around APC/PHP5 bug
+                       $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
+                       if( file_exists( $deps ) ) include_once( $deps );
+                       require_once( "{$wgStyleDirectory}/{$skinName}.php" );
+
+                       # Check if we got if not failback to default skin
+                       if( !class_exists( $className ) ) {
+                               # DO NOT die if the class isn't found. This breaks maintenance
+                               # scripts and can cause a user account to be unrecoverable
+                               # except by SQL manipulation if a previously valid skin name
+                               # is no longer valid.
+                               wfDebug( "Skin class does not exist: $className\n" );
+                               $className = 'SkinMonobook';
+                               require_once( "{$wgStyleDirectory}/MonoBook.php" );
+                       }
                }
                $skin = new $className;
                return $skin;
@@ -144,8 +144,8 @@ class Skin extends Linker {
        }
 
        /** @return string skin name */
-       function getSkinName() {
-               return 'standard';
+       public function getSkinName() {
+               return $this->skinname;
        }
 
        function qbSetting() {
@@ -157,30 +157,33 @@ class Skin extends Linker {
        }
 
        function initPage( &$out ) {
-               global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
+               global $wgFavicon, $wgAppleTouchIcon, $wgScriptPath, $wgScriptExtension;
 
-               $fname = 'Skin::initPage';
-               wfProfileIn( $fname );
+               wfProfileIn( __METHOD__ );
 
                if( false !== $wgFavicon ) {
                        $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
                }
 
+               if( false !== $wgAppleTouchIcon ) {
+                       $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
+               }
+
                # OpenSearch description link
-               $out->addLink( array( 
-                       'rel' => 'search', 
+               $out->addLink( array(
+                       'rel' => 'search',
                        'type' => 'application/opensearchdescription+xml',
-                       'href' => "$wgScriptPath/opensearch_desc.php",
-                       'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})",
+                       'href' => "$wgScriptPath/opensearch_desc{$wgScriptExtension}",
+                       'title' => wfMsgForContent( 'opensearch-desc' ),
                ));
 
                $this->addMetadataLinks($out);
 
                $this->mRevisionId = $out->mRevisionId;
-               
+
                $this->preloadExistence();
 
-               wfProfileOut( $fname );
+               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -189,19 +192,22 @@ class Skin extends Linker {
        function preloadExistence() {
                global $wgUser, $wgTitle;
 
-               if ( $wgTitle->isTalkPage() ) {
-                       $otherTab = $wgTitle->getSubjectPage();
+               // User/talk link
+               $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
+
+               // Other tab link
+               if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
+                       // nothing
+               } elseif ( $wgTitle->isTalkPage() ) {
+                       $titles[] = $wgTitle->getSubjectPage();
                } else {
-                       $otherTab = $wgTitle->getTalkPage();
+                       $titles[] = $wgTitle->getTalkPage();
                }
-               $lb = new LinkBatch( array( 
-                       $wgUser->getUserPage(),
-                       $wgUser->getTalkPage(),
-                       $otherTab
-               ));
+
+               $lb = new LinkBatch( $titles );
                $lb->execute();
        }
-       
+
        function addMetadataLinks( &$out ) {
                global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
                global $wgRightsPage, $wgRightsUrl;
@@ -241,7 +247,7 @@ class Skin extends Linker {
        function outputPage( &$out ) {
                global $wgDebugComments;
 
-               wfProfileIn( 'Skin::outputPage' );
+               wfProfileIn( __METHOD__ );
                $this->initPage( $out );
 
                $out->out( $out->headElement() );
@@ -265,9 +271,10 @@ class Skin extends Linker {
 
                $out->out( $this->bottomScripts() );
 
-               $out->out( $out->reportTime() );
+               $out->out( wfReportTime() );
 
                $out->out( "\n</body></html>" );
+               wfProfileOut( __METHOD__ );
        }
 
        static function makeVariablesScript( $data ) {
@@ -290,52 +297,90 @@ class Skin extends Linker {
         * The odd calling convention is for backwards compatibility
         */
        static function makeGlobalVariablesScript( $data ) {
-               global $wgStylePath, $wgUser;
+               global $wgScript, $wgStylePath, $wgUser;
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
                global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
-               global $wgBreakFrames;
+               global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
+               global $wgUseAjax, $wgAjaxWatch;
+               global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
+               global $wgRestrictionTypes, $wgLivePreview;
+               global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
 
                $ns = $wgTitle->getNamespace();
                $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
-               
-               $vars = array( 
+
+               $vars = array(
                        'skin' => $data['skinname'],
                        'stylepath' => $wgStylePath,
                        'wgArticlePath' => $wgArticlePath,
                        'wgScriptPath' => $wgScriptPath,
+                       'wgScript' => $wgScript,
+                       'wgVariantArticlePath' => $wgVariantArticlePath,
+                       'wgActionPaths' => $wgActionPaths,
                        'wgServer' => $wgServer,
                        'wgCanonicalNamespace' => $nsname,
-                       'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBKey() ),
+                       'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ),
                        'wgNamespaceNumber' => $wgTitle->getNamespace(),
                        'wgPageName' => $wgTitle->getPrefixedDBKey(),
                        'wgTitle' => $wgTitle->getText(),
+                       'wgAction' => $wgRequest->getText( 'action', 'view' ),
                        'wgArticleId' => $wgTitle->getArticleId(),
                        'wgIsArticle' => $wgOut->isArticle(),
                        'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
+                       'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
                        'wgUserLanguage' => $wgLang->getCode(),
                        'wgContentLanguage' => $wgContLang->getCode(),
                        'wgBreakFrames' => $wgBreakFrames,
                        'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
+                       'wgVersion' => $wgVersion,
+                       'wgEnableAPI' => $wgEnableAPI,
+                       'wgEnableWriteAPI' => $wgEnableWriteAPI,
                );
+               
+               if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false )){
+                       $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
+                       $vars['wgDBname'] = $wgDBname;
+                       $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
+                       $vars['wgMWSuggestMessages'] = array( wfMsg('search-mwsuggest-enabled'), wfMsg('search-mwsuggest-disabled'));
+               }
+
+               foreach( $wgRestrictionTypes as $type )
+                       $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
+
+               if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
+                       $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
+                       $vars['wgLivepreviewMessageReady']   = wfMsg( 'livepreview-ready' );
+                       $vars['wgLivepreviewMessageFailed']  = wfMsg( 'livepreview-failed' );
+                       $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 );
        }
 
-       function getHeadScripts() {
-               global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion;
+       function getHeadScripts( $allowUserJs ) {
+               global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
 
                $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
 
                $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() ) {
+                       $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();
                        $userjs = htmlspecialchars( self::makeUrl(
                                $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
@@ -373,7 +418,8 @@ class Skin extends Linker {
        function getUserStylesheet() {
                global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
                $sheet = $this->getStylesheet();
-               $s = "@import \"$wgStylePath/common/common.css?$wgStyleVersion\";\n";
+               $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n";
+               $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n";
                $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
                if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
 
@@ -386,39 +432,31 @@ 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;
-    }
+       }
 
        /**
         * Return html code that include User stylesheets
@@ -457,7 +495,7 @@ var wgAjaxWatch = {
        function reallyDoGetUserStyles() {
                global $wgUser;
                $s = '';
-               if (($undopt = $wgUser->getOption("underline")) != 2) {
+               if (($undopt = $wgUser->getOption("underline")) < 2) {
                        $underline = $undopt ? 'underline' : 'none';
                        $s .= "a { text-decoration: $underline; }\n";
                }
@@ -468,22 +506,19 @@ var wgAjaxWatch = {
 a.new, #quickbar a.new,
 a.stub, #quickbar a.stub {
        color: inherit;
-       text-decoration: inherit;
 }
 a.new:after, #quickbar a.new:after {
        content: "?";
        color: #CC2200;
-       text-decoration: $underline;
 }
 a.stub:after, #quickbar a.stub:after {
        content: "!";
        color: #772233;
-       text-decoration: $underline;
 }
 END;
                }
                if( $wgUser->getOption( 'justify' ) ) {
-                       $s .= "#article, #bodyContent { text-align: justify; }\n";
+                       $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
                }
                if( !$wgUser->getOption( 'showtoc' ) ) {
                        $s .= "#toc { display: none; }\n";
@@ -504,21 +539,17 @@ END;
                }
                else $a = array( 'bgcolor' => '#FFFFFF' );
                if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
-                 $wgTitle->userCanEdit() ) {
+                 $wgTitle->userCan( 'edit' ) ) {
                        $s = $wgTitle->getFullURL( $this->editUrlOptions() );
                        $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
                        $a += array ('ondblclick' => $s);
 
                }
                $a['onload'] = $wgOut->getOnloadHandler();
-               if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
-                       if( $a['onload'] != '' ) {
-                               $a['onload'] .= ';';
-                       }
-                       $a['onload'] .= 'setupRightClickEdit()';
-               }
-               $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
-               ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() );
+               $a['class'] =
+                       'mediawiki ns-'.$wgTitle->getNamespace().
+                       ' '.($wgContLang->isRTL() ? "rtl" : "ltr").
+                       ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() );
                return $a;
        }
 
@@ -601,9 +632,9 @@ END;
        }
 
 
-       function getCategoryLinks () {
+       function getCategoryLinks() {
                global $wgOut, $wgTitle, $wgUseCategoryBrowser;
-               global $wgContLang;
+               global $wgContLang, $wgUser;
 
                if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
 
@@ -615,11 +646,33 @@ END;
                $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
                $embed = "<span dir='$dir'>";
                $pop = '</span>';
-               $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
 
-               $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
-               $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
-                       . ': ' . $t;
+               $allCats = $wgOut->getCategoryLinks();
+               $s = '';
+               $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
+               if ( !empty( $allCats['normal'] ) ) {
+                       $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
+
+                       $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
+                       $s .= '<div id="mw-normal-catlinks">' .
+                               $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
+                               . $colon . $t . '</div>';
+               }
+
+               # Hidden categories
+               if ( isset( $allCats['hidden'] ) ) {
+                       if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
+                               $class ='mw-hidden-cats-user-shown';
+                       } elseif ( $wgTitle->getNamespace() == NS_CATEGORY ) {
+                               $class = 'mw-hidden-cats-ns-shown';
+                       } else {
+                               $class = 'mw-hidden-cats-hidden';
+                       }
+                       $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
+                               wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
+                               $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
+                               "</div>";
+               }
 
                # optional 'dmoz-like' category browser. Will be shown under the list
                # of categories an article belong to
@@ -665,8 +718,16 @@ END;
 
        function getCategories() {
                $catlinks=$this->getCategoryLinks();
-               if(!empty($catlinks)) {
-                       return "<p class='catlinks'>{$catlinks}</p>";
+
+               $classes = 'catlinks';
+
+               if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
+                       strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
+                       $classes .= ' catlinks-allhidden';
+               }
+
+               if( !empty( $catlinks ) ){
+                       return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
                }
        }
 
@@ -676,7 +737,7 @@ END;
 
        /**
         * This gets called shortly before the \</body\> tag.
-        * @return String HTML to be put before \</body\> 
+        * @return String HTML to be put before \</body\>
         */
        function afterContent() {
                $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
@@ -685,11 +746,13 @@ END;
 
        /**
         * This gets called shortly before the \</body\> tag.
-        * @return String HTML-wrapped JS code to be put before \</body\> 
+        * @return String HTML-wrapped JS code to be put before \</body\>
         */
        function bottomScripts() {
                global $wgJsMimeType;
-               return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
+               $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
+               wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
+               return $bottomScriptText;
        }
 
        /** @return string Retrievied from HTML text */
@@ -727,8 +790,8 @@ END;
                if ( $wgOut->isArticleRelated() ) {
                        if ( $wgTitle->getNamespace() == NS_IMAGE ) {
                                $name = $wgTitle->getDBkey();
-                               $image = new Image( $wgTitle );
-                               if( $image->exists() ) {
+                               $image = wfFindFile( $wgTitle );
+                               if( $image ) {
                                        $link = htmlspecialchars( $image->getURL() );
                                        $style = $this->getInternalLinkAttributes( $link, $name );
                                        $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
@@ -761,12 +824,12 @@ END;
        }
 
        function getUndeleteLink() {
-               global $wgUser, $wgTitle, $wgContLang, $action;
+               global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
                if(     $wgUser->isAllowed( 'deletedhistory' ) &&
                        (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
                        ($n = $wgTitle->isDeleted() ) )
                {
-                       if ( $wgUser->isAllowed( 'delete' ) ) {
+                       if ( $wgUser->isAllowed( 'undelete' ) ) {
                                $msg = 'thisisdeleted';
                        } else {
                                $msg = 'viewdeleted';
@@ -774,7 +837,7 @@ END;
                        return wfMsg( $msg,
                                $this->makeKnownLinkObj(
                                        SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
-                                       wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
+                                       wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
                }
                return '';
        }
@@ -815,42 +878,59 @@ END;
        }
 
        function subPageSubtitle() {
-               global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
                $subpages = '';
-               if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
+               if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
+                       return $subpages;
+
+               global $wgOut, $wgTitle;
+               if($wgOut->isArticle() && MWNamespace::hasSubpages( $wgTitle->getNamespace() )) {
                        $ptext=$wgTitle->getPrefixedText();
                        if(preg_match('/\//',$ptext)) {
                                $links = explode('/',$ptext);
+                               array_pop( $links );
                                $c = 0;
                                $growinglink = '';
+                               $display = '';
                                foreach($links as $link) {
-                                       $c++;
-                                       if ($c<count($links)) {
-                                               $growinglink .= $link;
-                                               $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
-                                               if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
+                                       $growinglink .= $link;
+                                       $display .= $link;
+                                       $linkObj = Title::newFromText( $growinglink );
+                                       if( is_object( $linkObj ) && $linkObj->exists() ){
+                                               $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
+                                               $c++;
                                                if ($c>1) {
                                                        $subpages .= ' | ';
                                                } else  {
                                                        $subpages .= '&lt; ';
                                                }
                                                $subpages .= $getlink;
-                                               $growinglink .= '/';
+                                               $display = '';
+                                       } else {
+                                               $display .= '/';
                                        }
+                                       $growinglink .= '/';
                                }
                        }
                }
                return $subpages;
        }
 
+       /**
+        * Returns true if the IP should be shown in the header
+        */
+       function showIPinHeader() {
+               global $wgShowIPinHeader;
+               return $wgShowIPinHeader && session_id() != '';
+       }
+
        function nameAndLogin() {
-               global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
+               global $wgUser, $wgTitle, $wgLang, $wgContLang;
 
                $lo = $wgContLang->specialPage( 'Userlogout' );
 
                $s = '';
                if ( $wgUser->isAnon() ) {
-                       if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
+                       if( $this->showIPinHeader() ) {
                                $n = wfGetIP();
 
                                $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
@@ -866,9 +946,12 @@ END;
                                $q = '';
                        } else { $q = "returnto={$rt}"; }
 
+                       $loginlink = $wgUser->isAllowed( 'createaccount' )
+                               ? 'nav-login-createaccount'
+                               : 'login';
                        $s .= "\n<br />" . $this->makeKnownLinkObj(
                                SpecialPage::getTitleFor( 'Userlogin' ),
-                               wfMsg( 'login' ), $q );
+                               wfMsg( $loginlink ), $q );
                } else {
                        $n = $wgUser->getName();
                        $rt = $wgTitle->getPrefixedURL();
@@ -902,13 +985,16 @@ END;
                global $wgRequest;
                $search = $wgRequest->getText( 'search' );
 
-               $s = '<form name="search" class="inline" method="post" action="'
+               $s = '<form id="searchform'.$this->searchboxes.'" name="search" class="inline" method="post" action="'
                  . $this->escapeSearchLink() . "\">\n"
-                 . '<input type="text" name="search" size="19" value="'
+                 . '<input type="text" id="searchInput'.$this->searchboxes.'" name="search" size="19" value="'
                  . htmlspecialchars(substr($search,0,256)) . "\" />\n"
                  . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
                  . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
 
+               // Ensure unique id's for search boxes made after the first
+               $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
+               
                return $s;
        }
 
@@ -925,14 +1011,14 @@ 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
@@ -950,7 +1036,7 @@ END;
                }
                return $s;
        }
-       
+
        /**
         * Language/charset variant links for classic-style skins
         * @return string
@@ -1040,14 +1126,17 @@ END;
                }
 
                if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
-                       $dbr =& wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_SLAVE );
                        $watchlist = $dbr->tableName( 'watchlist' );
                        $sql = "SELECT COUNT(*) AS n FROM $watchlist
-                               WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
+                               WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
                                "' AND  wl_namespace=" . $wgTitle->getNamespace() ;
                        $res = $dbr->query( $sql, 'Skin::pageStats');
                        $x = $dbr->fetchObject( $res );
-                       $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
+
+                       $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
+                               array( 'parseinline' ), $wgLang->formatNum($x->n)
+                       );
                }
 
                return $s . ' ' .  $this->getCopyright();
@@ -1114,7 +1203,7 @@ END;
        }
 
        function lastModified() {
-               global $wgLang, $wgArticle, $wgLoadBalancer;
+               global $wgLang, $wgArticle;
 
                $timestamp = $wgArticle->getTimestamp();
                if ( $timestamp ) {
@@ -1124,7 +1213,7 @@ END;
                } else {
                        $s = '';
                }
-               if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
+               if ( wfGetLB()->getLaggedSlaveMode() ) {
                        $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
                }
                return $s;
@@ -1184,39 +1273,42 @@ END;
                return $s;
        }
 
-       function privacyLink() {
-               $privacy = wfMsg( 'privacy' );
-               if ($privacy == '-') {
+       private function footerLink ( $desc, $page ) {
+               // if the link description has been set to "-" in the default language,
+               if ( wfMsgForContent( $desc )  == '-') {
+                       // then it is disabled, for all languages.
                        return '';
                } else {
-                       return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
+                       // Otherwise, we display the link for the user, described in their
+                       // language (which may or may not be the same as the default language),
+                       // but we make the link target be the one site-wide page.
+                       return $this->makeKnownLink( wfMsgForContent( $page ),
+                               wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
                }
        }
 
+       function privacyLink() {
+               return $this->footerLink( 'privacy', 'privacypage' );
+       }
+
        function aboutLink() {
-               $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
-                 wfMsg( 'aboutsite' ) );
-               return $s;
+               return $this->footerLink( 'aboutsite', 'aboutpage' );
        }
 
        function disclaimerLink() {
-               $disclaimers = wfMsg( 'disclaimers' );
-               if ($disclaimers == '-') {
-                       return '';
-               } else {
-                       return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
-                                                    $disclaimers );
-               }
+               return $this->footerLink( 'disclaimers', 'disclaimerpage' );
        }
 
        function editThisPage() {
                global $wgOut, $wgTitle;
 
-               if ( ! $wgOut->isArticleRelated() ) {
+               if ( !$wgOut->isArticleRelated() ) {
                        $s = wfMsg( 'protectedpage' );
                } else {
-                       if ( $wgTitle->userCanEdit() ) {
+                       if( $wgTitle->userCan( 'edit' ) && $wgTitle->exists() ) {
                                $t = wfMsg( 'editthispage' );
+                       } elseif( $wgTitle->userCan( 'create' ) && !$wgTitle->exists() ) {
+                               $t = wfMsg( 'create-this-page' );
                        } else {
                                $t = wfMsg( 'viewsource' );
                        }
@@ -1300,7 +1392,7 @@ END;
        function moveThisPage() {
                global $wgTitle;
 
-               if ( $wgTitle->userCanMove() ) {
+               if ( $wgTitle->userCan( 'move' ) ) {
                        return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
                          wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
                } else {
@@ -1319,15 +1411,15 @@ END;
        function whatLinksHere() {
                global $wgTitle;
 
-               return $this->makeKnownLinkObj( 
-                       SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ), 
+               return $this->makeKnownLinkObj(
+                       SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
                        wfMsg( 'whatlinkshere' ) );
        }
 
        function userContribsLink() {
                global $wgTitle;
 
-               return $this->makeKnownLinkObj( 
+               return $this->makeKnownLinkObj(
                        SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
                        wfMsg( 'contributions' ) );
        }
@@ -1346,7 +1438,7 @@ END;
        function emailUserLink() {
                global $wgTitle;
 
-               return $this->makeKnownLinkObj( 
+               return $this->makeKnownLinkObj(
                        SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
                        wfMsg( 'emailuser' ) );
        }
@@ -1357,8 +1449,8 @@ END;
                if ( ! $wgOut->isArticleRelated() ) {
                        return '(' . wfMsg( 'notanarticle' ) . ')';
                } else {
-                       return $this->makeKnownLinkObj( 
-                               SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ), 
+                       return $this->makeKnownLinkObj(
+                               SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
                                wfMsg( 'recentchangeslinked' ) );
                }
        }
@@ -1407,29 +1499,6 @@ END;
                return $s;
        }
 
-       function dateLink() {
-               $t1 = Title::newFromText( gmdate( 'F j' ) );
-               $t2 = Title::newFromText( gmdate( 'Y' ) );
-
-               $id = $t1->getArticleID();
-
-               if ( 0 == $id ) {
-                       $s = $this->makeBrokenLink( $t1->getText() );
-               } else {
-                       $s = $this->makeKnownLink( $t1->getText() );
-               }
-               $s .= ', ';
-
-               $id = $t2->getArticleID();
-
-               if ( 0 == $id ) {
-                       $s .= $this->makeBrokenLink( $t2->getText() );
-               } else {
-                       $s .= $this->makeKnownLink( $t2->getText() );
-               }
-               return $s;
-       }
-
        function talkLink() {
                global $wgTitle;
 
@@ -1484,18 +1553,18 @@ END;
                if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
                        return '';
                }
-               
+
                # __NEWSECTIONLINK___ changes behaviour here
                # If it's present, the link points to this page, otherwise
                # it points to the talk page
                if( $wgTitle->isTalkPage() ) {
-                       $title =& $wgTitle;
+                       $title = $wgTitle;
                } elseif( $wgOut->showNewSectionLink() ) {
-                       $title =& $wgTitle;
+                       $title = $wgTitle;
                } else {
-                       $title =& $wgTitle->getTalkPage();
+                       $title = $wgTitle->getTalkPage();
                }
-               
+
                return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
        }
 
@@ -1581,30 +1650,25 @@ END;
         * Build an array that represents the sidebar(s), the navigation bar among them
         *
         * @return array
-        * @private
         */
        function buildSidebar() {
-               global $parserMemc, $wgEnableSidebarCache;
-               global $wgLang, $wgContLang;
-
-               $fname = 'SkinTemplate::buildSidebar';
+               global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
+               global $wgLang;
+               wfProfileIn( __METHOD__ );
 
-               wfProfileIn( $fname );
+               $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
 
-               $key = wfMemcKey( 'sidebar' );
-               $cacheSidebar = $wgEnableSidebarCache &&
-                       ($wgLang->getCode() == $wgContLang->getCode());
-               
-               if ($cacheSidebar) {
+               if ( $wgEnableSidebarCache ) {
                        $cachedsidebar = $parserMemc->get( $key );
-                       if ($cachedsidebar!="") {
-                               wfProfileOut($fname);
+                       if ( $cachedsidebar ) {
+                               wfProfileOut( __METHOD__ );
                                return $cachedsidebar;
                        }
                }
 
                $bar = array();
                $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
+               $heading = '';
                foreach ($lines as $line) {
                        if (strpos($line, '*') !== 0)
                                continue;
@@ -1613,7 +1677,7 @@ END;
                                $heading = $line;
                        } else {
                                if (strpos($line, '|') !== false) { // sanity check
-                                       $line = explode( '|' , trim($line, '* '), 2 );
+                                       $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
                                        $link = wfMsgForContent( $line[0] );
                                        if ($link == '-')
                                                continue;
@@ -1643,10 +1707,8 @@ END;
                                } else { continue; }
                        }
                }
-               if ($cacheSidebar)
-                       $parserMemc->set( $key, $bar, 86400 );
-               wfProfileOut( $fname );
+               if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
+               wfProfileOut( __METHOD__ );
                return $bar;
        }
 }
-?>