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