devunt has uploaded a new change for review. https://gerrit.wikimedia.org/r/137581
Change subject: Provide user navigation links in User::getNavigationLinks ...................................................................... Provide user navigation links in User::getNavigationLinks Provide user navigation links in User::getNavigationLinks, and add navigation to other user-related pages. Especially [[Special:Listfiles]] and [[Special:Log]]. Bug: 27707 Change-Id: I9f364e40a8858e4aa6d2dba92a61616fd22bc4e1 --- M includes/User.php M includes/specials/SpecialContributions.php M includes/specials/SpecialDeletedContributions.php M includes/specials/SpecialListfiles.php M includes/specials/SpecialLog.php M languages/i18n/en.json M languages/i18n/qqq.json 7 files changed, 146 insertions(+), 263 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/81/137581/1 diff --git a/includes/User.php b/includes/User.php index b5fb1ff..46447ec 100644 --- a/includes/User.php +++ b/includes/User.php @@ -4938,4 +4938,97 @@ return Status::newFatal( 'badaccess-group0' ); } } + + /** + * Generate user navigation with links + * + * @since 1.24 + * @return Message User navigations (mostly for subheader) + */ + public function getNavigationLinks() { + global $wgUser, $wgLang; + if ( $this->isAnon() ) { + $user = htmlspecialchars( $this->getName() ); + } else { + $user = Linker::link( $this->getUserPage(), htmlspecialchars( $this->getName() ) ); + } + + $tools[] = Linker::link( $this->getTalkPage(), wfMessage( 'sp-contributions-talk' )->escaped() ); + $tools[] = Linker::linkKnown( + SpecialPage::getTitleFor( 'Contributions', $this->getName() ), + wfMessage( 'contribslink' ) + ); + if ( $this->isLoggedIn() || IP::isIPAddress( $this->getName() ) ) { + if ( $wgUser->isAllowed( 'block' ) ) { # Block / Change block / Unblock links + if ( $this->isBlocked() && $this->getBlock()->getType() != Block::TYPE_AUTO) { + $tools[] = Linker::linkKnown( # Change block link + SpecialPage::getTitleFor( 'Block', $this->getName() ), + wfMessage( 'change-blocklink' )->escaped() + ); + $tools[] = Linker::linkKnown( # Unblock link + SpecialPage::getTitleFor( 'Block', $this->getName() ), + wfMessage( 'unblocklink' )->escaped() + ); + } else { # User is not blocked + $tools[] = Linker::linkKnown( # Block link + SpecialPage::getTitleFor( 'Block', $this->getName() ), + wfMessage( 'blocklink' )->escaped() + ); + } + } + + # Block log link + $tools[] = Linker::linkKnown( + SpecialPage::getTitleFor( 'Log', 'block' ), + wfMessage( 'sp-contributions-blocklog' )->escaped(), + array(), + array( 'page' => $this->getUserPage()->getPrefixedText() ) + ); + + # Suppression log link (bug 59120) + if ( $wgUser->isAllowed( 'suppressionlog' ) ) { + $tools[] = Linker::linkKnown( + SpecialPage::getTitleFor( 'Log', 'suppress' ), + wfMessage( 'sp-contributions-suppresslog' )->escaped(), + array(), + array( 'offender' => $this->getName() ) + ); + } + } + + # Uploads + $tools[] = Linker::linkKnown( + SpecialPage::getTitleFor( 'Listfiles', $this->getName() ), + wfMessage( 'sp-contributions-uploads' )->escaped() + ); + + # Other logs link + $tools[] = Linker::linkKnown( + SpecialPage::getTitleFor( 'Log', $this->getName() ), + wfMessage( 'sp-contributions-logs' )->escaped() + ); + + # Add link to deleted user contributions for priviledged users + if ( $wgUser->isAllowed( 'deletedhistory' ) ) { + $tools[] = Linker::linkKnown( + SpecialPage::getTitleFor( 'DeletedContributions', $this->getName() ), + wfMessage( 'sp-contributions-deleted' ) + ); + } + + # Add a link to change user rights for priviledged users + $userrightspage = new UserrightsPage(); + $userrightspage->setContext( RequestContext::getMain() ); + if ( $userrightspage->userCanChangeRights( $this ) ) { + $tools[] = Linker::linkKnown( + SpecialPage::getTitleFor( 'Userrights', $this->getName() ), + wfMessage( 'sp-contributions-userrights' )->escaped() + ); + } + + wfRunHooks( 'ContributionsToolLinks', array ( $this->getId(), $this->getUserPage(), &$tools ) ); + + $links = $wgLang->pipeList( $tools ); + return wfMessage( 'usersub' )->rawParams( $user, $links )->params( $this->getName() ); + } } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 0571d0d..4fc3a27 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -92,7 +92,7 @@ if ( $this->opts['contribs'] != 'newbie' ) { $target = $nt->getText(); - $out->addSubtitle( $this->contributionsSub( $userObj ) ); + $out->addSubtitle( $userObj->getNavigationLinks() ); $out->setHTMLTitle( $this->msg( 'pagetitle', $this->msg( 'contributions-title', $target )->plain() @@ -233,150 +233,6 @@ } } } - } - - /** - * 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 getSubTitle in SpecialDeletedContributions.php. - * Could be combined. - */ - protected function contributionsSub( $userObj ) { - if ( $userObj->isAnon() ) { - // Show a warning message that the user being searched for doesn't exists - if ( !User::isIP( $userObj->getName() ) ) { - $this->getOutput()->wrapWikiMsg( - "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>", - array( - 'contributions-userdoesnotexist', - wfEscapeWikiText( $userObj->getName() ), - ) - ); - } - $user = htmlspecialchars( $userObj->getName() ); - } else { - $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) ); - } - $nt = $userObj->getUserPage(); - $talk = $userObj->getTalkPage(); - $links = ''; - if ( $talk ) { - $tools = $this->getUserLinks( $nt, $talk, $userObj ); - $links = $this->getLanguage()->pipeList( $tools ); - - // Show a note if the user is blocked and display the last block log entry. - // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs, - // and also this will display a totally irrelevant log entry as a current block. - if ( $userObj->isBlocked() && $userObj->getBlock()->getType() != Block::TYPE_AUTO ) { - $out = $this->getOutput(); // showLogExtract() wants first parameter by reference - LogEventsList::showLogExtract( - $out, - 'block', - $nt, - '', - array( - 'lim' => 1, - 'showIfEmpty' => false, - 'msgKey' => array( - $userObj->isAnon() ? - 'sp-contributions-blocked-notice-anon' : - 'sp-contributions-blocked-notice', - $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice' - ), - 'offset' => '' # don't use WebRequest parameter offset - ) - ); - } - } - - return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() ); - } - - /** - * Links to different places. - * @param Title $userpage Target user page - * @param Title $talkpage Talk page - * @param User $target Target user object - * @return array - */ - public function getUserLinks( Title $userpage, Title $talkpage, User $target ) { - - $id = $target->getId(); - $username = $target->getName(); - - $tools[] = Linker::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() ); - - if ( ( $id !== null ) || ( $id === null && IP::isIPAddress( $username ) ) ) { - if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links - if ( $target->isBlocked() && $target->getBlock()->getType() != Block::TYPE_AUTO ) { - $tools[] = Linker::linkKnown( # Change block link - SpecialPage::getTitleFor( 'Block', $username ), - $this->msg( 'change-blocklink' )->escaped() - ); - $tools[] = Linker::linkKnown( # Unblock link - SpecialPage::getTitleFor( 'Unblock', $username ), - $this->msg( 'unblocklink' )->escaped() - ); - } else { # User is not blocked - $tools[] = Linker::linkKnown( # Block link - SpecialPage::getTitleFor( 'Block', $username ), - $this->msg( 'blocklink' )->escaped() - ); - } - } - - # Block log link - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Log', 'block' ), - $this->msg( 'sp-contributions-blocklog' )->escaped(), - array(), - array( 'page' => $userpage->getPrefixedText() ) - ); - - # Suppression log link (bug 59120) - if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) { - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Log', 'suppress' ), - $this->msg( 'sp-contributions-suppresslog' )->escaped(), - array(), - array( 'offender' => $username ) - ); - } - } - # Uploads - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Listfiles', $username ), - $this->msg( 'sp-contributions-uploads' )->escaped() - ); - - # Other logs link - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Log', $username ), - $this->msg( 'sp-contributions-logs' )->escaped() - ); - - # Add link to deleted user contributions for priviledged users - if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) { - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'DeletedContributions', $username ), - $this->msg( 'sp-contributions-deleted' )->escaped() - ); - } - - # Add a link to change user rights for privileged users - $userrightsPage = new UserrightsPage(); - $userrightsPage->setContext( $this->getContext() ); - if ( $userrightsPage->userCanChangeRights( $target ) ) { - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Userrights', $username ), - $this->msg( 'sp-contributions-userrights' )->escaped() - ); - } - - wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) ); - - return $tools; } /** diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index 5bec95b..0ef5c89 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -329,7 +329,28 @@ $this->getSkin()->setRelevantUser( $userObj ); $target = $userObj->getName(); - $out->addSubtitle( $this->getSubTitle( $userObj ) ); + $out->addSubtitle( $userObj->getNavigationLinks() ); + + // Show a note if the user is blocked and display the last block log entry. + if ( $userObj->isBlocked() ) { + // LogEventsList::showLogExtract() wants the first parameter by ref + $out = $this->getOutput(); + LogEventsList::showLogExtract( + $out, + 'block', + $nt, + '', + array( + 'lim' => 1, + 'showIfEmpty' => false, + 'msgKey' => array( + 'sp-contributions-blocked-notice', + $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice' + ), + 'offset' => '' # don't use $this->getRequest() parameter offset + ) + ); + } if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) { $options['namespace'] = intval( $ns ); @@ -380,120 +401,6 @@ * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined. */ function getSubTitle( $userObj ) { - if ( $userObj->isAnon() ) { - $user = htmlspecialchars( $userObj->getName() ); - } else { - $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $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() ) { - $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(), - array(), - array( - '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(), - array(), - array( - '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(), - array(), - array( 'offender' => $userObj->getName() ) - ); - } - } - - # 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(), - array(), - array( 'user' => $nt->getText() ) - ); - # Link to contributions - $tools[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ), - $this->msg( 'sp-deletedcontributions-contribs' )->escaped() - ); - - # 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() - ); - } - - wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) ); - - $links = $this->getLanguage()->pipeList( $tools ); - - // Show a note if the user is blocked and display the last block log entry. - if ( $userObj->isBlocked() ) { - // LogEventsList::showLogExtract() wants the first parameter by ref - $out = $this->getOutput(); - LogEventsList::showLogExtract( - $out, - 'block', - $nt, - '', - array( - 'lim' => 1, - 'showIfEmpty' => false, - 'msgKey' => array( - 'sp-contributions-blocked-notice', - $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice' - ), - 'offset' => '' # don't use $this->getRequest() parameter offset - ) - ); - } - } - - return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() ); } /** diff --git a/includes/specials/SpecialListfiles.php b/includes/specials/SpecialListfiles.php index 3715b8b..f3e0b59 100644 --- a/includes/specials/SpecialListfiles.php +++ b/includes/specials/SpecialListfiles.php @@ -51,6 +51,13 @@ if ( $this->including() ) { $html = $pager->getBody(); } else { + $title = Title::makeTitleSafe( NS_USER, $userName ); + if ( $title ) { + $user = User::newFromName( $title->getText(), false ); + if ( $user ) { + $this->getOutput()->addSubtitle( $user->getNavigationLinks() ); + } + } $form = $pager->getForm(); $body = $pager->getBody(); $nav = $pager->getNavigationBar(); diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index 6da6674..9663a75 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -106,9 +106,27 @@ $target = Title::newFromText( $opts->getValue( 'page' ) ); if ( $target && $target->getNamespace() === NS_MAIN ) { # User forgot to add 'User:', we are adding it for him - $opts->setValue( 'page', - Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) ) - ); + $title = Title::makeTitleSafe( NS_USER, $opts->getValue( 'page' ) ); + if ( $title ) { + $title = $title->getPrefixedText(); + } + $opts->setValue( 'page', $title ); + } + } + + $title = Title::makeTitleSafe( NS_USER, $opts->getValue( 'user' ) ); + if ( $title ) { + $user = User::newFromName( $title->getText() ); + if ( $user ) { + $this->getOutput()->addSubtitle( $user->getNavigationLinks() ); + } + } + + $title = Title::newFromText( $opts->getValue( 'page' ) ); + if ( $title && $title->getNamespace() === NS_USER ) { + $user = User::newFromName( $title->getText() ); + if ( $user ) { + $this->getOutput()->addSubtitle( $user->getNavigationLinks() ); } } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index df4a05f..316237e 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1999,6 +1999,7 @@ "contributions-title": "User contributions for $1", "mycontris": "Contributions", "contribsub2": "For {{GENDER:$3|$1}} ($2)", + "usersub": "{{GENDER:$3|$1}} ($2)", "contributions-userdoesnotexist": "User account \"$1\" is not registered.", "nocontribs": "No changes were found matching these criteria.", "uctop": "(current)", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index d803787..bcca962 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2161,6 +2161,7 @@ "contributions-title": "{{Gender}}\nThe page title in your browser bar, but not the page title.\n\nParameters:\n* $1 - the username\nSee also:\n* {{msg-mw|Contributions}}", "mycontris": "In the personal urls page section - right upper corner.\n\nSee also:\n* {{msg-mw|Mycontris}}\n* {{msg-mw|Accesskey-pt-mycontris}}\n* {{msg-mw|Tooltip-pt-mycontris}}\n{{Identical|Contribution}}", "contribsub2": "Contributions for \"user\" (links). Parameters:\n* $1 is an IP address or a username, with a link which points to the user page (if registered user).\n* $2 is list of tool links. The list contains a link which has text {{msg-mw|Sp-contributions-talk}}.\n* $3 is a plain text username used for GENDER.\n{{Identical|For $1}}", + "usersub": "\"user\" (links). Parameters:\n* $1 is an IP address or a username, with a link which points to the user page (if registered user).\n* $2 is list of tool links. The list contains a link which has text {{msg-mw|Sp-contributions-talk}}.\n* $3 is a plain text username used for GENDER.\n{{Identical|For $1}}", "contributions-userdoesnotexist": "This message is used in [[Special:Contributions]]. It is used to tell the user that the name he searched for doesn't exists.\n\nParameters:\n* $1 - a username\n\n{{identical|userdoesnotexist}}", "nocontribs": "Used in [[Special:Contributions]] and [[Special:DeletedContributions]].\n\nSee examples: [[Special:Contributions/x]] and [[Special:DeletedContributions/x]].\n\nParameters:\n* $1 - (Unused) the user name", "uctop": "This message is used in [[Special:Contributions]]. It is used to show that a particular edit was the last made to a page. Example: 09:57, 11 February 2008 (hist) (diff) Pagenameā (edit summary) (current)\n{{Identical|Top}}", -- To view, visit https://gerrit.wikimedia.org/r/137581 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9f364e40a8858e4aa6d2dba92a61616fd22bc4e1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: devunt <dev...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits