25 use Wikimedia\Timestamp\TimestampException;
59 private $linkBatchFactory;
66 parent::__construct( $imagePage->getContext() );
67 $this->mImagePage = $imagePage;
68 $this->mTitle = $imagePage->getTitle()->createFragmentTarget(
'filehistory' );
71 $this->mRange = [ 0, 0 ];
74 $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
75 $this->mDefaultLimit = 10;
77 $this->mRequest->getLimitOffsetForUser(
82 $this->linkBatchFactory = $linkBatchFactory ?? MediaWikiServices::getInstance()->getLinkBatchFactory();
117 if ( count( $this->mHist ) ) {
118 if ( $this->mImg->isLocal() ) {
120 $linkBatch = $this->linkBatchFactory->newLinkBatch();
121 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
122 $file = $this->mHist[$i];
125 $linkBatch->add(
NS_USER, $uploader->getName() );
129 $linkBatch->execute();
134 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
135 $file = $this->mHist[$i];
136 $comments[$i] =
$file->getDescription(
141 $formattedComments = MediaWikiServices::getInstance()
142 ->getCommentFormatter()
143 ->formatStrings( $comments, $this->
getTitle() );
146 # Generate prev/next links
149 $s = Html::element(
'h2', [
'id' =>
'filehistory' ], $this->
msg(
'filehist' )->text() ) .
"\n"
150 . Html::openElement(
'div', [
'id' =>
'mw-imagepage-section-filehistory' ] ) .
"\n"
151 . $this->
msg(
'filehist-help' )->parseAsBlock()
154 $sList = $list->beginImageHistoryList();
155 $onlyCurrentFile =
true;
157 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
158 $file = $this->mHist[$i];
159 $sList .= $list->imageHistoryLine( !
$file->isOld(),
$file, $formattedComments[$i] );
160 $onlyCurrentFile = !
$file->isOld();
162 $sList .= $list->endImageHistoryList();
163 if ( $onlyCurrentFile || !$this->mImg->isLocal() ) {
168 $s .= $this->wrapWithActionButtons( $sList );
170 $s .= $navLink .
"\n" . Html::closeElement(
'div' ) .
"\n";
172 if ( $list->getPreventClickjacking() ) {
180 if ( $this->mQueryDone ) {
183 $this->mImg = $this->mImagePage->getPage()->getFile();
184 if ( !$this->mImg->exists() ) {
188 if ( $this->mOffset !==
null ) {
190 $this->mDb->timestamp( $this->mOffset );
191 }
catch ( TimestampException $e ) {
192 $this->mOffset =
null;
195 $queryLimit = $this->mLimit + 1;
196 if ( $this->mIsBackwards ) {
198 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
200 $numRows = count( $this->mHist );
201 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
202 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
206 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
210 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
212 $this->mHist = array_merge( $this->mHist,
213 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
215 $numRows = count( $this->mHist );
217 # Index value of top item in the list
218 $firstIndex = $this->mIsBackwards ?
219 [ $this->mHist[$numRows - 1]->getTimestamp() ] : [ $this->mHist[0]->getTimestamp() ];
220 # Discard the extra result row if there is one
221 if ( $numRows > $this->mLimit && $numRows > 1 ) {
222 if ( $this->mIsBackwards ) {
223 # Index value of item past the index
224 $this->mPastTheEndIndex = [ $this->mHist[0]->getTimestamp() ];
225 # Index value of bottom item in the list
226 $lastIndex = [ $this->mHist[1]->getTimestamp() ];
228 $this->mRange = [ 1, $numRows - 1 ];
230 # Index value of item past the index
231 $this->mPastTheEndIndex = [ $this->mHist[$numRows - 1]->getTimestamp() ];
232 # Index value of bottom item in the list
233 $lastIndex = [ $this->mHist[$numRows - 2]->getTimestamp() ];
235 $this->mRange = [ 0, $numRows - 2 ];
238 # Setting indexes to an empty array means that they will be
239 # omitted if they would otherwise appear in URLs. It just so
240 # happens that this is the right thing to do in the standard
241 # UI, in all the relevant cases.
242 $this->mPastTheEndIndex = [];
243 # Index value of bottom item in the list
244 $lastIndex = $this->mIsBackwards ?
245 [ $this->mHist[0]->getTimestamp() ] : [ $this->mHist[$numRows - 1]->getTimestamp() ];
247 $this->mRange = [ 0, $numRows - 1 ];
252 $this->mPastTheEndIndex = [];
254 if ( $this->mIsBackwards ) {
255 $this->mIsFirst = ( $numRows < $queryLimit );
256 $this->mIsLast = ( $this->mOffset ==
'' );
257 $this->mLastShown = $firstIndex;
258 $this->mFirstShown = $lastIndex;
260 $this->mIsFirst = ( $this->mOffset ==
'' );
261 $this->mIsLast = ( $numRows < $queryLimit );
262 $this->mLastShown = $lastIndex;
263 $this->mFirstShown = $firstIndex;
265 $this->mQueryDone =
true;
274 private function wrapWithActionButtons( $formcontents ) {
275 if ( !$this->
getAuthority()->isAllowed(
'deleterevision' ) ) {
276 return $formcontents;
279 # Show button to hide log entries
280 $s = Html::openElement(
282 [
'action' =>
wfScript(),
'id' =>
'mw-filehistory-deleterevision-submit' ]
284 $s .= Html::hidden(
'target', $this->
getTitle()->getPrefixedDBkey() ) .
"\n";
285 $s .= Html::hidden(
'action',
'historysubmit' ) .
"\n";
286 $s .= Html::hidden(
'type',
'oldimage' ) .
"\n";
289 $buttons = Html::element(
293 'name' =>
'revisiondelete',
295 'class' =>
"deleterevision-filehistory-submit mw-filehistory-deleterevision-button mw-ui-button"
297 $this->
msg(
'showhideselectedfileversions' )->text()
300 $s .= $buttons . $formcontents . $buttons;
301 $s .= Html::closeElement(
'form' );
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Builds the image revision log shown on image pages.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.