MediaWiki REL1_32
ImageHistoryList.php
Go to the documentation of this file.
1<?php
22
29
33 protected $title;
34
38 protected $img;
39
43 protected $imagePage;
44
48 protected $current;
49
50 protected $repo, $showThumb;
51 protected $preventClickjacking = false;
52
56 public function __construct( $imagePage ) {
58 $this->current = $imagePage->getPage()->getFile();
59 $this->img = $imagePage->getDisplayedFile();
60 $this->title = $imagePage->getTitle();
61 $this->imagePage = $imagePage;
62 $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender();
63 $this->setContext( $imagePage->getContext() );
64 }
65
69 public function getImagePage() {
70 return $this->imagePage;
71 }
72
76 public function getFile() {
77 return $this->img;
78 }
79
84 public function beginImageHistoryList( $navLinks = '' ) {
85 return Xml::element( 'h2', [ 'id' => 'filehistory' ], $this->msg( 'filehist' )->text() )
86 . "\n"
87 . "<div id=\"mw-imagepage-section-filehistory\">\n"
88 . $this->msg( 'filehist-help' )->parseAsBlock()
89 . $navLinks . "\n"
90 . Xml::openElement( 'table', [ 'class' => 'wikitable filehistory' ] ) . "\n"
91 . '<tr><th></th>'
92 . ( $this->current->isLocal()
93 && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<th></th>' : '' )
94 . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
95 . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
96 . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
97 . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
98 . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
99 . "</tr>\n";
100 }
101
106 public function endImageHistoryList( $navLinks = '' ) {
107 return "</table>\n$navLinks\n</div>\n";
108 }
109
115 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 );
123
124 $local = $this->current->isLocal();
125 $row = $selected = '';
126
127 // Deletion link
128 if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
129 $row .= '<td>';
130 # Link to remove from history
131 if ( $user->isAllowed( 'delete' ) ) {
132 $q = [ 'action' => 'delete' ];
133 if ( !$iscur ) {
134 $q['oldimage'] = $img;
135 }
136 $row .= Linker::linkKnown(
137 $this->title,
138 $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->escaped(),
139 [], $q
140 );
141 }
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' ) ) {
146 $row .= '<br />';
147 }
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 );
151 } else {
152 list( $ts, ) = explode( '!', $img, 2 );
153 $query = [
154 'type' => 'oldimage',
155 'target' => $this->title->getPrefixedText(),
156 'ids' => $ts,
157 ];
159 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
160 }
161 $row .= $del;
162 }
163 $row .= '</td>';
164 }
165
166 // Reversion link/current indicator
167 $row .= '<td>';
168 if ( $iscur ) {
169 $row .= $this->msg( 'filehist-current' )->escaped();
170 } elseif ( $local && $this->title->quickUserCan( 'edit', $user )
171 && $this->title->quickUserCan( 'upload', $user )
172 ) {
173 if ( $file->isDeleted( File::DELETED_FILE ) ) {
174 $row .= $this->msg( 'filehist-revert' )->escaped();
175 } else {
176 $row .= Linker::linkKnown(
177 $this->title,
178 $this->msg( 'filehist-revert' )->escaped(),
179 [],
180 [
181 'action' => 'revert',
182 'oldimage' => $img,
183 ]
184 );
185 }
186 }
187 $row .= '</td>';
188
189 // Date/time and image link
190 if ( $file->getTimestamp() === $this->img->getTimestamp() ) {
191 $selected = "class='filehistory-selected'";
192 }
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 ) ) {
199 if ( $local ) {
200 $this->preventClickjacking();
201 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
202 # Make a link to review the image
203 $url = Linker::linkKnown(
204 $revdel,
205 $lang->userTimeAndDate( $timestamp, $user ),
206 [],
207 [
208 'target' => $this->title->getPrefixedText(),
209 'file' => $img,
210 'token' => $user->getEditToken( $img )
211 ]
212 );
213 } else {
214 $url = $lang->userTimeAndDate( $timestamp, $user );
215 }
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>';
220 } else {
221 $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
222 $row .= Xml::element(
223 'a',
224 [ 'href' => $url ],
225 $lang->userTimeAndDate( $timestamp, $user )
226 );
227 }
228 $row .= "</td>";
229
230 // Thumbnail
231 if ( $this->showThumb ) {
232 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
233 }
234
235 // Image dimensions + size
236 $row .= '<td>';
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();
241 $row .= '</span>';
242 $row .= '</td>';
243
244 // Uploading user
245 $row .= '<td>';
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>';
250 } else {
251 if ( $local ) {
252 $row .= Linker::userLink( $userId, $userText );
253 $row .= '<span style="white-space: nowrap;">';
254 $row .= Linker::userToolLinks( $userId, $userText );
255 $row .= '</span>';
256 } else {
257 $row .= htmlspecialchars( $userText );
258 }
259 }
260 $row .= '</td>';
261
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>';
266 } else {
267 $row .=
268 '<td dir="' . MediaWikiServices::getInstance()->getContentLanguage()->getDir() .
269 '">' . Linker::formatComment( $description, $this->title ) . '</td>';
270 }
271
272 $rowClass = null;
273 Hooks::run( 'ImagePageFileHistoryLine', [ $this, $file, &$row, &$rowClass ] );
274 $classAttr = $rowClass ? " class='$rowClass'" : '';
275
276 return "<tr{$classAttr}>{$row}</tr>\n";
277 }
278
283 protected function getThumbForLine( $file ) {
284 $lang = $this->getLanguage();
285 $user = $this->getUser();
286 if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user )
287 && !$file->isDeleted( File::DELETED_FILE )
288 ) {
289 $params = [
290 'width' => '120',
291 'height' => '120',
292 ];
293 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
294
295 $thumbnail = $file->transform( $params );
296 $options = [
297 'alt' => $this->msg( 'filehist-thumbtext',
298 $lang->userTimeAndDate( $timestamp, $user ),
299 $lang->userDate( $timestamp, $user ),
300 $lang->userTime( $timestamp, $user ) )->text(),
301 'file-link' => true,
302 ];
303
304 if ( !$thumbnail ) {
305 return $this->msg( 'filehist-nothumb' )->escaped();
306 }
307
308 return $thumbnail->toHtml( $options );
309 } else {
310 return $this->msg( 'filehist-nothumb' )->escaped();
311 }
312 }
313
317 protected function preventClickjacking( $enable = true ) {
318 $this->preventClickjacking = $enable;
319 }
320
324 public function getPreventClickjacking() {
326 }
327}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
$wgShowArchiveThumbnails
Show thumbnails for old images on the image description page.
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:2232
getTitle()
Get the title object of the article.
Definition Article.php:221
getPage()
Get the WikiPage object of this instance.
Definition Article.php:231
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
setContext(IContextSource $context)
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:51
getName()
Return the name of this file.
Definition File.php:297
const DELETED_COMMENT
Definition File.php:54
const DELETED_RESTRICTED
Definition File.php:56
const DELETED_FILE
Definition File.php:53
const DELETED_USER
Definition File.php:55
const FOR_THIS_USER
Definition File.php:70
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:30
getDisplayedFile()
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition Linker.php:876
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition Linker.php:141
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition Linker.php:2114
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition Linker.php:914
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition Linker.php:2092
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:1088
MediaWikiServices is the service locator for the application scope of MediaWiki.
Represents a title within MediaWiki.
Definition Title.php:39
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2050
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1656
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
title
$params
if(!isset( $args[0])) $lang