68 parent::__construct( $imagePage->getContext() );
69 $this->mImagePage = $imagePage;
70 $this->mTitle = $imagePage->getTitle()->createFragmentTarget(
'filehistory' );
73 $this->mRange = [ 0, 0 ];
76 $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
77 $this->mDefaultLimit = 10;
79 $this->mRequest->getLimitOffsetForUser(
84 $this->linkBatchFactory = $linkBatchFactory ?? MediaWikiServices::getInstance()->getLinkBatchFactory();
119 if ( count( $this->mHist ) ) {
120 if ( $this->mImg->isLocal() ) {
122 $linkBatch = $this->linkBatchFactory->newLinkBatch();
123 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
124 $file = $this->mHist[$i];
127 $linkBatch->add(
NS_USER, $uploader->getName() );
131 $linkBatch->execute();
136 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
137 $file = $this->mHist[$i];
138 $comments[$i] =
$file->getDescription(
143 $formattedComments = MediaWikiServices::getInstance()
144 ->getCommentFormatter()
145 ->formatStrings( $comments, $this->
getTitle() );
148 # Generate prev/next links
151 $s = Html::element(
'h2', [
'id' =>
'filehistory' ], $this->
msg(
'filehist' )->text() ) .
"\n"
152 . Html::openElement(
'div', [
'id' =>
'mw-imagepage-section-filehistory' ] ) .
"\n"
153 . $this->
msg(
'filehist-help' )->parseAsBlock()
156 $sList = $list->beginImageHistoryList();
157 $onlyCurrentFile =
true;
159 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
160 $file = $this->mHist[$i];
161 $sList .= $list->imageHistoryLine( !
$file->isOld(),
$file, $formattedComments[$i] );
162 $onlyCurrentFile = !
$file->isOld();
164 $sList .= $list->endImageHistoryList();
165 if ( $onlyCurrentFile || !$this->mImg->isLocal() ) {
170 $s .= $this->wrapWithActionButtons( $sList );
172 $s .= $navLink .
"\n" . Html::closeElement(
'div' ) .
"\n";
174 if ( $list->getPreventClickjacking() ) {
182 if ( $this->mQueryDone ) {
185 $this->mImg = $this->mImagePage->getPage()->getFile();
186 if ( !$this->mImg->exists() ) {
190 if ( $this->mOffset !==
null ) {
192 $this->mDb->timestamp( $this->mOffset );
193 }
catch ( TimestampException $e ) {
194 $this->mOffset =
null;
197 $queryLimit = $this->mLimit + 1;
198 if ( $this->mIsBackwards ) {
200 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
202 $numRows = count( $this->mHist );
203 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
204 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
208 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
212 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
214 $this->mHist = array_merge( $this->mHist,
215 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
217 $numRows = count( $this->mHist );
219 # Index value of top item in the list
220 $firstIndex = $this->mIsBackwards ?
221 [ $this->mHist[$numRows - 1]->getTimestamp() ] : [ $this->mHist[0]->getTimestamp() ];
222 # Discard the extra result row if there is one
223 if ( $numRows > $this->mLimit && $numRows > 1 ) {
224 if ( $this->mIsBackwards ) {
225 # Index value of item past the index
226 $this->mPastTheEndIndex = [ $this->mHist[0]->getTimestamp() ];
227 # Index value of bottom item in the list
228 $lastIndex = [ $this->mHist[1]->getTimestamp() ];
230 $this->mRange = [ 1, $numRows - 1 ];
232 # Index value of item past the index
233 $this->mPastTheEndIndex = [ $this->mHist[$numRows - 1]->getTimestamp() ];
234 # Index value of bottom item in the list
235 $lastIndex = [ $this->mHist[$numRows - 2]->getTimestamp() ];
237 $this->mRange = [ 0, $numRows - 2 ];
240 # Setting indexes to an empty array means that they will be
241 # omitted if they would otherwise appear in URLs. It just so
242 # happens that this is the right thing to do in the standard
243 # UI, in all the relevant cases.
244 $this->mPastTheEndIndex = [];
245 # Index value of bottom item in the list
246 $lastIndex = $this->mIsBackwards ?
247 [ $this->mHist[0]->getTimestamp() ] : [ $this->mHist[$numRows - 1]->getTimestamp() ];
249 $this->mRange = [ 0, $numRows - 1 ];
254 $this->mPastTheEndIndex = [];
256 if ( $this->mIsBackwards ) {
257 $this->mIsFirst = ( $numRows < $queryLimit );
258 $this->mIsLast = ( $this->mOffset ==
'' );
259 $this->mLastShown = $firstIndex;
260 $this->mFirstShown = $lastIndex;
262 $this->mIsFirst = ( $this->mOffset ==
'' );
263 $this->mIsLast = ( $numRows < $queryLimit );
264 $this->mLastShown = $lastIndex;
265 $this->mFirstShown = $firstIndex;
267 $this->mQueryDone =
true;