Merge "CologneBlue rewrite: fix talkLink() to use generic nav links"
[lhc/web/wiklou.git] / skins / CologneBlue.php
index 8cec484..32aa902 100644 (file)
@@ -44,12 +44,19 @@ class SkinCologneBlue extends SkinTemplate {
                $out->addModuleStyles( 'skins.cologneblue' );
        }
 
+       /**
+        * Override langlink formatting behavior not to uppercase the language names.
+        * See otherLanguages() in CologneBlueTemplate.
+        */
+       function formatLanguageName( $name ) {
+               return $name;
+       }
 }
 
 class CologneBlueTemplate extends BaseTemplate {
-       protected $mWatchLinkNum = 0; // Appended to end of watch link id's
-       
        function execute() {
+               // Suppress warnings to prevent notices about missing indexes in $this->data
+               wfSuppressWarnings();
                $this->html( 'headelement' );
                echo $this->beforeContent();
                $this->html( 'bodytext' );
@@ -58,245 +65,71 @@ class CologneBlueTemplate extends BaseTemplate {
                $this->html( 'dataAfterContent' );
                $this->printTrail();
                echo "\n</body></html>";
+               wfRestoreWarnings();
        }
-       
 
        /**
         * Language/charset variant links for classic-style skins
         * @return string
+        *
+        * @fixed
         */
        function variantLinks() {
-               $s = '';
-
-               /* show links to different language variants */
-               global $wgDisableLangConversion, $wgLang;
-
-               $title = $this->getSkin()->getTitle();
-               $lang = $title->getPageLanguage();
-               $variants = $lang->getVariants();
-
-               if ( !$wgDisableLangConversion && sizeof( $variants ) > 1
-                       && !$title->isSpecialPage() ) {
-                       foreach ( $variants as $code ) {
-                               $varname = $lang->getVariantname( $code );
-
-                               if ( $varname == 'disable' ) {
-                                       continue;
-                               }
-                               $s = $wgLang->pipeList( array(
-                                       $s,
-                                       '<a href="' . htmlspecialchars( $title->getLocalURL( 'variant=' . $code ) ) . '" lang="' . $code . '" hreflang="' . $code .  '">' . htmlspecialchars( $varname ) . '</a>'
-                               ) );
-                       }
-               }
-
-               return $s;
-       }
-
-       /**
-        * Compatibility for extensions adding functionality through tabs.
-        * Eventually these old skins should be replaced with SkinTemplate-based
-        * versions, sigh...
-        * @return string
-        * @todo Exterminate! ...that, and replace it with normal SkinTemplate stuff
-        */
-       function extensionTabLinks() {
-               $tabs = array();
-               $out = '';
                $s = array();
-               wfRunHooks( 'SkinTemplateTabs', array( $this->getSkin(), &$tabs ) );
-               foreach ( $tabs as $tab ) {
-                       $s[] = Xml::element( 'a',
-                               array( 'href' => $tab['href'] ),
-                               $tab['text'] );
-               }
 
-               if ( count( $s ) ) {
-                       global $wgLang;
+               $variants = $this->data['content_navigation']['variants'];
 
-                       $out = wfMessage( 'pipe-separator' )->escaped();
-                       $out .= $wgLang->pipeList( $s );
+               foreach ( $variants as $key => $link ) {
+                       $s[] = $this->makeListItem( $key, $link, array( 'tag' => 'span' ) );
                }
 
-               return $out;
+               return $this->getSkin()->getLanguage()->pipeList( $s );
        }
-       
-       function otherLanguages() {
-               global $wgOut, $wgLang, $wgHideInterlanguageLinks;
 
+       // @fixed
+       function otherLanguages() {
+               global $wgHideInterlanguageLinks;
                if ( $wgHideInterlanguageLinks ) {
-                       return '';
-               }
-
-               $a = $wgOut->getLanguageLinks();
-
-               if ( 0 == count( $a ) ) {
-                       return '';
+                       return "";
                }
 
-               $s = wfMessage( 'otherlanguages' )->text() . wfMessage( 'colon-separator' )->text();
-               $first = true;
-
-               if ( $wgLang->isRTL() ) {
-                       $s .= '<span dir="ltr">';
+               // We override SkinTemplate->formatLanguageName() in SkinCologneBlue
+               // not to capitalize the language names.
+               $language_urls = $this->data['language_urls'];
+               if ( empty( $language_urls ) ) {
+                       return "";
                }
 
-               foreach ( $a as $l ) {
-                       if ( !$first ) {
-                               $s .= wfMessage( 'pipe-separator' )->escaped();
-                       }
-
-                       $first = false;
-
-                       $nt = Title::newFromText( $l );
-                       $text = Language::fetchLanguageName( $nt->getInterwiki() );
-
-                       $s .= Html::element( 'a',
-                               array( 'href' => $nt->getFullURL(), 'title' => $nt->getText(), 'class' => "external" ),
-                               $text == '' ? $l : $text );
-               }
-
-               if ( $wgLang->isRTL() ) {
-                       $s .= '</span>';
+               $s = array();
+               foreach ( $language_urls as $key => $data ) {
+                       $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
                }
 
-               return $s;
+               return wfMessage( 'otherlanguages' )->text()
+                       . wfMessage( 'colon-separator' )->text()
+                       . $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
+       // @fixed
        function pageTitleLinks() {
-               global $wgOut, $wgUser, $wgRequest, $wgLang;
-
-               $oldid = $wgRequest->getVal( 'oldid' );
-               $diff = $wgRequest->getVal( 'diff' );
-               $action = $wgRequest->getText( 'action' );
-
-               $skin = $this->getSkin();
-               $title = $skin->getTitle();
-
-               $s[] = $this->printableLink();
-               $disclaimer = $skin->disclaimerLink(); # may be empty
-
-               if ( $disclaimer ) {
-                       $s[] = $disclaimer;
-               }
-
-               $privacy = $skin->privacyLink(); # may be empty too
-
-               if ( $privacy ) {
-                       $s[] = $privacy;
-               }
-
-               if ( $wgOut->isArticleRelated() ) {
-                       if ( $title->getNamespace() == NS_FILE ) {
-                               $image = wfFindFile( $title );
-
-                               if ( $image ) {
-                                       $href = $image->getURL();
-                                       $s[] = Html::element( 'a', array( 'href' => $href,
-                                               'title' => $href ), $title->getText() );
-
-                               }
-                       }
-               }
-
-               if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
-                       $s[] .= Linker::linkKnown(
-                               $title,
-                               wfMessage( 'currentrev' )->text()
-                       );
-               }
-
-               if ( $wgUser->getNewtalk() ) {
-                       # do not show "You have new messages" text when we are viewing our
-                       # own talk page
-                       if ( !$title->equals( $wgUser->getTalkPage() ) ) {
-                               $tl = Linker::linkKnown(
-                                       $wgUser->getTalkPage(),
-                                       wfMessage( 'newmessageslink' )->escaped(),
-                                       array(),
-                                       array( 'redirect' => 'no' )
-                               );
-
-                               $dl = Linker::linkKnown(
-                                       $wgUser->getTalkPage(),
-                                       wfMessage( 'newmessagesdifflink' )->escaped(),
-                                       array(),
-                                       array( 'diff' => 'cur' )
-                               );
-                               $s[] = '<strong>' . wfMessage( 'youhavenewmessages', $tl, $dl )->text() . '</strong>';
-                               # disable caching
-                               $wgOut->setSquidMaxage( 0 );
-                               $wgOut->enableClientCache( false );
-                       }
-               }
-
-               $undelete = $skin->getUndeleteLink();
-
-               if ( !empty( $undelete ) ) {
-                       $s[] = $undelete;
-               }
-
-               return $wgLang->pipeList( $s );
-       }
-
-       function printableLink() {
-               global $wgOut, $wgRequest, $wgLang;
-
                $s = array();
+               $footlinks = $this->getFooterLinks();
 
-               if ( !$wgOut->isPrintable() ) {
-                       $printurl = htmlspecialchars( $this->getSkin()->getTitle()->getLocalUrl(
-                               $wgRequest->appendQueryValue( 'printable', 'yes', true ) ) );
-                       $s[] = "<a href=\"$printurl\" rel=\"alternate\">"
-                               . wfMessage( 'printableversion' )->text() . '</a>';
-               }
-
-               if ( $wgOut->isSyndicated() ) {
-                       foreach ( $wgOut->getSyndicationLinks() as $format => $link ) {
-                               $feedurl = htmlspecialchars( $link );
-                               $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
-                                               . " class=\"feedlink\">" . wfMessage( "feed-$format" )->escaped() . "</a>";
-                       }
-               }
-               return $wgLang->pipeList( $s );
-       }
-
-       /**
-        * Gets the h1 element with the page title.
-        * @return string
-        */
-       function pageTitle() {
-               global $wgOut;
-               $s = '<h1 class="pagetitle"><span dir="auto">' . $wgOut->getPageTitle() . '</span></h1>';
-               return $s;
-               }
-
-       function pageSubtitle() {
-               global $wgOut;
-
-               $sub = $wgOut->getSubtitle();
-
-               if ( $sub == '' ) {
-                       global $wgExtraSubtitle;
-                       $sub = wfMessage( 'tagline' )->parse() . $wgExtraSubtitle;
+               foreach ( $footlinks['places'] as $item ) {
+                       $s[] = $this->data[$item];
                }
 
-               $subpages = $this->getSkin()->subPageSubtitle();
-               $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
-               $s = "<p class='subtitle'>{$sub}</p>\n";
-
-               return $s;
+               return $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
        function bottomLinks() {
-               global $wgOut, $wgUser;
                $sep = wfMessage( 'pipe-separator' )->escaped() . "\n";
 
                $s = '';
-               if ( $wgOut->isArticleRelated() ) {
+               if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
                        $element[] = '<strong>' . $this->editThisPage() . '</strong>';
 
-                       if ( $wgUser->isLoggedIn() ) {
+                       if ( $this->getSkin()->getUser()->isLoggedIn() ) {
                                $element[] = $this->watchThisPage();
                        }
 
@@ -330,15 +163,15 @@ class CologneBlueTemplate extends BaseTemplate {
                                $s .= "\n<br />";
 
                                // Delete/protect/move links for privileged users
-                               if ( $wgUser->isAllowed( 'delete' ) ) {
+                               if ( $this->getSkin()->getUser()->isAllowed( 'delete' ) ) {
                                        $s .= $this->deleteThisPage();
                                }
 
-                               if ( $wgUser->isAllowed( 'protect' ) ) {
+                               if ( $this->getSkin()->getUser()->isAllowed( 'protect' ) ) {
                                        $s .= $sep . $this->protectThisPage();
                                }
 
-                               if ( $wgUser->isAllowed( 'move' ) ) {
+                               if ( $this->getSkin()->getUser()->isAllowed( 'move' ) ) {
                                        $s .= $sep . $this->moveThisPage();
                                }
                        }
@@ -350,9 +183,7 @@ class CologneBlueTemplate extends BaseTemplate {
        }
 
        function editThisPage() {
-               global $wgOut;
-
-               if ( !$wgOut->isArticleRelated() ) {
+               if ( !$this->getSkin()->getOutput()->isArticleRelated() ) {
                        $s = wfMessage( 'protectedpage' )->text();
                } else {
                        $title = $this->getSkin()->getTitle();
@@ -376,12 +207,10 @@ class CologneBlueTemplate extends BaseTemplate {
        }
 
        function deleteThisPage() {
-               global $wgUser, $wgRequest;
-
-               $diff = $wgRequest->getVal( 'diff' );
+               $diff = $this->getSkin()->getRequest()->getVal( 'diff' );
                $title = $this->getSkin()->getTitle();
 
-               if ( $title->getArticleID() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
+               if ( $title->getArticleID() && ( !$diff ) && $this->getSkin()->getUser()->isAllowed( 'delete' ) ) {
                        $t = wfMessage( 'deletethispage' )->text();
 
                        $s = Linker::linkKnown(
@@ -398,12 +227,10 @@ class CologneBlueTemplate extends BaseTemplate {
        }
 
        function protectThisPage() {
-               global $wgUser, $wgRequest;
-
-               $diff = $wgRequest->getVal( 'diff' );
+               $diff = $this->getSkin()->getRequest()->getVal( 'diff' );
                $title = $this->getSkin()->getTitle();
 
-               if ( $title->getArticleID() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
+               if ( $title->getArticleID() && ( ! $diff ) && $this->getSkin()->getUser()->isAllowed( 'protect' ) ) {
                        if ( $title->isProtected() ) {
                                $text = wfMessage( 'unprotectthispage' )->text();
                                $query = array( 'action' => 'unprotect' );
@@ -426,27 +253,24 @@ class CologneBlueTemplate extends BaseTemplate {
        }
 
        function watchThisPage() {
-               global $wgOut, $wgUser;
-               ++$this->mWatchLinkNum;
-
                // Cache
                $title = $this->getSkin()->getTitle();
 
-               if ( $wgOut->isArticleRelated() ) {
-                       if ( $wgUser->isWatched( $title ) ) {
+               if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
+                       if ( $this->getSkin()->getUser()->isWatched( $title ) ) {
                                $text = wfMessage( 'unwatchthispage' )->text();
                                $query = array(
                                        'action' => 'unwatch',
-                                       'token' => UnwatchAction::getUnwatchToken( $title, $wgUser ),
+                                       'token' => UnwatchAction::getUnwatchToken( $title, $this->getSkin()->getUser() ),
                                );
-                               $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
+                               $id = 'mw-unwatch-link';
                        } else {
                                $text = wfMessage( 'watchthispage' )->text();
                                $query = array(
                                        'action' => 'watch',
-                                       'token' => WatchAction::getWatchToken( $title, $wgUser ),
+                                       'token' => WatchAction::getWatchToken( $title, $this->getSkin()->getUser() ),
                                );
-                               $id = 'mw-watch-link' . $this->mWatchLinkNum;
+                               $id = 'mw-watch-link';
                        }
 
                        $s = Linker::linkKnown(
@@ -507,9 +331,7 @@ class CologneBlueTemplate extends BaseTemplate {
        }
 
        function watchPageLinksLink() {
-               global $wgOut;
-
-               if ( !$wgOut->isArticleRelated() ) {
+               if ( !$this->getSkin()->getOutput()->isArticleRelated() ) {
                        return wfMessage( 'parentheses', wfMessage( 'notanarticle' )->text() )->escaped();
                } else {
                        return Linker::linkKnown(
@@ -519,202 +341,178 @@ class CologneBlueTemplate extends BaseTemplate {
                }
        }
 
+       // @fixed
        function talkLink() {
                $title = $this->getSkin()->getTitle();
-               if ( NS_SPECIAL == $title->getNamespace() ) {
-                       # No discussion links for special pages
-                       return '';
-               }
-
-               $linkOptions = array();
-
-               if ( $title->isTalkPage() ) {
-                       $link = $title->getSubjectPage();
-                       switch( $link->getNamespace() ) {
-                               case NS_MAIN:
-                                       $text = wfMessage( 'articlepage' );
-                                       break;
-                               case NS_USER:
-                                       $text = wfMessage( 'userpage' );
-                                       break;
-                               case NS_PROJECT:
-                                       $text = wfMessage( 'projectpage' );
-                                       break;
-                               case NS_FILE:
-                                       $text = wfMessage( 'imagepage' );
-                                       # Make link known if image exists, even if the desc. page doesn't.
-                                       if ( wfFindFile( $link ) )
-                                               $linkOptions[] = 'known';
-                                       break;
-                               case NS_MEDIAWIKI:
-                                       $text = wfMessage( 'mediawikipage' );
-                                       break;
-                               case NS_TEMPLATE:
-                                       $text = wfMessage( 'templatepage' );
-                                       break;
-                               case NS_HELP:
-                                       $text = wfMessage( 'viewhelppage' );
-                                       break;
-                               case NS_CATEGORY:
-                                       $text = wfMessage( 'categorypage' );
-                                       break;
-                               default:
-                                       $text = wfMessage( 'articlepage' );
-                       }
-               } else {
-                       $link = $title->getTalkPage();
-                       $text = wfMessage( 'talkpage' );
-               }
-
-               $s = Linker::link( $link, $text->text(), array(), array(), $linkOptions );
 
-               return $s;
-       }
-
-       function commentLink() {
-               global $wgOut;
+               if ( $title->getNamespace() == NS_SPECIAL ) {
+                       // No discussion links for special pages
+                       return "";
+               }
+
+               $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
+               $companionNamespace = $companionTitle->getNamespace();
+
+               // TODO these messages appear to only be used by CologneBlue and legacy skins,
+               // kill and replace with something more sensibly named?
+               $nsToMessage = array(
+                       NS_MAIN => 'articlepage',
+                       NS_USER => 'userpage',
+                       NS_PROJECT => 'projectpage',
+                       NS_FILE => 'imagepage',
+                       NS_MEDIAWIKI => 'mediawikipage',
+                       NS_TEMPLATE => 'templatepage',
+                       NS_HELP => 'viewhelppage',
+                       NS_CATEGORY => 'categorypage',
+                       NS_FILE => 'imagepage',
+               );
 
-               $title = $this->getSkin()->getTitle();
-               if ( $title->isSpecialPage() ) {
-                       return '';
+               // Find out the message to use for link text. Use either the array above or,
+               // for non-talk pages, a generic "discuss this" message.
+               // Default is the same as for main namespace.
+               if ( isset( $nsToMessage[$companionNamespace] ) ) {
+                       $message = $nsToMessage[$companionNamespace];
+               } else {
+                       $message = $companionTitle->isTalkPage() ? 'talkpage' : 'articlepage';
                }
 
-               # __NEWSECTIONLINK___ changes behaviour here
-               # If it is present, the link points to this page, otherwise
-               # it points to the talk page
-               if ( !$title->isTalkPage() && !$wgOut->showNewSectionLink() ) {
-                       $title = $title->getTalkPage();
+               // Obviously this can't be reasonable and just return the key for talk namespace, only for content ones.
+               // Thus we have to mangle it in exactly the same way SkinTemplate does. (bug 40805)
+               $key = $companionTitle->getNamespaceKey( '' );
+               if ( $companionTitle->isTalkPage() ) {
+                       $key = ( $key == 'main' ? 'talk' : $key . "_talk" );
                }
 
-               return Linker::linkKnown(
-                       $title,
-                       wfMessage( 'postcomment' )->text(),
-                       array(),
-                       array(
-                               'action' => 'edit',
-                               'section' => 'new'
-                       )
-               );
-       }
+               // Use the regular navigational link, but replace its text. Everything else stays unmodified.
+               $namespacesLinks = $this->data['content_navigation']['namespaces'];
+               $link = $this->processNavlinkForDocument( $namespacesLinks[ $key ] );
+               $link['text'] = wfMessage( $message )->text();
 
-       function getUploadLink() {
-               global $wgUploadNavigationUrl;
-
-               if ( $wgUploadNavigationUrl ) {
-                       # Using an empty class attribute to avoid automatic setting of "external" class
-                       return Linker::makeExternalLink( $wgUploadNavigationUrl,
-                               wfMessage( 'upload' )->escaped(),
-                               false, null, array( 'class' => '' ) );
-               } else {
-                       return Linker::linkKnown(
-                               SpecialPage::getTitleFor( 'Upload' ),
-                               wfMessage( 'upload' )->escaped()
-                       );
-               }
+               return $this->makeListItem( $message, $link, array( 'tag' => 'span' ) );
        }
 
-       function pageStats() {
-               $ret = array();
-               $items = array( 'viewcount', 'credits', 'lastmod', 'numberofwatchingusers', 'copyright' );
-
-               foreach( $items as $item ) {
-                       if ( $this->data[$item] !== false ) {
-                               $ret[] = $this->data[$item];
+       /**
+        * Takes a navigational link generated by SkinTemplate in whichever way
+        * and mangles attributes unsuitable for repeated use. In particular, this modifies the ids
+        * and removes the accesskeys. This is necessary to be able to use the same navlink twice,
+        * e.g. in sidebar and in footer.
+        *
+        * @param $navlink array Navigational link generated by SkinTemplate
+        * @param $idPrefix mixed Prefix to add to id of this navlink. If false, id is removed entirely. Default is 'cb-'.
+        */
+       function processNavlinkForDocument( $navlink, $idPrefix='cb-' ) {
+               if ( $navlink['id'] ) {
+                       $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
+                       $navlink['tooltiponly'] = true; // but no accesskeys
+
+                       // mangle or remove the id
+                       if ( $idPrefix === false ) {
+                               unset( $navlink['id'] );
+                       } else {
+                               $navlink['id'] =  $idPrefix . $navlink['id'];
                        }
                }
 
-               return implode( ' ', $ret );
+               return $navlink;
        }
 
-
-
-
-       
        /**
         * @return string
+        *
+        * @fixed
         */
        function beforeContent() {
-               $mainPageObj = Title::newMainPage();
-
-               $s = "\n<div id='content'>\n<div id='topbar'>" .
-                 '<table style="width: 100%;" cellspacing="0" cellpadding="8"><tr>';
-
-               $s .= '<td class="top" nowrap="nowrap">';
-               $s .= '<a href="' . htmlspecialchars( $mainPageObj->getLocalURL() ) . '">';
-               $s .= '<span id="sitetitle">' . wfMessage( 'sitetitle' )->escaped() . '</span></a>';
-
-               $s .= '</td><td class="top" id="top-syslinks" style="width: 100%;">';
-               $s .= $this->sysLinks();
-               $s .= '</td></tr><tr><td class="top-subheader">';
-
-               $s .= '<font size="-1"><span id="sitesub">';
-               $s .= wfMessage( 'sitesubtitle' )->escaped() . '</span></font>';
-               $s .= '</td><td class="top-linkcollection">';
-
-               $s .= '<font size="-1"><span id="langlinks">';
-               $s .= str_replace( '<br />', '', $this->otherLanguages() );
-
-               $s .= $this->getSkin()->getCategories();
-
-               $s .= '<br />' . $this->pageTitleLinks();
-               $s .= '</span></font>';
-
-               $s .= "</td></tr></table>\n";
-
-               $s .= "\n</div>\n<div id='article'>";
+               ob_start();
+?>
+<div id="content">
+       <div id="topbar">
+               <p id="sitetitle">
+                       <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
+                               <?php echo wfMessage( 'sitetitle' )->escaped() ?>
+                       </a>
+               </p>
+               <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
+               <div id="toplinks">
+                       <p id="syslinks"><?php echo $this->sysLinks() ?></p>
+                       <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
+               </div>
+               <div id="linkcollection">
+                       <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
+                       <?php echo $this->getSkin()->getCategories() ?>
+                       <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
+                       <?php if ( $this->data['newtalk'] ) { ?>
+                       <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
+                       <?php } ?>
+               </div>
+       </div>
+       <div id="article">
+               <?php if ( $this->getSkin()->getSiteNotice() ) { ?>
+               <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
+               <?php } ?>
+               <h1 id="firstHeading"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
+               <?php if ( $this->translator->translate( 'tagline' ) ) { ?>
+               <p class="tagline"><?php echo htmlspecialchars( $this->translator->translate( 'tagline' ) ) ?></p>
+               <?php } ?>
+               <?php if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?>
+               <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
+               <?php } ?>
+               <?php if ( $this->getSkin()->subPageSubtitle() ) { ?>
+               <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
+               <?php } ?>
+<?php
+               $s = ob_get_contents();
+               ob_end_clean();
 
-               $notice = $this->getSkin()->getSiteNotice();
-               if( $notice ) {
-                       $s .= "\n<div id='siteNotice'>$notice</div>\n";
-               }
-               $s .= $this->pageTitle();
-               $s .= $this->pageSubtitle() . "\n";
                return $s;
        }
 
        /**
         * @return string
+        *
+        * @fixed
         */
-       function afterContent(){
-               $s = "\n</div><br clear='all' />\n";
-
-               $s .= "\n<div id='footer'>";
-               $s .= '<table style="width: 98%;" cellspacing="0"><tr>';
-
-               $s .= '<td class="bottom">';
+       function afterContent() {
+               ob_start();
+?>
+       </div>
+       <div id='footer'>
+<?php
+               // Page-related links
+               echo $this->bottomLinks();
+               echo "\n<br />";
 
-               $s .= $this->bottomLinks();
-               $s .= $this->getSkin()->getLanguage()->pipeList( array(
-                       "\n<br />" . Linker::linkKnown(
-                               Title::newMainPage()
-                       ),
+               // Footer and second searchbox
+               echo $this->getSkin()->getLanguage()->pipeList( array(
+                       $this->getSkin()->mainPageLink(),
                        $this->getSkin()->aboutLink(),
-                       $this->searchForm( wfMessage( 'qbfind' )->text() )
+                       $this->searchForm( 'footer' )
                ) );
+               echo "\n<br />";
 
-               $s .= "\n<br />" . $this->pageStats();
-
-               $s .= '</td>';
-               $s .= "</tr></table>\n</div>\n</div>\n";
+               // Standard footer info
+               $footlinks = $this->getFooterLinks();
+               if ( $footlinks['info'] ) {
+                       foreach ( $footlinks['info'] as $item ) {
+                               echo $this->data[$item] . ' ';
+                       }
+               }
+?>
+       </div>
+</div>
+<?php echo $this->quickBar() ?>
+<?php
+               $s = ob_get_contents();
+               ob_end_clean();
 
-               $s .= $this->quickBar();
                return $s;
        }
 
        /**
         * @return string
+        *
+        * @fixed
         */
        function sysLinks() {
-               $li = SpecialPage::getTitleFor( 'Userlogin' );
-               $lo = SpecialPage::getTitleFor( 'Userlogout' );
-
-               $rt = $this->getSkin()->getTitle()->getPrefixedURL();
-               if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
-                       $q = array();
-               } else {
-                       $q = array( 'returnto' => $rt );
-               }
-
                $s = array(
                        $this->getSkin()->mainPageLink(),
                        Linker::linkKnown(
@@ -729,221 +527,179 @@ class CologneBlueTemplate extends BaseTemplate {
                                Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
                                wfMessage( 'faq' )->text()
                        ),
-                       Linker::specialLink( 'Specialpages' )
                );
 
-               /* show links to different language variants */
-               if( $this->variantLinks() ) {
-                       $s[] = $this->variantLinks();
-               }
-               if( $this->extensionTabLinks() ) {
-                       $s[] = $this->extensionTabLinks();
-               }
-               if ( $this->data['loggedin'] ) {
-                       $s[] = Linker::linkKnown(
-                               $lo,
-                               wfMessage( 'logout' )->text(),
-                               array(),
-                               $q
-                       );
-               } else {
-                       $s[] = Linker::linkKnown(
-                               $li,
-                               wfMessage( 'login' )->text(),
-                               array(),
-                               $q
-                       );
+               $personalUrls = $this->getPersonalTools();
+               foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
+                       if ( $personalUrls[$key] ) {
+                               $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
+                       }
                }
 
                return $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
+       /**
+        * @param $heading string
+        * @return string
+        *
+        * @fixed
+        */
+       function menuHead( $heading ) {
+               return "\n<h6>" . htmlspecialchars( $heading ) . "</h6>";
+       }
+
        /**
         * Compute the sidebar
         * @access private
         *
         * @return string
+        *
+        * @fixed
         */
        function quickBar(){
                $s = "\n<div id='quickbar'>";
 
-               $sep = '<br />';
-               $s .= $this->menuHead( 'qbfind' );
-               $s .= $this->searchForm();
+               $sep = "<br />\n";
 
-               $s .= $this->menuHead( 'qbbrowse' );
+               $plain_bar = $this->data['sidebar'];
+               $bar = array();
 
-               # Use the first heading from the Monobook sidebar as the "browse" section
-               $bar = $this->getSkin()->buildSidebar();
-               unset( $bar['SEARCH'] );
-               unset( $bar['LANGUAGES'] );
-               unset( $bar['TOOLBOX'] );
-
-               $barnumber = 1;
-               foreach ( $bar as $heading => $browseLinks ) {
-                       if ( $barnumber > 1 ) {
-                               $headingMsg = wfMessage( $heading );
-                               if ( $headingMsg->exists() ) {
-                                       $h = $headingMsg->text();
-                               } else {
-                                       $h = $heading;
-                               }
-                               $s .= "\n<h6>" . htmlspecialchars( $h ) . "</h6>";
-                       }
-                       if( is_array( $browseLinks ) ) {
-                               foreach ( $browseLinks as $link ) {
-                                       if ( $link['text'] != '-' ) {
-                                               $s .= "<a href=\"{$link['href']}\">" .
-                                                       htmlspecialchars( $link['text'] ) . '</a>' . $sep;
-                                       }
-                               }
-                       }
-                       $barnumber++;
-               }
+               // Massage the sidebar
+               // We want to place SEARCH at the beginning and a lot of stuff before TOOLBOX (or at the end, if it's missing)
+               $additions_done = false;
+               while ( !$additions_done ) {
+                       $bar = array(); // Empty it out
 
-               $user = $this->getSkin()->getUser();
+                       // Always display search on top
+                       $bar['SEARCH'] = true;
 
-               if ( $this->data['isarticle'] ) {
-                       $s .= $this->menuHead( 'qbedit' );
-                       $s .= '<strong>' . $this->editThisPage() . '</strong>';
+                       foreach ( $plain_bar as $heading => $links ) {
+                               if ( $heading == 'TOOLBOX' ) {
+                                       if( $links !== NULL ) {
+                                               // If this is not a toolbox prosthetic we inserted outselves, fill it out
+                                               $plain_bar['TOOLBOX'] = $this->getToolbox();
+                                       }
 
-                       $s .= $sep . Linker::linkKnown(
-                               Title::newFromText( wfMessage( 'edithelppage' )->inContentLanguage()->text() ),
-                               wfMessage( 'edithelp' )->text()
-                       );
+                                       // And insert the stuff
+
+                                       // "This page" and "Edit" menus
+                                       // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
+                                       // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
+                                       // We also don't use $...['variants'], these are displayed in the top menu.
+                                       $content_navigation = $this->data['content_navigation'];
+                                       $qbpageoptions = array_merge(
+                                               $content_navigation['namespaces'],
+                                               array(
+                                                       'history' => $content_navigation['views']['history'],
+                                                       'watch' => $content_navigation['actions']['watch'],
+                                                       'unwatch' => $content_navigation['actions']['unwatch'],
+                                               )
+                                       );
+                                       $content_navigation['actions']['watch'] = null;
+                                       $content_navigation['actions']['unwatch'] = null;
+                                       $qbedit = array_merge(
+                                               array(
+                                                       'edit' => $content_navigation['views']['edit'],
+                                                       'addsection' => $content_navigation['views']['addsection'],
+                                               ),
+                                               $content_navigation['actions']
+                                       );
+                                       $bar['qbedit'] = $qbedit;
+                                       $bar['qbpageoptions'] = $qbpageoptions;
+
+                                       // Personal tools ("My pages")
+                                       $bar['qbmyoptions'] = $this->getPersonalTools();
+                                       foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
+                                               $bar['qbmyoptions'][$key] = null;
+                                       }
 
-                       if( $this->data['loggedin'] ) {
-                               $s .= $sep . $this->moveThisPage();
-                       }
-                       if ( $user->isAllowed( 'delete' ) ) {
-                               $dtp = $this->deleteThisPage();
-                               if ( $dtp != '' ) {
-                                       $s .= $sep . $dtp;
+                                       $additions_done = true;
                                }
-                       }
-                       if ( $user->isAllowed( 'protect' ) ) {
-                               $ptp = $this->protectThisPage();
-                               if ( $ptp != '' ) {
-                                       $s .= $sep . $ptp;
-                               }
-                       }
-                       $s .= $sep;
-
-                       $s .= $this->menuHead( 'qbpageoptions' );
-                       $s .= $this->talkLink()
-                                       . $sep . $this->commentLink()
-                                       . $sep . $this->printableLink();
-                       if ( $this->data['loggedin'] ) {
-                               $s .= $sep . $this->watchThisPage();
-                       }
 
-                       $s .= $sep;
-
-                       $s .= $this->menuHead( 'qbpageinfo' )
-                                       . $this->historyLink()
-                                       . $sep . $this->whatLinksHere()
-                                       . $sep . $this->watchPageLinksLink();
-
-                       $title = $this->getSkin()->getTitle();
-                       $tns = $title->getNamespace();
-                       if ( $tns == NS_USER || $tns == NS_USER_TALK ) {
-                               $id = User::idFromName( $title->getText() );
-                               if( $id != 0 ) {
-                                       $s .= $sep . $this->userContribsLink();
-                                       if( $this->getSkin()->showEmailUser( $id ) ) {
-                                               $s .= $sep . $this->emailUserLink();
-                                       }
+                               // Re-insert current heading, unless it's SEARCH
+                               if ( $heading != 'SEARCH' ) {
+                                       $bar[$heading] = $plain_bar[$heading];
                                }
                        }
-                       $s .= $sep;
-               }
 
-               $s .= $this->menuHead( 'qbmyoptions' );
-               if ( $this->data['loggedin'] ) {
-                       $tl = Linker::linkKnown(
-                               $user->getTalkPage(),
-                               wfMessage( 'mytalk' )->escaped()
-                       );
-                       if ( $user->getNewtalk() ) {
-                               $tl .= ' *';
+                       // If TOOLBOX is missing, $additions_done is still false
+                       if ( !$additions_done ) {
+                               $plain_bar['TOOLBOX'] = false;
                        }
-
-                       $s .= Linker::linkKnown(
-                                       $user->getUserPage(),
-                                       wfMessage( 'mypage' )->escaped()
-                               ) . $sep . $tl . $sep . Linker::specialLink( 'Watchlist' )
-                                       . $sep .
-                               Linker::linkKnown(
-                                       SpecialPage::getSafeTitleFor( 'Contributions', $user->getName() ),
-                                       wfMessage( 'mycontris' )->escaped()
-                               ) . $sep . Linker::specialLink( 'Preferences' )
-                               . $sep . Linker::specialLink( 'Userlogout' );
-               } else {
-                       $s .= Linker::specialLink( 'Userlogin' );
                }
 
-               $s .= $this->menuHead( 'qbspecialpages' )
-                       . Linker::specialLink( 'Newpages' )
-                       . $sep . Linker::specialLink( 'Listfiles' )
-                       . $sep . Linker::specialLink( 'Statistics' );
-               if( UploadBase::isEnabled() && UploadBase::isAllowed( $user ) === true ) {
-                       $s .= $sep . $this->getUploadLink();
-               }
+               foreach ( $bar as $heading => $links ) {
+                       if ( $heading == 'SEARCH' ) {
+                               $s .= $this->menuHead( wfMessage( 'qbfind' )->text() );
+                               $s .= $this->searchForm( 'sidebar' );
+                       } elseif ( $heading == 'LANGUAGES' ) {
+                               // discard these; we display languages below page content
+                       } elseif ( $links ) {
+                               if ( is_array( $links ) ) {
+                                       // Use the navigation heading from standard sidebar as the "browse" section
+                                       if ( $heading == 'navigation' ) {
+                                               $heading = 'qbbrowse';
+                                       }
+                                       if ( $heading == 'TOOLBOX' ) {
+                                               $heading = 'toolbox';
+                                       }
 
-               global $wgSiteSupportPage;
+                                       $headingMsg = wfMessage( $heading );
+                                       $any_link = false;
+                                       $t = $this->menuHead( $headingMsg->exists() ? $headingMsg->text() : $heading );
 
-               if( $wgSiteSupportPage ) {
-                       $s .= $sep . '<a href="' . htmlspecialchars( $wgSiteSupportPage ) . '" class="internal">'
-                                       . wfMessage( 'sitesupport' )->escaped() . '</a>';
-               }
+                                       foreach ( $links as $key => $link ) {
+                                               // Can be empty due to rampant sidebar massaging we're doing above
+                                               if ( $link ) {
+                                                       $any_link = true;
+                                                       $t .= $this->makeListItem( $key, $link, array( 'tag' => 'span' ) ) . $sep;
+                                               }
+                                       }
 
-               $s .= $sep . Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Specialpages' ),
-                       wfMessage( 'moredotdotdot' )->text()
-               );
+                                       if ( $any_link ) {
+                                               $s .= $t;
+                                       }
+                               } else {
+                                       // $links can be a HTML string
+                                       $s .= $links;
+                               }
+                       }
+               }
 
                $s .= $sep . "\n</div>\n";
                return $s;
        }
 
-       /**
-        * @param $key string
-        * @return string
-        */
-       function menuHead( $key ) {
-               $s = "\n<h6>" . wfMessage( $key )->text() . "</h6>";
-               return $s;
-       }
-
        /**
         * @param $label string
         * @return string
+        *
+        * @fixed
         */
-       function searchForm( $label = '' ) {
+       function searchForm( $which ) {
                global $wgUseTwoButtonsSearchForm;
 
                $search = $this->getSkin()->getRequest()->getText( 'search' );
                $action = $this->data['searchaction'];
-               $s = "<form id=\"searchform{$this->searchboxes}\" method=\"get\" class=\"inline\" action=\"$action\">";
-               if( $label != '' ) {
-                       $s .= "{$label}: ";
+               $s = "<form id=\"searchform-" . htmlspecialchars($which) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
+               if( $which == 'footer' ) {
+                       $s .= wfMessage( 'qbfind' )->text() . ": ";
                }
 
-               $s .= "<input type='text' id=\"searchInput{$this->searchboxes}\" class=\"mw-searchInput\" name=\"search\" size=\"14\" value=\""
-                       . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" /><br />"
-                       . "<input type='submit' id=\"searchGoButton{$this->searchboxes}\" class=\"searchButton\" name=\"go\" value=\"" . wfMessage( 'searcharticle' )->escaped() . "\" />";
+               $s .= "<input type='text' class=\"mw-searchInput\" name=\"search\" size=\"14\" value=\""
+                       . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />"
+                       . ($which == 'footer' ? " " : "<br />")
+                       . "<input type='submit' class=\"searchButton\" name=\"go\" value=\"" . wfMessage( 'searcharticle' )->escaped() . "\" />";
 
                if( $wgUseTwoButtonsSearchForm ) {
-                       $s .= "<input type='submit' id=\"mw-searchButton{$this->searchboxes}\" class=\"searchButton\" name=\"fulltext\" value=\"" . wfMessage( 'search' )->escaped() . "\" />\n";
+                       $s .= " <input type='submit' class=\"searchButton\" name=\"fulltext\" value=\"" . wfMessage( 'searchbutton' )->escaped() . "\" />\n";
                } else {
                        $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
                }
 
                $s .= '</form>';
 
-               // Ensure unique id's for search boxes made after the first
-               $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
-
                return $s;
        }
 }