MediaWiki  master
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' )
66  ->page( $title )
67  ->numParams( $limit )
68  ->text();
69 
70  if ( $offset > 0 ) {
71  $plink = $this->numLink(
72  $title,
73  max( $offset - $limit, 0 ),
74  $limit,
75  $query,
76  $prev,
77  'prevn-title',
78  'mw-prevlink'
79  );
80  } else {
81  $plink = htmlspecialchars( $prev );
82  }
83 
84  # Make 'next' link
85  $next = $this->messageLocalizer->msg( 'nextn' )
86  ->page( $title )
87  ->numParams( $limit )
88  ->text();
89  if ( $atend ) {
90  $nlink = htmlspecialchars( $next );
91  } else {
92  $nlink = $this->numLink(
93  $title,
94  $offset + $limit,
95  $limit,
96  $query,
97  $next,
98  'nextn-title',
99  'mw-nextlink'
100  );
101  }
102 
103  # Make links to set number of items per page
104  $numLinks = [];
105  // @phan-suppress-next-next-line PhanUndeclaredMethod
106  // @fixme MessageLocalizer doesn't have a getLanguage() method!
107  $lang = $this->messageLocalizer->getLanguage();
108  foreach ( [ 20, 50, 100, 250, 500 ] as $num ) {
109  $numLinks[] = $this->numLink(
110  $title,
111  $offset,
112  $num,
113  $query,
114  $lang->formatNum( $num ),
115  'shown-title',
116  'mw-numlink'
117  );
118  }
119 
120  return $this->messageLocalizer->msg( 'viewprevnext' )
121  ->page( $title )
122  ->rawParams( $plink, $nlink, $lang->pipeList( $numLinks ) )
123  ->escaped();
124  }
125 
138  private function numLink(
139  Title $title,
140  $offset,
141  $limit,
142  array $query,
143  $link,
144  $tooltipMsg,
145  $class
146  ) {
147  $query = [ 'limit' => $limit, 'offset' => $offset ] + $query;
148  $tooltip = $this->messageLocalizer->msg( $tooltipMsg )
149  ->page( $title )
150  ->numParams( $limit )
151  ->text();
152 
153  return Html::element(
154  'a',
155  [
156  'href' => $title->getLocalURL( $query ),
157  'title' => $tooltip,
158  'class' => $class,
159  ],
160  $link
161  );
162  }
163 
164 }
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
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:138
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:29
MediaWiki\Navigation\PrevNextNavigationRenderer\__construct
__construct(MessageLocalizer $messageLocalizer)
Definition: PrevNextNavigationRenderer.php:43
$title
$title
Definition: testCompression.php:38
MediaWiki\Navigation
Definition: PrevNextNavigationRenderer.php:21
Title
Represents a title within MediaWiki.
Definition: Title.php:49
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
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
Html
This class is a collection of static functions that serve two purposes:
Definition: Html.php:49