69 parent::__construct( $imagePage->getContext() );
70 $this->mImagePage = $imagePage;
71 $this->mTitle = $imagePage->getTitle()->createFragmentTarget(
'filehistory' );
74 $this->mRange = [ 0, 0 ];
77 $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
78 $this->mDefaultLimit = 10;
80 $this->mRequest->getLimitOffsetForUser(
85 $this->linkBatchFactory = $linkBatchFactory ?? MediaWikiServices::getInstance()->getLinkBatchFactory();
120 if ( count( $this->mHist ) ) {
121 if ( $this->mImg->isLocal() ) {
123 $linkBatch = $this->linkBatchFactory->newLinkBatch();
124 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
125 $file = $this->mHist[$i];
126 $uploader = $file->getUploader( File::FOR_THIS_USER, $this->
getAuthority() );
128 $linkBatch->add(
NS_USER, $uploader->getName() );
132 $linkBatch->execute();
137 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
138 $file = $this->mHist[$i];
139 $comments[$i] = $file->getDescription(
144 $formattedComments = MediaWikiServices::getInstance()
145 ->getCommentFormatter()
146 ->formatStrings( $comments, $this->
getTitle() );
149 # Generate prev/next links
152 $s = Html::element(
'h2', [
'id' =>
'filehistory' ], $this->
msg(
'filehist' )->text() ) .
"\n"
153 . Html::openElement(
'div', [
'id' =>
'mw-imagepage-section-filehistory' ] ) .
"\n"
154 . $this->
msg(
'filehist-help' )->parseAsBlock()
157 $sList = $list->beginImageHistoryList();
158 $onlyCurrentFile =
true;
160 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
161 $file = $this->mHist[$i];
162 $sList .= $list->imageHistoryLine( !$file->isOld(), $file, $formattedComments[$i] );
163 $onlyCurrentFile = !$file->isOld();
165 $sList .= $list->endImageHistoryList();
166 if ( $onlyCurrentFile || !$this->mImg->isLocal() ) {
171 $s .= $this->wrapWithActionButtons( $sList );
173 $s .= $navLink .
"\n" . Html::closeElement(
'div' ) .
"\n";
175 if ( $list->getPreventClickjacking() ) {
183 if ( $this->mQueryDone ) {
186 $this->mImg = $this->mImagePage->getPage()->getFile();
187 if ( !$this->mImg->exists() ) {
191 if ( $this->mOffset !==
null ) {
193 $this->mDb->timestamp( $this->mOffset );
194 }
catch ( TimestampException $e ) {
195 $this->mOffset =
null;
198 $queryLimit = $this->mLimit + 1;
199 if ( $this->mIsBackwards ) {
201 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
203 $numRows = count( $this->mHist );
204 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
205 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
209 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
213 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
215 $this->mHist = array_merge( $this->mHist,
216 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
218 $numRows = count( $this->mHist );
220 # Index value of top item in the list
221 $firstIndex = $this->mIsBackwards ?
222 [ $this->mHist[$numRows - 1]->getTimestamp() ] : [ $this->mHist[0]->getTimestamp() ];
223 # Discard the extra result row if there is one
224 if ( $numRows > $this->mLimit && $numRows > 1 ) {
225 if ( $this->mIsBackwards ) {
226 # Index value of item past the index
227 $this->mPastTheEndIndex = [ $this->mHist[0]->getTimestamp() ];
228 # Index value of bottom item in the list
229 $lastIndex = [ $this->mHist[1]->getTimestamp() ];
231 $this->mRange = [ 1, $numRows - 1 ];
233 # Index value of item past the index
234 $this->mPastTheEndIndex = [ $this->mHist[$numRows - 1]->getTimestamp() ];
235 # Index value of bottom item in the list
236 $lastIndex = [ $this->mHist[$numRows - 2]->getTimestamp() ];
238 $this->mRange = [ 0, $numRows - 2 ];
241 # Setting indexes to an empty array means that they will be
242 # omitted if they would otherwise appear in URLs. It just so
243 # happens that this is the right thing to do in the standard
244 # UI, in all the relevant cases.
245 $this->mPastTheEndIndex = [];
246 # Index value of bottom item in the list
247 $lastIndex = $this->mIsBackwards ?
248 [ $this->mHist[0]->getTimestamp() ] : [ $this->mHist[$numRows - 1]->getTimestamp() ];
250 $this->mRange = [ 0, $numRows - 1 ];
255 $this->mPastTheEndIndex = [];
257 if ( $this->mIsBackwards ) {
258 $this->mIsFirst = ( $numRows < $queryLimit );
259 $this->mIsLast = ( $this->mOffset ==
'' );
260 $this->mLastShown = $firstIndex;
261 $this->mFirstShown = $lastIndex;
263 $this->mIsFirst = ( $this->mOffset ==
'' );
264 $this->mIsLast = ( $numRows < $queryLimit );
265 $this->mLastShown = $lastIndex;
266 $this->mFirstShown = $firstIndex;
268 $this->mQueryDone =
true;