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();
132 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
133 $file = $this->mHist[$i];
134 $comments[$i] =
$file->getDescription(
139 $formattedComments = MediaWikiServices::getInstance()
140 ->getCommentFormatter()
141 ->formatStrings( $comments, $this->
getTitle() );
144 # Generate prev/next links
146 $s = $list->beginImageHistoryList( $navLink );
148 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
149 $file = $this->mHist[$i];
150 $s .= $list->imageHistoryLine( !
$file->isOld(),
$file, $formattedComments[$i] );
152 $s .= $list->endImageHistoryList( $navLink );
154 if ( $list->getPreventClickjacking() ) {
162 if ( $this->mQueryDone ) {
165 $this->mImg = $this->mImagePage->getPage()->getFile();
166 if ( !$this->mImg->exists() ) {
170 if ( $this->mOffset !==
null ) {
172 $sadlyWeCannotPassThisTimestampDownTheStack = $this->mDb->timestamp( $this->mOffset );
173 }
catch ( TimestampException $e ) {
174 $this->mOffset =
null;
177 $queryLimit = $this->mLimit + 1;
178 if ( $this->mIsBackwards ) {
180 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
182 $numRows = count( $this->mHist );
183 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
184 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
188 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
192 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
194 $this->mHist = array_merge( $this->mHist,
195 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
197 $numRows = count( $this->mHist );
199 # Index value of top item in the list
200 $firstIndex = $this->mIsBackwards ?
201 [ $this->mHist[$numRows - 1]->getTimestamp() ] : [ $this->mHist[0]->getTimestamp() ];
202 # Discard the extra result row if there is one
203 if ( $numRows > $this->mLimit && $numRows > 1 ) {
204 if ( $this->mIsBackwards ) {
205 # Index value of item past the index
206 $this->mPastTheEndIndex = [ $this->mHist[0]->getTimestamp() ];
207 # Index value of bottom item in the list
208 $lastIndex = [ $this->mHist[1]->getTimestamp() ];
210 $this->mRange = [ 1, $numRows - 1 ];
212 # Index value of item past the index
213 $this->mPastTheEndIndex = [ $this->mHist[$numRows - 1]->getTimestamp() ];
214 # Index value of bottom item in the list
215 $lastIndex = [ $this->mHist[$numRows - 2]->getTimestamp() ];
217 $this->mRange = [ 0, $numRows - 2 ];
220 # Setting indexes to an empty array means that they will be
221 # omitted if they would otherwise appear in URLs. It just so
222 # happens that this is the right thing to do in the standard
223 # UI, in all the relevant cases.
224 $this->mPastTheEndIndex = [];
225 # Index value of bottom item in the list
226 $lastIndex = $this->mIsBackwards ?
227 [ $this->mHist[0]->getTimestamp() ] : [ $this->mHist[$numRows - 1]->getTimestamp() ];
229 $this->mRange = [ 0, $numRows - 1 ];
234 $this->mPastTheEndIndex = [];
236 if ( $this->mIsBackwards ) {
237 $this->mIsFirst = ( $numRows < $queryLimit );
238 $this->mIsLast = ( $this->mOffset ==
'' );
239 $this->mLastShown = $firstIndex;
240 $this->mFirstShown = $lastIndex;
242 $this->mIsFirst = ( $this->mOffset ==
'' );
243 $this->mIsLast = ( $numRows < $queryLimit );
244 $this->mLastShown = $lastIndex;
245 $this->mFirstShown = $firstIndex;
247 $this->mQueryDone =
true;