r79398 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79397‎ | r79398 | r79399 >
Date:01:03, 1 January 2011
Author:dantman
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialLog.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMovepage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SkinTemplate.php
@@ -789,6 +789,9 @@
790790
791791 wfProfileIn( __METHOD__ );
792792
 793+ $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
 794+ $onPage = $title->equals($this->mTitle);
 795+
793796 $content_navigation = array(
794797 'namespaces' => array(),
795798 'views' => array(),
@@ -800,23 +803,23 @@
801804 $action = $wgRequest->getVal( 'action', 'view' );
802805 $section = $wgRequest->getVal( 'section' );
803806
804 - $userCanRead = $this->mTitle->userCanRead();
 807+ $userCanRead = $title->userCanRead();
805808 $skname = $this->skinname;
806809
807810 $preventActiveTabs = false;
808811 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
809812
810813 // Checks if page is some kind of content
811 - if( $this->iscontent ) {
 814+ if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
812815 // Gets page objects for the related namespaces
813 - $subjectPage = $this->mTitle->getSubjectPage();
814 - $talkPage = $this->mTitle->getTalkPage();
 816+ $subjectPage = $title->getSubjectPage();
 817+ $talkPage = $title->getTalkPage();
815818
816819 // Determines if this is a talk page
817 - $isTalk = $this->mTitle->isTalkPage();
 820+ $isTalk = $title->isTalkPage();
818821
819822 // Generates XML IDs from namespace names
820 - $subjectId = $this->mTitle->getNamespaceKey( '' );
 823+ $subjectId = $title->getNamespaceKey( '' );
821824
822825 if ( $subjectId == 'main' ) {
823826 $talkId = 'talk';
@@ -835,11 +838,11 @@
836839 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
837840
838841 // Adds view view link
839 - if ( $this->mTitle->exists() && $userCanRead ) {
 842+ if ( $title->exists() && $userCanRead ) {
840843 $content_navigation['views']['view'] = $this->tabAction(
841844 $isTalk ? $talkPage : $subjectPage,
842845 !wfEmptyMsg( "$skname-view-view" ) ? "$skname-view-view" : 'view',
843 - ( $action == 'view' ), '', true
 846+ ( $onPage && $action == 'view' ), '', true
844847 );
845848 $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
846849 }
@@ -849,12 +852,12 @@
850853 // Checks if user can...
851854 if (
852855 // read and edit the current page
853 - $userCanRead && $this->mTitle->quickUserCan( 'edit' ) &&
 856+ $userCanRead && $title->quickUserCan( 'edit' ) &&
854857 (
855858 // if it exists
856 - $this->mTitle->exists() ||
 859+ $title->exists() ||
857860 // or they can create one here
858 - $this->mTitle->quickUserCan( 'create' )
 861+ $title->quickUserCan( 'create' )
859862 )
860863 ) {
861864 // Builds CSS class for talk page links
@@ -862,15 +865,16 @@
863866
864867 // Determines if we're in edit mode
865868 $selected = (
 869+ $onPage &&
866870 ( $action == 'edit' || $action == 'submit' ) &&
867871 ( $section != 'new' )
868872 );
869 - $msgKey = $this->mTitle->exists() || ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $this->mTitle->getText() ) ) ?
 873+ $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $title->getText() ) ) ?
870874 "edit" : "create";
871875 $content_navigation['views']['edit'] = array(
872876 'class' => ( $selected ? 'selected' : '' ) . $isTalkClass,
873877 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->plain(),
874 - 'href' => $this->mTitle->getLocalURL( $this->editUrlOptions() ),
 878+ 'href' => $title->getLocalURL( $this->editUrlOptions() ),
875879 'primary' => true, // don't collapse this in vector
876880 );
877881 // Checks if this is a current rev of talk page and we should show a new
@@ -883,17 +887,17 @@
884888 $content_navigation['views']['addsection'] = array(
885889 'class' => $section == 'new' ? 'selected' : false,
886890 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->plain(),
887 - 'href' => $this->mTitle->getLocalURL( 'action=edit&section=new' )
 891+ 'href' => $title->getLocalURL( 'action=edit&section=new' )
888892 );
889893 }
890894 }
891895 // Checks if the page has some kind of viewable content
892 - } elseif ( $this->mTitle->hasSourceText() && $userCanRead ) {
 896+ } elseif ( $title->hasSourceText() && $userCanRead ) {
893897 // Adds view source view link
894898 $content_navigation['views']['viewsource'] = array(
895 - 'class' => ( $action == 'edit' ) ? 'selected' : false,
 899+ 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
896900 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->plain(),
897 - 'href' => $this->mTitle->getLocalURL( $this->editUrlOptions() ),
 901+ 'href' => $title->getLocalURL( $this->editUrlOptions() ),
898902 'primary' => true, // don't collapse this in vector
899903 );
900904 }
@@ -902,24 +906,24 @@
903907 wfProfileIn( __METHOD__ . '-live' );
904908
905909 // Checks if the page exists
906 - if ( $this->mTitle->exists() && $userCanRead ) {
 910+ if ( $title->exists() && $userCanRead ) {
907911 // Adds history view link
908912 $content_navigation['views']['history'] = array(
909 - 'class' => ( $action == 'history' ) ? 'selected' : false,
 913+ 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
910914 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->plain(),
911 - 'href' => $this->mTitle->getLocalURL( 'action=history' ),
 915+ 'href' => $title->getLocalURL( 'action=history' ),
912916 'rel' => 'archives',
913917 );
914918
915919 if( $wgUser->isAllowed( 'delete' ) ) {
916920 $content_navigation['actions']['delete'] = array(
917 - 'class' => ( $action == 'delete' ) ? 'selected' : false,
 921+ 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
918922 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->plain(),
919 - 'href' => $this->mTitle->getLocalURL( 'action=delete' )
 923+ 'href' => $title->getLocalURL( 'action=delete' )
920924 );
921925 }
922 - if ( $this->mTitle->quickUserCan( 'move' ) ) {
923 - $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
 926+ if ( $title->quickUserCan( 'move' ) ) {
 927+ $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
924928 $content_navigation['actions']['move'] = array(
925929 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
926930 'text' => wfMessageFallback( "$skname-action-move", 'move' )->plain(),
@@ -927,37 +931,37 @@
928932 );
929933 }
930934
931 - if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
932 - $mode = !$this->mTitle->isProtected() ? 'protect' : 'unprotect';
 935+ if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
 936+ $mode = !$title->isProtected() ? 'protect' : 'unprotect';
933937 $content_navigation['actions'][$mode] = array(
934 - 'class' => ( $action == $mode ) ? 'selected' : false,
 938+ 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
935939 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->plain(),
936 - 'href' => $this->mTitle->getLocalURL( "action=$mode" )
 940+ 'href' => $title->getLocalURL( "action=$mode" )
937941 );
938942 }
939943 } else {
940944 // article doesn't exist or is deleted
941945 if ( $wgUser->isAllowed( 'deletedhistory' ) ) {
942 - $n = $this->mTitle->isDeleted();
 946+ $n = $title->isDeleted();
943947 if( $n ) {
944948 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
945949 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
946950 $msgKey = $wgUser->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
947951 $content_navigation['actions']['undelete'] = array(
948 - 'class' => false,
 952+ 'class' => $this->mTitle->isSpecial( 'Undelete' ) ? 'selected' : false,
949953 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
950954 ->params( $wgLang->formatNum( $n ) )->text(),
951 - 'href' => $undelTitle->getLocalURL( array( 'target' => $this->thispage ) )
 955+ 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
952956 );
953957 }
954958 }
955959
956 - if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
957 - $mode = !$this->mTitle->getRestrictions( 'create' ) ? 'protect' : 'unprotect';
 960+ if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
 961+ $mode = !$title->getRestrictions( 'create' ) ? 'protect' : 'unprotect';
958962 $content_navigation['actions'][$mode] = array(
959 - 'class' => ( $action == $mode ) ? 'selected' : false,
 963+ 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
960964 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->plain(),
961 - 'href' => $this->mTitle->getLocalURL( "action=$mode" )
 965+ 'href' => $title->getLocalURL( "action=$mode" )
962966 );
963967 }
964968 }
@@ -974,11 +978,11 @@
975979 * a change to that procedure these messages will have to remain as
976980 * the global versions.
977981 */
978 - $mode = $this->mTitle->userIsWatching() ? 'unwatch' : 'watch';
 982+ $mode = $title->userIsWatching() ? 'unwatch' : 'watch';
