From 347636fa0a5b58fc1a010f5ef1b44da36126c1a1 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 1 Nov 2011 16:09:27 +0000 Subject: [PATCH] * Create all items in $nav_urls at the beginning so that we don't need to bother if they are set or not after that * Don't show 'whatlinkshere', 'recentchangeslinked' and 'trackbacklink' items if OutputPage::isArticleRelated() is false * Simplify the code to check if we show show user related items since the actual code is just to check if we have an User object * Moved the showEmailUser() check to the same location as other related user checks * Made Skin::showEmailUser() accept an User object instead of doing object -> int -> object conversion * Check if the items are present in BaseTemplate::getToolbox() instead of 'notspecialpage' and removed some empty() or isset() checks since all of these items are now set --- includes/Skin.php | 6 ++- includes/SkinTemplate.php | 77 ++++++++++++++++----------------------- 2 files changed, 36 insertions(+), 47 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index 6ead986bcd..9d57429746 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -929,7 +929,11 @@ abstract class Skin extends ContextSource { } function showEmailUser( $id ) { - $targetUser = User::newFromId( $id ); + if ( $id instanceof User ) { + $targetUser = $id; + } else { + $targetUser = User::newFromId( $id ); + } return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users } diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 4636720c72..b72b85bb54 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1154,8 +1154,15 @@ class SkinTemplate extends Skin { } $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) ); - // default permalink to being off, will override it as required below. + $nav_urls['print'] = false; $nav_urls['permalink'] = false; + $nav_urls['whatlinkshere'] = false; + $nav_urls['recentchangeslinked'] = false; + $nav_urls['trackbacklink'] = false; + $nav_urls['contributions'] = false; + $nav_urls['log'] = false; + $nav_urls['blockip'] = false; + $nav_urls['emailuser'] = false; // A print stylesheet is attached to all pages, but nobody ever // figures that out. :) Add a link... @@ -1182,72 +1189,50 @@ class SkinTemplate extends Skin { array( &$this, &$nav_urls, &$revid, &$revid ) ); } - if( $this->getTitle()->getNamespace() != NS_SPECIAL ) { - $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage ); + if ( $out->isArticleRelated() ) { $nav_urls['whatlinkshere'] = array( - 'href' => $wlhTitle->getLocalUrl() + 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalUrl() ); - if( $this->getTitle()->getArticleId() ) { - $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage ); + if ( $this->getTitle()->getArticleId() ) { $nav_urls['recentchangeslinked'] = array( - 'href' => $rclTitle->getLocalUrl() + 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalUrl() ); - } else { - $nav_urls['recentchangeslinked'] = false; } - if( $wgUseTrackbacks ) + if ( $wgUseTrackbacks ) { $nav_urls['trackbacklink'] = array( 'href' => $out->getTitle()->trackbackURL() ); + } } $user = $this->getRelevantUser(); if ( $user ) { - $id = $user->getID(); - $ip = $user->isAnon(); $rootUser = $user->getName(); - } else { - $id = 0; - $ip = false; - $rootUser = null; - } - if( $id || $ip ) { # both anons and non-anons have contribs list $nav_urls['contributions'] = array( 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser ) ); - if( $id ) { + if ( $user->isLoggedIn() ) { $logPage = SpecialPage::getTitleFor( 'Log' ); $nav_urls['log'] = array( - 'href' => $logPage->getLocalUrl( - array( - 'user' => $rootUser - ) - ) + 'href' => $logPage->getLocalUrl( array( 'user' => $rootUser ) ) ); - } else { - $nav_urls['log'] = false; } if ( $this->getUser()->isAllowed( 'block' ) ) { $nav_urls['blockip'] = array( 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser ) ); - } else { - $nav_urls['blockip'] = false; } - } else { - $nav_urls['contributions'] = false; - $nav_urls['log'] = false; - $nav_urls['blockip'] = false; - } - $nav_urls['emailuser'] = false; - if( $this->showEmailUser( $id ) ) { - $nav_urls['emailuser'] = array( - 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser ) - ); + + if ( $this->showEmailUser( $user ) ) { + $nav_urls['emailuser'] = array( + 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser ) + ); + } } + wfProfileOut( __METHOD__ ); return $nav_urls; } @@ -1441,16 +1426,16 @@ abstract class BaseTemplate extends QuickTemplate { wfProfileIn( __METHOD__ ); $toolbox = array(); - if ( $this->data['notspecialpage'] ) { + if ( $this->data['nav_urls']['whatlinkshere'] ) { $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere']; $toolbox['whatlinkshere']['id'] = 't-whatlinkshere'; - if ( $this->data['nav_urls']['recentchangeslinked'] ) { - $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked']; - $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox'; - $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked'; - } } - if( isset( $this->data['nav_urls']['trackbacklink'] ) && $this->data['nav_urls']['trackbacklink'] ) { + if ( $this->data['nav_urls']['recentchangeslinked'] ) { + $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked']; + $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox'; + $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked'; + } + if ( $this->data['nav_urls']['trackbacklink'] ) { $toolbox['trackbacklink'] = $this->data['nav_urls']['trackbacklink']; $toolbox['trackbacklink']['id'] = 't-trackbacklink'; } @@ -1471,7 +1456,7 @@ abstract class BaseTemplate extends QuickTemplate { $toolbox[$special]['id'] = "t-$special"; } } - if ( !empty( $this->data['nav_urls']['print']['href'] ) ) { + if ( $this->data['nav_urls']['print'] ) { $toolbox['print'] = $this->data['nav_urls']['print']; $toolbox['print']['rel'] = 'alternate'; $toolbox['print']['msg'] = 'printableversion'; -- 2.20.1