58 parent::__construct( $imagePage->getContext() );
59 $this->mImagePage = $imagePage;
60 $this->mTitle = $imagePage->getTitle()->createFragmentTarget(
'filehistory' );
63 $this->mRange = [ 0, 0 ];
66 array_unshift( $this->mLimitsShown, 10 );
67 $this->mDefaultLimit = 10;
69 $this->mRequest->getLimitOffsetForUser(
110 if ( count( $this->mHist ) ) {
111 if ( $this->mImg->isLocal() ) {
113 $linkBatch = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
114 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
115 $file = $this->mHist[$i];
118 $linkBatch->add(
NS_USER, $uploader->getName() );
122 $linkBatch->execute();
127 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
128 $file = $this->mHist[$i];
129 $comments[$i] = $file->getDescription(
135 ->getCommentFormatter()
136 ->formatStrings( $comments, $this->
getTitle() );
139 # Generate prev/next links
142 $s =
Html::element(
'h2', [
'id' =>
'filehistory' ], $this->
msg(
'filehist' )->text() ) .
"\n"
143 . Html::openElement(
'div', [
'id' =>
'mw-imagepage-section-filehistory' ] ) .
"\n"
144 . $this->
msg(
'filehist-help' )->parseAsBlock()
147 $sList = $list->beginImageHistoryList();
148 $onlyCurrentFile =
true;
150 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
151 $file = $this->mHist[$i];
152 $sList .= $list->imageHistoryLine( !$file->isOld(), $file, $formattedComments[$i] );
153 $onlyCurrentFile = !$file->isOld();
155 $sList .= $list->endImageHistoryList();
156 if ( $onlyCurrentFile || !$this->mImg->isLocal() ) {
161 $s .= $this->wrapWithActionButtons( $sList );
163 $s .= $navLink .
"\n" . Html::closeElement(
'div' ) .
"\n";
165 if ( $list->getPreventClickjacking() ) {
173 if ( $this->mQueryDone ) {
176 $this->mImg = $this->mImagePage->getPage()->getFile();
177 if ( !$this->mImg->exists() ) {
181 if ( $this->mOffset !==
null ) {
183 $this->mDb->timestamp( $this->mOffset );
184 }
catch ( TimestampException ) {
185 $this->mOffset =
null;
188 $queryLimit = $this->mLimit + 1;
189 if ( $this->mIsBackwards ) {
191 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
193 $numRows = count( $this->mHist );
194 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
195 array_unshift( $this->mHist, $this->mImg );
199 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
203 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
205 $this->mHist = array_merge( $this->mHist,
206 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
208 $numRows = count( $this->mHist );
210 # Index value of top item in the list
211 $firstIndex = $this->mIsBackwards ?
212 [ $this->mHist[$numRows - 1]->getTimestamp() ] : [ $this->mHist[0]->getTimestamp() ];
213 # Discard the extra result row if there is one
214 if ( $numRows > $this->mLimit && $numRows > 1 ) {
215 if ( $this->mIsBackwards ) {
216 # Index value of item past the index
217 $this->mPastTheEndIndex = [ $this->mHist[0]->getTimestamp() ];
218 # Index value of bottom item in the list
219 $lastIndex = [ $this->mHist[1]->getTimestamp() ];
221 $this->mRange = [ 1, $numRows - 1 ];
223 # Index value of item past the index
224 $this->mPastTheEndIndex = [ $this->mHist[$numRows - 1]->getTimestamp() ];
225 # Index value of bottom item in the list
226 $lastIndex = [ $this->mHist[$numRows - 2]->getTimestamp() ];
228 $this->mRange = [ 0, $numRows - 2 ];
231 # Setting indexes to an empty array means that they will be
232 # omitted if they would otherwise appear in URLs. It just so
233 # happens that this is the right thing to do in the standard
234 # UI, in all the relevant cases.
235 $this->mPastTheEndIndex = [];
236 # Index value of bottom item in the list
237 $lastIndex = $this->mIsBackwards ?
238 [ $this->mHist[0]->getTimestamp() ] : [ $this->mHist[$numRows - 1]->getTimestamp() ];
240 $this->mRange = [ 0, $numRows - 1 ];
245 $this->mPastTheEndIndex = [];
247 if ( $this->mIsBackwards ) {
248 $this->mIsFirst = ( $numRows < $queryLimit );
249 $this->mIsLast = ( $this->mOffset ==
'' );
250 $this->mLastShown = $firstIndex;
251 $this->mFirstShown = $lastIndex;
253 $this->mIsFirst = ( $this->mOffset ==
'' );
254 $this->mIsLast = ( $numRows < $queryLimit );
255 $this->mLastShown = $lastIndex;
256 $this->mFirstShown = $firstIndex;
258 $this->mQueryDone =
true;