979983 $content_navigation['actions'][$mode] = array(
980 - 'class' => ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
 984+ 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
981985 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
982 - 'href' => $this->mTitle->getLocalURL( 'action=' . $mode )
 986+ 'href' => $title->getLocalURL( 'action=' . $mode )
983987 );
984988 }
985989
@@ -1014,7 +1018,7 @@
10151019 $content_navigation['variants'][] = array(
10161020 'class' => ( $code == $preferred ) ? 'selected' : false,
10171021 'text' => $varname,
1018 - 'href' => $this->mTitle->getLocalURL( '', $code )
 1022+ 'href' => $title->getLocalURL( '', $code )
10191023 );
10201024 }
10211025 }
@@ -1179,10 +1183,10 @@
11801184 );
11811185 }
11821186
1183 - if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
1184 - $rootUser = strtok( $this->mTitle->getText(), '/' );
1185 - $id = User::idFromName( $rootUser );
1186 - $ip = User::isIP( $rootUser );
 1187+ if ( $user = $this->getRelevantUser() ) {
 1188+ $id = $user->getID();
 1189+ $ip = $user->isAnon();
 1190+ $rootUser = $user->getName();
11871191 } else {
11881192 $id = 0;
11891193 $ip = false;
Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -649,6 +649,7 @@
650650 }
651651 if ( $this->mTarget !== '' ) {
652652 $this->mTargetObj = Title::newFromURL( $this->mTarget );
 653+ $wgUser->getSkin()->setRelevantTitle( $this->mTargetObj );
653654 } else {
654655 $this->mTargetObj = null;
655656 }
Index: trunk/phase3/includes/specials/SpecialLog.php
@@ -106,6 +106,11 @@
107107 # Set title and add header
108108 $loglist->showHeader( $pager->getType() );
109109
 110+ # Set relevant user
 111+ if ( $pager->getUser() ) {
 112+ $wgUser->getSkin()->setRelevantUser( User::newFromName( $pager->getUser() ) );
 113+ }
 114+
