MediaWiki REL1_35
ImageHistoryList.php
Go to the documentation of this file.
1<?php
21use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
23
30 use ProtectedHookAccessorTrait;
31
35 protected $title;
36
40 protected $img;
41
45 protected $imagePage;
46
50 protected $current;
51
52 protected $repo, $showThumb;
53 protected $preventClickjacking = false;
54
58 public function __construct( $imagePage ) {
60 $this->current = $imagePage->getPage()->getFile();
61 $this->img = $imagePage->getDisplayedFile();
62 $this->title = $imagePage->getTitle();
63 $this->imagePage = $imagePage;
64 $this->showThumb = $context->getConfig()->get( 'ShowArchiveThumbnails' ) &&
65 $this->img->canRender();
66 $this->setContext( $context );
67 }
68
72 public function getImagePage() {
73 return $this->imagePage;
74 }
75
79 public function getFile() {
80 return $this->img;
81 }
82
87 public function beginImageHistoryList( $navLinks = '' ) {
88 return Xml::element( 'h2', [ 'id' => 'filehistory' ], $this->msg( 'filehist' )->text() )
89 . "\n"
90 . "<div id=\"mw-imagepage-section-filehistory\">\n"
91 . $this->msg( 'filehist-help' )->parseAsBlock()
92 . $navLinks . "\n"
93 . Xml::openElement( 'table', [ 'class' => 'wikitable filehistory' ] ) . "\n"
94 . '<tr><th></th>'
95 . ( $this->current->isLocal()
96 && ( MediaWikiServices::getInstance()
97 ->getPermissionManager()
98 ->userHasAnyRight( $this->getUser(), 'delete', 'deletedhistory' ) ) ? '<th></th>' : '' )
99 . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
100 . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
101 . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
102 . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
103 . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
104 . "</tr>\n";
105 }
106
111 public function endImageHistoryList( $navLinks = '' ) {
112 return "</table>\n$navLinks\n</div>\n";
113 }
114
120 public function imageHistoryLine( $iscur, $file ) {
121 $user = $this->getUser();
122 $lang = $this->getLanguage();
123 $pm = MediaWikiServices::getInstance()->getPermissionManager();
124 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
125 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
126 // @phan-suppress-next-line PhanUndeclaredMethod
127 $img = $iscur ? $file->getName() : $file->getArchiveName();
128 $userId = $file->getUser( 'id' );
129 $userText = $file->getUser( 'text' );
130 $description = $file->getDescription( File::FOR_THIS_USER, $user );
131
132 $local = $this->current->isLocal();
133 $row = $selected = '';
134
135 // Deletion link
136 if ( $local && ( $pm->userHasAnyRight( $user, 'delete', 'deletedhistory' ) ) ) {
137 $row .= '<td>';
138 # Link to remove from history
139 if ( $pm->userHasRight( $user, 'delete' ) ) {
140 $q = [ 'action' => 'delete' ];
141 if ( !$iscur ) {
142 $q['oldimage'] = $img;
143 }
144 $row .= $linkRenderer->makeKnownLink(
145 $this->title,
146 $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->text(),
147 [], $q
148 );
149 }
150 # Link to hide content. Don't show useless link to people who cannot hide revisions.
151 $canHide = $pm->userHasRight( $user, 'deleterevision' );
152 if ( $canHide || ( $pm->userHasRight( $user, 'deletedhistory' )
153 && $file->getVisibility() ) ) {
154 if ( $pm->userHasRight( $user, 'delete' ) ) {
155 $row .= '<br />';
156 }
157 // If file is top revision or locked from this user, don't link
158 if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
159 $del = Linker::revDeleteLinkDisabled( $canHide );
160 } else {
161 list( $ts, ) = explode( '!', $img, 2 );
162 $query = [
163 'type' => 'oldimage',
164 'target' => $this->title->getPrefixedText(),
165 'ids' => $ts,
166 ];
167 $del = Linker::revDeleteLink( $query,
168 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
169 }
170 $row .= $del;
171 }
172 $row .= '</td>';
173 }
174
175 // Reversion link/current indicator
176 $row .= '<td>';
177 if ( $iscur ) {
178 $row .= $this->msg( 'filehist-current' )->escaped();
179 } elseif ( $local && $pm->quickUserCan( 'edit', $user, $this->title )
180 && $pm->quickUserCan( 'upload', $user, $this->title )
181 ) {
182 if ( $file->isDeleted( File::DELETED_FILE ) ) {
183 $row .= $this->msg( 'filehist-revert' )->escaped();
184 } else {
185 $row .= $linkRenderer->makeKnownLink(
186 $this->title,
187 $this->msg( 'filehist-revert' )->text(),
188 [],
189 [
190 'action' => 'revert',
191 'oldimage' => $img,
192 ]
193 );
194 }
195 }
196 $row .= '</td>';
197
198 // Date/time and image link
199 if ( $file->getTimestamp() === $this->img->getTimestamp() ) {
200 $selected = "class='filehistory-selected'";
201 }
202 $row .= "<td $selected style='white-space: nowrap;'>";
203 if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
204 # Don't link to unviewable files
205 $row .= Html::element( 'span', [ 'class' => 'history-deleted' ],
206 $lang->userTimeAndDate( $timestamp, $user )
207 );
208 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
209 $timeAndDate = $lang->userTimeAndDate( $timestamp, $user );
210 if ( $local ) {
211 $this->preventClickjacking();
212 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
213 # Make a link to review the image
214 $url = $linkRenderer->makeKnownLink(
215 $revdel,
216 $timeAndDate,
217 [],
218 [
219 'target' => $this->title->getPrefixedText(),
220 'file' => $img,
221 'token' => $user->getEditToken( $img )
222 ]
223 );
224 } else {
225 $url = htmlspecialchars( $timeAndDate );
226 }
227 $row .= '<span class="history-deleted">' . $url . '</span>';
228 } elseif ( !$file->exists() ) {
229 $row .= Html::element( 'span', [ 'class' => 'mw-file-missing' ],
230 $lang->userTimeAndDate( $timestamp, $user )
231 );
232 } else {
233 $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
234 $row .= Xml::element(
235 'a',
236 [ 'href' => $url ],
237 $lang->userTimeAndDate( $timestamp, $user )
238 );
239 }
240 $row .= "</td>";
241
242 // Thumbnail
243 if ( $this->showThumb ) {
244 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
245 }
246
247 // Image dimensions + size
248 $row .= '<td>';
249 $row .= htmlspecialchars( $file->getDimensionsString() );
250 $row .= $this->msg( 'word-separator' )->escaped();
251 $row .= '<span style="white-space: nowrap;">';
252 $row .= $this->msg( 'parentheses' )->sizeParams( $file->getSize() )->escaped();
253 $row .= '</span>';
254 $row .= '</td>';
255
256 // Uploading user
257 $row .= '<td>';
258 // Hide deleted usernames
259 if ( $file->isDeleted( File::DELETED_USER ) ) {
260 $row .= '<span class="history-deleted">'
261 . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
262 } else {
263 if ( $local ) {
264 $row .= Linker::userLink( $userId, $userText );
265 $row .= '<span style="white-space: nowrap;">';
266 $row .= Linker::userToolLinks( $userId, $userText );
267 $row .= '</span>';
268 } else {
269 $row .= htmlspecialchars( $userText );
270 }
271 }
272 $row .= '</td>';
273
274 // Don't show deleted descriptions
275 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
276 $row .= '<td><span class="history-deleted">' .
277 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
278 } else {
279 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
280 $row .= Html::rawElement(
281 'td',
282 [ 'dir' => $contLang->getDir() ],
283 Linker::formatComment( $description, $this->title )
284 );
285 }
286
287 $rowClass = null;
288 $this->getHookRunner()->onImagePageFileHistoryLine( $this, $file, $row, $rowClass );
289 $classAttr = $rowClass ? " class='$rowClass'" : '';
290
291 return "<tr{$classAttr}>{$row}</tr>\n";
292 }
293
298 protected function getThumbForLine( $file ) {
299 $lang = $this->getLanguage();
300 $user = $this->getUser();
301 if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user )
302 && !$file->isDeleted( File::DELETED_FILE )
303 ) {
304 $params = [
305 'width' => '120',
306 'height' => '120',
307 ];
308 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
309
310 $thumbnail = $file->transform( $params );
311 $options = [
312 'alt' => $this->msg( 'filehist-thumbtext',
313 $lang->userTimeAndDate( $timestamp, $user ),
314 $lang->userDate( $timestamp, $user ),
315 $lang->userTime( $timestamp, $user ) )->text(),
316 'file-link' => true,
317 ];
318
319 if ( !$thumbnail ) {
320 return $this->msg( 'filehist-nothumb' )->escaped();
321 }
322
323 return $thumbnail->toHtml( $options );
324 } else {
325 return $this->msg( 'filehist-nothumb' )->escaped();
326 }
327 }
328
332 protected function preventClickjacking( $enable = true ) {
333 $this->preventClickjacking = $enable;
334 }
335
339 public function getPreventClickjacking() {
340 return $this->preventClickjacking;
341 }
342}
getUser()
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getContext()
Gets the context this Article is executed in.
Definition Article.php:2345
getTitle()
Get the title object of the article.
Definition Article.php:255
getPage()
Get the WikiPage object of this instance.
Definition Article.php:265
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
IContextSource $context
setContext(IContextSource $context)
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:63
getName()
Return the name of this file.
Definition File.php:315
Builds the image revision log shown on image pages.
endImageHistoryList( $navLinks='')
beginImageHistoryList( $navLinks='')
preventClickjacking( $enable=true)
imageHistoryLine( $iscur, $file)
__construct( $imagePage)
Class for viewing MediaWiki file description pages.
Definition ImagePage.php:33
getDisplayedFile()
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition Linker.php:906
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition Linker.php:2285
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition Linker.php:951
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition Linker.php:2263
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition Linker.php:1209
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Represents a title within MediaWiki.
Definition Title.php:42
getConfig()
Get the site configuration.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42
if(!isset( $args[0])) $lang