MediaWiki  1.29.1
ReverseChronologicalPager.php
Go to the documentation of this file.
1 <?php
23 use Wikimedia\Timestamp\TimestampException;
24 
29 abstract class ReverseChronologicalPager extends IndexPager {
31  public $mYear;
32  public $mMonth;
33  public $mDay;
34 
35  function getNavigationBar() {
36  if ( !$this->isNavigationBarShown() ) {
37  return '';
38  }
39 
40  if ( isset( $this->mNavigationBar ) ) {
41  return $this->mNavigationBar;
42  }
43 
44  $linkTexts = [
45  'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit )->escaped(),
46  'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit )->escaped(),
47  'first' => $this->msg( 'histlast' )->escaped(),
48  'last' => $this->msg( 'histfirst' )->escaped()
49  ];
50 
51  $pagingLinks = $this->getPagingLinks( $linkTexts );
52  $limitLinks = $this->getLimitLinks();
53  $limits = $this->getLanguage()->pipeList( $limitLinks );
54  $firstLastLinks = $this->msg( 'parentheses' )->rawParams( "{$pagingLinks['first']}" .
55  $this->msg( 'pipe-separator' )->escaped() .
56  "{$pagingLinks['last']}" )->escaped();
57 
58  $this->mNavigationBar = $firstLastLinks . ' ' .
59  $this->msg( 'viewprevnext' )->rawParams(
60  $pagingLinks['prev'], $pagingLinks['next'], $limits )->escaped();
61 
62  return $this->mNavigationBar;
63  }
64 
73  function getDateCond( $year, $month, $day = -1 ) {
74  $year = intval( $year );
75  $month = intval( $month );
76  $day = intval( $day );
77 
78  // Basic validity checks for year and month
79  $this->mYear = $year > 0 ? $year : false;
80  $this->mMonth = ( $month > 0 && $month < 13 ) ? $month : false;
81 
82  // If year and month are false, don't update the mOffset
83  if ( !$this->mYear && !$this->mMonth ) {
84  return null;
85  }
86 
87  // Given an optional year, month, and day, we need to generate a timestamp
88  // to use as "WHERE rev_timestamp <= result"
89  // Examples: year = 2006 equals < 20070101 (+000000)
90  // year=2005, month=1 equals < 20050201
91  // year=2005, month=12 equals < 20060101
92  // year=2005, month=12, day=5 equals < 20051206
93  if ( $this->mYear ) {
94  $year = $this->mYear;
95  } else {
96  // If no year given, assume the current one
97  $timestamp = MWTimestamp::getInstance();
98  $year = $timestamp->format( 'Y' );
99  // If this month hasn't happened yet this year, go back to last year's month
100  if ( $this->mMonth > $timestamp->format( 'n' ) ) {
101  $year--;
102  }
103  }
104 
105  if ( $this->mMonth ) {
106  $month = $this->mMonth;
107 
108  // Day validity check after we have month and year checked
109  $this->mDay = checkdate( $month, $day, $year ) ? $day : false;
110 
111  if ( $this->mDay ) {
112  // If we have a day, we want up to the day immediately afterward
113  $day = $this->mDay + 1;
114 
115  // Did we overflow the current month?
116  if ( !checkdate( $month, $day, $year ) ) {
117  $day = 1;
118  $month++;
119  }
120  } else {
121  // If no day, assume beginning of next month
122  $day = 1;
123  $month++;
124  }
125 
126  // Did we overflow the current year?
127  if ( $month > 12 ) {
128  $month = 1;
129  $year++;
130  }
131 
132  } else {
133  // No month implies we want up to the end of the year in question
134  $month = 1;
135  $day = 1;
136  $year++;
137  }
138 
139  // Y2K38 bug
140  if ( $year > 2032 ) {
141  $year = 2032;
142  }
143 
144  $ymd = (int)sprintf( "%04d%02d%02d", $year, $month, $day );
145 
146  if ( $ymd > 20320101 ) {
147  $ymd = 20320101;
148  }
149 
150  // Treat the given time in the wiki timezone and get a UTC timestamp for the database lookup
151  $timestamp = MWTimestamp::getInstance( "${ymd}000000" );
152  $timestamp->setTimezone( $this->getConfig()->get( 'Localtimezone' ) );
153 
154  try {
155  $this->mOffset = $this->mDb->timestamp( $timestamp->getTimestamp() );
156  } catch ( TimestampException $e ) {
157  // Invalid user provided timestamp (T149257)
158  return null;
159  }
160 
161  return $this->mOffset;
162  }
163 }
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
ReverseChronologicalPager\getDateCond
getDateCond( $year, $month, $day=-1)
Set and return the mOffset timestamp such that we can get all revisions with a timestamp up to the sp...
Definition: ReverseChronologicalPager.php:73
ReverseChronologicalPager\$mDay
$mDay
Definition: ReverseChronologicalPager.php:33
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
ReverseChronologicalPager\$mDefaultDirection
$mDefaultDirection
Definition: ReverseChronologicalPager.php:30
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
IndexPager\getLimitLinks
getLimitLinks()
Definition: IndexPager.php:645
php
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
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:143
MWTimestamp\getInstance
static getInstance( $ts=false)
Get a timestamp instance in GMT.
Definition: MWTimestamp.php:39
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
IndexPager\$mOffset
$mOffset
Definition: IndexPager.php:81
ReverseChronologicalPager\$mYear
$mYear
Definition: ReverseChronologicalPager.php:31
IndexPager\DIR_DESCENDING
const DIR_DESCENDING
Definition: IndexPager.php:76
IndexPager\isNavigationBarShown
isNavigationBarShown()
Returns whether to show the "navigation bar".
Definition: IndexPager.php:606
ReverseChronologicalPager\$mMonth
$mMonth
Definition: ReverseChronologicalPager.php:32
IndexPager
IndexPager is an efficient pager which uses a (roughly unique) index in the data set to implement pag...
Definition: IndexPager.php:69
IndexPager\$mNavigationBar
$mNavigationBar
Definition: IndexPager.php:117
ReverseChronologicalPager
IndexPager with a formatted navigation bar.
Definition: ReverseChronologicalPager.php:29
ReverseChronologicalPager\getNavigationBar
getNavigationBar()
Definition: ReverseChronologicalPager.php:35
IndexPager\getPagingLinks
getPagingLinks( $linkTexts, $disabledTexts=[])
Get paging links.
Definition: IndexPager.php:624