110115 # Show form options
111116 $loglist->showOptions( $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern(),
112117 $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $opts->getValue( 'tagfilter' ) );
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -78,6 +78,10 @@
7979 $target = $nt->getText();
8080 $wgOut->setSubtitle( $this->contributionsSub( $nt, $id ) );
8181 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsgExt( 'contributions-title', array( 'parsemag' ),$target ) ) );
 82+ $user = User::newFromName( $target, false );
 83+ if ( is_object($user) ) {
 84+ $wgUser->getSkin()->setRelevantUser( $user );
 85+ }
8286 } else {
8387 $wgOut->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') );
8488 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'sp-contributions-newbies-title' ) ) );
Index: trunk/phase3/includes/specials/SpecialBlockip.php
@@ -123,6 +123,9 @@
124124
125125 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
126126 $user = User::newFromName( $this->BlockAddress );
 127+ if ( is_object( $user ) || User::isIP( $this->BlockAddress ) ) {
 128+ $wgUser->getSkin()->setRelevantUser( is_object($user) ? $user : User::newFromName( $this->BlockAddress, false ) );
 129+ }
127130
128131 $alreadyBlocked = false;
129132 $otherBlockedMsgs = array();
Index: trunk/phase3/includes/specials/SpecialMovepage.php
@@ -109,6 +109,7 @@
110110
111111 $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle->getPrefixedText() ) );
112112 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
 113+ $skin->setRelevantTitle( $this->oldTitle );
113114
114115 $newTitle = $this->newTitle;
115116
Index: trunk/phase3/includes/Skin.php
@@ -27,6 +27,8 @@
2828 protected $skinname = 'standard';
2929 // @todo Fixme: should be protected :-\
3030 var $mTitle = null;
 31+ protected $mRelevantTitle = null;
 32+ protected $mRelevantUser = null;
3133
3234 /** Constructor, call parent constructor */
3335 function __construct() {
@@ -366,6 +368,66 @@
367369 }
368370
369371 /**
 372+ * Set the "relevant" title
 373+ * @see self::getRelevantTitle()
 374+ * @param $t Title object to use
 375+ */
 376+ public function setRelevantTitle( $t ) {
 377+ $this->mRelevantTitle = $t;
 378+ }
 379+
 380+ /**
 381+ * Return the "relevant" title.
 382+ * A "relevant" title is not necessarily the actual title of the page.
 383+ * Special pages like Special:MovePage use set the page they are acting on
 384+ * as their "relevant" title, this allows the skin system to display things
 385+ * such as content tabs which belong to to that page instead of displaying
 386+ * a basic special page tab which has almost no meaning.
 387+ */
 388+ public function getRelevantTitle() {
 389+ if ( isset($this->mRelevantTitle) ) {
 390+ return $this->mRelevantTitle;
 391+ }
 392+ return $this->mTitle;
 393+ }
 394+
 395+ /**
 396+ * Set the "relevant" user
 397+ * @see self::getRelevantUser()
 398+ * @param $u User object to use
 399+ */
 400+ public function setRelevantUser( $u ) {
 401+ $this->mRelevantUser = $u;
 402+ }
 403+
 404+ /**
 405+ * Return the "relevant" user.
 406+ * A "relevant" user is similar to a relevant title. Special pages like
 407+ * Special:Contributions mark the user which they are relevant to so that
 408+ * things like the toolbox can display the information they usually are only
 409+ * able to display on a user's userpage and talkpage.
 410+ */
 411+ public function getRelevantUser() {
 412+ if ( isset($this->mRelevantUser) ) {
 413+ return $this->mRelevantUser;
 414+ }
 415+ $title = $this->getRelevantTitle();
 416+ if( $title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK ) {
 417+ $rootUser = strtok( $title->getText(), '/' );
 418+ if ( User::isIP( $rootUser ) ) {
 419+ $this->mRelevantUser = User::newFromName( $rootUser, false );
 420+ } else {
 421+ $user = User::newFromName( $rootUser );
 422+ if ( $user->isLoggedIn() ) {
 423+ $this->mRelevantUser = $user;
 424+ }
 425+ }
 426+ return $this->mRelevantUser;
 427+ }
 428+ return null;
 429+ }
 430+
 431+ /**
370432 * Outputs the HTML generated by other functions.
371433 * @param $out Object: instance of OutputPage
372434 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r79399*sigh* I wish this were git... Followup r79398, small mistake that slipped th...dantman01:05, 1 January 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   06:53, 5 July 2011

MovePage...is nice :)

Status & tagging log