fixes Bug 26459 - The renderNavigation and renderPortals functions should be protecte...
[lhc/web/wiklou.git] / skins / Vector.php
index b57432e..74b2fff 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
- * Vector - Branch of MonoBook which has many usability improvements and
- * somewhat cleaner code.
+ * Vector - Modern version of MonoBook with fresh look and many usability
+ * improvements.
  *
  * @todo document
  * @file
@@ -18,7 +18,6 @@ if( !defined( 'MEDIAWIKI' ) ) {
  */
 class SkinVector extends SkinTemplate {
 
-       /* Functions */
        var $skinname = 'vector', $stylename = 'vector',
                $template = 'VectorTemplate', $useHeadElement = true;
 
@@ -34,11 +33,14 @@ class SkinVector extends SkinTemplate {
                // Append CSS which includes IE only behavior fixes for hover support -
                // this is better than including this in a CSS fille since it doesn't
                // wait for the CSS file to load before fetching the HTC file.
-               $out->addScript(
+               $min = $this->getRequest()->getFuzzyBool( 'debug' ) ? '' : '.min';
+               $out->addHeadItem( 'csshover',
                        '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' .
                                htmlspecialchars( $wgLocalStylePath ) .
-                               "/{$this->stylename}/csshover.htc\")}</style><![endif]-->"
+                               "/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->"
                );
+
+               $out->addModuleScripts( 'skins.vector' );
        }
 
        /**
@@ -50,348 +52,56 @@ class SkinVector extends SkinTemplate {
                parent::setupSkinUserCss( $out );
                $out->addModuleStyles( 'skins.vector' );
        }
-
-       /**
-        * Builds a structured array of links used for tabs and menus
-        * @return array
-        * @private
-        */
-       function buildNavigationUrls() {
-               global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
-               global $wgDisableLangConversion, $wgVectorUseIconWatch;
-
-               wfProfileIn( __METHOD__ );
-
-               $links = array(
-                       'namespaces' => array(),
-                       'views' => array(),
-                       'actions' => array(),
-                       'variants' => array()
-               );
-
-               // Detects parameters
-               $action = $wgRequest->getVal( 'action', 'view' );
-               $section = $wgRequest->getVal( 'section' );
-
-               // Checks if page is some kind of content
-               if( $this->iscontent ) {
-                       // Gets page objects for the related namespaces
-                       $subjectPage = $this->mTitle->getSubjectPage();
-                       $talkPage = $this->mTitle->getTalkPage();
-
-                       // Determines if this is a talk page
-                       $isTalk = $this->mTitle->isTalkPage();
-
-                       // Generates XML IDs from namespace names
-                       $subjectId = $this->mTitle->getNamespaceKey( '' );
-
-                       if ( $subjectId == 'main' ) {
-                               $talkId = 'talk';
-                       } else {
-                               $talkId = "{$subjectId}_talk";
-                       }
-
-                       // Adds namespace links
-                       $links['namespaces'][$subjectId] = $this->tabAction(
-                               $subjectPage, 'nstab-' . $subjectId, !$isTalk, '', true
-                       );
-                       $links['namespaces'][$subjectId]['context'] = 'subject';
-                       $links['namespaces'][$talkId] = $this->tabAction(
-                               $talkPage, 'talk', $isTalk, '', true
-                       );
-                       $links['namespaces'][$talkId]['context'] = 'talk';
-
-                       // Adds view view link
-                       if ( $this->mTitle->exists() ) {
-                               $links['views']['view'] = $this->tabAction(
-                                       $isTalk ? $talkPage : $subjectPage,
-                                               'vector-view-view', ( $action == 'view' ), '', true
-                               );
-                       }
-
-                       wfProfileIn( __METHOD__ . '-edit' );
-
-                       // Checks if user can...
-                       if (
-                               // edit the current page
-                               $this->mTitle->quickUserCan( 'edit' ) &&
-                               (
-                                       // if it exists
-                                       $this->mTitle->exists() ||
-                                       // or they can create one here
-                                       $this->mTitle->quickUserCan( 'create' )
-                               )
-                       ) {
-                               // Builds CSS class for talk page links
-                               $isTalkClass = $isTalk ? ' istalk' : '';
-
-                               // Determines if we're in edit mode
-                               $selected = (
-                                       ( $action == 'edit' || $action == 'submit' ) &&
-                                       ( $section != 'new' )
-                               );
-                               $links['views']['edit'] = array(
-                                       'class' => ( $selected ? 'selected' : '' ) . $isTalkClass,
-                                       'text' => $this->mTitle->exists()
-                                               ? wfMsg( 'vector-view-edit' )
-                                               : wfMsg( 'vector-view-create' ),
-                                       'href' =>
-                                               $this->mTitle->getLocalURL( $this->editUrlOptions() )
-                               );
-                               // Checks if this is a current rev of talk page and we should show a new
-                               // section link
-                               if ( ( $isTalk && $wgArticle && $wgArticle->isCurrent() ) || ( $wgOut->showNewSectionLink() ) ) {
-                                       // Checks if we should ever show a new section link
-                                       if ( !$wgOut->forceHideNewSectionLink() ) {
-                                               // Adds new section link
-                                               //$links['actions']['addsection']
-                                               $links['views']['addsection'] = array(
-                                                       'class' => 'collapsible ' . ( $section == 'new' ? 'selected' : false ),
-                                                       'text' => wfMsg( 'vector-action-addsection' ),
-                                                       'href' => $this->mTitle->getLocalURL(
-                                                               'action=edit&section=new'
-                                                       )
-                                               );
-                                       }
-                               }
-                       // Checks if the page has some kind of viewable content
-                       } elseif ( $this->mTitle->hasSourceText() ) {
-                               // Adds view source view link
-                               $links['views']['viewsource'] = array(
-                                       'class' => ( $action == 'edit' ) ? 'selected' : false,
-                                       'text' => wfMsg( 'vector-view-viewsource' ),
-                                       'href' =>
-                                               $this->mTitle->getLocalURL( $this->editUrlOptions() )
-                               );
-                       }
-                       wfProfileOut( __METHOD__ . '-edit' );
-
-                       wfProfileIn( __METHOD__ . '-live' );
-
-                       // Checks if the page exists
-                       if ( $this->mTitle->exists() ) {
-                               // Adds history view link
-                               $links['views']['history'] = array(
-                                       'class' => 'collapsible ' . ( ( $action == 'history' ) ? 'selected' : false ),
-                                       'text' => wfMsg( 'vector-view-history' ),
-                                       'href' => $this->mTitle->getLocalURL( 'action=history' ),
-                                       'rel' => 'archives',
-                               );
-
-                               if( $wgUser->isAllowed( 'delete' ) ) {
-                                       $links['actions']['delete'] = array(
-                                               'class' => ( $action == 'delete' ) ? 'selected' : false,
-                                               'text' => wfMsg( 'vector-action-delete' ),
-                                               'href' => $this->mTitle->getLocalURL( 'action=delete' )
-                                       );
-                               }
-                               if ( $this->mTitle->quickUserCan( 'move' ) ) {
-                                       $moveTitle = SpecialPage::getTitleFor(
-                                               'Movepage', $this->thispage
-                                       );
-                                       $links['actions']['move'] = array(
-                                               'class' => $this->mTitle->isSpecial( 'Movepage' ) ?
-                                                                               'selected' : false,
-                                               'text' => wfMsg( 'vector-action-move' ),
-                                               'href' => $moveTitle->getLocalURL()
-                                       );
-                               }
-
-                               if (
-                                       $this->mTitle->getNamespace() !== NS_MEDIAWIKI &&
-                                       $wgUser->isAllowed( 'protect' )
-                               ) {
-                                       if ( !$this->mTitle->isProtected() ) {
-                                               $links['actions']['protect'] = array(
-                                                       'class' => ( $action == 'protect' ) ?
-                                                                                       'selected' : false,
-                                                       'text' => wfMsg( 'vector-action-protect' ),
-                                                       'href' =>
-                                                               $this->mTitle->getLocalURL( 'action=protect' )
-                                               );
-
-                                       } else {
-                                               $links['actions']['unprotect'] = array(
-                                                       'class' => ( $action == 'unprotect' ) ?
-                                                                                       'selected' : false,
-                                                       'text' => wfMsg( 'vector-action-unprotect' ),
-                                                       'href' =>
-                                                               $this->mTitle->getLocalURL( 'action=unprotect' )
-                                               );
-                                       }
-                               }
-                       } else {
-                               // article doesn't exist or is deleted
-                               if (
-                                       $wgUser->isAllowed( 'deletedhistory' ) &&
-                                       $wgUser->isAllowed( 'undelete' )
-                               ) {
-                                       $n = $this->mTitle->isDeleted();
-                                       if( $n ) {
-                                               $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
-                                               $links['actions']['undelete'] = array(
-                                                       'class' => false,
-                                                       'text' => wfMsgExt(
-                                                               'vector-action-undelete',
-                                                               array( 'parsemag' ),
-                                                               $wgLang->formatNum( $n )
-                                                       ),
-                                                       'href' => $undelTitle->getLocalURL(
-                                                               'target=' . urlencode( $this->thispage )
-                                                       )
-                                               );
-                                       }
-                               }
-
-                               if (
-                                       $this->mTitle->getNamespace() !== NS_MEDIAWIKI &&
-                                       $wgUser->isAllowed( 'protect' )
-                               ) {
-                                       if ( !$this->mTitle->getRestrictions( 'create' ) ) {
-                                               $links['actions']['protect'] = array(
-                                                       'class' => ( $action == 'protect' ) ?
-                                                                                       'selected' : false,
-                                                       'text' => wfMsg( 'vector-action-protect' ),
-                                                       'href' =>
-                                                               $this->mTitle->getLocalURL( 'action=protect' )
-                                               );
-
-                                       } else {
-                                               $links['actions']['unprotect'] = array(
-                                                       'class' => ( $action == 'unprotect' ) ?
-                                                                                       'selected' : false,
-                                                       'text' => wfMsg( 'vector-action-unprotect' ),
-                                                       'href' =>
-                                                               $this->mTitle->getLocalURL( 'action=unprotect' )
-                                               );
-                                       }
-                               }
-                       }
-                       wfProfileOut( __METHOD__ . '-live' );
-                       /**
-                        * The following actions use messages which, if made particular to
-                        * the Vector skin, would break the Ajax code which makes this
-                        * action happen entirely inline. Skin::makeGlobalVariablesScript
-                        * defines a set of messages in a javascript object - and these
-                        * messages are assumed to be global for all skins. Without making
-                        * a change to that procedure these messages will have to remain as
-                        * the global versions.
-                        */
-                       // Checks if the user is logged in
-                       if ( $this->loggedin ) {
-                               if ( $wgVectorUseIconWatch ) {
-                                       $class = 'icon';
-                                       $place = 'views';
-                               } else {
-                                       $class = '';
-                                       $place = 'actions';
-                               }
-                               $mode = $this->mTitle->userIsWatching() ? 'unwatch' : 'watch';
-                               $links[$place][$mode] = array(
-                                       'class' => $class . ( ( $action == 'watch' || $action == 'unwatch' ) ? ' selected' : false ),
-                                       'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
-                                       'href' => $this->mTitle->getLocalURL( 'action=' . $mode )
-                               );
-                       }
-                       // This is instead of SkinTemplateTabs - which uses a flat array
-                       wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$links ) );
-
-               // If it's not content, it's got to be a special page
-               } else {
-                       $links['namespaces']['special'] = array(
-                               'class' => 'selected',
-                               'text' => wfMsg( 'nstab-special' ),
-                               'href' => $wgRequest->getRequestURL()
-                       );
-               }
-
-               // Gets list of language variants
-               $variants = $wgContLang->getVariants();
-               // Checks that language conversion is enabled and variants exist
-               if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
-                       // Gets preferred variant
-                       $preferred = $wgContLang->getPreferredVariant();
-                       // Loops over each variant
-                       foreach( $variants as $code ) {
-                               // Gets variant name from language code
-                               $varname = $wgContLang->getVariantname( $code );
-                               // Checks if the variant is marked as disabled
-                               if( $varname == 'disable' ) {
-                                       // Skips this variant
-                                       continue;
-                               }
-                               // Appends variant link
-                               $links['variants'][] = array(
-                                       'class' => ( $code == $preferred ) ? 'selected' : false,
-                                       'text' => $varname,
-                                       'href' => $this->mTitle->getLocalURL( '', $code )
-                               );
-                       }
-               }
-
-               wfProfileOut( __METHOD__ );
-
-               return $links;
-       }
 }
 
 /**
  * QuickTemplate class for Vector skin
  * @ingroup Skins
  */
