64 parent::__construct( $imagePage->getContext() );
65 $this->mImagePage = $imagePage;
66 $this->mTitle = $imagePage->getTitle()->createFragmentTarget(
'filehistory' );
69 $this->mRange = [ 0, 0 ];
72 $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
73 $this->mDefaultLimit = 10;
74 list( $this->mLimit, ) =
75 $this->mRequest->getLimitOffsetForUser(
80 $this->linkBatchFactory =
$linkBatchFactory ?? MediaWikiServices::getInstance()->getLinkBatchFactory();
115 if ( count( $this->mHist ) ) {
116 if ( $this->mImg->isLocal() ) {
118 $linkBatch = $this->linkBatchFactory->newLinkBatch();
119 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
120 $file = $this->mHist[$i];
123 $linkBatch->add(
NS_USER, $uploader->getName() );
127 $linkBatch->execute();
131 # Generate prev/next links
133 $s = $list->beginImageHistoryList( $navLink );
135 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
136 $file = $this->mHist[$i];
137 $s .= $list->imageHistoryLine( !
$file->isOld(),
$file );
139 $s .= $list->endImageHistoryList( $navLink );
141 if ( $list->getPreventClickjacking() ) {
149 if ( $this->mQueryDone ) {
152 $this->mImg = $this->mImagePage->getPage()->getFile();
153 if ( !$this->mImg->exists() ) {
157 if ( $this->mOffset !==
null ) {
159 $sadlyWeCannotPassThisTimestampDownTheStack = $this->mDb->timestamp( $this->mOffset );
160 }
catch ( TimestampException $e ) {
161 $this->mOffset =
null;
164 $queryLimit = $this->mLimit + 1;
165 if ( $this->mIsBackwards ) {
167 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
169 $numRows = count( $this->mHist );
170 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
171 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
175 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
179 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
181 $this->mHist = array_merge( $this->mHist,
182 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
184 $numRows = count( $this->mHist );
186 # Index value of top item in the list
187 $firstIndex = $this->mIsBackwards ?
188 [ $this->mHist[$numRows - 1]->getTimestamp() ] : [ $this->mHist[0]->getTimestamp() ];
189 # Discard the extra result row if there is one
190 if ( $numRows > $this->mLimit && $numRows > 1 ) {
191 if ( $this->mIsBackwards ) {
192 # Index value of item past the index
193 $this->mPastTheEndIndex = [ $this->mHist[0]->getTimestamp() ];
194 # Index value of bottom item in the list
195 $lastIndex = [ $this->mHist[1]->getTimestamp() ];
197 $this->mRange = [ 1, $numRows - 1 ];
199 # Index value of item past the index
200 $this->mPastTheEndIndex = [ $this->mHist[$numRows - 1]->getTimestamp() ];
201 # Index value of bottom item in the list
202 $lastIndex = [ $this->mHist[$numRows - 2]->getTimestamp() ];
204 $this->mRange = [ 0, $numRows - 2 ];
207 # Setting indexes to an empty array means that they will be
208 # omitted if they would otherwise appear in URLs. It just so
209 # happens that this is the right thing to do in the standard
210 # UI, in all the relevant cases.
211 $this->mPastTheEndIndex = [];
212 # Index value of bottom item in the list
213 $lastIndex = $this->mIsBackwards ?
214 [ $this->mHist[0]->getTimestamp() ] : [ $this->mHist[$numRows - 1]->getTimestamp() ];
216 $this->mRange = [ 0, $numRows - 1 ];
221 $this->mPastTheEndIndex = [];
223 if ( $this->mIsBackwards ) {
224 $this->mIsFirst = ( $numRows < $queryLimit );
225 $this->mIsLast = ( $this->mOffset ==
'' );
226 $this->mLastShown = $firstIndex;
227 $this->mFirstShown = $lastIndex;
229 $this->mIsFirst = ( $this->mOffset ==
'' );
230 $this->mIsLast = ( $numRows < $queryLimit );
231 $this->mLastShown = $lastIndex;
232 $this->mFirstShown = $firstIndex;
234 $this->mQueryDone =
true;