From 19c3472b909fb7dfc14195465a9ec1838a20d079 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Thu, 26 Jul 2018 16:51:58 +0800 Subject: [PATCH] ContribsPager: Factor revision check out of formatRow This is needed by MobileFrontend. Also helps with readability and understanding what is going on inside the larger formatRow method. Bug: T199066 Change-Id: I679f4bf4305ca5b0fd523e844a01f06b4bd38b5c --- includes/specials/pagers/ContribsPager.php | 43 ++++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index 59fa948ac6..81a1f5a506 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -407,24 +407,13 @@ class ContribsPager extends RangeChronologicalPager { } /** - * Generates each row in the contributions list. + * Check whether the revision associated is valid for formatting. If has no associated revision + * id then null is returned. * - * Contributions which are marked "top" are currently on top of the history. - * For these contributions, a [rollback] link is shown for users with roll- - * back privileges. The rollback link restores the most recent version that - * was not written by the target user. - * - * @todo This would probably look a lot nicer in a table. * @param object $row - * @return string + * @return Revision|null */ - function formatRow( $row ) { - $ret = ''; - $classes = []; - $attribs = []; - - $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); - + public function tryToCreateValidRevision( $row ) { /* * There may be more than just revision rows. To make sure that we'll only be processing * revisions here, let's _try_ to build a revision out of our row (without displaying @@ -440,8 +429,30 @@ class ContribsPager extends RangeChronologicalPager { $validRevision = false; } Wikimedia\restoreWarnings(); + return $validRevision ? $rev : null; + } + + /** + * Generates each row in the contributions list. + * + * Contributions which are marked "top" are currently on top of the history. + * For these contributions, a [rollback] link is shown for users with roll- + * back privileges. The rollback link restores the most recent version that + * was not written by the target user. + * + * @todo This would probably look a lot nicer in a table. + * @param object $row + * @return string + */ + function formatRow( $row ) { + $ret = ''; + $classes = []; + $attribs = []; + + $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); - if ( $validRevision ) { + $rev = $this->tryToCreateValidRevision( $row ); + if ( $rev ) { $attribs['data-mw-revid'] = $rev->getId(); $page = Title::newFromRow( $row ); -- 2.20.1