diff --git a/includes/Views/AbuseFilterViewHistory.php b/includes/Views/AbuseFilterViewHistory.php index f391b82be..0353c1d20 100644 --- a/includes/Views/AbuseFilterViewHistory.php +++ b/includes/Views/AbuseFilterViewHistory.php @@ -7,7 +7,7 @@ class AbuseFilterViewHistory extends AbuseFilterView { */ public function __construct( SpecialAbuseFilter $page, $params ) { parent::__construct( $page, $params ); - $this->mFilter = $this->mParams[1] ?? null; + $this->mFilter = $this->mParams['filter'] ?? null; } /** @@ -16,9 +16,7 @@ class AbuseFilterViewHistory extends AbuseFilterView { public function show() { $out = $this->getOutput(); $out->enableOOUI(); - $filter = $this->getRequest()->getText( 'filter' ) ?: $this->mFilter; - // Ensure the parameter is a valid filter ID - $filter = (int)$filter; + $filter = $this->getRequest()->getIntOrNull( 'filter' ) ?: $this->mFilter; if ( $filter ) { $out->setPageTitle( $this->msg( 'abusefilter-history' )->numParams( $filter ) ); diff --git a/includes/pagers/AbuseFilterHistoryPager.php b/includes/pagers/AbuseFilterHistoryPager.php index 948f9cd7d..e2133d1e6 100644 --- a/includes/pagers/AbuseFilterHistoryPager.php +++ b/includes/pagers/AbuseFilterHistoryPager.php @@ -4,7 +4,7 @@ use MediaWiki\Linker\LinkRenderer; class AbuseFilterHistoryPager extends TablePager { /** - * @var int The filter ID + * @var int|null The filter ID */ public $mFilter; /** @@ -17,12 +17,12 @@ class AbuseFilterHistoryPager extends TablePager { public $mUser; /** - * @param int $filter + * @param ?int $filter * @param AbuseFilterViewHistory $page * @param string $user User name * @param LinkRenderer $linkRenderer */ - public function __construct( int $filter, AbuseFilterViewHistory $page, $user, + public function __construct( ?int $filter, AbuseFilterViewHistory $page, $user, LinkRenderer $linkRenderer ) { parent::__construct( $page->getContext(), $linkRenderer ); $this->mFilter = $filter; @@ -252,6 +252,7 @@ class AbuseFilterHistoryPager extends TablePager { * @return Title */ public function getTitle() { - return $this->mPage->getTitle( 'history/' . $this->mFilter ); + $subpage = $this->mFilter ? ( 'history/' . $this->mFilter ) : 'history'; + return $this->mPage->getTitle( $subpage ); } } diff --git a/includes/special/SpecialAbuseFilter.php b/includes/special/SpecialAbuseFilter.php index adb8661d6..07761fe48 100644 --- a/includes/special/SpecialAbuseFilter.php +++ b/includes/special/SpecialAbuseFilter.php @@ -114,9 +114,7 @@ class SpecialAbuseFilter extends AbuseFilterSpecialPage { if ( $params[0] === 'history' || $params[0] === 'log' ) { if ( count( $params ) <= 2 ) { - if ( isset( $params[1] ) ) { - $params[1] = (int)$params[1]; - } + $params = isset( $params[1] ) ? [ 'filter' => (int)$params[1] ] : []; return [ AbuseFilterViewHistory::class, 'recentchanges', $params ]; } if ( count( $params ) === 4 && $params[2] === 'item' ) { diff --git a/tests/phpunit/unit/SpecialAbuseFilterTest.php b/tests/phpunit/unit/SpecialAbuseFilterTest.php index 519eb99ef..a44730643 100644 --- a/tests/phpunit/unit/SpecialAbuseFilterTest.php +++ b/tests/phpunit/unit/SpecialAbuseFilterTest.php @@ -20,16 +20,16 @@ class SpecialAbuseFilterTest extends MediaWikiUnitTestCase { [ 'foo', AbuseFilterViewList::class, 'home' ], [ '1', AbuseFilterViewEdit::class, 'edit', [ 'filter' => 1 ] ], [ 'new', AbuseFilterViewEdit::class, 'edit', [ 'filter' => null ] ], - [ 'history', AbuseFilterViewHistory::class, 'recentchanges', [ 'history' ] ], - [ 'history/1', AbuseFilterViewHistory::class, 'recentchanges', [ 'history', 1 ] ], + [ 'history', AbuseFilterViewHistory::class, 'recentchanges', [] ], + [ 'history/1', AbuseFilterViewHistory::class, 'recentchanges', [ 'filter' => 1 ] ], [ 'history/1/item/2', AbuseFilterViewEdit::class, '', [ 'filter' => 1, 'history' => 2 ] ], [ 'history/foo/bar', AbuseFilterViewList::class, 'home' ], [ 'history/1/diff/2/3', AbuseFilterViewDiff::class, '', [ 'history', '1', 'diff', '2', '3' ] ], [ 'history/1/diff/prev/3', AbuseFilterViewDiff::class, '', [ 'history', '1', 'diff', 'prev', '3' ] ], [ 'history/1/diff/prev/cur', AbuseFilterViewDiff::class, '', [ 'history', '1', 'diff', 'prev', 'cur' ] ], [ 'history/1/foo/2/3', AbuseFilterViewList::class, 'home' ], - [ 'log', AbuseFilterViewHistory::class, 'recentchanges', [ 'log' ] ], - [ 'log/1', AbuseFilterViewHistory::class, 'recentchanges', [ 'log', 1 ] ], + [ 'log', AbuseFilterViewHistory::class, 'recentchanges', [] ], + [ 'log/1', AbuseFilterViewHistory::class, 'recentchanges', [ 'filter' => 1 ] ], [ 'log/1/item/2', AbuseFilterViewEdit::class, '', [ 'filter' => 1, 'history' => 2 ] ], [ 'log/foo/bar', AbuseFilterViewList::class, 'home' ], [ 'log/1/diff/2/3', AbuseFilterViewDiff::class, '', [ 'log', '1', 'diff', '2', '3' ] ],