From 5de2e4037979bd3d809e18bdb087b7852f03189e Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sat, 1 Jan 2011 01:03:02 +0000 Subject: [PATCH] Implement "relevant" title and user in the skin system and update undelete, log, contributions, blockip, and movepage to use it. A "Relevant" is used by the skin to determine what title to display tabs for. This setting allows pages like Special:MovePage (which is linked to from the tabs themselves) to retain the tabs specific to the page relevant to it when switching to the special page. Similaly a "Relevant" user is used by the skin to display things in the toolbox which would usually only be displayed on the user's userpage and talkpage, pages like Special:Contributions which are linked to by the toolbox can use this to retain the toolbox links when switching between the user pages and these special pages. --- includes/Skin.php | 62 +++++++++++++++ includes/SkinTemplate.php | 90 +++++++++++----------- includes/specials/SpecialBlockip.php | 3 + includes/specials/SpecialContributions.php | 4 + includes/specials/SpecialLog.php | 5 ++ includes/specials/SpecialMovepage.php | 1 + includes/specials/SpecialUndelete.php | 1 + 7 files changed, 123 insertions(+), 43 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index fe57e5f518..8f6937d6da 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -27,6 +27,8 @@ class Skin extends Linker { protected $skinname = 'standard'; // @todo Fixme: should be protected :-\ var $mTitle = null; + protected $mRelevantTitle = null; + protected $mRelevantUser = null; /** Constructor, call parent constructor */ function __construct() { @@ -365,6 +367,66 @@ class Skin extends Linker { return $this->mTitle; } + /** + * Set the "relevant" title + * @see self::getRelevantTitle() + * @param $t Title object to use + */ + public function setRelevantTitle( $t ) { + $this->mRelevantTitle = $t; + } + + /** + * Return the "relevant" title. + * A "relevant" title is not necessarily the actual title of the page. + * Special pages like Special:MovePage use set the page they are acting on + * as their "relevant" title, this allows the skin system to display things + * such as content tabs which belong to to that page instead of displaying + * a basic special page tab which has almost no meaning. + */ + public function getRelevantTitle() { + if ( isset($this->mRelevantTitle) ) { + return $this->mRelevantTitle; + } + return $this->mTitle; + } + + /** + * Set the "relevant" user + * @see self::getRelevantUser() + * @param $u User object to use + */ + public function setRelevantUser( $u ) { + $this->mRelevantUser = $u; + } + + /** + * Return the "relevant" user. + * A "relevant" user is similar to a relevant title. Special pages like + * Special:Contributions mark the user which they are relevant to so that + * things like the toolbox can display the information they usually are only + * able to display on a user's userpage and talkpage. + */ + public function getRelevantUser() { + if ( isset($this->mRelevantUser) ) { + return $this->mRelevantUser; + } + $title = $this->getRelevantTitle(); + if( $title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK ) { + $rootUser = strtok( $title->getText(), '/' ); + if ( User::isIP( $rootUser ) ) { + $this->mRelevantUser = User::newFromName( $rootUser, false ); + } else { + $user = User::newFromName( $rootUser ); + if ( $user->isLoggedIn() ) { + $this->mRelevantUser = $user; + } + } + return $this->mRelevantUser; + } + return null; + } + /** * Outputs the HTML generated by other functions. * @param $out Object: instance of OutputPage diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 60c52d6105..46c84d355a 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -789,6 +789,9 @@ class SkinTemplate extends Skin { wfProfileIn( __METHOD__ ); + $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself + $onPage = $title->equals($this->mTitle); + $content_navigation = array( 'namespaces' => array(), 'views' => array(), @@ -800,23 +803,23 @@ class SkinTemplate extends Skin { $action = $wgRequest->getVal( 'action', 'view' ); $section = $wgRequest->getVal( 'section' ); - $userCanRead = $this->mTitle->userCanRead(); + $userCanRead = $title->userCanRead(); $skname = $this->skinname; $preventActiveTabs = false; wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) ); // Checks if page is some kind of content - if( $this->iscontent ) { + if( $this->mTitle->getNamespace() != NS_SPECIAL ) { // Gets page objects for the related namespaces - $subjectPage = $this->mTitle->getSubjectPage(); - $talkPage = $this->mTitle->getTalkPage(); + $subjectPage = $title->getSubjectPage(); + $talkPage = $title->getTalkPage(); // Determines if this is a talk page - $isTalk = $this->mTitle->isTalkPage(); + $isTalk = $title->isTalkPage(); // Generates XML IDs from namespace names - $subjectId = $this->mTitle->getNamespaceKey( '' ); + $subjectId = $title->getNamespaceKey( '' ); if ( $subjectId == 'main' ) { $talkId = 'talk'; @@ -835,11 +838,11 @@ class SkinTemplate extends Skin { $content_navigation['namespaces'][$talkId]['context'] = 'talk'; // Adds view view link - if ( $this->mTitle->exists() && $userCanRead ) { + if ( $title->exists() && $userCanRead ) { $content_navigation['views']['view'] = $this->tabAction( $isTalk ? $talkPage : $subjectPage, !wfEmptyMsg( "$skname-view-view" ) ? "$skname-view-view" : 'view', - ( $action == 'view' ), '', true + ( $onPage && $action == 'view' ), '', true ); $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions } @@ -849,12 +852,12 @@ class SkinTemplate extends Skin { // Checks if user can... if ( // read and edit the current page - $userCanRead && $this->mTitle->quickUserCan( 'edit' ) && + $userCanRead && $title->quickUserCan( 'edit' ) && ( // if it exists - $this->mTitle->exists() || + $title->exists() || // or they can create one here - $this->mTitle->quickUserCan( 'create' ) + $title->quickUserCan( 'create' ) ) ) { // Builds CSS class for talk page links @@ -862,15 +865,16 @@ class SkinTemplate extends Skin { // Determines if we're in edit mode $selected = ( + $onPage && ( $action == 'edit' || $action == 'submit' ) && ( $section != 'new' ) ); - $msgKey = $this->mTitle->exists() || ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $this->mTitle->getText() ) ) ? + $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $title->getText() ) ) ? "edit" : "create"; $content_navigation['views']['edit'] = array( 'class' => ( $selected ? 'selected' : '' ) . $isTalkClass, 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->plain(), - 'href' => $this->mTitle->getLocalURL( $this->editUrlOptions() ), + 'href' => $title->getLocalURL( $this->editUrlOptions() ), 'primary' => true, // don't collapse this in vector ); // Checks if this is a current rev of talk page and we should show a new @@ -883,17 +887,17 @@ class SkinTemplate extends Skin { $content_navigation['views']['addsection'] = array( 'class' => $section == 'new' ? 'selected' : false, 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->plain(), - 'href' => $this->mTitle->getLocalURL( 'action=edit§ion=new' ) + 'href' => $title->getLocalURL( 'action=edit§ion=new' ) ); } } // Checks if the page has some kind of viewable content - } elseif ( $this->mTitle->hasSourceText() && $userCanRead ) { + } elseif ( $title->hasSourceText() && $userCanRead ) { // Adds view source view link $content_navigation['views']['viewsource'] = array( - 'class' => ( $action == 'edit' ) ? 'selected' : false, + 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false, 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->plain(), - 'href' => $this->mTitle->getLocalURL( $this->editUrlOptions() ), + 'href' => $title->getLocalURL( $this->editUrlOptions() ), 'primary' => true, // don't collapse this in vector ); } @@ -902,24 +906,24 @@ class SkinTemplate extends Skin { wfProfileIn( __METHOD__ . '-live' ); // Checks if the page exists - if ( $this->mTitle->exists() && $userCanRead ) { + if ( $title->exists() && $userCanRead ) { // Adds history view link $content_navigation['views']['history'] = array( - 'class' => ( $action == 'history' ) ? 'selected' : false, + 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false, 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->plain(), - 'href' => $this->mTitle->getLocalURL( 'action=history' ), + 'href' => $title->getLocalURL( 'action=history' ), 'rel' => 'archives', ); if( $wgUser->isAllowed( 'delete' ) ) { $content_navigation['actions']['delete'] = array( - 'class' => ( $action == 'delete' ) ? 'selected' : false, + 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false, 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->plain(), - 'href' => $this->mTitle->getLocalURL( 'action=delete' ) + 'href' => $title->getLocalURL( 'action=delete' ) ); } - if ( $this->mTitle->quickUserCan( 'move' ) ) { - $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage ); + if ( $title->quickUserCan( 'move' ) ) { + $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() ); $content_navigation['actions']['move'] = array( 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false, 'text' => wfMessageFallback( "$skname-action-move", 'move' )->plain(), @@ -927,37 +931,37 @@ class SkinTemplate extends Skin { ); } - if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) { - $mode = !$this->mTitle->isProtected() ? 'protect' : 'unprotect'; + if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) { + $mode = !$title->isProtected() ? 'protect' : 'unprotect'; $content_navigation['actions'][$mode] = array( - 'class' => ( $action == $mode ) ? 'selected' : false, + 'class' => ( $onPage && $action == $mode ) ? 'selected' : false, 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->plain(), - 'href' => $this->mTitle->getLocalURL( "action=$mode" ) + 'href' => $title->getLocalURL( "action=$mode" ) ); } } else { // article doesn't exist or is deleted if ( $wgUser->isAllowed( 'deletedhistory' ) ) { - $n = $this->mTitle->isDeleted(); + $n = $title->isDeleted(); if( $n ) { $undelTitle = SpecialPage::getTitleFor( 'Undelete' ); // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead $msgKey = $wgUser->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted'; $content_navigation['actions']['undelete'] = array( - 'class' => false, + 'class' => $this->mTitle->isSpecial( 'Undelete' ) ? 'selected' : false, 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" ) ->params( $wgLang->formatNum( $n ) )->text(), - 'href' => $undelTitle->getLocalURL( array( 'target' => $this->thispage ) ) + 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) ) ); } } - if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) { - $mode = !$this->mTitle->getRestrictions( 'create' ) ? 'protect' : 'unprotect'; + if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) { + $mode = !$title->getRestrictions( 'create' ) ? 'protect' : 'unprotect'; $content_navigation['actions'][$mode] = array( - 'class' => ( $action == $mode ) ? 'selected' : false, + 'class' => ( $onPage && $action == $mode ) ? 'selected' : false, 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->plain(), - 'href' => $this->mTitle->getLocalURL( "action=$mode" ) + 'href' => $title->getLocalURL( "action=$mode" ) ); } } @@ -974,11 +978,11 @@ class SkinTemplate extends Skin { * a change to that procedure these messages will have to remain as * the global versions. */ - $mode = $this->mTitle->userIsWatching() ? 'unwatch' : 'watch'; + $mode = $title->userIsWatching() ? 'unwatch' : 'watch'; $content_navigation['actions'][$mode] = array( - 'class' => ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false, + 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false, 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message - 'href' => $this->mTitle->getLocalURL( 'action=' . $mode ) + 'href' => $title->getLocalURL( 'action=' . $mode ) ); } @@ -1014,7 +1018,7 @@ class SkinTemplate extends Skin { $content_navigation['variants'][] = array( 'class' => ( $code == $preferred ) ? 'selected' : false, 'text' => $varname, - 'href' => $this->mTitle->getLocalURL( '', $code ) + 'href' => $title->getLocalURL( '', $code ) ); } } @@ -1179,10 +1183,10 @@ class SkinTemplate extends Skin { ); } - if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) { - $rootUser = strtok( $this->mTitle->getText(), '/' ); - $id = User::idFromName( $rootUser ); - $ip = User::isIP( $rootUser ); + if ( $user = $this->getRelevantUser() ) { + $id = $user->getID(); + $ip = $user->isAnon(); + $rootUser = $user->getName(); } else { $id = 0; $ip = false; diff --git a/includes/specials/SpecialBlockip.php b/includes/specials/SpecialBlockip.php index ad44b344fc..438bc35896 100644 --- a/includes/specials/SpecialBlockip.php +++ b/includes/specials/SpecialBlockip.php @@ -123,6 +123,9 @@ class IPBlockForm extends SpecialPage { $titleObj = SpecialPage::getTitleFor( 'Blockip' ); $user = User::newFromName( $this->BlockAddress ); + if ( is_object( $user ) || User::isIP( $this->BlockAddress ) ) { + $wgUser->getSkin()->setRelevantUser( is_object($user) ? $user : User::newFromName( $this->BlockAddress, false ) ); + } $alreadyBlocked = false; $otherBlockedMsgs = array(); diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index a01030c05f..fb9d394ff2 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -78,6 +78,10 @@ class SpecialContributions extends SpecialPage { $target = $nt->getText(); $wgOut->setSubtitle( $this->contributionsSub( $nt, $id ) ); $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsgExt( 'contributions-title', array( 'parsemag' ),$target ) ) ); + $user = User::newFromName( $target, false ); + if ( is_object($user) ) { + $wgUser->getSkin()->setRelevantUser( $user ); + } } else { $wgOut->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') ); $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'sp-contributions-newbies-title' ) ) ); diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index a2af8de5c1..e34a341ce9 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -106,6 +106,11 @@ class SpecialLog extends SpecialPage { # Set title and add header $loglist->showHeader( $pager->getType() ); + # Set relevant user + if ( $pager->getUser() ) { + $wgUser->getSkin()->setRelevantUser( User::newFromName( $pager->getUser() ) ); + } + # Show form options $loglist->showOptions( $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern(), $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $opts->getValue( 'tagfilter' ) ); diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 2f156c6549..eea2720011 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -109,6 +109,7 @@ class MovePageForm extends UnlistedSpecialPage { $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle->getPrefixedText() ) ); $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) ); + $skin->setRelevantTitle( $this->oldTitle ); $newTitle = $this->newTitle; diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index 1cf61d2653..efbeb3dcbf 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -649,6 +649,7 @@ class UndeleteForm extends SpecialPage { } if ( $this->mTarget !== '' ) { $this->mTargetObj = Title::newFromURL( $this->mTarget ); + $wgUser->getSkin()->setRelevantTitle( $this->mTargetObj ); } else { $this->mTargetObj = null; } -- 2.20.1