disallow embedded line breaks in ISBNs; allowing them breaks things in a most interes...
[lhc/web/wiklou.git] / includes / Skin.php
index 124bc59..924deef 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 if ( ! defined( 'MEDIAWIKI' ) )
-       die();
+       die( 1 );
 
 /**
  *
@@ -9,35 +9,15 @@ if ( ! defined( 'MEDIAWIKI' ) )
  */
 
 # See skin.txt
-require_once( 'Linker.php' );
-require_once( 'Image.php' );
-
-# Get a list of all skins available in /skins/
-# Build using the regular expression '^(.*).php$'
-# Array keys are all lower case, array value keep the case used by filename
-#
-
-$skinDir = dir($IP.'/skins');
-
-# while code from www.php.net
-while (false !== ($file = $skinDir->read())) {
-       if(preg_match('/^([^.].*)\.php$/',$file, $matches)) {
-               $aSkin = $matches[1];
-               $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
-       }
-}
-$skinDir->close();
-unset($matches);
 
 /**
- * The main skin class that provide methods and properties for all other skins
- * including PHPTal skins.
+ * The main skin class that provide methods and properties for all other skins.
  * This base class is also the "Standard" skin.
  * @package MediaWiki
  */
 class Skin extends Linker {
        /**#@+
-        * @access private
+        * @private
         */
        var $lastdate, $lastline;
        var $rc_cache ; # Cache for Enhanced Recent Changes
@@ -53,8 +33,31 @@ class Skin extends Linker {
         * @return array of strings
         * @static
         */
-       function getSkinNames() {
+       static function &getSkinNames() {
                global $wgValidSkinNames;
+               static $skinsInitialised = false;
+               if ( !$skinsInitialised ) {
+                       # Get a list of available skins
+                       # Build using the regular expression '^(.*).php$'
+                       # Array keys are all lower case, array value keep the case used by filename
+                       #
+                       wfProfileIn( __METHOD__ . '-init' );
+                       global $wgStyleDirectory;
+                       $skinDir = dir( $wgStyleDirectory );
+
+                       # while code from www.php.net
+                       while (false !== ($file = $skinDir->read())) {
+                               // Skip non-PHP files, hidden files, and '.dep' includes
+                               $matches = array();
+                               if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
+                                       $aSkin = $matches[1];
+                                       $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
+                               }
+                       }
+                       $skinDir->close();
+                       $skinsInitialised = true;
+                       wfProfileOut( __METHOD__ . '-init' );
+               }
                return $wgValidSkinNames;
        }
 
@@ -66,7 +69,7 @@ class Skin extends Linker {
         * @return string
         * @static
         */
-       function normalizeKey( $key ) {
+       static function normalizeKey( $key ) {
                global $wgDefaultSkin;
                $skinNames = Skin::getSkinNames();
 
@@ -105,17 +108,19 @@ class Skin extends Linker {
         * @return Skin
         * @static
         */
-       function &newFromKey( $key ) {
+       static function &newFromKey( $key ) {
+               global $wgStyleDirectory;
+               
                $key = Skin::normalizeKey( $key );
 
                $skinNames = Skin::getSkinNames();
                $skinName = $skinNames[$key];
 
-               global $IP;
-
-               # Grab the skin class and initialise it. Each skin checks for PHPTal
-               # and will not load if it's not enabled.
-               require_once( $IP.'/skins/'.$skinName.'.php' );
+               # 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;
@@ -124,16 +129,17 @@ class Skin extends Linker {
                        # 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( $IP.'/skins/Standard.php' );
+                       require_once( "{$wgStyleDirectory}/Standard.php" );
                }
-               $skin =& new $className;
+               $skin = new $className;
                return $skin;
        }
 
        /** @return string path to the skin stylesheet */
        function getStylesheet() {
-               return 'common/wikistandard.css?1';
+               return 'common/wikistandard.css';
        }
 
        /** @return string skin name */
@@ -151,18 +157,51 @@ class Skin extends Linker {
        }
 
        function initPage( &$out ) {
+               global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
+
                $fname = 'Skin::initPage';
                wfProfileIn( $fname );
 
-               $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
+               if( false !== $wgFavicon ) {
+                       $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
+               }
+
+               # OpenSearch description link
+               $out->addLink( array( 
+                       'rel' => 'search', 
+                       'type' => 'application/opensearchdescription+xml',
+                       'href' => "$wgScriptPath/opensearch_desc.php",
+                       'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})",
+               ));
 
                $this->addMetadataLinks($out);
 
                $this->mRevisionId = $out->mRevisionId;
+               
+               $this->preloadExistence();
 
                wfProfileOut( $fname );
        }
 
+       /**
+        * Preload the existence of three commonly-requested pages in a single query
+        */
+       function preloadExistence() {
+               global $wgUser, $wgTitle;
+
+               if ( $wgTitle->isTalkPage() ) {
+                       $otherTab = $wgTitle->getSubjectPage();
+               } else {
+                       $otherTab = $wgTitle->getTalkPage();
+               }
+               $lb = new LinkBatch( array( 
+                       $wgUser->getUserPage(),
+                       $wgUser->getTalkPage(),
+                       $otherTab
+               ));
+               $lb->execute();
+       }
+       
        function addMetadataLinks( &$out ) {
                global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
                global $wgRightsPage, $wgRightsUrl;
@@ -224,17 +263,78 @@ class Skin extends Linker {
 
                $out->out( $this->afterContent() );
 
+               $out->out( $this->bottomScripts() );
+
                $out->out( $out->reportTime() );
 
                $out->out( "\n</body></html>" );
        }
 
+       static function makeGlobalVariablesScript( $data ) {
+               $r = '<script type= "' . $data['jsmimetype'] . '">
+                       var skin = "' . Xml::escapeJsString( $data['skinname'] ) . '";
+                       var stylepath = "' . Xml::escapeJsString( $data['stylepath'] ) . '";
+
+                       var wgArticlePath = "' . Xml::escapeJsString( $data['articlepath'] ) . '";
+                       var wgScriptPath = "' . Xml::escapeJsString( $data['scriptpath'] ) . '";
+                       var wgServer = "' . Xml::escapeJsString( $data['serverurl'] ) . '";
+                        
+                       var wgCanonicalNamespace = "' . Xml::escapeJsString( $data['nscanonical'] ) . '";
+                       var wgNamespaceNumber = ' . (int)$data['nsnumber'] . ';
+                       var wgPageName = "' . Xml::escapeJsString( $data['titleprefixeddbkey'] ) . '";
+                       var wgTitle = "' . Xml::escapeJsString( $data['titletext'] ) . '";
+                       var wgArticleId = ' . (int)$data['articleid'] . ';
+                       var wgIsArticle = ' . ( $data['isarticle'] ? 'true' : 'false' ) . ';
+                        
+                       var wgUserName = ' . ( $data['username'] == NULL ? 'null' : ( '"' . Xml::escapeJsString( $data['username'] ) . '"' ) ) . ';
+                       var wgUserLanguage = "' . Xml::escapeJsString( $data['userlang'] ) . '";
+                       var wgContentLanguage = "' . Xml::escapeJsString( $data['lang'] ) . '";
+               </script>
+               ';
+               
+               return $r;
+       }
+
        function getHeadScripts() {
-               global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
-               $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
+               global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion;
+               global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
+               global $wgTitle, $wgCanonicalNamespaceNames, $wgOut;
+
+               $ns = $wgTitle->getNamespace();
+               $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
+               
+               $vars = array( 
+                       'jsmimetype' => $wgJsMimeType,
+                       'skinname' => $this->getSkinName(),
+                       'stylepath' => $wgStylePath,
+                       'articlepath' => $wgArticlePath,
+                       'scriptpath' => $wgScriptPath,
+                       'serverurl' => $wgServer,
+                       'nscanonical' => $nsname,
+                       'nsnumber' => $wgTitle->getNamespace(),
+                       'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
+                       'titletext' => $wgTitle->getText(),
+                       'articleid' => $wgTitle->getArticleId(),
+                       'isarticle' => $wgOut->isArticle(),
+                       'username' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
+                       'userlang' => $wgLang->getCode(),
+                       'lang' => $wgContLang->getCode(),
+               );
+
+               $r = self::makeGlobalVariablesScript( $vars );
+
+               $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( $this->makeUrl(
+                       $userjs = htmlspecialchars( self::makeUrl(
                                $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
                                'action=raw&ctype='.$wgJsMimeType));
                        $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
@@ -251,7 +351,7 @@ class Skin extends Linker {
         *
         * @param string $action
         * @return bool
-        * @access private
+        * @private
         */
        function userCanPreview( $action ) {
                global $wgTitle, $wgRequest, $wgUser;
@@ -266,32 +366,49 @@ class Skin extends Linker {
                        $wgRequest->getVal( 'wpEditToken' ) );
        }
 
-       # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
+       # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
        function getUserStylesheet() {
-               global $wgOut, $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 = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
-               $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
-                       '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
+               $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
+               $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
+                       '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
 
                $s .= $this->doGetUserStyles();
                return $s."\n";
        }
 
        /**
-        * 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
         */
        function getUserStyles() {
-               global $wgOut, $wgStylePath;
                $s = "<style type='text/css'>\n";
                $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
                $s .= $this->getUserStylesheet();
@@ -304,16 +421,16 @@ class Skin extends Linker {
         * Some styles that are set by user through the user settings interface.
         */
        function doGetUserStyles() {
-               global $wgUser, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
+               global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
 
                $s = '';
 
                if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
-                       if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
+                       if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
                                $s .= $wgRequest->getText('wpTextbox1');
                        } else {
                                $userpage = $wgUser->getUserPage();
-                               $s.= '@import "'.$this->makeUrl(
+                               $s.= '@import "'.self::makeUrl(
                                        $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
                                        'action=raw&ctype=text/css').'";'."\n";
                        }
@@ -363,7 +480,7 @@ END;
        }
 
        function getBodyOptions() {
-               global $wgUser, $wgTitle, $wgOut, $wgRequest;
+               global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
 
                extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
 
@@ -373,7 +490,6 @@ END;
                else $a = array( 'bgcolor' => '#FFFFFF' );
                if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
                  $wgTitle->userCanEdit() ) {
-                       $t = wfMsg( 'editthispage' );
                        $s = $wgTitle->getFullURL( $this->editUrlOptions() );
                        $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
                        $a += array ('ondblclick' => $s);
@@ -386,6 +502,8 @@ END;
                        }
                        $a['onload'] .= 'setupRightClickEdit()';
                }
+               $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
+               ' '.Sanitizer::escapeId( 'page-'.$wgTitle->getPrefixedText() );
                return $a;
        }
 
@@ -406,7 +524,7 @@ END;
        }
 
        function doBeforeContent() {
-               global $wgOut, $wgTitle, $wgContLang;
+               global $wgContLang;
                $fname = 'Skin::doBeforeContent';
                wfProfileIn( $fname );
 
@@ -474,16 +592,18 @@ END;
 
                if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
 
+               # Separator
+               $sep = wfMsgHtml( 'catseparator' );
+
                // Use Unicode bidi embedding override characters,
                // to make sure links don't smash each other up in ugly ways.
                $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
                $embed = "<span dir='$dir'>";
                $pop = '</span>';
-               $t = $embed . implode ( "$pop | $embed" , $wgOut->mCategoryLinks ) . $pop;
+               $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
 
-               $msg = count( $wgOut->mCategoryLinks ) === 1 ? 'categories1' : 'categories';
-               $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
-                       wfMsg( $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
@@ -507,9 +627,9 @@ END;
        }
 
        /** Render the array as a serie of links.
-        * @param array $tree Categories tree returned by Title::getParentCategoryTree
-        * @param object &skin Skin passed by reference
-        * @return string separated by &gt;, terminate with "\n"
+        * @param $tree Array: categories tree returned by Title::getParentCategoryTree
+        * @param &skin Object: skin passed by reference
+        * @return String separated by &gt;, terminate with "\n"
         */
        function drawCategoryBrowser($tree, &$skin) {
                $return = '';
@@ -540,14 +660,23 @@ END;
        }
 
        /**
-        * This gets called immediately before the </body> tag.
-        * @return string HTML to be put after </body> ???
+        * This gets called shortly before the \</body\> tag.
+        * @return String HTML to be put before \</body\> 
         */
        function afterContent() {
                $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
                return $printfooter . $this->doAfterContent();
        }
 
+       /**
+        * This gets called shortly before the \</body\> tag.
+        * @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";
+       }
+
        /** @return string Retrievied from HTML text */
        function printSource() {
                global $wgTitle;
@@ -564,9 +693,10 @@ END;
        function doAfterContent() { }
 
        function pageTitleLinks() {
-               global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgRequest;
+               global $wgOut, $wgTitle, $wgUser, $wgRequest;
 
-               extract( $wgRequest->getValues( 'oldid', 'diff' ) );
+               $oldid = $wgRequest->getVal( 'oldid' );
+               $diff = $wgRequest->getVal( 'diff' );
                $action = $wgRequest->getText( 'action' );
 
                $s = $this->printableLink();
@@ -599,7 +729,7 @@ END;
                        # do not show "You have new messages" text when we are viewing our
                        # own talk page
                        if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
-                               $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ) );
+                               $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
                                $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
                                $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
                                # disable caching
@@ -629,7 +759,7 @@ END;
                        return wfMsg( $msg,
                                $this->makeKnownLink(
                                        $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
-                                       wfMsg( 'restorelink' . ($n == 1 ? '1' : ''), $n ) ) );
+                                       wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
                }
                return '';
        }
@@ -657,8 +787,7 @@ END;
        }
 
        function pageTitle() {
-               global $wgOut, $wgTitle, $wgUser;
-
+               global $wgOut;
                $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
                return $s;
        }
@@ -690,7 +819,7 @@ END;
                                        $c++;
                                        if ($c<count($links)) {
                                                $growinglink .= $link;
-                                               $getlink = $this->makeLink( $growinglink, $link );
+                                               $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
                                                if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
                                                if ($c>1) {
                                                        $subpages .= ' | ';
@@ -709,7 +838,6 @@ END;
        function nameAndLogin() {
                global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
 
-               $li = $wgContLang->specialPage( 'Userlogin' );
                $lo = $wgContLang->specialPage( 'Userlogout' );
 
                $s = '';
@@ -731,7 +859,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();
@@ -743,7 +871,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' );
                }
@@ -754,7 +882,7 @@ END;
        }
 
        function getSearchLink() {
-               $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
+               $searchPage = SpecialPage::getTitleFor( 'Search' );
                return $searchPage->getLocalURL();
        }
 
@@ -770,8 +898,8 @@ END;
                  . $this->escapeSearchLink() . "\">\n"
                  . '<input type="text" name="search" size="19" value="'
                  . htmlspecialchars(substr($search,0,256)) . "\" />\n"
-                 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
-                 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
+                 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
+                 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
 
                return $s;
        }
@@ -789,7 +917,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();
@@ -798,10 +957,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;
        }
 
@@ -852,7 +1010,8 @@ END;
                global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
                global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
 
-               extract( $wgRequest->getValues( 'oldid', 'diff' ) );
+               $oldid = $wgRequest->getVal( 'oldid' );
+               $diff = $wgRequest->getVal( 'diff' );
                if ( ! $wgOut->isArticle() ) { return ''; }
                if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
                if ( 0 == $wgArticle->getID() ) { return ''; }
@@ -861,7 +1020,7 @@ END;
                if ( !$wgDisableCounters ) {
                        $count = $wgLang->formatNum( $wgArticle->getCount() );
                        if ( $count ) {
-                               $s = wfMsg( 'viewcount', $count );
+                               $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
                        }
                }
 
@@ -874,7 +1033,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() ;
@@ -886,14 +1045,21 @@ END;
                return $s . ' ' .  $this->getCopyright();
        }
 
-       function getCopyright() {
+       function getCopyright( $type = 'detect' ) {
                global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
 
+               if ( $type == 'detect' ) {
+                       $oldid = $wgRequest->getVal( 'oldid' );
+                       $diff = $wgRequest->getVal( 'diff' );
 
-               $oldid = $wgRequest->getVal( 'oldid' );
-               $diff = $wgRequest->getVal( 'diff' );
+                       if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
+                               $type = 'history';
+                       } else {
+                               $type = 'normal';
+                       }
+               }
 
-               if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
+               if ( $type == 'history' ) {
                        $msg = 'history_copyright';
                } else {
                        $msg = 'copyright';
@@ -913,7 +1079,7 @@ END;
        }
 
        function getCopyrightIcon() {
-               global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
+               global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
                $out = '';
                if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
                        $out = $wgCopyrightIcon;
@@ -944,8 +1110,9 @@ END;
 
                $timestamp = $wgArticle->getTimestamp();
                if ( $timestamp ) {
-                       $d = $wgLang->timeanddate( $timestamp, true );
-                       $s = ' ' . wfMsg( 'lastmodified', $d );
+                       $d = $wgLang->date( $timestamp, true );
+                       $t = $wgLang->time( $timestamp, true );
+                       $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
                } else {
                        $s = '';
                }
@@ -974,30 +1141,12 @@ END;
 
        /**
         * show a drop-down box of special pages
-        * @TODO crash bug913. Need to be rewrote completly.
         */
        function specialPagesList() {
-               global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
-               require_once('SpecialPage.php');
-               $a = array();
-               $pages = SpecialPage::getPages();
-
-               // special pages without access restriction
-               foreach ( $pages[''] as $name => $page ) {
-                       $a[$name] = $page->getDescription();
-               }
-
-               // Other special pages that are restricted.
-               // Copied from SpecialSpecialpages.php
-               foreach($wgAvailableRights as $right) {
-                       if( $wgUser->isAllowed($right) ) {
-                               /** Add all pages for this right */
-                               if(isset($pages[$right])) {
-                                       foreach($pages[$right] as $name => $page) {
-                                       $a[$name] = $page->getDescription();
-                                       }
-                               }
-                       }
+               global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
+               $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
+               foreach ( $pages as $name => $page ) {
+                       $pages[$name] = $page->getDescription();
                }
 
                $go = wfMsg( 'go' );
@@ -1010,7 +1159,7 @@ END;
                $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
 
 
-               foreach ( $a as $name => $desc ) {
+               foreach ( $pages as $name => $desc ) {
                        $p = $wgContLang->specialPage( $name );
                        $s .= "<option value=\"{$p}\">{$desc}</option>\n";
                }
@@ -1059,7 +1208,7 @@ END;
        }
 
        function editThisPage() {
-               global $wgOut, $wgTitle, $wgRequest;
+               global $wgOut, $wgTitle;
 
                if ( ! $wgOut->isArticleRelated() ) {
                        $s = wfMsg( 'protectedpage' );
@@ -1080,7 +1229,7 @@ END;
         * This may include an 'oldid' specifier, if the current page view is such.
         *
         * @return string
-        * @access private
+        * @private
         */
        function editUrlOptions() {
                global $wgArticle;
@@ -1093,7 +1242,7 @@ END;
        }
 
        function deleteThisPage() {
-               global $wgUser, $wgOut, $wgTitle, $wgRequest;
+               global $wgUser, $wgTitle, $wgRequest;
 
                $diff = $wgRequest->getVal( 'diff' );
                if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
@@ -1107,7 +1256,7 @@ END;
        }
 
        function protectThisPage() {
-               global $wgUser, $wgOut, $wgTitle, $wgRequest;
+               global $wgUser, $wgTitle, $wgRequest;
 
                $diff = $wgRequest->getVal( 'diff' );
                if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
@@ -1126,7 +1275,7 @@ END;
        }
 
        function watchThisPage() {
-               global $wgUser, $wgOut, $wgTitle;
+               global $wgOut, $wgTitle;
 
                if ( $wgOut->isArticleRelated() ) {
                        if ( $wgTitle->userIsWatching() ) {
@@ -1147,7 +1296,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
@@ -1165,15 +1314,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 ) {
@@ -1190,8 +1341,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() {
@@ -1200,9 +1352,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' ) );
                }
        }
 
@@ -1214,7 +1366,7 @@ END;
        }
 
        function otherLanguages() {
-               global $wgOut, $wgContLang, $wgTitle, $wgHideInterlanguageLinks;
+               global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
 
                if ( $wgHideInterlanguageLinks ) {
                        return '';
@@ -1284,20 +1436,32 @@ END;
                if( $wgTitle->isTalkPage() ) {
                        $link = $wgTitle->getSubjectPage();
                        switch( $link->getNamespace() ) {
-                       case NS_MAIN:
-                               $text = wfMsg('articlepage');
-                               break;
-                       case NS_USER:
-                               $text = wfMsg('userpage');
-                               break;
-                       case NS_PROJECT:
-                               $text = wfMsg('wikipediapage');
-                               break;
-                       case NS_IMAGE:
-                               $text = wfMsg('imagepage');
-                               break;
-                       default:
-                               $text= wfMsg('articlepage');
+                               case NS_MAIN:
+                                       $text = wfMsg( 'articlepage' );
+                                       break;
+                               case NS_USER:
+                                       $text = wfMsg( 'userpage' );
+                                       break;
+                               case NS_PROJECT:
+                                       $text = wfMsg( 'projectpage' );
+                                       break;
+                               case NS_IMAGE:
+                                       $text = wfMsg( 'imagepage' );
+                                       break;
+                               case NS_MEDIAWIKI:
+                                       $text = wfMsg( 'mediawikipage' );
+                                       break;
+                               case NS_TEMPLATE:
+                                       $text = wfMsg( 'templatepage' );
+                                       break;
+                               case NS_HELP:
+                                       $text = wfMsg( 'viewhelppage' );
+                                       break;
+                               case NS_CATEGORY:
+                                       $text = wfMsg( 'categorypage' );
+                                       break;
+                               default:
+                                       $text = wfMsg( 'articlepage' );
                        }
                } else {
                        $link = $wgTitle->getTalkPage();
@@ -1310,66 +1474,77 @@ END;
        }
 
        function commentLink() {
-               global $wgContLang, $wgTitle;
+               global $wgTitle, $wgOut;
 
                if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
                        return '';
                }
-               return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
-                       wfMsg( 'postcomment' ), 'action=edit&section=new' );
+               
+               # __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;
+               } elseif( $wgOut->showNewSectionLink() ) {
+                       $title =& $wgTitle;
+               } else {
+                       $title =& $wgTitle->getTalkPage();
+               }
+               
+               return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
        }
 
-       /* these are used extensively in SkinPHPTal, but also some other places */
-       /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
-               $title = Title::makeTitle( NS_SPECIAL, $name );
+       /* these are used extensively in SkinTemplate, but also some other places */
+       static function makeSpecialUrl( $name, $urlaction = '' ) {
+               $title = SpecialPage::getTitleFor( $name );
                return $title->getLocalURL( $urlaction );
        }
 
-       /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
-               $title = Title::newFromText( wfMsgForContent($name) );
-               $this->checkTitle($title, $name);
+       static function makeI18nUrl( $name, $urlaction = '' ) {
+               $title = Title::newFromText( wfMsgForContent( $name ) );
+               self::checkTitle( $title, $name );
                return $title->getLocalURL( $urlaction );
        }
 
-       /*static*/ function makeUrl ( $name, $urlaction='' ) {
+       static function makeUrl( $name, $urlaction = '' ) {
                $title = Title::newFromText( $name );
-               $this->checkTitle($title, $name);
+               self::checkTitle( $title, $name );
                return $title->getLocalURL( $urlaction );
        }
 
        # If url string starts with http, consider as external URL, else
        # internal
-       /*static*/ function makeInternalOrExternalUrl( $name ) {
+       static function makeInternalOrExternalUrl( $name ) {
                if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
                        return $name;
                } else {
-                       return $this->makeUrl( $name );
+                       return self::makeUrl( $name );
                }
        }
 
        # this can be passed the NS number as defined in Language.php
-       /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
+       static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
                $title = Title::makeTitleSafe( $namespace, $name );
-               $this->checkTitle($title, $name);
+               self::checkTitle( $title, $name );
                return $title->getLocalURL( $urlaction );
        }
 
        /* these return an array with the 'href' and boolean 'exists' */
-       /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
+       static function makeUrlDetails( $name, $urlaction = '' ) {
                $title = Title::newFromText( $name );
-               $this->checkTitle($title, $name);
+               self::checkTitle( $title, $name );
                return array(
                        'href' => $title->getLocalURL( $urlaction ),
-                       'exists' => $title->getArticleID() != 0?true:false
+                       'exists' => $title->getArticleID() != 0 ? true : false
                );
        }
 
        /**
         * Make URL details where the article exists (or at least it's convenient to think so)
         */
-       function makeKnownUrlDetails( $name, $urlaction='' ) {
+       static function makeKnownUrlDetails( $name, $urlaction = '' ) {
                $title = Title::newFromText( $name );
-               $this->checkTitle($title, $name);
+               self::checkTitle( $title, $name );
                return array(
                        'href' => $title->getLocalURL( $urlaction ),
                        'exists' => true
@@ -1377,10 +1552,10 @@ END;
        }
 
        # make sure we have some title to operate on
-       /*static*/ function checkTitle ( &$title, &$name ) {
-               if(!is_object($title)) {
+       static function checkTitle( &$title, &$name ) {
+               if( !is_object( $title ) ) {
                        $title = Title::newFromText( $name );
-                       if(!is_object($title)) {
+                       if( !is_object( $title ) ) {
                                $title = Title::newFromText( '--error: link target missing--' );
                        }
                }
@@ -1390,15 +1565,28 @@ END;
         * Build an array that represents the sidebar(s), the navigation bar among them
         *
         * @return array
-        * @access private
+        * @private
         */
        function buildSidebar() {
-               global $wgTitle, $action;
+               global $parserMemc, $wgEnableSidebarCache;
+               global $wgLang, $wgContLang;
 
                $fname = 'SkinTemplate::buildSidebar';
-               $pageurl = $wgTitle->getLocalURL();
+
                wfProfileIn( $fname );
 
+               $key = wfMemcKey( 'sidebar' );
+               $cacheSidebar = $wgEnableSidebarCache &&
+                       ($wgLang->getCode() == $wgContLang->getCode());
+               
+               if ($cacheSidebar) {
+                       $cachedsidebar = $parserMemc->get( $key );
+                       if ($cachedsidebar!="") {
+                               wfProfileOut($fname);
+                               return $cachedsidebar;
+                       }
+               }
+
                $bar = array();
                $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
                foreach ($lines as $line) {
@@ -1417,17 +1605,30 @@ END;
                                                $text = $line[1];
                                        if (wfEmptyMsg($line[0], $link))
                                                $link = $line[0];
-                                       $href = $this->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,
                                                'id' => 'n-' . strtr($line[1], ' ', '-'),
-                                               'active' => $pageurl == $href
+                                               'active' => false
                                        );
                                } else { continue; }
                        }
                }
-
+               if ($cacheSidebar)
+                       $parserMemc->set( $key, $bar, 86400 );
                wfProfileOut( $fname );
                return $bar;
        }