MediaWiki  1.33.0
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 = $context->getConfig()->get( 'ShowArchiveThumbnails' ) &&
63  $this->img->canRender();
64  $this->setContext( $context );
65  }
66 
70  public function getImagePage() {
71  return $this->imagePage;
72  }
73 
77  public function getFile() {
78  return $this->img;
79  }
80 
85  public function beginImageHistoryList( $navLinks = '' ) {
86  return Xml::element( 'h2', [ 'id' => 'filehistory' ], $this->msg( 'filehist' )->text() )
87  . "\n"
88  . "<div id=\"mw-imagepage-section-filehistory\">\n"
89  . $this->msg( 'filehist-help' )->parseAsBlock()
90  . $navLinks . "\n"
91  . Xml::openElement( 'table', [ 'class' => 'wikitable filehistory' ] ) . "\n"
92  . '<tr><th></th>'
93  . ( $this->current->isLocal()
94  && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<th></th>' : '' )
95  . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
96  . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
97  . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
98  . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
99  . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
100  . "</tr>\n";
101  }
102 
107  public function endImageHistoryList( $navLinks = '' ) {
108  return "</table>\n$navLinks\n</div>\n";
109  }
110 
116  public function imageHistoryLine( $iscur, $file ) {
117  $user = $this->getUser();
118  $lang = $this->getLanguage();
119  $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
120  $img = $iscur ? $file->getName() : $file->getArchiveName();
121  $userId = $file->getUser( 'id' );
122  $userText = $file->getUser( 'text' );
123  $description = $file->getDescription( File::FOR_THIS_USER, $user );
124 
125  $local = $this->current->isLocal();
126  $row = $selected = '';
127 
128  // Deletion link
129  if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
130  $row .= '<td>';
131  # Link to remove from history
132  if ( $user->isAllowed( 'delete' ) ) {
133  $q = [ 'action' => 'delete' ];
134  if ( !$iscur ) {
135  $q['oldimage'] = $img;
136  }
137  $row .= Linker::linkKnown(
138  $this->title,
139  $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->escaped(),
140  [], $q
141  );
142  }
143  # Link to hide content. Don't show useless link to people who cannot hide revisions.
144  $canHide = $user->isAllowed( 'deleterevision' );
145  if ( $canHide || ( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) {
146  if ( $user->isAllowed( 'delete' ) ) {
147  $row .= '<br />';
148  }
149  // If file is top revision or locked from this user, don't link
150  if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
151  $del = Linker::revDeleteLinkDisabled( $canHide );
152  } else {
153  list( $ts, ) = explode( '!', $img, 2 );
154  $query = [
155  'type' => 'oldimage',
156  'target' => $this->title->getPrefixedText(),
157  'ids' => $ts,
158  ];
160  $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
161  }
162  $row .= $del;
163  }
164  $row .= '</td>';
165  }
166 
167  // Reversion link/current indicator
168  $row .= '<td>';
169  if ( $iscur ) {
170  $row .= $this->msg( 'filehist-current' )->escaped();
171  } elseif ( $local && $this->title->quickUserCan( 'edit', $user )
172  && $this->title->quickUserCan( 'upload', $user )
173  ) {
174  if ( $file->isDeleted( File::DELETED_FILE ) ) {
175  $row .= $this->msg( 'filehist-revert' )->escaped();
176  } else {
177  $row .= Linker::linkKnown(
178  $this->title,
179  $this->msg( 'filehist-revert' )->escaped(),
180  [],
181  [
182  'action' => 'revert',
183  'oldimage' => $img,
184  ]
185  );
186  }
187  }
188  $row .= '</td>';
189 
190  // Date/time and image link
191  if ( $file->getTimestamp() === $this->img->getTimestamp() ) {
192  $selected = "class='filehistory-selected'";
193  }
194  $row .= "<td $selected style='white-space: nowrap;'>";
195  if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
196  # Don't link to unviewable files
197  $row .= Html::element( 'span', [ 'class' => 'history-deleted' ],
198  $lang->userTimeAndDate( $timestamp, $user )
199  );
200  } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
201  $timeAndDate = htmlspecialchars( $lang->userTimeAndDate( $timestamp, $user ) );
202  if ( $local ) {
203  $this->preventClickjacking();
204  $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
205  # Make a link to review the image
206  $url = Linker::linkKnown(
207  $revdel,
208  $timeAndDate,
209  [],
210  [
211  'target' => $this->title->getPrefixedText(),
212  'file' => $img,
213  'token' => $user->getEditToken( $img )
214  ]
215  );
216  } else {
217  $url = $timeAndDate;
218  }
219  $row .= '<span class="history-deleted">' . $url . '</span>';
220  } elseif ( !$file->exists() ) {
221  $row .= Html::element( 'span', [ 'class' => 'mw-file-missing' ],
222  $lang->userTimeAndDate( $timestamp, $user )
223  );
224  } else {
225  $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
226  $row .= Xml::element(
227  'a',
228  [ 'href' => $url ],
229  $lang->userTimeAndDate( $timestamp, $user )
230  );
231  }
232  $row .= "</td>";
233 
234  // Thumbnail
235  if ( $this->showThumb ) {
236  $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
237  }
238 
239  // Image dimensions + size
240  $row .= '<td>';
241  $row .= htmlspecialchars( $file->getDimensionsString() );
242  $row .= $this->msg( 'word-separator' )->escaped();
243  $row .= '<span style="white-space: nowrap;">';
244  $row .= $this->msg( 'parentheses' )->sizeParams( $file->getSize() )->escaped();
245  $row .= '</span>';
246  $row .= '</td>';
247 
248  // Uploading user
249  $row .= '<td>';
250  // Hide deleted usernames
251  if ( $file->isDeleted( File::DELETED_USER ) ) {
252  $row .= '<span class="history-deleted">'
253  . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
254  } else {
255  if ( $local ) {
256  $row .= Linker::userLink( $userId, $userText );
257  $row .= '<span style="white-space: nowrap;">';
258  $row .= Linker::userToolLinks( $userId, $userText );
259  $row .= '</span>';
260  } else {
261  $row .= htmlspecialchars( $userText );
262  }
263  }
264  $row .= '</td>';
265 
266  // Don't show deleted descriptions
267  if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
268  $row .= '<td><span class="history-deleted">' .
269  $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
270  } else {
271  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
272  $row .= Html::rawElement(
273  'td',
274  [ 'dir' => $contLang->getDir() ],
275  Linker::formatComment( $description, $this->title )
276  );
277  }
278 
279  $rowClass = null;
280  Hooks::run( 'ImagePageFileHistoryLine', [ $this, $file, &$row, &$rowClass ] );
281  $classAttr = $rowClass ? " class='$rowClass'" : '';
282 
283  return "<tr{$classAttr}>{$row}</tr>\n";
284  }
285 
290  protected function getThumbForLine( $file ) {
291  $lang = $this->getLanguage();
292  $user = $this->getUser();
293  if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user )
294  && !$file->isDeleted( File::DELETED_FILE )
295  ) {
296  $params = [
297  'width' => '120',
298  'height' => '120',
299  ];
300  $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
301 
302  $thumbnail = $file->transform( $params );
303  $options = [
304  'alt' => $this->msg( 'filehist-thumbtext',
305  $lang->userTimeAndDate( $timestamp, $user ),
306  $lang->userDate( $timestamp, $user ),
307  $lang->userTime( $timestamp, $user ) )->text(),
308  'file-link' => true,
309  ];
310 
311  if ( !$thumbnail ) {
312  return $this->msg( 'filehist-nothumb' )->escaped();
313  }
314 
315  return $thumbnail->toHtml( $options );
316  } else {
317  return $this->msg( 'filehist-nothumb' )->escaped();
318  }
319  }
320 
324  protected function preventClickjacking( $enable = true ) {
325  $this->preventClickjacking = $enable;
326  }
327 
331  public function getPreventClickjacking() {
333  }
334 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
File\DELETED_USER
const DELETED_USER
Definition: File.php:56
ImageHistoryList\$img
File $img
Definition: ImageHistoryList.php:38
ImageHistoryList
Builds the image revision log shown on image pages.
Definition: ImageHistoryList.php:28
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:892
File\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: File.php:57
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ImageHistoryList\$showThumb
$showThumb
Definition: ImageHistoryList.php:50
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
ImageHistoryList\imageHistoryLine
imageHistoryLine( $iscur, $file)
Definition: ImageHistoryList.php:116
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
Linker\userToolLinks
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:931
ImageHistoryList\__construct
__construct( $imagePage)
Definition: ImageHistoryList.php:56
$params
$params
Definition: styleTest.css.php:44
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:146
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:82
ImagePage
Class for viewing MediaWiki file description pages.
Definition: ImagePage.php:31
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
php
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:35
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:128
ImageHistoryList\getImagePage
getImagePage()
Definition: ImageHistoryList.php:70
$query
null for the 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:1588
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:52
File\DELETED_COMMENT
const DELETED_COMMENT
Definition: File.php:55
Article\getTitle
getTitle()
Get the title object of the article.
Definition: Article.php:220
ImageHistoryList\$repo
$repo
Definition: ImageHistoryList.php:50
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:29
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
Article\getPage
getPage()
Get the WikiPage object of this instance.
Definition: Article.php:230
Article\getContext
getContext()
Gets the context this Article is executed in.
Definition: Article.php:2233
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Linker\revDeleteLinkDisabled
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2111
File\FOR_THIS_USER
const FOR_THIS_USER
Definition: File.php:71
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:55
ImageHistoryList\preventClickjacking
preventClickjacking( $enable=true)
Definition: ImageHistoryList.php:324
list
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
ImageHistoryList\$imagePage
ImagePage $imagePage
Definition: ImageHistoryList.php:43
ImageHistoryList\getFile
getFile()
Definition: ImageHistoryList.php:77
title
title
Definition: parserTests.txt:245
ImagePage\getDisplayedFile
getDisplayedFile()
Definition: ImagePage.php:215
Linker\formatComment
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:1122
text
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
Definition: All_system_messages.txt:1267
Title
Represents a title within MediaWiki.
Definition: Title.php:40
ImageHistoryList\$title
Title $title
Definition: ImageHistoryList.php:33
ImageHistoryList\getThumbForLine
getThumbForLine( $file)
Definition: ImageHistoryList.php:290
$options
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:1985
IContextSource\getConfig
getConfig()
Get the site configuration.
Linker\revDeleteLink
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2089
ImageHistoryList\beginImageHistoryList
beginImageHistoryList( $navLinks='')
Definition: ImageHistoryList.php:85
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:54
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
ImageHistoryList\$preventClickjacking
$preventClickjacking
Definition: ImageHistoryList.php:51
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
ImageHistoryList\$current
File $current
Definition: ImageHistoryList.php:48
ImageHistoryList\getPreventClickjacking
getPreventClickjacking()
Definition: ImageHistoryList.php:331
ImageHistoryList\endImageHistoryList
endImageHistoryList( $navLinks='')
Definition: ImageHistoryList.php:107