73 parent::__construct( $imagePage->getContext() );
74 $this->mImagePage = $imagePage;
75 $this->mTitle = $imagePage->getTitle()->createFragmentTarget(
'filehistory' );
78 $this->mRange = [ 0, 0 ];
81 $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
82 $this->mDefaultLimit = 10;
84 $this->mRequest->getLimitOffsetForUser(
124 if ( count( $this->mHist ) ) {
125 if ( $this->mImg->isLocal() ) {
127 $linkBatch = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
128 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
129 $file = $this->mHist[$i];
132 $linkBatch->add(
NS_USER, $uploader->getName() );
136 $linkBatch->execute();
141 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
142 $file = $this->mHist[$i];
143 $comments[$i] = $file->getDescription(
149 ->getCommentFormatter()
150 ->formatStrings( $comments, $this->
getTitle() );
153 # Generate prev/next links
156 $s =
Html::element(
'h2', [
'id' =>
'filehistory' ], $this->
msg(
'filehist' )->text() ) .
"\n"
157 . Html::openElement(
'div', [
'id' =>
'mw-imagepage-section-filehistory' ] ) .
"\n"
158 . $this->
msg(
'filehist-help' )->parseAsBlock()
161 $sList = $list->beginImageHistoryList();
162 $onlyCurrentFile =
true;
164 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
165 $file = $this->mHist[$i];
166 $sList .= $list->imageHistoryLine( !$file->isOld(), $file, $formattedComments[$i] );
167 $onlyCurrentFile = !$file->isOld();
169 $sList .= $list->endImageHistoryList();
170 if ( $onlyCurrentFile || !$this->mImg->isLocal() ) {
175 $s .= $this->wrapWithActionButtons( $sList );
177 $s .= $navLink .
"\n" . Html::closeElement(
'div' ) .
"\n";
179 if ( $list->getPreventClickjacking() ) {
187 if ( $this->mQueryDone ) {
190 $this->mImg = $this->mImagePage->getPage()->getFile();
191 if ( !$this->mImg->exists() ) {
195 if ( $this->mOffset !==
null ) {
197 $this->mDb->timestamp( $this->mOffset );
198 }
catch ( TimestampException ) {
199 $this->mOffset =
null;
202 $queryLimit = $this->mLimit + 1;
203 if ( $this->mIsBackwards ) {
205 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
207 $numRows = count( $this->mHist );
208 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
209 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
213 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
217 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
219 $this->mHist = array_merge( $this->mHist,
220 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
222 $numRows = count( $this->mHist );
224 # Index value of top item in the list
225 $firstIndex = $this->mIsBackwards ?
226 [ $this->mHist[$numRows - 1]->getTimestamp() ] : [ $this->mHist[0]->getTimestamp() ];
227 # Discard the extra result row if there is one
228 if ( $numRows > $this->mLimit && $numRows > 1 ) {
229 if ( $this->mIsBackwards ) {
230 # Index value of item past the index
231 $this->mPastTheEndIndex = [ $this->mHist[0]->getTimestamp() ];
232 # Index value of bottom item in the list
233 $lastIndex = [ $this->mHist[1]->getTimestamp() ];
235 $this->mRange = [ 1, $numRows - 1 ];
237 # Index value of item past the index
238 $this->mPastTheEndIndex = [ $this->mHist[$numRows - 1]->getTimestamp() ];
239 # Index value of bottom item in the list
240 $lastIndex = [ $this->mHist[$numRows - 2]->getTimestamp() ];
242 $this->mRange = [ 0, $numRows - 2 ];
245 # Setting indexes to an empty array means that they will be
246 # omitted if they would otherwise appear in URLs. It just so
247 # happens that this is the right thing to do in the standard
248 # UI, in all the relevant cases.
249 $this->mPastTheEndIndex = [];
250 # Index value of bottom item in the list
251 $lastIndex = $this->mIsBackwards ?
252 [ $this->mHist[0]->getTimestamp() ] : [ $this->mHist[$numRows - 1]->getTimestamp() ];
254 $this->mRange = [ 0, $numRows - 1 ];
259 $this->mPastTheEndIndex = [];
261 if ( $this->mIsBackwards ) {
262 $this->mIsFirst = ( $numRows < $queryLimit );
263 $this->mIsLast = ( $this->mOffset ==
'' );
264 $this->mLastShown = $firstIndex;
265 $this->mFirstShown = $lastIndex;
267 $this->mIsFirst = ( $this->mOffset ==
'' );
268 $this->mIsLast = ( $numRows < $queryLimit );
269 $this->mLastShown = $lastIndex;
270 $this->mFirstShown = $firstIndex;
272 $this->mQueryDone =
true;