23 use Wikimedia\Timestamp\TimestampException;
57 private $linkBatchFactory;
64 parent::__construct( $imagePage->getContext() );
65 $this->mImagePage = $imagePage;
66 $this->mTitle = $imagePage->getTitle()->createFragmentTarget(
'filehistory' );
69 $this->mRange = [ 0, 0 ];
72 $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
73 $this->mDefaultLimit = 10;
75 $this->mRequest->getLimitOffsetForUser(
80 $this->linkBatchFactory = $linkBatchFactory ?? MediaWikiServices::getInstance()->getLinkBatchFactory();
115 if ( count( $this->mHist ) ) {
116 if ( $this->mImg->isLocal() ) {
118 $linkBatch = $this->linkBatchFactory->newLinkBatch();
119 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
120 $file = $this->mHist[$i];
123 $linkBatch->add(
NS_USER, $uploader->getName() );
127 $linkBatch->execute();
132 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
133 $file = $this->mHist[$i];
134 $comments[$i] =
$file->getDescription(
139 $formattedComments = MediaWikiServices::getInstance()
140 ->getCommentFormatter()
141 ->formatStrings( $comments, $this->
getTitle() );
144 # Generate prev/next links
147 $s =
Html::element(
'h2', [
'id' =>
'filehistory' ], $this->
msg(
'filehist' )->text() ) .
"\n"
148 .
Html::openElement(
'div', [
'id' =>
'mw-imagepage-section-filehistory' ] ) .
"\n"
149 . $this->
msg(
'filehist-help' )->parseAsBlock()
152 $sList = $list->beginImageHistoryList();
153 $onlyCurrentFile =
true;
155 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
156 $file = $this->mHist[$i];
157 $sList .= $list->imageHistoryLine( !
$file->isOld(),
$file, $formattedComments[$i] );
158 $onlyCurrentFile = !
$file->isOld();
160 $sList .= $list->endImageHistoryList();
161 if ( $onlyCurrentFile || !$this->mImg->isLocal() ) {
166 $s .= $this->wrapWithActionButtons( $sList );
170 if ( $list->getPreventClickjacking() ) {
178 if ( $this->mQueryDone ) {
181 $this->mImg = $this->mImagePage->getPage()->getFile();
182 if ( !$this->mImg->exists() ) {
186 if ( $this->mOffset !==
null ) {
188 $this->mDb->timestamp( $this->mOffset );
189 }
catch ( TimestampException $e ) {
190 $this->mOffset =
null;
193 $queryLimit = $this->mLimit + 1;
194 if ( $this->mIsBackwards ) {
196 $this->mHist = $this->mImg->getHistory( $queryLimit,
null, $this->mOffset,
false );
198 $numRows = count( $this->mHist );
199 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
200 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
204 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
208 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
210 $this->mHist = array_merge( $this->mHist,
211 $this->mImg->getHistory( $oiLimit, $this->mOffset,
null,
false ) );
213 $numRows = count( $this->mHist );
215 # Index value of top item in the list
216 $firstIndex = $this->mIsBackwards ?
217 [ $this->mHist[$numRows - 1]->getTimestamp() ] : [ $this->mHist[0]->getTimestamp() ];
218 # Discard the extra result row if there is one
219 if ( $numRows > $this->mLimit && $numRows > 1 ) {
220 if ( $this->mIsBackwards ) {
221 # Index value of item past the index
222 $this->mPastTheEndIndex = [ $this->mHist[0]->getTimestamp() ];
223 # Index value of bottom item in the list
224 $lastIndex = [ $this->mHist[1]->getTimestamp() ];
226 $this->mRange = [ 1, $numRows - 1 ];
228 # Index value of item past the index
229 $this->mPastTheEndIndex = [ $this->mHist[$numRows - 1]->getTimestamp() ];
230 # Index value of bottom item in the list
231 $lastIndex = [ $this->mHist[$numRows - 2]->getTimestamp() ];
233 $this->mRange = [ 0, $numRows - 2 ];
236 # Setting indexes to an empty array means that they will be
237 # omitted if they would otherwise appear in URLs. It just so
238 # happens that this is the right thing to do in the standard
239 # UI, in all the relevant cases.
240 $this->mPastTheEndIndex = [];
241 # Index value of bottom item in the list
242 $lastIndex = $this->mIsBackwards ?
243 [ $this->mHist[0]->getTimestamp() ] : [ $this->mHist[$numRows - 1]->getTimestamp() ];
245 $this->mRange = [ 0, $numRows - 1 ];
250 $this->mPastTheEndIndex = [];
252 if ( $this->mIsBackwards ) {
253 $this->mIsFirst = ( $numRows < $queryLimit );
254 $this->mIsLast = ( $this->mOffset ==
'' );
255 $this->mLastShown = $firstIndex;
256 $this->mFirstShown = $lastIndex;
258 $this->mIsFirst = ( $this->mOffset ==
'' );
259 $this->mIsLast = ( $numRows < $queryLimit );
260 $this->mLastShown = $lastIndex;
261 $this->mFirstShown = $firstIndex;
263 $this->mQueryDone =
true;
272 private function wrapWithActionButtons( $formcontents ) {
273 if ( !$this->
getAuthority()->isAllowed(
'deleterevision' ) ) {
274 return $formcontents;
277 # Show button to hide log entries
280 [
'action' =>
wfScript(),
'id' =>
'mw-filehistory-deleterevision-submit' ]
291 'name' =>
'revisiondelete',
293 'class' =>
"deleterevision-filehistory-submit mw-filehistory-deleterevision-button mw-ui-button"
295 $this->
msg(
'showhideselectedfileversions' )->text()
298 $s .= $buttons . $formcontents . $buttons;
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()
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
static closeElement( $element)
Returns "</$element>".
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Builds the image revision log shown on image pages.
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.