-class VectorTemplate extends QuickTemplate {
-
-       /* Members */
-
-       /**
-        * @var Cached skin object
-        */
-       var $skin;
+class VectorTemplate extends BaseTemplate {
 
        /* Functions */
 
        /**
-        * Outputs the entire contents of the XHTML page
+        * Outputs the entire contents of the (X)HTML page
         */
        public function execute() {
-               global $wgRequest, $wgLang;
-
-               $this->skin = $this->data['skin'];
-               $action = $wgRequest->getText( 'action' );
+               global $wgVectorUseIconWatch;
 
                // Build additional attributes for navigation urls
-               $nav = $this->skin->buildNavigationUrls();
+               $nav = $this->data['content_navigation'];
+
+               if ( $wgVectorUseIconWatch ) {
+                       $mode = $this->getSkin()->getTitle()->userIsWatching() ? 'unwatch' : 'watch';
+                       if ( isset( $nav['actions'][$mode] ) ) {
+                               $nav['views'][$mode] = $nav['actions'][$mode];
+                               $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
+                               $nav['views'][$mode]['primary'] = true;
+                               unset( $nav['actions'][$mode] );
+                       }
+               }
+
+               $xmlID = '';
                foreach ( $nav as $section => $links ) {
                        foreach ( $links as $key => $link ) {
-                               $xmlID = $key;
-                               if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
-                                       $xmlID = 'ca-nstab-' . $xmlID;
-                               } else if ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
-                                       $xmlID = 'ca-talk';
-                               } else {
-                                       $xmlID = 'ca-' . $xmlID;
+                               if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
+                                       $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
                                }
+
+                               $xmlID = isset( $link['id'] ) ? $link['id'] : 'ca-' . $xmlID;
                                $nav[$section][$key]['attributes'] =
                                        ' id="' . Sanitizer::escapeId( $xmlID ) . '"';
-                               if ( $nav[$section][$key]['class'] ) {
+                               if ( $link['class'] ) {
                                        $nav[$section][$key]['attributes'] .=
                                                ' class="' . htmlspecialchars( $link['class'] ) . '"';
                                        unset( $nav[$section][$key]['class'] );
                                }
-                               // We don't want to give the watch tab an accesskey if the page
-                               // is being edited, because that conflicts with the accesskey on
-                               // the watch checkbox.  We also don't want to give the edit tab
-                               // an accesskey, because that's fairly superfluous and conflicts
-                               // with an accesskey (Ctrl-E) often used for editing in Safari.
-                               if (
-                                       in_array( $action, array( 'edit', 'submit' ) ) &&
-                                       in_array( $key, array( 'edit', 'watch', 'unwatch' ) )
-                               ) {
+                               if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
                                        $nav[$section][$key]['key'] =
-                                               $this->skin->tooltip( $xmlID );
+                                               Linker::tooltip( $xmlID );
                                } else {
                                        $nav[$section][$key]['key'] =
-                                               $this->skin->tooltipAndAccesskey( $xmlID );
+                                               Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
                                }
                        }
                }
@@ -399,39 +109,9 @@ class VectorTemplate extends QuickTemplate {
                $this->data['view_urls'] = $nav['views'];
                $this->data['action_urls'] = $nav['actions'];
                $this->data['variant_urls'] = $nav['variants'];
-               // Build additional attributes for personal_urls
-               foreach ( $this->data['personal_urls'] as $key => $item) {
-                       $this->data['personal_urls'][$key]['attributes'] =
-                               ' id="' . Sanitizer::escapeId( "pt-$key" ) . '"';
-                       if ( isset( $item['active'] ) && $item['active'] ) {
-                               $this->data['personal_urls'][$key]['attributes'] .=
-                                       ' class="active"';
-                       }
-                       $this->data['personal_urls'][$key]['key'] =
-                               $this->skin->tooltipAndAccesskey('pt-'.$key);
-               }
-
-               // Generate additional footer links
-               $footerlinks = $this->data["footerlinks"];
-               // footerlinks doesn't include icons for now, so we'll just append the default
-               $footerlinks["icons"] = array( 'poweredbyico', 'copyrightico', );
-               
-               $footerlinksClasses = array(
-                       'icons' => array( 'noprint' )
-               );
 
-               // Reduce footer links down to only those which are being used
-               $validFooterLinks = array();
-               foreach( $footerlinks as $category => $links ) {
-                       $validFooterLinks[$category] = array();
-                       foreach( $links as $link ) {
-                               if( isset( $this->data[$link] ) && $this->data[$link] ) {
-                                       $validFooterLinks[$category][] = $link;
-                               }
-                       }
-               }
                // Reverse horizontally rendered navigation elements
-               if ( $wgLang->isRTL() ) {
+               if ( $this->data['rtl'] ) {
                        $this->data['view_urls'] =
                                array_reverse( $this->data['view_urls'] );
                        $this->data['namespace_urls'] =
@@ -445,46 +125,57 @@ class VectorTemplate extends QuickTemplate {
                <div id="mw-page-base" class="noprint"></div>
                <div id="mw-head-base" class="noprint"></div>
                <!-- content -->
-               <div id="content"<?php $this->html('specialpageattributes') ?>>
+               <div id="content" class="mw-body">
                        <a id="top"></a>
-                       <div id="mw-js-message" style="display:none;"<?php $this->html('userlangattributes') ?>></div>
+                       <div id="mw-js-message" style="display:none;"<?php $this->html( 'userlangattributes' ) ?>></div>
                        <?php if ( $this->data['sitenotice'] ): ?>
                        <!-- sitenotice -->
                        <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
                        <!-- /sitenotice -->
                        <?php endif; ?>
                        <!-- firstHeading -->
-                       <h1 id="firstHeading" class="firstHeading"><?php $this->html( 'title' ) ?></h1>
+                       <h1 id="firstHeading" class="firstHeading">
+                               <span dir="auto"><?php $this->html( 'title' ) ?></span>
+                       </h1>
                        <!-- /firstHeading -->
                        <!-- bodyContent -->
                        <div id="bodyContent">
+                               <?php if ( $this->data['isarticle'] ): ?>
                                <!-- tagline -->
                                <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
                                <!-- /tagline -->
+                               <?php endif; ?>
                                <!-- subtitle -->
-                               <div id="contentSub"<?php $this->html('userlangattributes') ?>><?php $this->html( 'subtitle' ) ?></div>
+                               <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
                                <!-- /subtitle -->
                                <?php if ( $this->data['undelete'] ): ?>
                                <!-- undelete -->
                                <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
                                <!-- /undelete -->
                                <?php endif; ?>
-                               <?php if($this->data['newtalk'] ): ?>
+                               <?php if( $this->data['newtalk'] ): ?>
                                <!-- newtalk -->
                                <div class="usermessage"><?php $this->html( 'newtalk' )  ?></div>
                                <!-- /newtalk -->
                                <?php endif; ?>
                                <?php if ( $this->data['showjumplinks'] ): ?>
                                <!-- jumpto -->
-                               <div id="jump-to-nav">
+                               <div id="jump-to-nav" class="mw-jump">
                                        <?php $this->msg( 'jumpto' ) ?> <a href="#mw-head"><?php $this->msg( 'jumptonavigation' ) ?></a>,
                                        <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
                                </div>
                                <!-- /jumpto -->
                                <?php endif; ?>
-                               <!-- bodytext -->
-                               <?php $this->html( 'bodytext' ) ?>
-                               <!-- /bodytext -->
+                               <!-- bodycontent -->
+                               <?php $this->html( 'bodycontent' ) ?>
+                               <!-- /bodycontent -->
+                               <?php if ( $this->data['printfooter'] ): ?>
+                               <!-- printfooter -->
+                               <div class="printfooter">
+                               <?php $this->html( 'printfooter' ); ?>
+                               </div>
+                               <!-- /printfooter -->
+                               <?php endif; ?>
                                <?php if ( $this->data['catlinks'] ): ?>
                                <!-- catlinks -->
                                <?php $this->html( 'catlinks' ); ?>
@@ -496,6 +187,9 @@ class VectorTemplate extends QuickTemplate {
                                <!-- /dataAfterContent -->
                                <?php endif; ?>
                                <div class="visualClear"></div>
+                               <!-- debughtml -->
+                               <?php $this->html( 'debughtml' ); ?>
+                               <!-- /debughtml -->
                        </div>
                        <!-- /bodyContent -->
                </div>
@@ -514,35 +208,38 @@ class VectorTemplate extends QuickTemplate {
                <!-- panel -->
                        <div id="mw-panel" class="noprint">
                                <!-- logo -->
-                                       <div id="p-logo"><a style="background-image: url(<?php $this->text( 'logopath' ) ?>);" href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>" <?php echo $this->skin->tooltipAndAccesskey( 'p-logo' ) ?>></a></div>
+                                       <div id="p-logo"><a style="background-image: url(<?php $this->text( 'logopath' ) ?>);" href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>" <?php echo Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) ) ?>></a></div>
                                <!-- /logo -->
                                <?php $this->renderPortals( $this->data['sidebar'] ); ?>
                        </div>
                <!-- /panel -->
                <!-- footer -->
-               <div id="footer"<?php $this->html('userlangattributes') ?>>
-                       <?php foreach( $validFooterLinks as $category => $links ): ?>
-                               <?php if ( count( $links ) > 0 ): ?>
-                               <ul id="footer-<?php echo $category ?>"<?php if (isset($footerlinksClasses[$category])) echo ' class="' . implode(" ", $footerlinksClasses[$category]) . '"'; ?>>
+               <div id="footer"<?php $this->html( 'userlangattributes' ) ?>>
+                       <?php foreach( $this->getFooterLinks() as $category => $links ): ?>
+                               <ul id="footer-<?php echo $category ?>">
                                        <?php foreach( $links as $link ): ?>
-                                               <?php if( isset( $this->data[$link] ) && $this->data[$link] ): ?>
                                                <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
-                                               <?php endif; ?>
                                        <?php endforeach; ?>
                                </ul>
-                               <?php endif; ?>
                        <?php endforeach; ?>
+                       <?php $footericons = $this->getFooterIcons("icononly");
+                       if ( count( $footericons ) > 0 ): ?>
+                               <ul id="footer-icons" class="noprint">
+<?php                  foreach ( $footericons as $blockName => $footerIcons ): ?>
+                                       <li id="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
+<?php                          foreach ( $footerIcons as $icon ): ?>
+                                               <?php echo $this->getSkin()->makeFooterIcon( $icon ); ?>
+
+<?php                          endforeach; ?>
+                                       </li>
+<?php                  endforeach; ?>
+                               </ul>
+                       <?php endif; ?>
                        <div style="clear:both"></div>
                </div>
                <!-- /footer -->
-               <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
-               <!-- fixalpha -->
-               <script type="<?php $this->text('jsmimetype') ?>"> if ( window.isMSIE55 ) fixalpha(); </script>
-               <!-- /fixalpha -->
-               <?php $this->html( 'reporttime' ) ?>
-               <?php if ( $this->data['debug'] ): ?>
-               <!-- Debug output: <?php $this->text( 'debug' ); ?> -->
-               <?php endif; ?>
+               <?php $this->printTrail(); ?>
+
        </body>
 </html>
 <?php
@@ -550,111 +247,98 @@ class VectorTemplate extends QuickTemplate {
 
        /**
         * Render a series of portals
+        *
+        * @param $portals array
         */
-       private function renderPortals( $portals ) {
+       protected function renderPortals( $portals ) {
                // Force the rendering of the following portals
-               if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true;
-               if ( !isset( $portals['TOOLBOX'] ) ) $portals['TOOLBOX'] = true;
-               if ( !isset( $portals['LANGUAGES'] ) ) $portals['LANGUAGES'] = true;
+               if ( !isset( $portals['SEARCH'] ) ) {
+                       $portals['SEARCH'] = true;
+               }
+               if ( !isset( $portals['TOOLBOX'] ) ) {
+                       $portals['TOOLBOX'] = true;
+               }
+               if ( !isset( $portals['LANGUAGES'] ) ) {
+                       $portals['LANGUAGES'] = true;
+               }
                // Render portals
                foreach ( $portals as $name => $content ) {
+                       if ( $content === false )
+                               continue;
+
                        echo "\n<!-- {$name} -->\n";
                        switch( $name ) {
                                case 'SEARCH':
                                        break;
                                case 'TOOLBOX':
-?>
-<div class="portal" id="p-tb">
-       <h5<?php $this->html('userlangattributes') ?>><?php $this->msg( 'toolbox' ) ?></h5>
-       <div class="body">
-               <ul>
-               <?php if( $this->data['notspecialpage'] ): ?>
-                       <li id="t-whatlinkshere"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['whatlinkshere']['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-whatlinkshere' ) ?>><?php $this->msg( 'whatlinkshere' ) ?></a></li>
-                       <?php if( $this->data['nav_urls']['recentchangeslinked'] ): ?>
-                       <li id="t-recentchangeslinked"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['recentchangeslinked']['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-recentchangeslinked' ) ?>><?php $this->msg( 'recentchangeslinked-toolbox' ) ?></a></li>
-                       <?php endif; ?>
-               <?php endif; ?>
-               <?php if( isset( $this->data['nav_urls']['trackbacklink'] ) ): ?>
-               <li id="t-trackbacklink"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['trackbacklink']['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-trackbacklink' ) ?>><?php $this->msg( 'trackbacklink' ) ?></a></li>
-               <?php endif; ?>
-               <?php if( $this->data['feeds']): ?>
-               <li id="feedlinks">
-                       <?php foreach( $this->data['feeds'] as $key => $feed ): ?>
-                       <a id="<?php echo Sanitizer::escapeId( "feed-$key" ) ?>" href="<?php echo htmlspecialchars( $feed['href'] ) ?>" rel="alternate" type="application/<?php echo $key ?>+xml" class="feedlink"<?php echo $this->skin->tooltipAndAccesskey( 'feed-' . $key ) ?>><?php echo htmlspecialchars( $feed['text'] ) ?></a>
-                       <?php endforeach; ?>
-               </li>
-               <?php endif; ?>
-               <?php foreach( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ): ?>
-                       <?php if( $this->data['nav_urls'][$special]): ?>
-                       <li id="t-<?php echo $special ?>"><a href="<?php echo htmlspecialchars( $this->data['nav_urls'][$special]['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-' . $special ) ?>><?php $this->msg( $special ) ?></a></li>
-                       <?php endif; ?>
-               <?php endforeach; ?>
-               <?php if( !empty( $this->data['nav_urls']['print']['href'] ) ): ?>
-               <li id="t-print"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['print']['href'] ) ?>" rel="alternate"<?php echo $this->skin->tooltipAndAccesskey( 't-print' ) ?>><?php $this->msg( 'printableversion' ) ?></a></li>
-               <?php endif; ?>
-               <?php if (  !empty(  $this->data['nav_urls']['permalink']['href'] ) ): ?>
-               <li id="t-permalink"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['permalink']['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-permalink' ) ?>><?php $this->msg( 'permalink' ) ?></a></li>
-               <?php elseif ( $this->data['nav_urls']['permalink']['href'] === '' ): ?>
-               <li id="t-ispermalink"<?php echo $this->skin->tooltip( 't-ispermalink' ) ?>><?php $this->msg( 'permalink' ) ?></li>
-               <?php endif; ?>
-               <?php wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) ); ?>
-               </ul>
-       </div>
-</div>
-<?php
+                                       $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
                                        break;
                                case 'LANGUAGES':
                                        if ( $this->data['language_urls'] ) {
-?>
-<div class="portal" id="p-lang">
-       <h5<?php $this->html('userlangattributes') ?>><?php $this->msg( 'otherlanguages' ) ?></h5>
-       <div class="body">
-               <ul>
-               <?php foreach ( $this->data['language_urls'] as $langlink ): ?>
-                       <li class="<?php echo htmlspecialchars(  $langlink['class'] ) ?>"><a href="<?php echo htmlspecialchars( $langlink['href'] ) ?>" title="<?php echo htmlspecialchars( $langlink['title'] ) ?>"><?php echo $langlink['text'] ?></a></li>
-               <?php endforeach; ?>
-               </ul>
-       </div>
-</div>
-<?php
+                                               $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
                                        }
                                        break;
                                default:
-?>
-<div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo $this->skin->tooltip( 'p-' . $name ) ?>>
-       <h5<?php $this->html('userlangattributes') ?>><?php $out = wfMsg( $name ); if ( wfEmptyMsg( $name, $out ) ) echo htmlspecialchars( $name ); else echo htmlspecialchars( $out ); ?></h5>
+                                       $this->renderPortal( $name, $content );
+                               break;
+                       }
+                       echo "\n<!-- /{$name} -->\n";
+               }
+       }
+
+       /**
+        * @param $name string
+        * @param $content array
+        * @param $msg null|string
+        * @param $hook null|string|array
+        */
+       protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
+               if ( $msg === null ) {
+                       $msg = $name;
+               }
+               ?>
+<div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo Linker::tooltip( 'p-' . $name ) ?>>
+       <h5<?php $this->html( 'userlangattributes' ) ?>><?php $msgObj = wfMessage( $msg ); echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg ); ?></h5>
        <div class="body">
-               <?php if ( is_array( $content ) ): ?>
+<?php
+               if ( is_array( $content ) ): ?>
                <ul>
-               <?php foreach( $content as $val ): ?>
-                       <li id="<?php echo Sanitizer::escapeId( $val['id'] ) ?>"<?php if ( $val['active'] ): ?> class="active" <?php endif; ?>><a href="<?php echo htmlspecialchars( $val['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( $val['id'] ) ?>><?php echo htmlspecialchars( $val['text'] ) ?></a></li>
-               <?php endforeach; ?>
+<?php
+                       foreach( $content as $key => $val ): ?>
+                       <?php echo $this->makeListItem( $key, $val ); ?>
+
+<?php
+                       endforeach;
+                       if ( $hook !== null ) {
+                               wfRunHooks( $hook, array( &$this, true ) );
+                       }
+                       ?>
                </ul>
-               <?php else: ?>
+<?php
+               else: ?>
                <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
-               <?php endif; ?>
+<?php
+               endif; ?>
        </div>
 </div>
 <?php
-                               break;
-                       }
-                       echo "\n<!-- /{$name} -->\n";
-               }
        }
 
        /**
         * Render one or more navigations elements by name, automatically reveresed
         * when UI is in RTL mode
+        *
+        * @param $elements array
         */
-       private function renderNavigation( $elements ) {
-               global $wgVectorUseSimpleSearch, $wgVectorShowVariantName, $wgUser;
+       protected function renderNavigation( $elements ) {
+               global $wgVectorUseSimpleSearch;
 
                // If only one element was given, wrap it in an array, allowing more
                // flexible arguments
                if ( !is_array( $elements ) ) {
                        $elements = array( $elements );
                // If there's a series of elements, reverse them when in RTL mode
-               } else if ( wfUILang()->isRTL() ) {
+               } elseif ( $this->data['rtl'] ) {
                        $elements = array_reverse( $elements );
                }
                // Render elements
@@ -664,9 +348,9 @@ class VectorTemplate extends QuickTemplate {
                                case 'NAMESPACES':
 ?>
 <div id="p-namespaces" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
-       <h5><?php $this->msg('namespaces') ?></h5>
-       <ul<?php $this->html('userlangattributes') ?>>
-               <?php foreach ($this->data['namespace_urls'] as $link ): ?>
+       <h5><?php $this->msg( 'namespaces' ) ?></h5>
+       <ul<?php $this->html( 'userlangattributes' ) ?>>
+               <?php foreach ( $this->data['namespace_urls'] as $link ): ?>
                        <li <?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></span></li>
                <?php endforeach; ?>
        </ul>
@@ -676,18 +360,16 @@ class VectorTemplate extends QuickTemplate {
                                case 'VARIANTS':
 ?>
 <div id="p-variants" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
-       <?php if ( $wgVectorShowVariantName ): ?>
-               <h4>
-               <?php foreach ( $this->data['variant_urls'] as $link ): ?>
-                       <?php if ( stripos( $link['attributes'], 'selected' ) !== false ): ?>
-                               <?php echo htmlspecialchars( $link['text'] ) ?>
-                       <?php endif; ?>
-               <?php endforeach; ?>
-               </h4>
-       <?php endif; ?>
-       <h5><span><?php $this->msg('variants') ?></span><a href="#"></a></h5>
+       <h4>
+       <?php foreach ( $this->data['variant_urls'] as $link ): ?>
+               <?php if ( stripos( $link['attributes'], 'selected' ) !== false ): ?>
+                       <?php echo htmlspecialchars( $link['text'] ) ?>
+               <?php endif; ?>
+       <?php endforeach; ?>
+       </h4>
+       <h5><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h5>
        <div class="menu">
-               <ul<?php $this->html('userlangattributes') ?>>
+               <ul<?php $this->html( 'userlangattributes' ) ?>>
                        <?php foreach ( $this->data['variant_urls'] as $link ): ?>
                                <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
                        <?php endforeach; ?>
@@ -698,11 +380,16 @@ class VectorTemplate extends QuickTemplate {
                                break;
                                case 'VIEWS':
 ?>
-<div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
+<div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
        <h5><?php $this->msg('views') ?></h5>
        <ul<?php $this->html('userlangattributes') ?>>
                <?php foreach ( $this->data['view_urls'] as $link ): ?>
-                       <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo (array_key_exists('img',$link) ?  '<img src="'.$link['img'].'" alt="'.$link['text'].'" />' : htmlspecialchars( $link['text'] ) ) ?></a></span></li>
+                       <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
+                               // $link['text'] can be undefined - bug 27764
+                               if ( array_key_exists( 'text', $link ) ) {
+                                       echo array_key_exists( 'img', $link ) ?  '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
+                               }
+                               ?></a></span></li>
                <?php endforeach; ?>
        </ul>
 </div>
@@ -711,10 +398,10 @@ class VectorTemplate extends QuickTemplate {
                                case 'ACTIONS':
 ?>
 <div id="p-cactions" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
-       <h5><span><?php $this->msg('actions') ?></span><a href="#"></a></h5>
+       <h5><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h5>
        <div class="menu">
-               <ul<?php $this->html('userlangattributes') ?>>
-                       <?php foreach ($this->data['action_urls'] as $link ): ?>
+               <ul<?php $this->html( 'userlangattributes' ) ?>>
+                       <?php foreach ( $this->data['action_urls'] as $link ): ?>
                                <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
                        <?php endforeach; ?>
                </ul>
@@ -725,11 +412,12 @@ class VectorTemplate extends QuickTemplate {
                                case 'PERSONAL':
 ?>
 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
-       <h5><?php $this->msg('personaltools') ?></h5>
-       <ul<?php $this->html('userlangattributes') ?>>
-               <?php foreach($this->data['personal_urls'] as $item): ?>
-                       <li <?php echo $item['attributes'] ?>><a href="<?php echo htmlspecialchars($item['href']) ?>"<?php echo $item['key'] ?><?php if(!empty($item['class'])): ?> class="<?php echo htmlspecialchars($item['class']) ?>"<?php endif; ?>><?php echo htmlspecialchars($item['text']) ?></a></li>
-               <?php endforeach; ?>
+       <h5><?php $this->msg( 'personaltools' ) ?></h5>
+       <ul<?php $this->html( 'userlangattributes' ) ?>>
+<?php                  foreach( $this->getPersonalTools() as $key => $item ) { ?>
+               <?php echo $this->makeListItem( $key, $item ); ?>
+
+<?php                  } ?>
        </ul>
 </div>
 <?php
@@ -737,19 +425,25 @@ class VectorTemplate extends QuickTemplate {
                                case 'SEARCH':
 ?>
 <div id="p-search">
-       <h5<?php $this->html('userlangattributes') ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
+       <h5<?php $this->html( 'userlangattributes' ) ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
        <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
-               <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
-               <?php if ( $wgVectorUseSimpleSearch && $wgUser->getOption( 'vector-simplesearch' ) ): ?>
+               <?php if ( $wgVectorUseSimpleSearch && $this->getSkin()->getUser()->getOption( 'vector-simplesearch' ) ): ?>
                <div id="simpleSearch">
-                       <input id="searchInput" name="search" type="text" <?php echo $this->skin->tooltipAndAccesskey( 'search' ); ?> <?php if( isset( $this->data['search'] ) ): ?> value="<?php $this->text( 'search' ) ?>"<?php endif; ?> />
-                       <button id="searchButton" type='submit' name='button' <?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?>><img src="<?php echo $this->skin->getSkinStylePath('images/search-' . ( $this->data['rtl'] ? 'rtl' : 'ltr' ) . '.png'); ?>" alt="<?php $this->msg( 'searchbutton' ) ?>" /></button>
-               </div>
+                       <?php if ( $this->data['rtl'] ): ?>
+                       <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->getSkin()->getSkinStylePath( 'images/search-rtl.png' ) ) ); ?>
+                       <?php endif; ?>
+                       <?php echo $this->makeSearchInput( array( 'id' => 'searchInput', 'type' => 'text' ) ); ?>
+                       <?php if ( !$this->data['rtl'] ): ?>
+                       <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->getSkin()->getSkinStylePath( 'images/search-ltr.png' ) ) ); ?>
+                       <?php endif; ?>
                <?php else: ?>
-               <input id="searchInput" name="search" type="text" <?php echo $this->skin->tooltipAndAccesskey( 'search' ); ?> <?php if( isset( $this->data['search'] ) ): ?> value="<?php $this->text( 'search' ) ?>"<?php endif; ?> />
-               <input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg( 'searcharticle' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-go' ); ?> />
-               <input type="submit" name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg( 'searchbutton' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> />
+               <div>
+                       <?php echo $this->makeSearchInput( array( 'id' => 'searchInput' ) ); ?>
+                       <?php echo $this->makeSearchButton( 'go', array( 'id' => 'searchGoButton', 'class' => 'searchButton' ) ); ?>
+                       <?php echo $this->makeSearchButton( 'fulltext', array( 'id' => 'mw-searchButton', 'class' => 'searchButton' ) ); ?>
                <?php endif; ?>
+                       <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
+               </div>
        </form>
 </div>
 <?php