From b95d2083406752c53dd1795fa5ad154b3776c8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sat, 21 May 2022 21:51:06 +0200 Subject: [PATCH] =?UTF-8?q?IndexPager:=20Wrap=20inactive=20paging=20links?= =?UTF-8?q?=20in=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: T308364 Change-Id: Icf3597604ea100b2fce2f47fe5057cbfd12b96ed --- includes/pager/IndexPager.php | 43 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/includes/pager/IndexPager.php b/includes/pager/IndexPager.php index 647c22bfedb..08ce39eb867 100644 --- a/includes/pager/IndexPager.php +++ b/includes/pager/IndexPager.php @@ -669,18 +669,15 @@ abstract class IndexPager extends ContextSource implements Pager { * @stable to override * * @param string $text Text displayed on the link - * @param array|null $query Associative array of parameter to be in the query string + * @param array|null $query Associative array of parameter to be in the query string. + * If null, no link is generated. * @param string|null $type Link type used to create additional attributes, like "rel", "class" or * "title". Valid values (non-exhaustive list): 'first', 'last', 'prev', 'next', 'asc', 'desc'. * @return string HTML fragment */ protected function makeLink( $text, array $query = null, $type = null ) { - if ( $query === null ) { - return $text; - } - $attrs = []; - if ( in_array( $type, [ 'prev', 'next' ] ) ) { + if ( $query !== null && in_array( $type, [ 'prev', 'next' ] ) ) { $attrs['rel'] = $type; } @@ -692,12 +689,16 @@ abstract class IndexPager extends ContextSource implements Pager { $attrs['class'] = "mw-{$type}link"; } - return $this->getLinkRenderer()->makeKnownLink( - $this->getTitle(), - new HtmlArmor( $text ), - $attrs, - $query + $this->getDefaultQuery() - ); + if ( $query !== null ) { + return $this->getLinkRenderer()->makeKnownLink( + $this->getTitle(), + new HtmlArmor( $text ), + $attrs, + $query + $this->getDefaultQuery() + ); + } else { + return Html::rawElement( 'span', $attrs, $text ); + } } /** @@ -851,17 +852,15 @@ abstract class IndexPager extends ContextSource implements Pager { $links = []; foreach ( $queries as $type => $query ) { - if ( $query !== false ) { - $links[$type] = $this->makeLink( - $linkTexts[$type], - $query, - $type - ); - } elseif ( isset( $disabledTexts[$type] ) ) { - $links[$type] = $disabledTexts[$type]; - } else { - $links[$type] = $linkTexts[$type]; + $linkText = $linkTexts[$type]; + if ( !$query && isset( $disabledTexts[$type] ) ) { + $linkText = $disabledTexts[$type]; } + $links[$type] = $this->makeLink( + $linkText, + $query ?: null, + $type + ); } return $links;