messageLocalizer = $messageLocalizer; } /** * Generate (prev x| next x) (20|50|100...) type links for paging * * @param LinkTarget $title LinkTarget object to link * @param int $offset * @param int $limit * @param array $query Optional URL query parameter string * @param bool $atend Optional param for specified if this is the last page * @return string */ public function buildPrevNextNavigation( LinkTarget $title, $offset, $limit, array $query = [], $atend = false ) { # Make 'previous' link $prev = $this->messageLocalizer->msg( 'prevn' )->title( $title ) ->numParams( $limit )->text(); if ( $offset > 0 ) { $plink = $this->numLink( $title, max( $offset - $limit, 0 ), $limit, $query, $prev, 'prevn-title', 'mw-prevlink' ); } else { $plink = htmlspecialchars( $prev ); } # Make 'next' link $next = $this->messageLocalizer->msg( 'nextn' )->title( $title ) ->numParams( $limit )->text(); if ( $atend ) { $nlink = htmlspecialchars( $next ); } else { $nlink = $this->numLink( $title, $offset + $limit, $limit, $query, $next, 'nextn-title', 'mw-nextlink' ); } # Make links to set number of items per page $numLinks = []; $lang = $this->messageLocalizer->getLanguage(); foreach ( [ 20, 50, 100, 250, 500 ] as $num ) { $numLinks[] = $this->numLink( $title, $offset, $num, $query, $lang->formatNum( $num ), 'shown-title', 'mw-numlink' ); } return $this->messageLocalizer->msg( 'viewprevnext' )->title( $title )->rawParams( $plink, $nlink, $lang->pipeList( $numLinks ) )->escaped(); } /** * Helper function for buildPrevNextNavigation() that generates links * * @param LinkTarget $title LinkTarget object to link * @param int $offset * @param int $limit * @param array $query Extra query parameters * @param string $link Text to use for the link; will be escaped * @param string $tooltipMsg Name of the message to use as tooltip * @param string $class Value of the "class" attribute of the link * @return string HTML fragment */ private function numLink( LinkTarget $title, $offset, $limit, array $query, $link, $tooltipMsg, $class ) { $query = [ 'limit' => $limit, 'offset' => $offset ] + $query; $tooltip = $this->messageLocalizer->msg( $tooltipMsg )->title( $title ) ->numParams( $limit )->text(); return Html::element( 'a', [ 'href' => $title->getLocalURL( $query ), 'title' => $tooltip, 'class' => $class ], $link ); } }