3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 * Builds the image revision log shown on image pages
26 class ImageHistoryList
extends ContextSource
{
48 protected $repo, $showThumb;
49 protected $preventClickjacking = false;
52 * @param ImagePage $imagePage
54 public function __construct( $imagePage ) {
55 global $wgShowArchiveThumbnails;
56 $this->current
= $imagePage->getPage()->getFile();
57 $this->img
= $imagePage->getDisplayedFile();
58 $this->title
= $imagePage->getTitle();
59 $this->imagePage
= $imagePage;
60 $this->showThumb
= $wgShowArchiveThumbnails && $this->img
->canRender();
61 $this->setContext( $imagePage->getContext() );
67 public function getImagePage() {
68 return $this->imagePage
;
74 public function getFile() {
79 * @param string $navLinks
82 public function beginImageHistoryList( $navLinks = '' ) {
83 return Xml
::element( 'h2', [ 'id' => 'filehistory' ], $this->msg( 'filehist' )->text() )
85 . "<div id=\"mw-imagepage-section-filehistory\">\n"
86 . $this->msg( 'filehist-help' )->parseAsBlock()
88 . Xml
::openElement( 'table', [ 'class' => 'wikitable filehistory' ] ) . "\n"
90 . ( $this->current
->isLocal()
91 && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ?
'<th></th>' : '' )
92 . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
93 . ( $this->showThumb ?
'<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
94 . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
95 . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
96 . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
101 * @param string $navLinks
104 public function endImageHistoryList( $navLinks = '' ) {
105 return "</table>\n$navLinks\n</div>\n";
113 public function imageHistoryLine( $iscur, $file ) {
116 $user = $this->getUser();
117 $lang = $this->getLanguage();
118 $timestamp = wfTimestamp( TS_MW
, $file->getTimestamp() );
119 $img = $iscur ?
$file->getName() : $file->getArchiveName();
120 $userId = $file->getUser( 'id' );
121 $userText = $file->getUser( 'text' );
122 $description = $file->getDescription( File
::FOR_THIS_USER
, $user );
124 $local = $this->current
->isLocal();
125 $row = $selected = '';
128 if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
130 # Link to remove from history
131 if ( $user->isAllowed( 'delete' ) ) {
132 $q = [ 'action' => 'delete' ];
134 $q['oldimage'] = $img;
136 $row .= Linker
::linkKnown(
138 $this->msg( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' )->escaped(),
142 # Link to hide content. Don't show useless link to people who cannot hide revisions.
143 $canHide = $user->isAllowed( 'deleterevision' );
144 if ( $canHide ||
( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) {
145 if ( $user->isAllowed( 'delete' ) ) {
148 // If file is top revision or locked from this user, don't link
149 if ( $iscur ||
!$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
150 $del = Linker
::revDeleteLinkDisabled( $canHide );
152 list( $ts, ) = explode( '!', $img, 2 );
154 'type' => 'oldimage',
155 'target' => $this->title
->getPrefixedText(),
158 $del = Linker
::revDeleteLink( $query,
159 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
166 // Reversion link/current indicator
169 $row .= $this->msg( 'filehist-current' )->escaped();
170 } elseif ( $local && $this->title
->quickUserCan( 'edit', $user )
171 && $this->title
->quickUserCan( 'upload', $user )
173 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
174 $row .= $this->msg( 'filehist-revert' )->escaped();
176 $row .= Linker
::linkKnown(
178 $this->msg( 'filehist-revert' )->escaped(),
181 'action' => 'revert',
189 // Date/time and image link
190 if ( $file->getTimestamp() === $this->img
->getTimestamp() ) {
191 $selected = "class='filehistory-selected'";
193 $row .= "<td $selected style='white-space: nowrap;'>";
194 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
195 # Don't link to unviewable files
196 $row .= '<span class="history-deleted">'
197 . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
198 } elseif ( $file->isDeleted( File
::DELETED_FILE
) ) {
200 $this->preventClickjacking();
201 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
202 # Make a link to review the image
203 $url = Linker
::linkKnown(
205 $lang->userTimeAndDate( $timestamp, $user ),
208 'target' => $this->title
->getPrefixedText(),
210 'token' => $user->getEditToken( $img )
214 $url = $lang->userTimeAndDate( $timestamp, $user );
216 $row .= '<span class="history-deleted">' . $url . '</span>';
217 } elseif ( !$file->exists() ) {
218 $row .= '<span class="mw-file-missing">'
219 . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
221 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
222 $row .= Xml
::element(
225 $lang->userTimeAndDate( $timestamp, $user )
231 if ( $this->showThumb
) {
232 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
235 // Image dimensions + size
237 $row .= htmlspecialchars( $file->getDimensionsString() );
238 $row .= $this->msg( 'word-separator' )->escaped();
239 $row .= '<span style="white-space: nowrap;">';
240 $row .= $this->msg( 'parentheses' )->sizeParams( $file->getSize() )->escaped();
246 // Hide deleted usernames
247 if ( $file->isDeleted( File
::DELETED_USER
) ) {
248 $row .= '<span class="history-deleted">'
249 . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
252 $row .= Linker
::userLink( $userId, $userText );
253 $row .= '<span style="white-space: nowrap;">';
254 $row .= Linker
::userToolLinks( $userId, $userText );
257 $row .= htmlspecialchars( $userText );
262 // Don't show deleted descriptions
263 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
264 $row .= '<td><span class="history-deleted">' .
265 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
267 $row .= '<td dir="' . $wgContLang->getDir() . '">' .
268 Linker
::formatComment( $description, $this->title
) . '</td>';
272 Hooks
::run( 'ImagePageFileHistoryLine', [ $this, $file, &$row, &$rowClass ] );
273 $classAttr = $rowClass ?
" class='$rowClass'" : '';
275 return "<tr{$classAttr}>{$row}</tr>\n";
282 protected function getThumbForLine( $file ) {
283 $lang = $this->getLanguage();
284 $user = $this->getUser();
285 if ( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
, $user )
286 && !$file->isDeleted( File
::DELETED_FILE
)
292 $timestamp = wfTimestamp( TS_MW
, $file->getTimestamp() );
294 $thumbnail = $file->transform( $params );
296 'alt' => $this->msg( 'filehist-thumbtext',
297 $lang->userTimeAndDate( $timestamp, $user ),
298 $lang->userDate( $timestamp, $user ),
299 $lang->userTime( $timestamp, $user ) )->text(),
304 return $this->msg( 'filehist-nothumb' )->escaped();
307 return $thumbnail->toHtml( $options );
309 return $this->msg( 'filehist-nothumb' )->escaped();
314 * @param bool $enable
316 protected function preventClickjacking( $enable = true ) {
317 $this->preventClickjacking
= $enable;
323 public function getPreventClickjacking() {
324 return $this->preventClickjacking
;