MediaWiki  1.27.2
ReverseChronologicalPager.php
Go to the documentation of this file.
1 <?php
28 abstract class ReverseChronologicalPager extends IndexPager {
30  public $mYear;
31  public $mMonth;
32 
33  function getNavigationBar() {
34  if ( !$this->isNavigationBarShown() ) {
35  return '';
36  }
37 
38  if ( isset( $this->mNavigationBar ) ) {
39  return $this->mNavigationBar;
40  }
41 
42  $linkTexts = [
43  'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit )->escaped(),
44  'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit )->escaped(),
45  'first' => $this->msg( 'histlast' )->escaped(),
46  'last' => $this->msg( 'histfirst' )->escaped()
47  ];
48 
49  $pagingLinks = $this->getPagingLinks( $linkTexts );
50  $limitLinks = $this->getLimitLinks();
51  $limits = $this->getLanguage()->pipeList( $limitLinks );
52  $firstLastLinks = $this->msg( 'parentheses' )->rawParams( "{$pagingLinks['first']}" .
53  $this->msg( 'pipe-separator' )->escaped() .
54  "{$pagingLinks['last']}" )->escaped();
55 
56  $this->mNavigationBar = $firstLastLinks . ' ' .
57  $this->msg( 'viewprevnext' )->rawParams(
58  $pagingLinks['prev'], $pagingLinks['next'], $limits )->escaped();
59 
60  return $this->mNavigationBar;
61  }
62 
63  function getDateCond( $year, $month ) {
64  $year = intval( $year );
65  $month = intval( $month );
66 
67  // Basic validity checks
68  $this->mYear = $year > 0 ? $year : false;
69  $this->mMonth = ( $month > 0 && $month < 13 ) ? $month : false;
70 
71  // Given an optional year and month, we need to generate a timestamp
72  // to use as "WHERE rev_timestamp <= result"
73  // Examples: year = 2006 equals < 20070101 (+000000)
74  // year=2005, month=1 equals < 20050201
75  // year=2005, month=12 equals < 20060101
76  if ( !$this->mYear && !$this->mMonth ) {
77  return;
78  }
79 
80  if ( $this->mYear ) {
81  $year = $this->mYear;
82  } else {
83  // If no year given, assume the current one
85  $year = $timestamp->format( 'Y' );
86  // If this month hasn't happened yet this year, go back to last year's month
87  if ( $this->mMonth > $timestamp->format( 'n' ) ) {
88  $year--;
89  }
90  }
91 
92  if ( $this->mMonth ) {
93  $month = $this->mMonth + 1;
94  // For December, we want January 1 of the next year
95  if ( $month > 12 ) {
96  $month = 1;
97  $year++;
98  }
99  } else {
100  // No month implies we want up to the end of the year in question
101  $month = 1;
102  $year++;
103  }
104 
105  // Y2K38 bug
106  if ( $year > 2032 ) {
107  $year = 2032;
108  }
109 
110  $ymd = (int)sprintf( "%04d%02d01", $year, $month );
111 
112  if ( $ymd > 20320101 ) {
113  $ymd = 20320101;
114  }
115 
116  // Treat the given time in the wiki timezone and get a UTC timestamp for the database lookup
117  $timestamp = MWTimestamp::getInstance( "${ymd}000000" );
118  $timestamp->setTimezone( $this->getConfig()->get( 'Localtimezone' ) );
119 
120  $this->mOffset = $this->mDb->timestamp( $timestamp->getTimestamp() );
121  }
122 }
const DIR_DESCENDING
Definition: IndexPager.php:73
getLanguage()
Get the Language object.
IndexPager with a formatted navigation bar.
IndexPager is an efficient pager which uses a (roughly unique) index in the data set to implement pag...
Definition: IndexPager.php:66
msg()
Get a Message object with context set Parameters are the same as wfMessage()
if($limit) $timestamp
static getInstance($ts=false)
Get a timestamp instance in GMT.
getConfig()
Get the Config object.
isNavigationBarShown()
Returns whether to show the "navigation bar".
Definition: IndexPager.php:603
getPagingLinks($linkTexts, $disabledTexts=[])
Get paging links.
Definition: IndexPager.php:621
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35