* (bug 889) Improve conflict-handling between shared upload repository (commons)...
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 */
4
5 /**
6 *
7 */
8 if( !defined( 'MEDIAWIKI' ) )
9 die( 1 );
10
11 /**
12 * Special handling for image description pages
13 *
14 * @addtogroup Media
15 */
16 class ImagePage extends Article {
17
18 /* private */ var $img; // Image object this page is shown for
19 /* private */ var $repo;
20 var $mExtraDescription = false;
21
22 function __construct( $title, $time = false ) {
23 parent::__construct( $title );
24 $this->img = wfFindFile( $this->mTitle, $time );
25 if ( !$this->img ) {
26 $this->img = wfLocalFile( $this->mTitle );
27 $this->current = $this->img;
28 } else {
29 $this->current = $time ? wfLocalFile( $this->mTitle ) : $this->img;
30 }
31 $this->repo = $this->img->repo;
32 }
33
34 /**
35 * Handler for action=render
36 * Include body text only; none of the image extras
37 */
38 function render() {
39 global $wgOut;
40 $wgOut->setArticleBodyOnly( true );
41 parent::view();
42 }
43
44 function view() {
45 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
46
47 $diff = $wgRequest->getVal( 'diff' );
48 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
49
50 if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) )
51 return Article::view();
52
53 if ($wgShowEXIF && $this->img->exists()) {
54 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
55 $formattedMetadata = $this->img->formatMetadata();
56 $showmeta = $formattedMetadata !== false;
57 } else {
58 $showmeta = false;
59 }
60
61 if ($this->img->exists())
62 $wgOut->addHTML($this->showTOC($showmeta));
63
64 $this->openShowImage();
65
66 # No need to display noarticletext, we use our own message, output in openShowImage()
67 if ( $this->getID() ) {
68 Article::view();
69 } else {
70 # Just need to set the right headers
71 $wgOut->setArticleFlag( true );
72 $wgOut->setRobotpolicy( 'noindex,nofollow' );
73 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
74 $this->viewUpdates();
75 }
76
77 # Show shared description, if needed
78 if ( $this->mExtraDescription ) {
79 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
80 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
81 $wgOut->addWikiText( $fol );
82 }
83 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
84 } else {
85 $this->checkSharedConflict();
86 }
87
88 $this->closeShowImage();
89 $this->imageHistory();
90 $this->imageLinks();
91
92 if ( $showmeta ) {
93 global $wgStylePath, $wgStyleVersion;
94 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
95 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
96 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
97 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
98 $wgOut->addHTML(
99 "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?$wgStyleVersion\"></script>\n" .
100 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
101 }
102 }
103
104 /**
105 * Create the TOC
106 *
107 * @access private
108 *
109 * @param bool $metadata Whether or not to show the metadata link
110 * @return string
111 */
112 function showTOC( $metadata ) {
113 global $wgLang;
114 $r = '<ul id="filetoc">
115 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
116 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
117 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
118 ($metadata ? ' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
119 </ul>';
120 return $r;
121 }
122
123 /**
124 * Make a table with metadata to be shown in the output page.
125 *
126 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
127 *
128 * @access private
129 *
130 * @param array $exif The array containing the EXIF data
131 * @return string
132 */
133 function makeMetadataTable( $metadata ) {
134 $r = wfMsg( 'metadata-help' ) . "\n\n";
135 $r .= "{| id=mw_metadata class=mw_metadata\n";
136 foreach ( $metadata as $type => $stuff ) {
137 foreach ( $stuff as $v ) {
138 $class = Sanitizer::escapeId( $v['id'] );
139 if( $type == 'collapsed' ) {
140 $class .= ' collapsable';
141 }
142 $r .= "|- class=\"$class\"\n";
143 $r .= "!| {$v['name']}\n";
144 $r .= "|| {$v['value']}\n";
145 }
146 }
147 $r .= '|}';
148 return $r;
149 }
150
151 /**
152 * Overloading Article's getContent method.
153 *
154 * Omit noarticletext if sharedupload; text will be fetched from the
155 * shared upload server if possible.
156 */
157 function getContent() {
158 if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
159 return '';
160 }
161 return Article::getContent();
162 }
163
164 function openShowImage() {
165 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
166
167 $full_url = $this->img->getURL();
168 $linkAttribs = false;
169 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
170 if( !isset( $wgImageLimits[$sizeSel] ) ) {
171 $sizeSel = User::getDefaultOption( 'imagesize' );
172
173 // The user offset might still be incorrect, specially if
174 // $wgImageLimits got changed (see bug #8858).
175 if( !isset( $wgImageLimits[$sizeSel] ) ) {
176 // Default to the first offset in $wgImageLimits
177 $sizeSel = 0;
178 }
179 }
180 $max = $wgImageLimits[$sizeSel];
181 $maxWidth = $max[0];
182 $maxHeight = $max[1];
183 $sk = $wgUser->getSkin();
184 $dirmark = $wgContLang->getDirMark();
185
186 if ( $this->img->exists() ) {
187 # image
188 $page = $wgRequest->getIntOrNull( 'page' );
189 if ( is_null( $page ) ) {
190 $params = array();
191 $page = 1;
192 } else {
193 $params = array( 'page' => $page );
194 }
195 $width_orig = $this->img->getWidth();
196 $width = $width_orig;
197 $height_orig = $this->img->getHeight();
198 $height = $height_orig;
199 $mime = $this->img->getMimeType();
200 $showLink = false;
201 $linkAttribs = array( 'href' => $full_url );
202 $longDesc = $this->img->getLongDesc();
203
204 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
205
206 if ( $this->img->allowInlineDisplay() ) {
207 # image
208
209 # "Download high res version" link below the image
210 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
211 # We'll show a thumbnail of this image
212 if ( $width > $maxWidth || $height > $maxHeight ) {
213 # Calculate the thumbnail size.
214 # First case, the limiting factor is the width, not the height.
215 if ( $width / $height >= $maxWidth / $maxHeight ) {
216 $height = round( $height * $maxWidth / $width);
217 $width = $maxWidth;
218 # Note that $height <= $maxHeight now.
219 } else {
220 $newwidth = floor( $width * $maxHeight / $height);
221 $height = round( $height * $newwidth / $width );
222 $width = $newwidth;
223 # Note that $height <= $maxHeight now, but might not be identical
224 # because of rounding.
225 }
226 $msgbig = wfMsgHtml( 'show-big-image' );
227 $msgsmall = wfMsgExt( 'show-big-image-thumb',
228 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
229 } else {
230 # Image is small enough to show full size on image page
231 $msgbig = htmlspecialchars( $this->img->getName() );
232 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
233 }
234
235 $params['width'] = $width;
236 $thumbnail = $this->img->transform( $params );
237
238 $anchorclose = "<br />";
239 if( $this->img->mustRender() ) {
240 $showLink = true;
241 } else {
242 $anchorclose .=
243 $msgsmall .
244 '<br />' . Xml::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
245 }
246
247 if ( $this->img->isMultipage() ) {
248 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
249 }
250
251 if ( $thumbnail ) {
252 $options = array(
253 'alt' => $this->img->getTitle()->getPrefixedText(),
254 'file-link' => true,
255 );
256 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
257 $thumbnail->toHtml( $options ) .
258 $anchorclose . '</div>' );
259 }
260
261 if ( $this->img->isMultipage() ) {
262 $count = $this->img->pageCount();
263
264 if ( $page > 1 ) {
265 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
266 $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
267 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
268 array( 'page' => $page - 1 ) );
269 } else {
270 $thumb1 = '';
271 }
272
273 if ( $page < $count ) {
274 $label = wfMsg( 'imgmultipagenext' );
275 $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
276 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
277 array( 'page' => $page + 1 ) );
278 } else {
279 $thumb2 = '';
280 }
281
282 global $wgScript;
283 $select = '<form name="pageselector" action="' .
284 htmlspecialchars( $wgScript ) .
285 '" method="get" onchange="document.pageselector.submit();">' .
286 Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() );
287 $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) .
288 ' <select id="pageselector" name="page">';
289 for ( $i=1; $i <= $count; $i++ ) {
290 $select .= Xml::option( $wgLang->formatNum( $i ), $i,
291 $i == $page );
292 }
293 $select .= '</select>' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) .
294 '<input type="submit" value="' .
295 htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '"></form>';
296
297 $wgOut->addHTML( '</td><td><div class="multipageimagenavbox">' .
298 "$select<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>" );
299 }
300 } else {
301 #if direct link is allowed but it's not a renderable image, show an icon.
302 if ($this->img->isSafeFile()) {
303 $icon= $this->img->iconThumb();
304
305 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
306 $icon->toHtml( array( 'desc-link' => true ) ) .
307 '</div>' );
308 }
309
310 $showLink = true;
311 }
312
313
314 if ($showLink) {
315 $filename = wfEscapeWikiText( $this->img->getName() );
316
317 if (!$this->img->isSafeFile()) {
318 $warning = wfMsgNoTrans( 'mediawarning' );
319 $wgOut->addWikiText( <<<EOT
320 <div class="fullMedia">
321 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
322 <span class="fileInfo"> $longDesc</span>
323 </div>
324
325 <div class="mediaWarning">$warning</div>
326 EOT
327 );
328 } else {
329 $wgOut->addWikiText( <<<EOT
330 <div class="fullMedia">
331 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
332 </div>
333 EOT
334 );
335 }
336 }
337
338 if(!$this->img->isLocal()) {
339 $this->printSharedImageText();
340 }
341 } else {
342 # Image does not exist
343
344 $title = SpecialPage::getTitleFor( 'Upload' );
345 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
346 'wpDestFile=' . urlencode( $this->img->getName() ) );
347 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
348 }
349 }
350
351 /**
352 * Show a notice that the file is from a shared repository
353 */
354 function printSharedImageText() {
355 global $wgOut, $wgUser;
356
357 $descUrl = $this->img->getDescriptionUrl();
358 $descText = $this->img->getDescriptionText();
359 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
360 if ( $descUrl ) {
361 $sk = $wgUser->getSkin();
362 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
363 $msg = ( $descText ) ? 'shareduploadwiki-desc' : 'shareduploadwiki';
364 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
365 if ( $msg != '-' ) {
366 # Show message only if not voided by local sysops
367 $s .= $msg;
368 }
369 }
370 $s .= "</div>";
371 $wgOut->addHTML( $s );
372
373 if ( $descText ) {
374 $this->mExtraDescription = $descText;
375 }
376 }
377
378 function checkSharedConflict() {
379 global $wgOut, $wgUser, $wgUseSharedUploads;
380 if( !$wgUseSharedUploads ) {
381 return;
382 }
383 if( $this->repo->getName() != 'local' ) {
384 return;
385 }
386
387 $repo = RepoGroup::singleton()->getRepoByName( 'shared' );
388 $dupfile = $repo->newFile( $this->img->getTitle() );
389 if( !$dupfile->exists() ) {
390 return;
391 }
392 $same = (
393 ($this->img->getSha1() == $dupfile->getSha1()) &&
394 ($this->img->getSize() == $dupfile->getSize())
395 );
396
397 $sk = $wgUser->getSkin();
398 $descUrl = $dupfile->getDescriptionUrl();
399 if( $same ) {
400 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
401 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
402 } else {
403 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
404 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
405 }
406 }
407
408 function getUploadUrl() {
409 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
410 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
411 }
412
413 /**
414 * Print out the various links at the bottom of the image page, e.g. reupload,
415 * external editing (and instructions link) etc.
416 */
417 function uploadLinksBox() {
418 global $wgUser, $wgOut;
419
420 if( !$this->img->isLocal() )
421 return;
422
423 $sk = $wgUser->getSkin();
424
425 $wgOut->addHtml( '<br /><ul>' );
426
427 # "Upload a new version of this file" link
428 if( UploadForm::userCanReUpload($wgUser,$this->img->name) ) {
429 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
430 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
431 }
432
433 # Link to Special:FileDuplicateSearch
434 $dupeLink = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'FileDuplicateSearch', $this->mTitle->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
435 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
436
437 # External editing link
438 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
439 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
440
441 $wgOut->addHtml( '</ul>' );
442 }
443
444 function closeShowImage()
445 {
446 # For overloading
447
448 }
449
450 /**
451 * If the page we've just displayed is in the "Image" namespace,
452 * we follow it with an upload history of the image and its usage.
453 */
454 function imageHistory()
455 {
456 global $wgUser, $wgOut, $wgUseExternalEditor;
457
458 $sk = $wgUser->getSkin();
459
460 if ( $this->img->exists() ) {
461 $list = new ImageHistoryList( $sk, $this->current );
462 $file = $this->current;
463 $dims = $file->getDimensionsString();
464 $s = $list->beginImageHistoryList() .
465 $list->imageHistoryLine( true, $file );
466 // old image versions
467 $hist = $this->img->getHistory();
468 foreach( $hist as $file ) {
469 $dims = $file->getDimensionsString();
470 $s .= $list->imageHistoryLine( false, $file );
471 }
472 $s .= $list->endImageHistoryList();
473 } else { $s=''; }
474 $wgOut->addHTML( $s );
475
476 $this->img->resetHistory(); // free db resources
477
478 # Exist check because we don't want to show this on pages where an image
479 # doesn't exist along with the noimage message, that would suck. -ævar
480 if( $wgUseExternalEditor && $this->img->exists() ) {
481 $this->uploadLinksBox();
482 }
483
484 }
485
486 function imageLinks()
487 {
488 global $wgUser, $wgOut;
489
490 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
491
492 $dbr = wfGetDB( DB_SLAVE );
493 $page = $dbr->tableName( 'page' );
494 $imagelinks = $dbr->tableName( 'imagelinks' );
495
496 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
497 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
498 $sql = $dbr->limitResult($sql, 500, 0);
499 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
500
501 if ( 0 == $dbr->numRows( $res ) ) {
502 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
503 return;
504 }
505 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
506
507 $sk = $wgUser->getSkin();
508 while ( $s = $dbr->fetchObject( $res ) ) {
509 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
510 $link = $sk->makeKnownLinkObj( $name, "" );
511 $wgOut->addHTML( "<li>{$link}</li>\n" );
512 }
513 $wgOut->addHTML( "</ul>\n" );
514 }
515
516 /**
517 * Delete the file, or an earlier version of it
518 */
519 public function delete() {
520 if( !$this->img->exists() || !$this->img->isLocal() ) {
521 // Standard article deletion
522 Article::delete();
523 return;
524 }
525 $deleter = new FileDeleteForm( $this->img );
526 $deleter->execute();
527 }
528
529 /**
530 * Revert the file to an earlier version
531 */
532 public function revert() {
533 $reverter = new FileRevertForm( $this->img );
534 $reverter->execute();
535 }
536
537 /**
538 * Override handling of action=purge
539 */
540 function doPurge() {
541 if( $this->img->exists() ) {
542 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
543 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
544 $update->doUpdate();
545 $this->img->upgradeRow();
546 $this->img->purgeCache();
547 } else {
548 wfDebug( "ImagePage::doPurge no image\n" );
549 }
550 parent::doPurge();
551 }
552
553 /**
554 * Display an error with a wikitext description
555 */
556 function showError( $description ) {
557 global $wgOut;
558 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
559 $wgOut->setRobotpolicy( "noindex,nofollow" );
560 $wgOut->setArticleRelated( false );
561 $wgOut->enableClientCache( false );
562 $wgOut->addWikiText( $description );
563 }
564
565 }
566
567 /**
568 * Builds the image revision log shown on image pages
569 *
570 * @addtogroup Media
571 */
572 class ImageHistoryList {
573
574 protected $img, $skin, $title, $repo;
575
576 public function __construct( $skin, $img ) {
577 $this->skin = $skin;
578 $this->img = $img;
579 $this->title = $img->getTitle();
580 }
581
582 public function beginImageHistoryList() {
583 global $wgOut, $wgUser;
584 $deleteColumn = $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deleterevision' );
585 return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
586 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
587 . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
588 . '<tr><td></td>'
589 . ( $this->img->isLocal() && $deleteColumn ? '<td></td>' : '' )
590 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
591 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
592 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
593 . '<th class="mw-imagepage-filesize">' . wfMsgHtml( 'filehist-filesize' ) . '</th>'
594 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
595 . "</tr>\n";
596 }
597
598 public function endImageHistoryList() {
599 return "</table>\n";
600 }
601
602 public function imageHistoryLine( $iscur, $file ) {
603 global $wgUser, $wgLang, $wgContLang, $wgTitle;
604
605 $timestamp = wfTimestamp(TS_MW, $file->getTimestamp());
606 $img = $iscur ? $file->getName() : $file->getArchiveName();
607 $user = $file->getUser('id');
608 $usertext = $file->getUser('text');
609 $size = $file->getSize();
610 $description = $file->getDescription();
611 $dims = $file->getDimensionsString();
612 $sha1 = $file->getSha1();
613
614 $local = $this->img->isLocal();
615 $row = '';
616
617 // Deletion link
618 if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ) {
619 $row .= '<td>';
620 # Link to remove from history
621 if( $wgUser->isAllowed( 'delete' ) ) {
622 $q = array();
623 $q[] = 'action=delete';
624 if( !$iscur )
625 $q[] = 'oldimage=' . urlencode( $img );
626 $row .= $this->skin->makeKnownLinkObj(
627 $this->title,
628 wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
629 implode( '&', $q )
630 );
631 $row .= '<br/>';
632 }
633 # Link to hide content
634 if( $wgUser->isAllowed( 'deleterevision' ) ) {
635 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
636 // If file is top revision or locked from this user, don't link
637 if( $iscur || !$file->userCan(File::DELETED_RESTRICTED) ) {
638 $del = wfMsgHtml( 'rev-delundel' );
639 } else {
640 // If the file was hidden, link to sha-1
641 list($ts,$name) = explode('!',$img,2);
642 $del = $this->skin->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
643 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
644 '&oldimage=' . urlencode( $ts ) );
645 // Bolden oversighted content
646 if( $file->isDeleted(File::DELETED_RESTRICTED) )
647 $del = "<strong>$del</strong>";
648 }
649 $row .= "<tt><small>$del</small></tt>";
650 }
651 $row .= '</td>';
652 }
653
654 // Reversion link/current indicator
655 $row .= '<td>';
656 if( $iscur ) {
657 $row .= wfMsgHtml( 'filehist-current' );
658 } elseif( $local && $wgUser->isLoggedIn() && $this->title->userCan( 'edit' ) ) {
659 if( $file->isDeleted(File::DELETED_FILE) ) {
660 $row .= wfMsgHtml('filehist-revert');
661 } else {
662 $q = array();
663 $q[] = 'action=revert';
664 $q[] = 'oldimage=' . urlencode( $img );
665 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
666 $row .= $this->skin->makeKnownLinkObj( $this->title,
667 wfMsgHtml( 'filehist-revert' ),
668 implode( '&', $q ) );
669 }
670 }
671 $row .= '</td>';
672
673 // Date/time and image link
674 $row .= '<td>';
675 if( !$file->userCan(File::DELETED_FILE) ) {
676 # Don't link to unviewable files
677 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
678 } else if( $file->isDeleted(File::DELETED_FILE) ) {
679 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
680 # Make a link to review the image
681 $url = $this->skin->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
682 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->img->getExtension() );
683 $row .= '<span class="history-deleted">'.$url.'</span>';
684 } else {
685 $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
686 $row .= Xml::element( 'a',
687 array( 'href' => $url ),
688 $wgLang->timeAndDate( $timestamp, true ) );
689 }
690
691 $row .= '</td>';
692
693 // Uploading user
694 $row .= '<td>';
695 if( $local ) {
696 // Hide deleted usernames
697 if( $file->isDeleted(File::DELETED_USER) )
698 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
699 else
700 $row .= $this->skin->userLink( $user, $usertext ) .
701 $this->skin->userToolLinks( $user, $usertext );
702 } else {
703 $row .= htmlspecialchars( $usertext );
704 }
705 $row .= '</td>';
706
707 // Image dimensions
708 $row .= '<td>' . htmlspecialchars( $dims ) . '</td>';
709
710 // File size
711 $row .= '<td class="mw-imagepage-filesize">' . $this->skin->formatSize( $size ) . '</td>';
712
713 // Don't show deleted descriptions
714 if ( $file->isDeleted(File::DELETED_COMMENT) )
715 $row .= '<td><span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span></td>';
716 else
717 $row .= '<td>' . $this->skin->commentBlock( $description, $this->title ) . '</td>';
718
719 return "<tr>{$row}</tr>\n";
720 }
721 }