MediaWiki  1.34.0
PrevNextNavigationRenderer.php
Go to the documentation of this file.
1 <?php
22 
23 use Html;
25 use Title;
26 
34 
39 
44  $this->messageLocalizer = $messageLocalizer;
45  }
46 
57  public function buildPrevNextNavigation(
58  Title $title,
59  $offset,
60  $limit,
61  array $query = [],
62  $atend = false
63  ) {
64  # Make 'previous' link
65  $prev = $this->messageLocalizer->msg( 'prevn' )->title( $title )
66  ->numParams( $limit )->text();
67 
68  if ( $offset > 0 ) {
69  $plink = $this->numLink( $title, max( $offset - $limit, 0 ), $limit, $query,
70  $prev, 'prevn-title', 'mw-prevlink' );
71  } else {
72  $plink = htmlspecialchars( $prev );
73  }
74 
75  # Make 'next' link
76  $next = $this->messageLocalizer->msg( 'nextn' )->title( $title )
77  ->numParams( $limit )->text();
78  if ( $atend ) {
79  $nlink = htmlspecialchars( $next );
80  } else {
81  $nlink = $this->numLink( $title, $offset + $limit, $limit,
82  $query, $next, 'nextn-title', 'mw-nextlink' );
83  }
84 
85  # Make links to set number of items per page
86  $numLinks = [];
87  // @phan-suppress-next-next-line PhanUndeclaredMethod
88  // @fixme MessageLocalizer doesn't have a getLanguage() method!
89  $lang = $this->messageLocalizer->getLanguage();
90  foreach ( [ 20, 50, 100, 250, 500 ] as $num ) {
91  $numLinks[] = $this->numLink( $title, $offset, $num, $query,
92  $lang->formatNum( $num ), 'shown-title', 'mw-numlink' );
93  }
94 
95  return $this->messageLocalizer->msg( 'viewprevnext' )->title( $title
96  )->rawParams( $plink, $nlink, $lang->pipeList( $numLinks ) )->escaped();
97  }
98 
111  private function numLink( Title $title, $offset, $limit, array $query, $link,
112  $tooltipMsg, $class
113  ) {
114  $query = [ 'limit' => $limit, 'offset' => $offset ] + $query;
115  $tooltip = $this->messageLocalizer->msg( $tooltipMsg )->title( $title )
116  ->numParams( $limit )->text();
117  return Html::element( 'a', [ 'href' => $title->getLocalURL( $query ),
118  'title' => $tooltip, 'class' => $class ], $link );
119  }
120 
121 }
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
MediaWiki\Navigation\PrevNextNavigationRenderer\$messageLocalizer
MessageLocalizer $messageLocalizer
Definition: PrevNextNavigationRenderer.php:38
MediaWiki\Navigation\PrevNextNavigationRenderer
Helper class for generating prev/next links for paging.
Definition: PrevNextNavigationRenderer.php:33
MediaWiki\Navigation\PrevNextNavigationRenderer\numLink
numLink(Title $title, $offset, $limit, array $query, $link, $tooltipMsg, $class)
Helper function for buildPrevNextNavigation() that generates links.
Definition: PrevNextNavigationRenderer.php:111
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:28
MediaWiki\Navigation\PrevNextNavigationRenderer\__construct
__construct(MessageLocalizer $messageLocalizer)
Definition: PrevNextNavigationRenderer.php:43
$title
$title
Definition: testCompression.php:34
MediaWiki\Navigation
Definition: PrevNextNavigationRenderer.php:21
Title
Represents a title within MediaWiki.
Definition: Title.php:42
MediaWiki\Navigation\PrevNextNavigationRenderer\buildPrevNextNavigation
buildPrevNextNavigation(Title $title, $offset, $limit, array $query=[], $atend=false)
Generate (prev x| next x) (20|50|100...) type links for paging.
Definition: PrevNextNavigationRenderer.php:57