From f851b529b30117791d9ffa1ad59d43d09f335cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Tue, 22 Sep 2020 21:11:11 +0200 Subject: [PATCH] Deduplicate instance variables in Pagers These have been saved in the parent class for quite some time. Refactor accessors in method overrides. Change-Id: I9819caa5ab87ac3a8e47efb32b00d89c3e2a61af --- includes/pagers/AbuseFilterHistoryPager.php | 15 +++++---------- includes/pagers/AbuseFilterPager.php | 21 +++++++++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/includes/pagers/AbuseFilterHistoryPager.php b/includes/pagers/AbuseFilterHistoryPager.php index a3d0ae8b1..8c3ed9803 100644 --- a/includes/pagers/AbuseFilterHistoryPager.php +++ b/includes/pagers/AbuseFilterHistoryPager.php @@ -16,11 +16,6 @@ class AbuseFilterHistoryPager extends TablePager { */ public $mUser; - /** - * @var LinkRenderer - */ - protected $linkRenderer; - /** * @param int $filter * @param AbuseFilterViewHistory $page @@ -29,12 +24,11 @@ class AbuseFilterHistoryPager extends TablePager { */ public function __construct( int $filter, AbuseFilterViewHistory $page, $user, LinkRenderer $linkRenderer ) { + parent::__construct( $page->getContext(), $linkRenderer ); $this->mFilter = $filter; $this->mPage = $page; $this->mUser = $user; $this->mDefaultDirection = true; - $this->linkRenderer = $linkRenderer; - parent::__construct( $this->mPage->getContext() ); } /** @@ -77,12 +71,13 @@ class AbuseFilterHistoryPager extends TablePager { */ public function formatValue( $name, $value ) { $lang = $this->getLanguage(); + $linkRenderer = $this->getLinkRenderer(); $row = $this->mCurrentRow; switch ( $name ) { case 'afh_filter': - $formatted = $this->linkRenderer->makeLink( + $formatted = $linkRenderer->makeLink( SpecialPage::getTitleFor( 'AbuseFilter', $row->afh_filter ), $lang->formatNum( $row->afh_filter ) ); @@ -90,7 +85,7 @@ class AbuseFilterHistoryPager extends TablePager { case 'afh_timestamp': $title = SpecialPage::getTitleFor( 'AbuseFilter', 'history/' . $row->afh_filter . '/item/' . $row->afh_id ); - $formatted = $this->linkRenderer->makeLink( + $formatted = $linkRenderer->makeLink( $title, $lang->timeanddate( $row->afh_timestamp, true ) ); @@ -145,7 +140,7 @@ class AbuseFilterHistoryPager extends TablePager { ) { $title = $this->mPage->getTitle( 'history/' . $row->afh_filter . "/diff/prev/$value" ); - $formatted = $this->linkRenderer->makeLink( + $formatted = $linkRenderer->makeLink( $title, new HtmlArmor( $this->msg( 'abusefilter-history-diff' )->parse() ) ); diff --git a/includes/pagers/AbuseFilterPager.php b/includes/pagers/AbuseFilterPager.php index 0a5d462d4..482f5d786 100644 --- a/includes/pagers/AbuseFilterPager.php +++ b/includes/pagers/AbuseFilterPager.php @@ -8,11 +8,6 @@ use Wikimedia\AtEase\AtEase; */ class AbuseFilterPager extends TablePager { - /** - * @var LinkRenderer - */ - protected $linkRenderer; - /** * @var AbuseFilterViewList The associated page */ @@ -46,10 +41,11 @@ class AbuseFilterPager extends TablePager { ) { $this->mPage = $page; $this->mConds = $conds; - $this->linkRenderer = $linkRenderer; $this->mSearchPattern = $searchPattern; $this->mSearchMode = $searchMode; - parent::__construct( $this->mPage->getContext() ); + // needs to be at the end, some attributes are needed by methods + // called from ancestors' constructors + parent::__construct( $page->getContext(), $linkRenderer ); } /** @@ -154,7 +150,7 @@ class AbuseFilterPager extends TablePager { 'af_hidden' => 'abusefilter-list-visibility', ]; - $user = $this->mPage->getUser(); + $user = $this->getUser(); if ( SpecialAbuseLog::canSeeDetails( $user ) ) { $headers['af_hit_count'] = 'abusefilter-list-hitcount'; } @@ -182,18 +178,19 @@ class AbuseFilterPager extends TablePager { public function formatValue( $name, $value ) { $lang = $this->getLanguage(); $user = $this->getUser(); + $linkRenderer = $this->getLinkRenderer(); $row = $this->mCurrentRow; switch ( $name ) { case 'af_id': - return $this->linkRenderer->makeLink( + return $linkRenderer->makeLink( SpecialPage::getTitleFor( 'AbuseFilter', $value ), $lang->formatNum( intval( $value ) ) ); case 'af_pattern': return $this->getHighlightedPattern( $row ); case 'af_public_comments': - return $this->linkRenderer->makeLink( + return $linkRenderer->makeLink( SpecialPage::getTitleFor( 'AbuseFilter', $row->af_id ), $value ); @@ -233,7 +230,7 @@ class AbuseFilterPager extends TablePager { if ( SpecialAbuseLog::canSeeDetails( $user, $row->af_id, $global, $row->af_hidden ) ) { $count_display = $this->msg( 'abusefilter-hitcount' ) ->numParams( $value )->text(); - $link = $this->linkRenderer->makeKnownLink( + $link = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'AbuseLog' ), $count_display, [], @@ -379,7 +376,7 @@ class AbuseFilterPager extends TablePager { 'af_hidden', 'af_group', ]; - if ( SpecialAbuseLog::canSeeDetails( $this->mPage->getUser() ) ) { + if ( SpecialAbuseLog::canSeeDetails( $this->getUser() ) ) { $sortable_fields[] = 'af_hit_count'; $sortable_fields[] = 'af_public_comments'; }