From: jdlrobson Date: Tue, 26 Mar 2019 16:47:08 +0000 (-0700) Subject: DRY up rev link generation in History and Contributions X-Git-Tag: 1.34.0-rc.0~2249^2~1 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=ea0a8e4e5c2c242ab4a36bba3e5675251bab2270;p=lhc%2Fweb%2Fwiklou.git DRY up rev link generation in History and Contributions ContribsPager and HistoryPager both duplicate efforts. Instead move this code into a new static function inside ChangesList that is shared between the two. Bug: T216420 Change-Id: I0025d2e515d086b60670bd3f37307caac8d662a2 --- diff --git a/includes/actions/pagers/HistoryPager.php b/includes/actions/pagers/HistoryPager.php index b3333726a0..3d5c0e6b02 100644 --- a/includes/actions/pagers/HistoryPager.php +++ b/includes/actions/pagers/HistoryPager.php @@ -473,22 +473,8 @@ class HistoryPager extends ReverseChronologicalPager { * @return string */ function revLink( $rev ) { - $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() ); - if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) { - $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink( - $this->getTitle(), - $date, - [ 'class' => 'mw-changeslist-date' ], - [ 'oldid' => $rev->getId() ] - ); - } else { - $link = htmlspecialchars( $date ); - } - if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) { - $link = "$link"; - } - - return $link; + return ChangesList::revDateLink( $rev, $this->getUser(), $this->getLanguage(), + $this->getTitle() ); } /** diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php index bf275b36d3..2389997949 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -395,6 +395,36 @@ class ChangesList extends ContextSource { return $out; } + /** + * Render the date and time of a revision in the current user language + * based on whether the user is able to view this information or not. + * @param Revision $rev + * @param User $user + * @param Language $lang + * @param Title|null $title (optional) where Title does not match + * the Title associated with the Revision + * @internal For usage by Pager classes only (e.g. HistoryPager and ContribsPager). + * @return string HTML + */ + public static function revDateLink( Revision $rev, User $user, Language $lang, $title = null ) { + $ts = $rev->getTimestamp(); + $date = $lang->userTimeAndDate( $ts, $user ); + if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) { + $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink( + $title !== null ? $title : $rev->getTitle(), + $date, + [ 'class' => 'mw-changeslist-date' ], + [ 'oldid' => $rev->getId() ] + ); + } else { + $link = htmlspecialchars( $date ); + } + if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) { + $link = "$link"; + } + return $link; + } + /** * @param string &$s HTML to update * @param mixed $rc_timestamp @@ -517,6 +547,7 @@ class ChangesList extends ContextSource { * and a separator * * @param RecentChange $rc + * @deprecated use revDateLink instead. * @return string HTML fragment */ public function getTimestamp( $rc ) { diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index 626fc48c00..3ffbde5e0a 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -647,19 +647,7 @@ class ContribsPager extends RangeChronologicalPager { $lang = $this->getLanguage(); $comment = $lang->getDirMark() . Linker::revComment( $rev, false, true, false ); $date = $lang->userTimeAndDate( $row->rev_timestamp, $user ); - if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) { - $d = $linkRenderer->makeKnownLink( - $page, - $date, - [ 'class' => 'mw-changeslist-date' ], - [ 'oldid' => intval( $row->rev_id ) ] - ); - } else { - $d = htmlspecialchars( $date ); - } - if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) { - $d = '' . $d . ''; - } + $d = ChangesList::revDateLink( $rev, $user, $lang, $page ); # Show user names for /newbies as there may be different users. # Note that only unprivileged users have rows with hidden user names excluded.