MediaWiki REL1_35
PrevNextNavigationRenderer.php
Go to the documentation of this file.
1<?php
22
23use Html;
25use Title;
26
34
39
44 $this->messageLocalizer = $messageLocalizer;
45 }
46
57 public function buildPrevNextNavigation(
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(
113 $offset,
114 $limit,
115 array $query,
116 $link,
117 $tooltipMsg,
118 $class
119 ) {
120 $query = [ 'limit' => $limit, 'offset' => $offset ] + $query;
121 $tooltip = $this->messageLocalizer->msg( $tooltipMsg )->title( $title )
122 ->numParams( $limit )->text();
123 return Html::element( 'a', [ 'href' => $title->getLocalURL( $query ),
124 'title' => $tooltip, 'class' => $class ], $link );
125 }
126
127}
This class is a collection of static functions that serve two purposes:
Definition Html.php:49
Helper class for generating prev/next links for paging.
numLink(Title $title, $offset, $limit, array $query, $link, $tooltipMsg, $class)
Helper function for buildPrevNextNavigation() that generates links.
buildPrevNextNavigation(Title $title, $offset, $limit, array $query=[], $atend=false)
Generate (prev x| next x) (20|50|100...) type links for paging.
Represents a title within MediaWiki.
Definition Title.php:42
Interface for localizing messages in MediaWiki.
if(!isset( $args[0])) $lang