getContext();
$this->current = $imagePage->getPage()->getFile();
$this->img = $imagePage->getDisplayedFile();
$this->title = $imagePage->getTitle();
$this->imagePage = $imagePage;
$this->showThumb = $context->getConfig()->get( 'ShowArchiveThumbnails' ) &&
$this->img->canRender();
$this->setContext( $context );
}
/**
* @return ImagePage
*/
public function getImagePage() {
return $this->imagePage;
}
/**
* @return File
*/
public function getFile() {
return $this->img;
}
/**
* @param string $navLinks
* @return string
*/
public function beginImageHistoryList( $navLinks = '' ) {
return Xml::element( 'h2', [ 'id' => 'filehistory' ], $this->msg( 'filehist' )->text() )
. "\n"
. "
\n"
. $this->msg( 'filehist-help' )->parseAsBlock()
. $navLinks . "\n"
. Xml::openElement( 'table', [ 'class' => 'wikitable filehistory' ] ) . "\n"
. '
| '
. ( $this->current->isLocal()
&& ( MediaWikiServices::getInstance()
->getPermissionManager()
->userHasAnyRight( $this->getUser(), 'delete', 'deletedhistory' ) ) ? ' | ' : '' )
. '' . $this->msg( 'filehist-datetime' )->escaped() . ' | '
. ( $this->showThumb ? '' . $this->msg( 'filehist-thumb' )->escaped() . ' | ' : '' )
. '' . $this->msg( 'filehist-dimensions' )->escaped() . ' | '
. '' . $this->msg( 'filehist-user' )->escaped() . ' | '
. '' . $this->msg( 'filehist-comment' )->escaped() . ' | '
. "
\n";
}
/**
* @param string $navLinks
* @return string
*/
public function endImageHistoryList( $navLinks = '' ) {
return "\n$navLinks\n\n";
}
/**
* @param bool $iscur
* @param File $file
* @return string
*/
public function imageHistoryLine( $iscur, $file ) {
$user = $this->getUser();
$lang = $this->getLanguage();
$pm = MediaWikiServices::getInstance()->getPermissionManager();
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
$timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
// @phan-suppress-next-line PhanUndeclaredMethod
$img = $iscur ? $file->getName() : $file->getArchiveName();
$userId = $file->getUser( 'id' );
$userText = $file->getUser( 'text' );
$description = $file->getDescription( File::FOR_THIS_USER, $user );
$local = $this->current->isLocal();
$row = $selected = '';
// Deletion link
if ( $local && ( $pm->userHasAnyRight( $user, 'delete', 'deletedhistory' ) ) ) {
$row .= '';
# Link to remove from history
if ( $pm->userHasRight( $user, 'delete' ) ) {
$q = [ 'action' => 'delete' ];
if ( !$iscur ) {
$q['oldimage'] = $img;
}
$row .= $linkRenderer->makeKnownLink(
$this->title,
$this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->text(),
[], $q
);
}
# Link to hide content. Don't show useless link to people who cannot hide revisions.
$canHide = $pm->userHasRight( $user, 'deleterevision' );
if ( $canHide || ( $pm->userHasRight( $user, 'deletedhistory' )
&& $file->getVisibility() ) ) {
if ( $pm->userHasRight( $user, 'delete' ) ) {
$row .= ' ';
}
// If file is top revision or locked from this user, don't link
if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
$del = Linker::revDeleteLinkDisabled( $canHide );
} else {
list( $ts, ) = explode( '!', $img, 2 );
$query = [
'type' => 'oldimage',
'target' => $this->title->getPrefixedText(),
'ids' => $ts,
];
$del = Linker::revDeleteLink( $query,
$file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
}
$row .= $del;
}
$row .= ' | ';
}
// Reversion link/current indicator
$row .= '';
if ( $iscur ) {
$row .= $this->msg( 'filehist-current' )->escaped();
} elseif ( $local && $pm->quickUserCan( 'edit', $user, $this->title )
&& $pm->quickUserCan( 'upload', $user, $this->title )
) {
if ( $file->isDeleted( File::DELETED_FILE ) ) {
$row .= $this->msg( 'filehist-revert' )->escaped();
} else {
$row .= $linkRenderer->makeKnownLink(
$this->title,
$this->msg( 'filehist-revert' )->text(),
[],
[
'action' => 'revert',
'oldimage' => $img,
]
);
}
}
$row .= ' | ';
// Date/time and image link
if ( $file->getTimestamp() === $this->img->getTimestamp() ) {
$selected = "class='filehistory-selected'";
}
$row .= "";
if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
# Don't link to unviewable files
$row .= Html::element( 'span', [ 'class' => 'history-deleted' ],
$lang->userTimeAndDate( $timestamp, $user )
);
} elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
$timeAndDate = $lang->userTimeAndDate( $timestamp, $user );
if ( $local ) {
$this->preventClickjacking();
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
# Make a link to review the image
$url = $linkRenderer->makeKnownLink(
$revdel,
$timeAndDate,
[],
[
'target' => $this->title->getPrefixedText(),
'file' => $img,
'token' => $user->getEditToken( $img )
]
);
} else {
$url = htmlspecialchars( $timeAndDate );
}
$row .= '' . $url . '';
} elseif ( !$file->exists() ) {
$row .= Html::element( 'span', [ 'class' => 'mw-file-missing' ],
$lang->userTimeAndDate( $timestamp, $user )
);
} else {
$url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
$row .= Xml::element(
'a',
[ 'href' => $url ],
$lang->userTimeAndDate( $timestamp, $user )
);
}
$row .= " | ";
// Thumbnail
if ( $this->showThumb ) {
$row .= '' . $this->getThumbForLine( $file ) . ' | ';
}
// Image dimensions + size
$row .= '';
$row .= htmlspecialchars( $file->getDimensionsString() );
$row .= $this->msg( 'word-separator' )->escaped();
$row .= '';
$row .= $this->msg( 'parentheses' )->sizeParams( $file->getSize() )->escaped();
$row .= '';
$row .= ' | ';
// Uploading user
$row .= '';
// Hide deleted usernames
if ( $file->isDeleted( File::DELETED_USER ) ) {
$row .= ''
. $this->msg( 'rev-deleted-user' )->escaped() . '';
} else {
if ( $local ) {
$row .= Linker::userLink( $userId, $userText );
$row .= '';
$row .= Linker::userToolLinks( $userId, $userText );
$row .= '';
} else {
$row .= htmlspecialchars( $userText );
}
}
$row .= ' | ';
// Don't show deleted descriptions
if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
$row .= '' .
$this->msg( 'rev-deleted-comment' )->escaped() . ' | ';
} else {
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
$row .= Html::rawElement(
'td',
[ 'dir' => $contLang->getDir() ],
Linker::formatComment( $description, $this->title )
);
}
$rowClass = null;
$this->getHookRunner()->onImagePageFileHistoryLine( $this, $file, $row, $rowClass );
$classAttr = $rowClass ? " class='$rowClass'" : '';
return "{$row}
\n";
}
/**
* @param File $file
* @return string
*/
protected function getThumbForLine( $file ) {
$lang = $this->getLanguage();
$user = $this->getUser();
if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user )
&& !$file->isDeleted( File::DELETED_FILE )
) {
$params = [
'width' => '120',
'height' => '120',
];
$timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
$thumbnail = $file->transform( $params );
$options = [
'alt' => $this->msg( 'filehist-thumbtext',
$lang->userTimeAndDate( $timestamp, $user ),
$lang->userDate( $timestamp, $user ),
$lang->userTime( $timestamp, $user ) )->text(),
'file-link' => true,
];
if ( !$thumbnail ) {
return $this->msg( 'filehist-nothumb' )->escaped();
}
return $thumbnail->toHtml( $options );
} else {
return $this->msg( 'filehist-nothumb' )->escaped();
}
}
/**
* @param bool $enable
*/
protected function preventClickjacking( $enable = true ) {
$this->preventClickjacking = $enable;
}
/**
* @return bool
*/
public function getPreventClickjacking() {
return $this->preventClickjacking;
}
}