Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/303087
Change subject: Unify Special:Contribs/DeletedContribs subtitle implementation ...................................................................... Unify Special:Contribs/DeletedContribs subtitle implementation Basically all of the code was duplicated, except that Contribs had a link to DeletedContribs, and DeletedContribs had a link to Contribs. Now DeletedContribs will call the function in Contribs, and remove the DeletedContribs link, and add its own link to Contribs instead of needing to duplicate the entire list of links. Change-Id: Ia004a4a69427fd5b554131b19b0e263523b7da67 --- M includes/specials/SpecialContributions.php M includes/specials/SpecialDeletedContributions.php 2 files changed, 40 insertions(+), 105 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/87/303087/1 diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index ab46dda..ac71fe2 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -273,7 +273,7 @@ $talk = $userObj->getTalkPage(); $links = ''; if ( $talk ) { - $tools = $this->getUserLinks( $nt, $talk, $userObj ); + $tools = self::getUserLinks( $this, $userObj ); $links = $this->getLanguage()->pipeList( $tools ); // Show a note if the user is blocked and display the last block log entry. @@ -313,87 +313,90 @@ /** * Links to different places. - * @param Title $userpage Target user page - * @param Title $talkpage Talk page + * + * @note This function is also called in DeletedContributionsPage + * @param SpecialPage $sp SpecialPage instance, for context * @param User $target Target user object * @return array */ - public function getUserLinks( Title $userpage, Title $talkpage, User $target ) { + public static function getUserLinks( SpecialPage $sp, User $target ) { $id = $target->getId(); $username = $target->getName(); + $userpage = $target->getUserPage(); + $talkpage = $target->getTalkPage(); - $linkRenderer = $this->getLinkRenderer(); - $tools[] = $linkRenderer->makeLink( $talkpage, $this->msg( 'sp-contributions-talk' )->text() ); + $linkRenderer = $sp->getLinkRenderer(); + $tools['user-talk'] = $linkRenderer->makeLink( $talkpage, $sp->msg( 'sp-contributions-talk' )->text() ); if ( ( $id !== null ) || ( $id === null && IP::isIPAddress( $username ) ) ) { - if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links + if ( $sp->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links if ( $target->isBlocked() && $target->getBlock()->getType() != Block::TYPE_AUTO ) { - $tools[] = $linkRenderer->makeKnownLink( # Change block link + $tools['block'] = $linkRenderer->makeKnownLink( # Change block link SpecialPage::getTitleFor( 'Block', $username ), - $this->msg( 'change-blocklink' )->text() + $sp->msg( 'change-blocklink' )->text() ); - $tools[] = $linkRenderer->makeKnownLink( # Unblock link + $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link SpecialPage::getTitleFor( 'Unblock', $username ), - $this->msg( 'unblocklink' )->text() + $sp->msg( 'unblocklink' )->text() ); } else { # User is not blocked - $tools[] = $linkRenderer->makeKnownLink( # Block link + $tools['block'] = $linkRenderer->makeKnownLink( # Block link SpecialPage::getTitleFor( 'Block', $username ), - $this->msg( 'blocklink' )->text() + $sp->msg( 'blocklink' )->text() ); } } # Block log link - $tools[] = $linkRenderer->makeKnownLink( + $tools['log-block'] = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'Log', 'block' ), - $this->msg( 'sp-contributions-blocklog' )->text(), + $sp->msg( 'sp-contributions-blocklog' )->text(), [], [ 'page' => $userpage->getPrefixedText() ] ); # Suppression log link (bug 59120) - if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) { - $tools[] = $linkRenderer->makeKnownLink( + if ( $sp->getUser()->isAllowed( 'suppressionlog' ) ) { + $tools['log-suppression'] = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'Log', 'suppress' ), - $this->msg( 'sp-contributions-suppresslog' )->text(), + $sp->msg( 'sp-contributions-suppresslog' )->text(), [], [ 'offender' => $username ] ); } } # Uploads - $tools[] = $linkRenderer->makeKnownLink( + $tools['uploads'] = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'Listfiles', $username ), - $this->msg( 'sp-contributions-uploads' )->text() + $sp->msg( 'sp-contributions-uploads' )->text() ); # Other logs link - $tools[] = $linkRenderer->makeKnownLink( + $tools['logs'] = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'Log', $username ), - $this->msg( 'sp-contributions-logs' )->text() + $sp->msg( 'sp-contributions-logs' )->text() ); # Add link to deleted user contributions for priviledged users - if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) { - $tools[] = $linkRenderer->makeKnownLink( + if ( $sp->getUser()->isAllowed( 'deletedhistory' ) ) { + $tools['deletedcontribs'] = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'DeletedContributions', $username ), - $this->msg( 'sp-contributions-deleted' )->text() + $sp->msg( 'sp-contributions-deleted' )->text() ); } # Add a link to change user rights for privileged users $userrightsPage = new UserrightsPage(); - $userrightsPage->setContext( $this->getContext() ); + $userrightsPage->setContext( $sp->getContext() ); if ( $userrightsPage->userCanChangeRights( $target ) ) { - $tools[] = $linkRenderer->makeKnownLink( + $tools['userrights'] = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'Userrights', $username ), - $this->msg( 'sp-contributions-userrights' )->text() + $sp->msg( 'sp-contributions-userrights' )->text() ); } - Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $this ] ); + Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $sp ] ); return $tools; } diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index a402d3c..8e168b2 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -129,97 +129,29 @@ * Generates the subheading with links * @param User $userObj User object for the target * @return string Appropriately-escaped HTML to be output literally - * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined. */ function getSubTitle( $userObj ) { + $linkRenderer = $this->getLinkRenderer(); if ( $userObj->isAnon() ) { $user = htmlspecialchars( $userObj->getName() ); } else { - $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) ); + $user = $linkRenderer->makeKnownLink( $userObj->getUserPage(), $userObj->getName() ); } $links = ''; $nt = $userObj->getUserPage(); - $id = $userObj->getId(); $talk = $nt->getTalkPage(); if ( $talk ) { - # Talk page link - $tools[] = Linker::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() ); - if ( ( $id !== null ) || ( $id === null && IP::isIPAddress( $nt->getText() ) ) ) { - # Block / Change block / Unblock links - if ( $this->getUser()->isAllowed( 'block' ) ) { - if ( $userObj->isBlocked() && $userObj->getBlock()->getType() !== Block::TYPE_AUTO ) { - $tools[] = Linker::linkKnown( # Change block link - SpecialPage::getTitleFor( 'Block', $nt->getDBkey() ), - $this->msg( 'change-blocklink' )->escaped() - ); - $tools[] = Linker::linkKnown( # Unblock link - SpecialPage::getTitleFor( 'BlockList' ), - $this->msg( 'unblocklink' )->escaped(), - [], - [ - 'action' => 'unblock', - 'ip' => $nt->getDBkey() - ] - ); - } else { - # User is not blocked - $tools[] = Linker::linkKnown( # Block link - SpecialPage::getTitleFor( 'Block', $nt->getDBkey() ), - $this->msg( 'blocklink' )->escaped() - ); - } - } - # Block log link - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Log' ), - $this->msg( 'sp-contributions-blocklog' )->escaped(), - [], - [ - 'type' => 'block', - 'page' => $nt->getPrefixedText() - ] - ); - # Suppression log link (bug 59120) - if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) { - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Log', 'suppress' ), - $this->msg( 'sp-contributions-suppresslog' )->escaped(), - [], - [ 'offender' => $userObj->getName() ] - ); - } - } + $tools = SpecialContributions::getUserLinks( $this, $userObj ); - # Uploads - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Listfiles', $userObj->getName() ), - $this->msg( 'sp-contributions-uploads' )->escaped() - ); - - # Other logs link - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Log' ), - $this->msg( 'sp-contributions-logs' )->escaped(), - [], - [ 'user' => $nt->getText() ] - ); # Link to contributions - $tools[] = Linker::linkKnown( + $insert['contribs'] = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ), - $this->msg( 'sp-deletedcontributions-contribs' )->escaped() + $this->msg( 'sp-deletedcontributions-contribs' )->text() ); - # Add a link to change user rights for privileged users - $userrightsPage = new UserrightsPage(); - $userrightsPage->setContext( $this->getContext() ); - if ( $userrightsPage->userCanChangeRights( $userObj ) ) { - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Userrights', $nt->getDBkey() ), - $this->msg( 'sp-contributions-userrights' )->escaped() - ); - } - - Hooks::run( 'ContributionsToolLinks', [ $id, $nt, &$tools, $this ] ); + // Swap out the deletedcontribs link for our contribs one + $tools = wfArrayInsertAfter( $tools, $insert, 'deletedcontribs' ); + unset( $tools['deletedcontribs'] ); $links = $this->getLanguage()->pipeList( $tools ); -- To view, visit https://gerrit.wikimedia.org/r/303087 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia004a4a69427fd5b554131b19b0e263523b7da67 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits