21 use Wikimedia\Timestamp\TimestampException;
58 parent::__construct( $imagePage->getContext() );
59 $this->mImagePage = $imagePage;
60 $this->mTitle = $imagePage->getTitle()->createFragmentTarget(
'filehistory' );
63 $this->mRange = [ 0, 0 ];
66 $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
67 $this->mDefaultLimit = 10;
68 list( $this->mLimit, ) =
69 $this->mRequest->getLimitOffset( $this->mDefaultLimit,
'' );
104 if (
count( $this->mHist ) ) {
105 if ( $this->mImg->isLocal() ) {
108 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
109 $file = $this->mHist[$i];
114 $linkBatch->execute();
118 # Generate prev/next links
120 $s = $list->beginImageHistoryList( $navLink );
122 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
123 $file = $this->mHist[$i];
124 $s .= $list->imageHistoryLine( !
$file->isOld(),
$file );
126 $s .= $list->endImageHistoryList( $navLink );
128 if ( $list->getPreventClickjacking() ) {
136 if ( $this->mQueryDone ) {
139 $this->mImg = $this->mImagePage->getPage()->getFile();
140 if ( !$this->mImg->exists() ) {
144 if ( $this->mOffset !==
null ) {
146 $sadlyWeCannotPassThisTimestampDownTheStack = $this->mDb->timestamp( $this->mOffset );
147 }
catch ( TimestampException
$e ) {
148 $this->mOffset =
null;
151 $queryLimit = $this->mLimit + 1;
152 if ( $this->mIsBackwards ) {
154 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
156 $numRows =
count( $this->mHist );
157 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() >
$this->mOffset ) {
158 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
162 if ( !$this->mOffset || $this->mImg->getTimestamp() <
$this->mOffset ) {
166 $oiLimit =
count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
168 $this->mHist = array_merge( $this->mHist,
169 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
171 $numRows =
count( $this->mHist );
173 # Index value of top item in the list
174 $firstIndex = $this->mIsBackwards ?
175 $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
176 # Discard the extra result row if there is one
177 if ( $numRows > $this->mLimit && $numRows > 1 ) {
178 if ( $this->mIsBackwards ) {
179 # Index value of item past the index
180 $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
181 # Index value of bottom item in the list
182 $lastIndex = $this->mHist[1]->getTimestamp();
184 $this->mRange = [ 1, $numRows - 1 ];
186 # Index value of item past the index
187 $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
188 # Index value of bottom item in the list
189 $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
191 $this->mRange = [ 0, $numRows - 2 ];
194 # Setting indexes to an empty string means that they will be
195 # omitted if they would otherwise appear in URLs. It just so
196 # happens that this is the right thing to do in the standard
197 # UI, in all the relevant cases.
198 $this->mPastTheEndIndex =
'';
199 # Index value of bottom item in the list
200 $lastIndex = $this->mIsBackwards ?
201 $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
203 $this->mRange = [ 0, $numRows - 1 ];
208 $this->mPastTheEndIndex =
'';
210 if ( $this->mIsBackwards ) {
211 $this->mIsFirst = ( $numRows < $queryLimit );
212 $this->mIsLast = ( $this->mOffset ==
'' );
213 $this->mLastShown = $firstIndex;
214 $this->mFirstShown = $lastIndex;
216 $this->mIsFirst = ( $this->mOffset ==
'' );
217 $this->mIsLast = ( $numRows < $queryLimit );
218 $this->mLastShown = $lastIndex;
219 $this->mFirstShown = $firstIndex;
221 $this->mQueryDone =
true;